Skip to content

Commit

Permalink
Reland "[lldb] [llgs] Support multiprocess in qfThreadInfo"
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mgorny committed Jun 25, 2022
1 parent 1f69f7e commit 1452e2e
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,9 @@ class GDBRemoteCommunicationServerLLGS

PacketResult Handle_qRegisterInfo(StringExtractorGDBRemote &packet);

void AddProcessThreads(StreamGDBRemote &response,
NativeProcessProtocol &process, bool &had_any);

PacketResult Handle_qfThreadInfo(StringExtractorGDBRemote &packet);

PacketResult Handle_qsThreadInfo(StringExtractorGDBRemote &packet);
Expand Down
4 changes: 0 additions & 4 deletions lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,6 @@ def test_vCont_all_processes_implicit(self):
self.expect_gdbremote_sequence()

@add_test_categories(["fork"])
@expectedFailureAll() # qfThreadInfo changes temporarily reverted
def test_threadinfo(self):
parent_pid, parent_tid, child_pid, child_tid = (
self.start_fork_test(["fork", "thread:new", "trap"]))
Expand Down Expand Up @@ -529,7 +528,6 @@ def test_memory_read_write(self):
self.reset_test_sequence()

@add_test_categories(["fork"])
@expectedFailureAll() # qfThreadInfo changes temporarily reverted
def test_register_read_write(self):
parent_pid, parent_tid, child_pid, child_tid = (
self.start_fork_test(["fork", "thread:new", "trap"]))
Expand Down Expand Up @@ -626,7 +624,6 @@ def test_register_read_write(self):
self.assertEqual(data, old_val[1])

@add_test_categories(["fork"])
@expectedFailureAll() # qfThreadInfo changes temporarily reverted
def test_qC(self):
parent_pid, parent_tid, child_pid, child_tid = (
self.start_fork_test(["fork", "thread:new", "trap"]))
Expand Down Expand Up @@ -661,7 +658,6 @@ def test_qC(self):
self.expect_gdbremote_sequence()

@add_test_categories(["fork"])
@expectedFailureAll() # qfThreadInfo changes temporarily reverted
def test_T(self):
parent_pid, parent_tid, child_pid, child_tid = (
self.start_fork_test(["fork", "thread:new", "trap"]))
Expand Down

0 comments on commit 1452e2e

Please sign in to comment.