Skip to content

Commit

Permalink
[lldb] [llgs] Introduce an AppendThreadIDToResponse() helper
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mgorny committed Jun 24, 2022
1 parent e827e51 commit 4b485fc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -826,10 +826,8 @@ GDBRemoteCommunicationServerLLGS::PrepareStopReplyPacketForThread(

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

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

StreamString response;
response.PutCString("QC");
if (bool(m_extensions_supported & NativeProcessProtocol::Extension::multiprocess))
response.Format("p{0:x-}.", m_current_process->GetID());
response.Format("{0:x-}", thread->GetID());
AppendThreadIDToResponse(response, m_current_process->GetID(),
thread->GetID());

return SendPacketNoLock(response.GetString());
}
Expand Down Expand Up @@ -1996,10 +1993,7 @@ void GDBRemoteCommunicationServerLLGS::AddProcessThreads(
LLDB_LOG(log, "iterated thread {0} (tid={1})", thread_index,
thread->GetID());
response.PutChar(had_any ? ',' : 'm');
if (bool(m_extensions_supported &
NativeProcessProtocol::Extension::multiprocess))
response.Format("p{0:x-}.", pid);
response.Format("{0:x-}", thread->GetID());
AppendThreadIDToResponse(response, pid, thread->GetID());
had_any = true;
}
}
Expand Down Expand Up @@ -4143,6 +4137,14 @@ GDBRemoteCommunicationServerLLGS::SendContinueSuccessResponse() {
return m_non_stop ? SendOKResponse() : PacketResult::Success;
}

void GDBRemoteCommunicationServerLLGS::AppendThreadIDToResponse(
Stream &response, lldb::pid_t pid, lldb::tid_t tid) {
if (bool(m_extensions_supported &
NativeProcessProtocol::Extension::multiprocess))
response.Format("p{0:x-}.", pid);
response.Format("{0:x-}", tid);
}

std::string
lldb_private::process_gdb_remote::LLGSArgToURL(llvm::StringRef url_arg,
bool reverse_connect) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,9 @@ class GDBRemoteCommunicationServerLLGS
// in non-stop mode, no response otherwise.
PacketResult SendContinueSuccessResponse();

void AppendThreadIDToResponse(Stream &response, lldb::pid_t pid,
lldb::tid_t tid);

private:
llvm::Expected<std::unique_ptr<llvm::MemoryBuffer>> BuildTargetXml();

Expand Down

0 comments on commit 4b485fc

Please sign in to comment.