summaryrefslogtreecommitdiffstats
path: root/lldb/unittests/Process/gdb-remote/GDBRemoteCommunicationClientTest.cpp
diff options
context:
space:
mode:
authorPavel Labath <labath@google.com>2016-08-18 08:30:03 +0000
committerPavel Labath <labath@google.com>2016-08-18 08:30:03 +0000
commit4b6f9591d390c317084e63ed3e695c7a19c64543 (patch)
tree2d7a1151219b81ee322add30cadffd173d47cd77 /lldb/unittests/Process/gdb-remote/GDBRemoteCommunicationClientTest.cpp
parentc233995b1e2b514a4366248827e904e3c37e7582 (diff)
downloadbcm5719-llvm-4b6f9591d390c317084e63ed3e695c7a19c64543.tar.gz
bcm5719-llvm-4b6f9591d390c317084e63ed3e695c7a19c64543.zip
gdb-remote: Centralize thread specific packet handling
Summary: Before this, each function had a copy of the code which handled appending of the thread suffix to the packet (or using $Hg instead). I have moved that code into a single function and made everyone else use that. The function takes the partial packet as a StreamString rvalue reference, to avoid a copy and to remind the users that the packet will have undeterminate contents after the call. This also fixes the incorrect formatting of the QRestoreRegisterState packet in case thread suffix is not supported. Reviewers: clayborg Subscribers: lldb-commits Differential Revision: https://reviews.llvm.org/D23604 llvm-svn: 279040
Diffstat (limited to 'lldb/unittests/Process/gdb-remote/GDBRemoteCommunicationClientTest.cpp')
-rw-r--r--lldb/unittests/Process/gdb-remote/GDBRemoteCommunicationClientTest.cpp62
1 files changed, 56 insertions, 6 deletions
diff --git a/lldb/unittests/Process/gdb-remote/GDBRemoteCommunicationClientTest.cpp b/lldb/unittests/Process/gdb-remote/GDBRemoteCommunicationClientTest.cpp
index c920abbbcdd..265f9261ffe 100644
--- a/lldb/unittests/Process/gdb-remote/GDBRemoteCommunicationClientTest.cpp
+++ b/lldb/unittests/Process/gdb-remote/GDBRemoteCommunicationClientTest.cpp
@@ -54,6 +54,8 @@ HandlePacket(MockServer &server, llvm::StringRef expected, llvm::StringRef respo
ASSERT_EQ(PacketResult::Success, server.SendPacket(response));
}
+const char all_registers[] = "404142434445464748494a4b4c4d4e4f";
+
} // end anonymous namespace
class GDBRemoteCommunicationClientTest : public GDBRemoteTest
@@ -78,10 +80,9 @@ TEST_F(GDBRemoteCommunicationClientTest, WriteRegister)
HandlePacket(server, "P4=41424344;thread:0047;", "OK");
ASSERT_TRUE(write_result.get());
- write_result = std::async(std::launch::async,
- [&] { return client.WriteAllRegisters(tid, "404142434445464748494a4b4c4d4e4f"); });
+ write_result = std::async(std::launch::async, [&] { return client.WriteAllRegisters(tid, all_registers); });
- HandlePacket(server, "G404142434445464748494a4b4c4d4e4f;thread:0047;", "OK");
+ HandlePacket(server, std::string("G") + all_registers + ";thread:0047;", "OK");
ASSERT_TRUE(write_result.get());
}
@@ -103,9 +104,58 @@ TEST_F(GDBRemoteCommunicationClientTest, WriteRegisterNoSuffix)
HandlePacket(server, "P4=41424344", "OK");
ASSERT_TRUE(write_result.get());
- write_result = std::async(std::launch::async,
- [&] { return client.WriteAllRegisters(tid, "404142434445464748494a4b4c4d4e4f"); });
+ write_result = std::async(std::launch::async, [&] { return client.WriteAllRegisters(tid, all_registers); });
- HandlePacket(server, "G404142434445464748494a4b4c4d4e4f", "OK");
+ HandlePacket(server, std::string("G") + all_registers, "OK");
ASSERT_TRUE(write_result.get());
}
+
+TEST_F(GDBRemoteCommunicationClientTest, ReadRegister)
+{
+ TestClient client;
+ MockServer server;
+ Connect(client, server);
+ if (HasFailure())
+ return;
+
+ const lldb::tid_t tid = 0x47;
+ const uint32_t reg_num = 4;
+ std::future<bool> async_result = std::async(std::launch::async, [&] { return client.GetpPacketSupported(tid); });
+ Handle_QThreadSuffixSupported(server, true);
+ HandlePacket(server, "p0;thread:0047;", "41424344");
+ ASSERT_TRUE(async_result.get());
+
+ StringExtractorGDBRemote response;
+ async_result = std::async(std::launch::async, [&] { return client.ReadRegister(tid, reg_num, response); });
+ HandlePacket(server, "p4;thread:0047;", "41424344");
+ ASSERT_TRUE(async_result.get());
+ ASSERT_EQ("41424344", response.GetStringRef());
+
+ async_result = std::async(std::launch::async, [&] { return client.ReadAllRegisters(tid, response); });
+ HandlePacket(server, "g;thread:0047;", all_registers);
+ ASSERT_TRUE(async_result.get());
+ ASSERT_EQ(all_registers, response.GetStringRef());
+}
+
+TEST_F(GDBRemoteCommunicationClientTest, SaveRestoreRegistersNoSuffix)
+{
+ TestClient client;
+ MockServer server;
+ Connect(client, server);
+ if (HasFailure())
+ return;
+
+ const lldb::tid_t tid = 0x47;
+ uint32_t save_id;
+ std::future<bool> async_result =
+ std::async(std::launch::async, [&] { return client.SaveRegisterState(tid, save_id); });
+ Handle_QThreadSuffixSupported(server, false);
+ HandlePacket(server, "Hg47", "OK");
+ HandlePacket(server, "QSaveRegisterState", "1");
+ ASSERT_TRUE(async_result.get());
+ EXPECT_EQ(1u, save_id);
+
+ async_result = std::async(std::launch::async, [&] { return client.RestoreRegisterState(tid, save_id); });
+ HandlePacket(server, "QRestoreRegisterState:1", "OK");
+ ASSERT_TRUE(async_result.get());
+}
OpenPOWER on IntegriCloud