Index: lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h =================================================================== --- lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h +++ lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h @@ -334,7 +334,8 @@ // and response times. bool SendSpeedTestPacket(uint32_t send_size, uint32_t recv_size); - bool SetCurrentThread(uint64_t tid); + bool SetCurrentThread(uint64_t tid, + lldb::pid_t pid = LLDB_INVALID_PROCESS_ID); bool SetCurrentThreadForRun(uint64_t tid); @@ -567,6 +568,7 @@ m_supports_jModulesInfo : 1; lldb::pid_t m_curr_pid; + lldb::pid_t m_override_pid; // Used when handling forks lldb::tid_t m_curr_tid; // Current gdb remote protocol thread index for all // other operations lldb::tid_t m_curr_tid_run; // Current gdb remote protocol thread index for Index: lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp =================================================================== --- lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp +++ lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp @@ -98,7 +98,9 @@ m_supports_QEnvironmentHexEncoded(true), m_supports_qSymbol(true), m_qSymbol_requests_done(false), m_supports_qModuleInfo(true), m_supports_jThreadsInfo(true), m_supports_jModulesInfo(true), - m_curr_pid(LLDB_INVALID_PROCESS_ID), m_curr_tid(LLDB_INVALID_THREAD_ID), + m_curr_pid(LLDB_INVALID_PROCESS_ID), + m_override_pid(LLDB_INVALID_PROCESS_ID), + m_curr_tid(LLDB_INVALID_THREAD_ID), m_curr_tid_run(LLDB_INVALID_THREAD_ID), m_num_supported_hardware_watchpoints(0), m_host_arch(), m_process_arch(), m_os_build(), m_os_kernel(), m_hostname(), m_gdb_server_name(), @@ -2598,22 +2600,32 @@ return false; } -bool GDBRemoteCommunicationClient::SetCurrentThread(uint64_t tid) { - if (m_curr_tid == tid) +bool GDBRemoteCommunicationClient::SetCurrentThread(uint64_t tid, + lldb::pid_t pid) { + if (m_curr_tid == tid && m_override_pid == pid) return true; - char packet[32]; - int packet_len; + lldb_private::StreamString packet; + packet.PutCString("Hg"); + if (m_override_pid != pid) { + if (pid == LLDB_INVALID_PROCESS_ID) { + assert(m_curr_pid != LLDB_INVALID_PROCESS_ID); + pid = m_curr_pid; + } + packet.PutChar('p'); + packet.PutHex64(pid); + packet.PutChar('.'); + } if (tid == UINT64_MAX) - packet_len = ::snprintf(packet, sizeof(packet), "Hg-1"); + packet.PutCString("-1"); else - packet_len = ::snprintf(packet, sizeof(packet), "Hg%" PRIx64, tid); - assert(packet_len + 1 < (int)sizeof(packet)); - UNUSED_IF_ASSERT_DISABLED(packet_len); + packet.PutHex64(tid); + StringExtractorGDBRemote response; - if (SendPacketAndWaitForResponse(packet, response, false) == + if (SendPacketAndWaitForResponse(packet.GetString(), response, false) == PacketResult::Success) { if (response.IsOKResponse()) { + m_override_pid = pid; m_curr_tid = tid; return true; }