From 27402d2a12fad5e347879e23eb91ba63778b3360 Mon Sep 17 00:00:00 2001 From: Pavel Labath Date: Thu, 18 Aug 2016 12:32:41 +0000 Subject: [PATCH] Move QSyncThreadState packet generation to the gdb-remote client llvm-svn: 279057 --- .../gdb-remote/GDBRemoteCommunicationClient.cpp | 19 +++++++++++++--- .../gdb-remote/GDBRemoteCommunicationClient.h | 3 +++ .../gdb-remote/GDBRemoteRegisterContext.cpp | 25 ++-------------------- .../Process/gdb-remote/GDBRemoteRegisterContext.h | 3 --- .../GDBRemoteCommunicationClientTest.cpp | 15 +++++++++++++ 5 files changed, 36 insertions(+), 29 deletions(-) diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp index 7600c13..fc0cf6e 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp @@ -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; diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h index 7b6e5e6..b041ecb 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h @@ -509,6 +509,9 @@ public: bool RestoreRegisterState (lldb::tid_t tid, uint32_t save_id); + bool + SyncThreadState(lldb::tid_t tid); + const char * GetGDBServerProgramName(); diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp index dbdb3a8..dd8ac9e 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp @@ -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)) { diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.h b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.h index 0e26c69..0021b5e 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.h +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.h @@ -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 m_reg_valid; DataExtractor m_reg_data; diff --git a/lldb/unittests/Process/gdb-remote/GDBRemoteCommunicationClientTest.cpp b/lldb/unittests/Process/gdb-remote/GDBRemoteCommunicationClientTest.cpp index 265f926..702052d 100644 --- a/lldb/unittests/Process/gdb-remote/GDBRemoteCommunicationClientTest.cpp +++ b/lldb/unittests/Process/gdb-remote/GDBRemoteCommunicationClientTest.cpp @@ -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 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()); +} -- 2.7.4