Skip to content

Commit

Permalink
[gdb-remote] Move broadcasting logic down to GDBRemoteClientBase
Browse files Browse the repository at this point in the history
Move the broadcasting support from GDBRemoteCommunication
to GDBRemoteClientBase since this is where it is actually used.  Remove
GDBRemoteCommunication and subclass constructor arguments left over
after Communication cleanup.

Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.llvm.org/D133427
  • Loading branch information
mgorny committed Sep 9, 2022
1 parent 28bd794 commit bdb4468
Show file tree
Hide file tree
Showing 15 changed files with 29 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,9 @@ static const seconds kWakeupInterval(5);

GDBRemoteClientBase::ContinueDelegate::~ContinueDelegate() = default;

GDBRemoteClientBase::GDBRemoteClientBase(const char *comm_name,
const char *listener_name)
: GDBRemoteCommunication(comm_name, listener_name), m_async_count(0),
m_is_running(false), m_should_stop(false) {}
GDBRemoteClientBase::GDBRemoteClientBase(const char *comm_name)
: GDBRemoteCommunication(), Broadcaster(nullptr, comm_name),
m_async_count(0), m_is_running(false), m_should_stop(false) {}

StateType GDBRemoteClientBase::SendContinuePacketAndWaitForResponse(
ContinueDelegate &delegate, const UnixSignals &signals,
Expand Down
8 changes: 6 additions & 2 deletions lldb/source/Plugins/Process/gdb-remote/GDBRemoteClientBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@
namespace lldb_private {
namespace process_gdb_remote {

class GDBRemoteClientBase : public GDBRemoteCommunication {
class GDBRemoteClientBase : public GDBRemoteCommunication, public Broadcaster {
public:
enum {
eBroadcastBitRunPacketSent = (1u << 0),
};

struct ContinueDelegate {
virtual ~ContinueDelegate();
virtual void HandleAsyncStdout(llvm::StringRef out) = 0;
Expand All @@ -31,7 +35,7 @@ class GDBRemoteClientBase : public GDBRemoteCommunication {
virtual void HandleAsyncStructuredDataPacket(llvm::StringRef data) = 0;
};

GDBRemoteClientBase(const char *comm_name, const char *listener_name);
GDBRemoteClientBase(const char *comm_name);

bool SendAsyncSignal(int signo, std::chrono::seconds interrupt_timeout);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,8 @@ using namespace lldb_private;
using namespace lldb_private::process_gdb_remote;

// GDBRemoteCommunication constructor
GDBRemoteCommunication::GDBRemoteCommunication(const char *comm_name,
const char *listener_name)
: Communication(), Broadcaster(nullptr, comm_name),
GDBRemoteCommunication::GDBRemoteCommunication()
: Communication(),
#ifdef LLDB_CONFIGURATION_DEBUG
m_packet_timeout(1000),
#else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,8 @@ enum GDBErrno {

class ProcessGDBRemote;

class GDBRemoteCommunication : public Communication, public Broadcaster {
class GDBRemoteCommunication : public Communication {
public:
enum {
eBroadcastBitRunPacketSent = (1u << 0),
};

enum class PacketType { Invalid = 0, Standard, Notify };

enum class PacketResult {
Expand Down Expand Up @@ -120,7 +116,7 @@ class GDBRemoteCommunication : public Communication, public Broadcaster {
bool m_timeout_modified;
};

GDBRemoteCommunication(const char *comm_name, const char *listener_name);
GDBRemoteCommunication();

~GDBRemoteCommunication() override;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ llvm::raw_ostream &process_gdb_remote::operator<<(llvm::raw_ostream &os,

// GDBRemoteCommunicationClient constructor
GDBRemoteCommunicationClient::GDBRemoteCommunicationClient()
: GDBRemoteClientBase("gdb-remote.client", "gdb-remote.client.rx_packet"),
: GDBRemoteClientBase("gdb-remote.client"),

m_supports_qProcessInfoPID(true), m_supports_qfProcessInfo(true),
m_supports_qUserName(true), m_supports_qGroupName(true),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ using namespace lldb_private;
using namespace lldb_private::process_gdb_remote;
using namespace llvm;

GDBRemoteCommunicationServer::GDBRemoteCommunicationServer(
const char *comm_name, const char *listener_name)
: GDBRemoteCommunication(comm_name, listener_name), m_exit_now(false) {
GDBRemoteCommunicationServer::GDBRemoteCommunicationServer()
: GDBRemoteCommunication(), m_exit_now(false) {
RegisterPacketHandler(
StringExtractorGDBRemote::eServerPacketType_QEnableErrorStrings,
[this](StringExtractorGDBRemote packet, Status &error, bool &interrupt,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ class GDBRemoteCommunicationServer : public GDBRemoteCommunication {
std::function<PacketResult(StringExtractorGDBRemote &packet,
Status &error, bool &interrupt, bool &quit)>;

GDBRemoteCommunicationServer(const char *comm_name,
const char *listener_name);
GDBRemoteCommunicationServer();

~GDBRemoteCommunicationServer() override;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,9 @@ const static uint32_t g_default_packet_timeout_sec = 0; // not specified
#endif

// GDBRemoteCommunicationServerCommon constructor
GDBRemoteCommunicationServerCommon::GDBRemoteCommunicationServerCommon(
const char *comm_name, const char *listener_name)
: GDBRemoteCommunicationServer(comm_name, listener_name),
m_process_launch_info(), m_process_launch_error(), m_proc_infos(),
m_proc_infos_index(0) {
GDBRemoteCommunicationServerCommon::GDBRemoteCommunicationServerCommon()
: GDBRemoteCommunicationServer(), m_process_launch_info(),
m_process_launch_error(), m_proc_infos(), m_proc_infos_index(0) {
RegisterMemberFunctionHandler(StringExtractorGDBRemote::eServerPacketType_A,
&GDBRemoteCommunicationServerCommon::Handle_A);
RegisterMemberFunctionHandler(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ class ProcessGDBRemote;

class GDBRemoteCommunicationServerCommon : public GDBRemoteCommunicationServer {
public:
GDBRemoteCommunicationServerCommon(const char *comm_name,
const char *listener_name);
GDBRemoteCommunicationServerCommon();

~GDBRemoteCommunicationServerCommon() override;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,9 @@ enum GDBRemoteServerError {
// GDBRemoteCommunicationServerLLGS constructor
GDBRemoteCommunicationServerLLGS::GDBRemoteCommunicationServerLLGS(
MainLoop &mainloop, const NativeProcessProtocol::Factory &process_factory)
: GDBRemoteCommunicationServerCommon("gdb-remote.server",
"gdb-remote.server.rx_packet"),
m_mainloop(mainloop), m_process_factory(process_factory),
m_current_process(nullptr), m_continue_process(nullptr),
m_stdio_communication() {
: GDBRemoteCommunicationServerCommon(), m_mainloop(mainloop),
m_process_factory(process_factory), m_current_process(nullptr),
m_continue_process(nullptr), m_stdio_communication() {
RegisterPacketHandlers();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,7 @@ bool GDBRemoteCommunicationServerPlatform::PortMap::empty() const {
// GDBRemoteCommunicationServerPlatform constructor
GDBRemoteCommunicationServerPlatform::GDBRemoteCommunicationServerPlatform(
const Socket::SocketProtocol socket_protocol, const char *socket_scheme)
: GDBRemoteCommunicationServerCommon("gdb-remote.server",
"gdb-remote.server.rx_packet"),
: GDBRemoteCommunicationServerCommon(),
m_socket_protocol(socket_protocol), m_socket_scheme(socket_scheme),
m_spawned_pids_mutex(), m_port_map(), m_port_offset(0) {
m_pending_gdb_server.pid = LLDB_INVALID_PROCESS_ID;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1168,7 +1168,7 @@ Status ProcessGDBRemote::DoResume() {
ListenerSP listener_sp(
Listener::MakeListener("gdb-remote.resume-packet-sent"));
if (listener_sp->StartListeningForEvents(
&m_gdb_comm, GDBRemoteCommunication::eBroadcastBitRunPacketSent)) {
&m_gdb_comm, GDBRemoteClientBase::eBroadcastBitRunPacketSent)) {
listener_sp->StartListeningForEvents(
&m_async_broadcaster,
ProcessGDBRemote::eBroadcastBitAsyncThreadDidExit);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ struct MockDelegate : public GDBRemoteClientBase::ContinueDelegate {
};

struct TestClient : public GDBRemoteClientBase {
TestClient() : GDBRemoteClientBase("test.client", "test.client.listener") {
TestClient() : GDBRemoteClientBase("test.client") {
m_send_acks = false;
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ namespace {

class TestClient : public GDBRemoteCommunication {
public:
TestClient()
: GDBRemoteCommunication("test.client", "test.client.listener") {}
TestClient() : GDBRemoteCommunication() {}

PacketResult ReadPacket(StringExtractorGDBRemote &response) {
return GDBRemoteCommunication::ReadPacket(response, std::chrono::seconds(1),
Expand Down
3 changes: 1 addition & 2 deletions lldb/unittests/Process/gdb-remote/GDBRemoteTestUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ class MockConnection : public lldb_private::Connection {

class MockServer : public GDBRemoteCommunicationServer {
public:
MockServer()
: GDBRemoteCommunicationServer("mock-server", "mock-server.listener") {
MockServer() : GDBRemoteCommunicationServer() {
m_send_acks = false;
m_send_error_strings = true;
}
Expand Down

0 comments on commit bdb4468

Please sign in to comment.