Move QSyncThreadState packet generation to the gdb-remote client
authorPavel Labath <labath@google.com>
Thu, 18 Aug 2016 12:32:41 +0000 (12:32 +0000)
committerPavel Labath <labath@google.com>
Thu, 18 Aug 2016 12:32:41 +0000 (12:32 +0000)
llvm-svn: 279057

lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h
lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp
lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.h
lldb/unittests/Process/gdb-remote/GDBRemoteCommunicationClientTest.cpp

index 7600c13..fc0cf6e 100644 (file)
@@ -3582,9 +3582,22 @@ GDBRemoteCommunicationClient::RestoreRegisterState (lldb::tid_t tid, uint32_t sa
 }
 
 bool
-GDBRemoteCommunicationClient::GetModuleInfo (const FileSpec& module_file_spec,
-                                             const lldb_private::ArchSpec& arch_spec,
-                                             ModuleSpec &module_spec)
+GDBRemoteCommunicationClient::SyncThreadState(lldb::tid_t tid)
+{
+    if (!GetSyncThreadStateSupported())
+        return false;
+
+    StreamString packet;
+    StringExtractorGDBRemote response;
+    packet.Printf("QSyncThreadState:%4.4" PRIx64 ";", tid);
+    return SendPacketAndWaitForResponse(packet.GetString(), response, false) ==
+               GDBRemoteCommunication::PacketResult::Success &&
+           response.IsOKResponse();
+}
+
+bool
+GDBRemoteCommunicationClient::GetModuleInfo(const FileSpec &module_file_spec, const lldb_private::ArchSpec &arch_spec,
+                                            ModuleSpec &module_spec)
 {
     if (!m_supports_qModuleInfo)
         return false;
index 7b6e5e6..b041ecb 100644 (file)
@@ -509,6 +509,9 @@ public:
     bool
     RestoreRegisterState (lldb::tid_t tid, uint32_t save_id);
 
+    bool
+    SyncThreadState(lldb::tid_t tid);
+
     const char *
     GetGDBServerProgramName();
     
index dbdb3a8..dd8ac9e 100644 (file)
@@ -334,28 +334,6 @@ GDBRemoteRegisterContext::SetPrimordialRegister(const RegisterInfo *reg_info,
                         reg_info->byte_size));
 }
 
-void
-GDBRemoteRegisterContext::SyncThreadState(Process *process)
-{
-    // NB.  We assume our caller has locked the sequence mutex.
-    
-    GDBRemoteCommunicationClient &gdb_comm (((ProcessGDBRemote *) process)->GetGDBRemote());
-    if (!gdb_comm.GetSyncThreadStateSupported())
-        return;
-
-    StreamString packet;
-    StringExtractorGDBRemote response;
-    packet.Printf ("QSyncThreadState:%4.4" PRIx64 ";", m_thread.GetProtocolID());
-    if (gdb_comm.SendPacketAndWaitForResponse(packet.GetString().c_str(),
-                                              packet.GetString().size(),
-                                              response,
-                                              false) == GDBRemoteCommunication::PacketResult::Success)
-    {
-        if (response.IsOKResponse())
-            InvalidateAllRegisters();
-    }
-}
-
 bool
 GDBRemoteRegisterContext::WriteRegisterBytes (const RegisterInfo *reg_info, DataExtractor &data, uint32_t data_offset)
 {
@@ -562,7 +540,8 @@ GDBRemoteRegisterContext::ReadAllRegisterValues (lldb::DataBufferSP &data_sp)
     GDBRemoteClientBase::Lock lock(gdb_comm, false);
     if (lock)
     {
-        SyncThreadState(process);
+        if (gdb_comm.SyncThreadState(m_thread.GetProtocolID()))
+            InvalidateAllRegisters();
 
         if (use_g_packet && gdb_comm.ReadAllRegisters(m_thread.GetProtocolID(), response))
         {
index 0e26c69..0021b5e 100644 (file)
@@ -143,9 +143,6 @@ protected:
             m_reg_valid[reg] = valid;
     }
 
-    void
-    SyncThreadState(Process *process);  // Assumes the sequence mutex has already been acquired.
-    
     GDBRemoteDynamicRegisterInfo &m_reg_info;
     std::vector<bool> m_reg_valid;
     DataExtractor m_reg_data;
index 265f926..702052d 100644 (file)
@@ -159,3 +159,18 @@ TEST_F(GDBRemoteCommunicationClientTest, SaveRestoreRegistersNoSuffix)
     HandlePacket(server, "QRestoreRegisterState:1", "OK");
     ASSERT_TRUE(async_result.get());
 }
+
+TEST_F(GDBRemoteCommunicationClientTest, SyncThreadState)
+{
+    TestClient client;
+    MockServer server;
+    Connect(client, server);
+    if (HasFailure())
+        return;
+
+    const lldb::tid_t tid = 0x47;
+    std::future<bool> async_result = std::async(std::launch::async, [&] { return client.SyncThreadState(tid); });
+    HandlePacket(server, "qSyncThreadStateSupported", "OK");
+    HandlePacket(server, "QSyncThreadState:0047;", "OK");
+    ASSERT_TRUE(async_result.get());
+}