Skip to content

Commit 1452e2e

Browse files
committed
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
1 parent 1f69f7e commit 1452e2e

File tree

3 files changed

+32
-28
lines changed

3 files changed

+32
-28
lines changed

lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1976,38 +1976,43 @@ GDBRemoteCommunicationServerLLGS::Handle_qRegisterInfo(
19761976
return SendPacketNoLock(response.GetString());
19771977
}
19781978

1979-
GDBRemoteCommunication::PacketResult
1980-
GDBRemoteCommunicationServerLLGS::Handle_qfThreadInfo(
1981-
StringExtractorGDBRemote &packet) {
1979+
void GDBRemoteCommunicationServerLLGS::AddProcessThreads(
1980+
StreamGDBRemote &response, NativeProcessProtocol &process, bool &had_any) {
19821981
Log *log = GetLog(LLDBLog::Thread);
19831982

1984-
// Fail if we don't have a current process.
1985-
if (!m_current_process ||
1986-
(m_current_process->GetID() == LLDB_INVALID_PROCESS_ID)) {
1987-
LLDB_LOG(log, "no process ({0}), returning OK",
1988-
m_current_process ? "invalid process id"
1989-
: "null m_current_process");
1990-
return SendOKResponse();
1991-
}
1992-
1993-
StreamGDBRemote response;
1994-
response.PutChar('m');
1983+
lldb::pid_t pid = process.GetID();
1984+
if (pid == LLDB_INVALID_PROCESS_ID)
1985+
return;
19951986

1996-
LLDB_LOG(log, "starting thread iteration");
1987+
LLDB_LOG(log, "iterating over threads of process {0}", process.GetID());
19971988
NativeThreadProtocol *thread;
19981989
uint32_t thread_index;
1999-
for (thread_index = 0,
2000-
thread = m_current_process->GetThreadAtIndex(thread_index);
2001-
thread; ++thread_index,
2002-
thread = m_current_process->GetThreadAtIndex(thread_index)) {
2003-
LLDB_LOG(log, "iterated thread {0}(tid={2})", thread_index,
1990+
for (thread_index = 0, thread = process.GetThreadAtIndex(thread_index);
1991+
thread;
1992+
++thread_index, thread = process.GetThreadAtIndex(thread_index)) {
1993+
LLDB_LOG(log, "iterated thread {0} (tid={1})", thread_index,
20041994
thread->GetID());
2005-
if (thread_index > 0)
2006-
response.PutChar(',');
2007-
response.Printf("%" PRIx64, thread->GetID());
1995+
response.PutChar(had_any ? ',' : 'm');
1996+
AppendThreadIDToResponse(response, pid, thread->GetID());
1997+
had_any = true;
20081998
}
1999+
}
20092000

2010-
LLDB_LOG(log, "finished thread iteration");
2001+
GDBRemoteCommunication::PacketResult
2002+
GDBRemoteCommunicationServerLLGS::Handle_qfThreadInfo(
2003+
StringExtractorGDBRemote &packet) {
2004+
assert(m_debugged_processes.size() == 1 ||
2005+
bool(m_extensions_supported &
2006+
NativeProcessProtocol::Extension::multiprocess));
2007+
2008+
bool had_any = false;
2009+
StreamGDBRemote response;
2010+
2011+
for (auto &pid_ptr : m_debugged_processes)
2012+
AddProcessThreads(response, *pid_ptr.second, had_any);
2013+
2014+
if (!had_any)
2015+
return SendOKResponse();
20112016
return SendPacketNoLock(response.GetString());
20122017
}
20132018

lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,9 @@ class GDBRemoteCommunicationServerLLGS
159159

160160
PacketResult Handle_qRegisterInfo(StringExtractorGDBRemote &packet);
161161

162+
void AddProcessThreads(StreamGDBRemote &response,
163+
NativeProcessProtocol &process, bool &had_any);
164+
162165
PacketResult Handle_qfThreadInfo(StringExtractorGDBRemote &packet);
163166

164167
PacketResult Handle_qsThreadInfo(StringExtractorGDBRemote &packet);

lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,6 @@ def test_vCont_all_processes_implicit(self):
396396
self.expect_gdbremote_sequence()
397397

398398
@add_test_categories(["fork"])
399-
@expectedFailureAll() # qfThreadInfo changes temporarily reverted
400399
def test_threadinfo(self):
401400
parent_pid, parent_tid, child_pid, child_tid = (
402401
self.start_fork_test(["fork", "thread:new", "trap"]))
@@ -529,7 +528,6 @@ def test_memory_read_write(self):
529528
self.reset_test_sequence()
530529

531530
@add_test_categories(["fork"])
532-
@expectedFailureAll() # qfThreadInfo changes temporarily reverted
533531
def test_register_read_write(self):
534532
parent_pid, parent_tid, child_pid, child_tid = (
535533
self.start_fork_test(["fork", "thread:new", "trap"]))
@@ -626,7 +624,6 @@ def test_register_read_write(self):
626624
self.assertEqual(data, old_val[1])
627625

628626
@add_test_categories(["fork"])
629-
@expectedFailureAll() # qfThreadInfo changes temporarily reverted
630627
def test_qC(self):
631628
parent_pid, parent_tid, child_pid, child_tid = (
632629
self.start_fork_test(["fork", "thread:new", "trap"]))
@@ -661,7 +658,6 @@ def test_qC(self):
661658
self.expect_gdbremote_sequence()
662659

663660
@add_test_categories(["fork"])
664-
@expectedFailureAll() # qfThreadInfo changes temporarily reverted
665661
def test_T(self):
666662
parent_pid, parent_tid, child_pid, child_tid = (
667663
self.start_fork_test(["fork", "thread:new", "trap"]))

0 commit comments

Comments
 (0)