[Lldb-commits] [lldb] [lldb] Name GDB-remote communication channels (PR #237417)
satyanarayana reddy janga via lldb-commits
lldb-commits at lists.llvm.org
Mon Nov 2 16:54:53 PST 2026
https://github.com/satyajanga updated https://github.com/llvm/llvm-project/pull/237417
>From f181ca146e56deb102e67566b189d5826fec3574 Mon Sep 17 00:00:00 2001
From: satya janga <satyajanga at fb.com>
Date: Fri, 30 Oct 2026 15:21:18 -0700
Subject: [PATCH 1/2] [lldb] Name GDB-remote communication channels
---
.../gdb-remote/GDBRemoteClientBase.cpp | 2 +-
.../gdb-remote/GDBRemoteCommunication.cpp | 39 +++++++++++--------
.../gdb-remote/GDBRemoteCommunication.h | 7 +++-
.../GDBRemoteCommunicationServer.cpp | 4 +-
.../gdb-remote/GDBRemoteCommunicationServer.h | 2 +-
.../GDBRemoteCommunicationServerCommon.cpp | 5 ++-
.../GDBRemoteCommunicationServerCommon.h | 2 +-
.../GDBRemoteCommunicationServerLLGS.cpp | 5 ++-
.../GDBRemoteCommunicationServerLLGS.h | 4 +-
.../GDBRemoteCommunicationServerPlatform.cpp | 3 +-
.../Mock/LLDBServerMockAcceleratorPlugin.cpp | 2 +-
lldb/tools/lldb-server/lldb-gdbserver.cpp | 3 +-
.../gdb-remote/GDBRemoteCommunicationTest.cpp | 30 +++++++++++++-
.../Process/gdb-remote/GDBRemoteTestUtils.h | 2 +-
14 files changed, 76 insertions(+), 34 deletions(-)
diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteClientBase.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteClientBase.cpp
index fa927b74d56fad..a30a8496b151ad 100644
--- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteClientBase.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteClientBase.cpp
@@ -33,7 +33,7 @@ static const seconds kWakeupInterval(5);
GDBRemoteClientBase::ContinueDelegate::~ContinueDelegate() = default;
GDBRemoteClientBase::GDBRemoteClientBase(const char *comm_name)
- : GDBRemoteCommunication(), Broadcaster(nullptr, comm_name),
+ : GDBRemoteCommunication(comm_name), Broadcaster(nullptr, comm_name),
m_async_count(0), m_is_running(false), m_should_stop(false) {}
StateType GDBRemoteClientBase::SendContinuePacketAndWaitForResponse(
diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
index 38233f2eed3d61..03bad3f7ed9418 100644
--- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
@@ -47,7 +47,7 @@ using namespace lldb_private;
using namespace lldb_private::process_gdb_remote;
// GDBRemoteCommunication constructor
-GDBRemoteCommunication::GDBRemoteCommunication()
+GDBRemoteCommunication::GDBRemoteCommunication(llvm::StringRef name)
: Communication(),
#ifdef LLDB_CONFIGURATION_DEBUG
m_packet_timeout(1000),
@@ -56,7 +56,7 @@ GDBRemoteCommunication::GDBRemoteCommunication()
#endif
m_echo_number(0), m_supports_qEcho(eLazyBoolCalculate), m_history(512),
m_send_acks(true), m_is_platform(false),
- m_compression_type(CompressionType::None) {
+ m_compression_type(CompressionType::None), m_name(name) {
}
// Destructor
@@ -85,7 +85,8 @@ size_t GDBRemoteCommunication::SendAck() {
ConnectionStatus status = eConnectionStatusSuccess;
char ch = '+';
const size_t bytes_written = WriteAll(&ch, 1, status, nullptr);
- LLDB_LOGF(log, "<%4" PRIu64 "> send packet: %c", (uint64_t)bytes_written, ch);
+ LLDB_LOGF(log, "%s <%4" PRIu64 "> send packet: %c", m_name.c_str(),
+ (uint64_t)bytes_written, ch);
m_history.AddPacket(ch, GDBRemotePacket::ePacketTypeSend, bytes_written);
return bytes_written;
}
@@ -95,7 +96,8 @@ size_t GDBRemoteCommunication::SendNack() {
ConnectionStatus status = eConnectionStatusSuccess;
char ch = '-';
const size_t bytes_written = WriteAll(&ch, 1, status, nullptr);
- LLDB_LOGF(log, "<%4" PRIu64 "> send packet: %c", (uint64_t)bytes_written, ch);
+ LLDB_LOGF(log, "%s <%4" PRIu64 "> send packet: %c", m_name.c_str(),
+ (uint64_t)bytes_written, ch);
m_history.AddPacket(ch, GDBRemotePacket::ePacketTypeSend, bytes_written);
return bytes_written;
}
@@ -170,8 +172,9 @@ GDBRemoteCommunication::SendRawPacketNoLock(llvm::StringRef packet,
if (binary_start_offset) {
StreamString strm;
// Print non binary data header
- strm.Printf("<%4" PRIu64 "> send packet: %.*s", (uint64_t)bytes_written,
- (int)binary_start_offset, packet_data);
+ strm.Printf("%s <%4" PRIu64 "> send packet: %.*s", m_name.c_str(),
+ (uint64_t)bytes_written, (int)binary_start_offset,
+ packet_data);
const uint8_t *p;
// Print binary data exactly as sent
for (p = (const uint8_t *)packet_data + binary_start_offset; *p != '#';
@@ -181,7 +184,7 @@ GDBRemoteCommunication::SendRawPacketNoLock(llvm::StringRef packet,
strm.Printf("%*s", (int)3, p);
log->PutString(strm.GetString());
} else
- LLDB_LOGF(log, "<%4" PRIu64 "> send packet: %.*s",
+ LLDB_LOGF(log, "%s <%4" PRIu64 "> send packet: %.*s", m_name.c_str(),
(uint64_t)bytes_written, (int)packet_length, packet_data);
}
@@ -627,7 +630,7 @@ bool GDBRemoteCommunication::DecompressPacket() {
static void AddToLog(llvm::StringRef content, llvm::StringRef payload,
uint64_t original_packet_size,
GDBRemoteCommunicationHistory &history,
- bool compression_enabled) {
+ bool compression_enabled, llvm::StringRef name) {
Log *log = GetLog(GDBRLog::Packets);
if (!log)
return;
@@ -649,22 +652,24 @@ static void AddToLog(llvm::StringRef content, llvm::StringRef payload,
uint64_t total_length = payload.size();
if (!binary) {
if (compression_enabled)
- LLDB_LOGF(log, "<%4" PRIu64 ":%" PRIu64 "> read packet: %.*s",
- original_packet_size, total_length, (int)(total_length),
- payload.data());
+ LLDB_LOGF(log, "%.*s <%4" PRIu64 ":%" PRIu64 "> read packet: %.*s",
+ (int)name.size(), name.data(), original_packet_size,
+ total_length, (int)(total_length), payload.data());
else
- LLDB_LOGF(log, "<%4" PRIu64 "> read packet: %.*s", total_length,
- (int)(total_length), payload.data());
+ LLDB_LOGF(log, "%.*s <%4" PRIu64 "> read packet: %.*s", (int)name.size(),
+ name.data(), total_length, (int)(total_length), payload.data());
return;
}
StreamString strm;
// Packet header.
if (compression_enabled)
- strm.Printf("<%4" PRIu64 ":%" PRIu64 "> read packet: %c",
- original_packet_size, total_length, payload[0]);
+ strm.Printf("%.*s <%4" PRIu64 ":%" PRIu64 "> read packet: %c",
+ (int)name.size(), name.data(), original_packet_size,
+ total_length, payload[0]);
else
- strm.Printf("<%4" PRIu64 "> read packet: %c", total_length, payload[0]);
+ strm.Printf("%.*s <%4" PRIu64 "> read packet: %c", (int)name.size(),
+ name.data(), total_length, payload[0]);
for (size_t i = 0; i < content.size(); ++i) {
// Remove binary escaped bytes when displaying the packet.
const char ch = content[i];
@@ -793,7 +798,7 @@ GDBRemoteCommunication::CheckForPacket(const uint8_t *src, size_t src_len,
AddToLog(llvm::StringRef(m_bytes).slice(content_start, content_end),
llvm::StringRef(m_bytes).take_front(total_length),
- original_packet_size, m_history, CompressionIsEnabled());
+ original_packet_size, m_history, CompressionIsEnabled(), m_name);
m_history.AddPacket(m_bytes, total_length,
GDBRemotePacket::ePacketTypeRecv, total_length);
diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h
index 6c7611e6a49ec8..9349e25594a41d 100644
--- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h
+++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h
@@ -109,7 +109,10 @@ class GDBRemoteCommunication : public Communication {
bool m_timeout_modified;
};
- GDBRemoteCommunication();
+ /// Construct a GDB-remote communication channel named \p name.
+ ///
+ /// The name identifies the channel in packet logs.
+ explicit GDBRemoteCommunication(llvm::StringRef name);
~GDBRemoteCommunication() override;
@@ -199,6 +202,8 @@ class GDBRemoteCommunication : public Communication {
bool DecompressPacket();
private:
+ const std::string m_name;
+
#if HAVE_LIBCOMPRESSION
CompressionType m_decompression_scratch_type = CompressionType::None;
void *m_decompression_scratch = nullptr;
diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp
index 5bd29ae40aa9eb..4c0c1e9348b6d0 100644
--- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp
@@ -24,8 +24,8 @@ using namespace lldb_private;
using namespace lldb_private::process_gdb_remote;
using namespace llvm;
-GDBRemoteCommunicationServer::GDBRemoteCommunicationServer()
- : GDBRemoteCommunication(), m_exit_now(false) {
+GDBRemoteCommunicationServer::GDBRemoteCommunicationServer(llvm::StringRef name)
+ : GDBRemoteCommunication(name), m_exit_now(false) {
RegisterPacketHandler(
StringExtractorGDBRemote::eServerPacketType_QEnableErrorStrings,
[this](StringExtractorGDBRemote packet, Status &error, bool &interrupt,
diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.h b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.h
index ccbcd0ac5bf586..dda0114dcd2a10 100644
--- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.h
+++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.h
@@ -31,7 +31,7 @@ class GDBRemoteCommunicationServer : public GDBRemoteCommunication {
std::function<PacketResult(StringExtractorGDBRemote &packet,
Status &error, bool &interrupt, bool &quit)>;
- GDBRemoteCommunicationServer();
+ explicit GDBRemoteCommunicationServer(llvm::StringRef name);
~GDBRemoteCommunicationServer() override;
diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp
index d87c50c78e27b7..a399f515036c2e 100644
--- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp
@@ -58,8 +58,9 @@ const static uint32_t g_default_packet_timeout_sec = 0; // not specified
#endif
// GDBRemoteCommunicationServerCommon constructor
-GDBRemoteCommunicationServerCommon::GDBRemoteCommunicationServerCommon()
- : GDBRemoteCommunicationServer(), m_process_launch_info(),
+GDBRemoteCommunicationServerCommon::GDBRemoteCommunicationServerCommon(
+ llvm::StringRef name)
+ : GDBRemoteCommunicationServer(name), m_process_launch_info(),
m_process_launch_error(), m_proc_infos(), m_proc_infos_index(0) {
RegisterMemberFunctionHandler(StringExtractorGDBRemote::eServerPacketType_A,
&GDBRemoteCommunicationServerCommon::Handle_A);
diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.h b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.h
index aa756c81a791ed..1b61b458284147 100644
--- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.h
+++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.h
@@ -25,7 +25,7 @@ class ProcessGDBRemote;
class GDBRemoteCommunicationServerCommon : public GDBRemoteCommunicationServer {
public:
- GDBRemoteCommunicationServerCommon();
+ explicit GDBRemoteCommunicationServerCommon(llvm::StringRef name);
~GDBRemoteCommunicationServerCommon() override;
diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
index 5466817d844c59..37d389457f0e8c 100644
--- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
@@ -75,8 +75,9 @@ enum GDBRemoteServerError {
// GDBRemoteCommunicationServerLLGS constructor
GDBRemoteCommunicationServerLLGS::GDBRemoteCommunicationServerLLGS(
- MainLoop &mainloop, NativeProcessProtocol::Manager &process_manager)
- : GDBRemoteCommunicationServerCommon(), m_mainloop(mainloop),
+ MainLoop &mainloop, NativeProcessProtocol::Manager &process_manager,
+ llvm::StringRef name)
+ : GDBRemoteCommunicationServerCommon(name), m_mainloop(mainloop),
m_process_manager(process_manager), m_current_process(nullptr),
m_continue_process(nullptr), m_stdio_communication() {
RegisterPacketHandlers();
diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.h b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.h
index efb7c30b9464f7..8c93cf576ded83 100644
--- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.h
+++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.h
@@ -37,8 +37,8 @@ class GDBRemoteCommunicationServerLLGS
public:
// Constructors and Destructors
GDBRemoteCommunicationServerLLGS(
- MainLoop &mainloop,
- NativeProcessProtocol::Manager &process_manager);
+ MainLoop &mainloop, NativeProcessProtocol::Manager &process_manager,
+ llvm::StringRef name);
void SetLaunchInfo(const ProcessLaunchInfo &info);
diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp
index 4f740dbd38da43..470559dbd8493b 100644
--- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp
@@ -47,7 +47,8 @@ using namespace lldb_private;
GDBRemoteCommunicationServerPlatform::GDBRemoteCommunicationServerPlatform(
FileSpec debugserver_path, const Socket::SocketProtocol socket_protocol,
uint16_t gdbserver_port)
- : m_debugserver_path(std::move(debugserver_path)),
+ : GDBRemoteCommunicationServerCommon("lldb-platform.server"),
+ m_debugserver_path(std::move(debugserver_path)),
m_socket_protocol(socket_protocol), m_gdbserver_port(gdbserver_port) {
RegisterMemberFunctionHandler(
diff --git a/lldb/tools/lldb-server/Plugins/Accelerator/Mock/LLDBServerMockAcceleratorPlugin.cpp b/lldb/tools/lldb-server/Plugins/Accelerator/Mock/LLDBServerMockAcceleratorPlugin.cpp
index 069bee0e4ef52b..eef3a8fde18753 100644
--- a/lldb/tools/lldb-server/Plugins/Accelerator/Mock/LLDBServerMockAcceleratorPlugin.cpp
+++ b/lldb/tools/lldb-server/Plugins/Accelerator/Mock/LLDBServerMockAcceleratorPlugin.cpp
@@ -155,7 +155,7 @@ LLDBServerMockAcceleratorPlugin::CreateConnection() {
m_process_manager_up =
std::make_unique<ProcessMockAccelerator::Manager>(m_mock_main_loop);
m_accelerator_gdb_server = std::make_unique<GDBRemoteCommunicationServerLLGS>(
- m_mock_main_loop, *m_process_manager_up);
+ m_mock_main_loop, *m_process_manager_up, "lldb-server.mock-accelerator");
m_accelerator_gdb_server->SetConnectionAcceleratorPlugin(*this);
// LLGS creates its current process from a launch; the manager ignores the
diff --git a/lldb/tools/lldb-server/lldb-gdbserver.cpp b/lldb/tools/lldb-server/lldb-gdbserver.cpp
index 98a79dedf65c02..cf14e93c59bd05 100644
--- a/lldb/tools/lldb-server/lldb-gdbserver.cpp
+++ b/lldb/tools/lldb-server/lldb-gdbserver.cpp
@@ -452,7 +452,8 @@ int main_gdbserver(int argc, char *argv[]) {
}
NativeProcessManager manager(mainloop);
- GDBRemoteCommunicationServerLLGS gdb_server(mainloop, manager);
+ GDBRemoteCommunicationServerLLGS gdb_server(mainloop, manager,
+ "lldb-server.native");
#if defined(LLDB_ENABLE_MOCK_ACCELERATOR_PLUGIN)
gdb_server.InstallPlugin(
diff --git a/lldb/unittests/Process/gdb-remote/GDBRemoteCommunicationTest.cpp b/lldb/unittests/Process/gdb-remote/GDBRemoteCommunicationTest.cpp
index e96d587b10e25b..4086d89034251c 100644
--- a/lldb/unittests/Process/gdb-remote/GDBRemoteCommunicationTest.cpp
+++ b/lldb/unittests/Process/gdb-remote/GDBRemoteCommunicationTest.cpp
@@ -7,7 +7,10 @@
//===----------------------------------------------------------------------===//
#include "GDBRemoteTestUtils.h"
+#include "Plugins/Process/gdb-remote/ProcessGDBRemoteLog.h"
#include "lldb/Host/ConnectionFileDescriptor.h"
+#include "lldb/Utility/Log.h"
+#include "llvm/ADT/ScopeExit.h"
#include "llvm/Testing/Support/Error.h"
using namespace lldb_private::process_gdb_remote;
@@ -17,9 +20,16 @@ typedef GDBRemoteCommunication::PacketResult PacketResult;
namespace {
+class CapturingLogHandler : public LogHandler {
+public:
+ void Emit(llvm::StringRef message) override { output += message; }
+
+ std::string output;
+};
+
class TestClient : public GDBRemoteCommunication {
public:
- TestClient() : GDBRemoteCommunication() {}
+ TestClient() : GDBRemoteCommunication("test.client") {}
PacketResult ReadPacket(StringExtractorGDBRemote &response) {
return GDBRemoteCommunication::ReadPacket(response, std::chrono::seconds(1),
@@ -50,6 +60,24 @@ class GDBRemoteCommunicationTest : public GDBRemoteTest {
};
} // end anonymous namespace
+TEST_F(GDBRemoteCommunicationTest, PacketLogsIncludeChannelName) {
+ ProcessGDBRemoteLog::Initialize();
+ llvm::scope_exit cleanup([] { ProcessGDBRemoteLog::Terminate(); });
+
+ auto handler = std::make_shared<CapturingLogHandler>();
+ ASSERT_THAT_ERROR(
+ Log::EnableLogChannel(handler, 0, "gdb-remote", {"packets"}),
+ llvm::Succeeded());
+
+ ASSERT_EQ(PacketResult::Success, server.SendPacket("OK"));
+ StringExtractorGDBRemote response;
+ ASSERT_EQ(PacketResult::Success, client.ReadPacket(response));
+
+ llvm::StringRef output = handler->output;
+ EXPECT_TRUE(output.contains("test.server < 6> send packet: $OK#9a"));
+ EXPECT_TRUE(output.contains("test.client < 6> read packet: $OK#9a"));
+}
+
// Test that we can decode packets correctly. In particular, verify that
// checksum calculation works.
TEST_F(GDBRemoteCommunicationTest, ReadPacket) {
diff --git a/lldb/unittests/Process/gdb-remote/GDBRemoteTestUtils.h b/lldb/unittests/Process/gdb-remote/GDBRemoteTestUtils.h
index ef7593dc444325..a6f55006eb720f 100644
--- a/lldb/unittests/Process/gdb-remote/GDBRemoteTestUtils.h
+++ b/lldb/unittests/Process/gdb-remote/GDBRemoteTestUtils.h
@@ -53,7 +53,7 @@ class MockConnection : public lldb_private::Connection {
class MockServer : public GDBRemoteCommunicationServer {
public:
- MockServer() : GDBRemoteCommunicationServer() {
+ MockServer() : GDBRemoteCommunicationServer("test.server") {
m_send_acks = false;
m_send_error_strings = true;
}
>From bffa2a0ffd8a8a6e2f5ded762003f4b24317a37a Mon Sep 17 00:00:00 2001
From: satya janga <satyajanga at fb.com>
Date: Mon, 2 Nov 2026 16:44:20 -0800
Subject: [PATCH 2/2] [lldb] Document GDB-remote channel log name
---
lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h | 1 +
1 file changed, 1 insertion(+)
diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h
index 9349e25594a41d..63dbb3033fe30c 100644
--- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h
+++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h
@@ -202,6 +202,7 @@ class GDBRemoteCommunication : public Communication {
bool DecompressPacket();
private:
+ /// The communication channel name included in packet logs.
const std::string m_name;
#if HAVE_LIBCOMPRESSION
More information about the lldb-commits
mailing list