Skip to content

Commit 4b485fc

Browse files
committed
[lldb] [llgs] Introduce an AppendThreadIDToResponse() helper
Introduce a helper function to append GDB Remote Serial Protocol "thread IDs", with optional PID in multiprocess mode. Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.llvm.org/D128324
1 parent e827e51 commit 4b485fc

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

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

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -826,10 +826,8 @@ GDBRemoteCommunicationServerLLGS::PrepareStopReplyPacketForThread(
826826

827827
// Include the (pid and) tid.
828828
response.PutCString("thread:");
829-
if (bool(m_extensions_supported &
830-
NativeProcessProtocol::Extension::multiprocess))
831-
response.Format("p{0:x-}.", process.GetID());
832-
response.Format("{0:x-};", thread.GetID());
829+
AppendThreadIDToResponse(response, process.GetID(), thread.GetID());
830+
response.PutChar(';');
833831

834832
// Include the thread name if there is one.
835833
const std::string thread_name = thread.GetName();
@@ -1425,9 +1423,8 @@ GDBRemoteCommunicationServerLLGS::Handle_qC(StringExtractorGDBRemote &packet) {
14251423

14261424
StreamString response;
14271425
response.PutCString("QC");
1428-
if (bool(m_extensions_supported & NativeProcessProtocol::Extension::multiprocess))
1429-
response.Format("p{0:x-}.", m_current_process->GetID());
1430-
response.Format("{0:x-}", thread->GetID());
1426+
AppendThreadIDToResponse(response, m_current_process->GetID(),
1427+
thread->GetID());
14311428

14321429
return SendPacketNoLock(response.GetString());
14331430
}
@@ -1996,10 +1993,7 @@ void GDBRemoteCommunicationServerLLGS::AddProcessThreads(
19961993
LLDB_LOG(log, "iterated thread {0} (tid={1})", thread_index,
19971994
thread->GetID());
19981995
response.PutChar(had_any ? ',' : 'm');
1999-
if (bool(m_extensions_supported &
2000-
NativeProcessProtocol::Extension::multiprocess))
2001-
response.Format("p{0:x-}.", pid);
2002-
response.Format("{0:x-}", thread->GetID());
1996+
AppendThreadIDToResponse(response, pid, thread->GetID());
20031997
had_any = true;
20041998
}
20051999
}
@@ -4143,6 +4137,14 @@ GDBRemoteCommunicationServerLLGS::SendContinueSuccessResponse() {
41434137
return m_non_stop ? SendOKResponse() : PacketResult::Success;
41444138
}
41454139

4140+
void GDBRemoteCommunicationServerLLGS::AppendThreadIDToResponse(
4141+
Stream &response, lldb::pid_t pid, lldb::tid_t tid) {
4142+
if (bool(m_extensions_supported &
4143+
NativeProcessProtocol::Extension::multiprocess))
4144+
response.Format("p{0:x-}.", pid);
4145+
response.Format("{0:x-}", tid);
4146+
}
4147+
41464148
std::string
41474149
lldb_private::process_gdb_remote::LLGSArgToURL(llvm::StringRef url_arg,
41484150
bool reverse_connect) {

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,9 @@ class GDBRemoteCommunicationServerLLGS
273273
// in non-stop mode, no response otherwise.
274274
PacketResult SendContinueSuccessResponse();
275275

276+
void AppendThreadIDToResponse(Stream &response, lldb::pid_t pid,
277+
lldb::tid_t tid);
278+
276279
private:
277280
llvm::Expected<std::unique_ptr<llvm::MemoryBuffer>> BuildTargetXml();
278281

0 commit comments

Comments
 (0)