aboutsummaryrefslogtreecommitdiff
path: root/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
diff options
context:
space:
mode:
authorMichał Górny <mgorny@moritz.systems>2022-06-25 15:04:26 +0200
committerMichał Górny <mgorny@moritz.systems>2022-06-25 15:15:37 +0200
commit1452e2e5cbfe69cd6622a3c9e80dd485f1fb542b (patch)
treec22dac5d8ee9ea84ac8ffd4e2ebc96848280a92a /lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
parent1f69f7ea9af4bd4e8001a25044aa026557f366f7 (diff)
downloadllvm-1452e2e5cbfe69cd6622a3c9e80dd485f1fb542b.zip
llvm-1452e2e5cbfe69cd6622a3c9e80dd485f1fb542b.tar.gz
llvm-1452e2e5cbfe69cd6622a3c9e80dd485f1fb542b.tar.bz2
Reland "[lldb] [llgs] Support multiprocess in qfThreadInfo"
Now preserving the non-standard behavior of returning "OK" response when there is no debugged process. Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.llvm.org/D128152
Diffstat (limited to 'lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp')
-rw-r--r--lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp53
1 files changed, 29 insertions, 24 deletions
diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
index 770edbf..2c009ef 100644
--- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
@@ -1976,38 +1976,43 @@ GDBRemoteCommunicationServerLLGS::Handle_qRegisterInfo(
return SendPacketNoLock(response.GetString());
}
-GDBRemoteCommunication::PacketResult
-GDBRemoteCommunicationServerLLGS::Handle_qfThreadInfo(
- StringExtractorGDBRemote &packet) {
+void GDBRemoteCommunicationServerLLGS::AddProcessThreads(
+ StreamGDBRemote &response, NativeProcessProtocol &process, bool &had_any) {
Log *log = GetLog(LLDBLog::Thread);
- // Fail if we don't have a current process.
- if (!m_current_process ||
- (m_current_process->GetID() == LLDB_INVALID_PROCESS_ID)) {
- LLDB_LOG(log, "no process ({0}), returning OK",
- m_current_process ? "invalid process id"
- : "null m_current_process");
- return SendOKResponse();
- }
-
- StreamGDBRemote response;
- response.PutChar('m');
+ lldb::pid_t pid = process.GetID();
+ if (pid == LLDB_INVALID_PROCESS_ID)
+ return;
- LLDB_LOG(log, "starting thread iteration");
+ LLDB_LOG(log, "iterating over threads of process {0}", process.GetID());
NativeThreadProtocol *thread;
uint32_t thread_index;
- for (thread_index = 0,
- thread = m_current_process->GetThreadAtIndex(thread_index);
- thread; ++thread_index,
- thread = m_current_process->GetThreadAtIndex(thread_index)) {
- LLDB_LOG(log, "iterated thread {0}(tid={2})", thread_index,
+ for (thread_index = 0, thread = process.GetThreadAtIndex(thread_index);
+ thread;
+ ++thread_index, thread = process.GetThreadAtIndex(thread_index)) {
+ LLDB_LOG(log, "iterated thread {0} (tid={1})", thread_index,
thread->GetID());
- if (thread_index > 0)
- response.PutChar(',');
- response.Printf("%" PRIx64, thread->GetID());
+ response.PutChar(had_any ? ',' : 'm');
+ AppendThreadIDToResponse(response, pid, thread->GetID());
+ had_any = true;
}
+}
- LLDB_LOG(log, "finished thread iteration");
+GDBRemoteCommunication::PacketResult
+GDBRemoteCommunicationServerLLGS::Handle_qfThreadInfo(
+ StringExtractorGDBRemote &packet) {
+ assert(m_debugged_processes.size() == 1 ||
+ bool(m_extensions_supported &
+ NativeProcessProtocol::Extension::multiprocess));
+
+ bool had_any = false;
+ StreamGDBRemote response;
+
+ for (auto &pid_ptr : m_debugged_processes)
+ AddProcessThreads(response, *pid_ptr.second, had_any);
+
+ if (!had_any)
+ return SendOKResponse();
return SendPacketNoLock(response.GetString());
}