[Lldb-commits] [PATCH] D100262: [lldb] [gdb-remote client] Support switching PID along with TID
Michał Górny via Phabricator via lldb-commits
lldb-commits at lists.llvm.org
Sun Apr 11 05:04:34 PDT 2021
mgorny created this revision.
mgorny added reviewers: labath, emaste, krytarowski.
mgorny requested review of this revision.
Extend the SetCurrentThread() method to support specifying an alternate
PID to switch to. This makes it possible to issue requests to forked
processes.
https://reviews.llvm.org/D100262
Files:
lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h
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;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D100262.336660.patch
Type: text/x-patch
Size: 3247 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20210411/fb6e9461/attachment-0001.bin>
More information about the lldb-commits
mailing list