Skip to content

Commit cf9546b

Browse files
authored
[lldb] Remove GDBRemoteCommunication::ConnectLocally (#145293)
Originally added for reproducers, it is now only used for test code. While we could make it a test helper, I think that after #145015 it is simple enough to not be needed. Also squeeze in a change to make ConnectionFileDescriptor accept a unique_ptr<Socket>.
1 parent 46e1e9f commit cf9546b

File tree

11 files changed

+39
-47
lines changed

11 files changed

+39
-47
lines changed

lldb/include/lldb/Host/posix/ConnectionFileDescriptorPosix.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,10 @@
1818
#include "lldb/Host/Pipe.h"
1919
#include "lldb/Host/Socket.h"
2020
#include "lldb/Utility/Connection.h"
21-
#include "lldb/Utility/IOObject.h"
2221

2322
namespace lldb_private {
2423

2524
class Status;
26-
class Socket;
27-
class SocketAddress;
2825

2926
class ConnectionFileDescriptor : public Connection {
3027
public:
@@ -35,7 +32,7 @@ class ConnectionFileDescriptor : public Connection {
3532

3633
ConnectionFileDescriptor(int fd, bool owns_fd);
3734

38-
ConnectionFileDescriptor(Socket *socket);
35+
ConnectionFileDescriptor(std::unique_ptr<Socket> socket_up);
3936

4037
~ConnectionFileDescriptor() override;
4138

@@ -136,8 +133,6 @@ class ConnectionFileDescriptor : public Connection {
136133
std::string m_uri;
137134

138135
private:
139-
void InitializeSocket(Socket *socket);
140-
141136
ConnectionFileDescriptor(const ConnectionFileDescriptor &) = delete;
142137
const ConnectionFileDescriptor &
143138
operator=(const ConnectionFileDescriptor &) = delete;

lldb/source/Host/posix/ConnectionFileDescriptorPosix.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,11 @@ ConnectionFileDescriptor::ConnectionFileDescriptor(int fd, bool owns_fd)
7272
OpenCommandPipe();
7373
}
7474

75-
ConnectionFileDescriptor::ConnectionFileDescriptor(Socket *socket)
76-
: Connection(), m_pipe(), m_mutex(), m_shutting_down(false) {
77-
InitializeSocket(socket);
75+
ConnectionFileDescriptor::ConnectionFileDescriptor(
76+
std::unique_ptr<Socket> socket_up)
77+
: m_shutting_down(false) {
78+
m_uri = socket_up->GetRemoteConnectionURI();
79+
m_io_sp = std::move(socket_up);
7880
}
7981

8082
ConnectionFileDescriptor::~ConnectionFileDescriptor() {
@@ -796,8 +798,3 @@ ConnectionStatus ConnectionFileDescriptor::ConnectSerialPort(
796798
#endif // LLDB_ENABLE_POSIX
797799
llvm_unreachable("this function should be only called w/ LLDB_ENABLE_POSIX");
798800
}
799-
800-
void ConnectionFileDescriptor::InitializeSocket(Socket *socket) {
801-
m_io_sp.reset(socket);
802-
m_uri = socket->GetRemoteConnectionURI();
803-
}

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

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1128,8 +1128,8 @@ Status GDBRemoteCommunication::StartDebugserverProcess(
11281128
Socket *accepted_socket = nullptr;
11291129
error = sock_up->Accept(/*timeout=*/std::nullopt, accepted_socket);
11301130
if (accepted_socket) {
1131-
SetConnection(
1132-
std::make_unique<ConnectionFileDescriptor>(accepted_socket));
1131+
SetConnection(std::make_unique<ConnectionFileDescriptor>(
1132+
std::unique_ptr<Socket>(accepted_socket)));
11331133
}
11341134
}
11351135

@@ -1138,20 +1138,6 @@ Status GDBRemoteCommunication::StartDebugserverProcess(
11381138

11391139
void GDBRemoteCommunication::DumpHistory(Stream &strm) { m_history.Dump(strm); }
11401140

1141-
llvm::Error
1142-
GDBRemoteCommunication::ConnectLocally(GDBRemoteCommunication &client,
1143-
GDBRemoteCommunication &server) {
1144-
llvm::Expected<Socket::Pair> pair = Socket::CreatePair();
1145-
if (!pair)
1146-
return pair.takeError();
1147-
1148-
client.SetConnection(
1149-
std::make_unique<ConnectionFileDescriptor>(pair->first.release()));
1150-
server.SetConnection(
1151-
std::make_unique<ConnectionFileDescriptor>(pair->second.release()));
1152-
return llvm::Error::success();
1153-
}
1154-
11551141
GDBRemoteCommunication::ScopedTimeout::ScopedTimeout(
11561142
GDBRemoteCommunication &gdb_comm, std::chrono::seconds timeout)
11571143
: m_gdb_comm(gdb_comm), m_saved_timeout(0), m_timeout_modified(false) {

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,6 @@ class GDBRemoteCommunication : public Communication {
149149

150150
void DumpHistory(Stream &strm);
151151

152-
static llvm::Error ConnectLocally(GDBRemoteCommunication &client,
153-
GDBRemoteCommunication &server);
154-
155152
/// Expand GDB run-length encoding.
156153
static std::optional<std::string> ExpandRLE(std::string);
157154

lldb/tools/lldb-server/lldb-platform.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -485,8 +485,8 @@ int main_platform(int argc, char *argv[]) {
485485

486486
GDBRemoteCommunicationServerPlatform platform(socket->GetSocketProtocol(),
487487
gdbserver_port);
488-
platform.SetConnection(std::unique_ptr<Connection>(
489-
new ConnectionFileDescriptor(socket.release())));
488+
platform.SetConnection(
489+
std::make_unique<ConnectionFileDescriptor>(std::move(socket)));
490490
client_handle(platform, inferior_arguments);
491491
return 0;
492492
}

lldb/unittests/Core/CommunicationTest.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ static void CommunicationReadTest(bool use_read_thread) {
4141

4242
ThreadedCommunication comm("test");
4343
comm.SetConnection(
44-
std::make_unique<ConnectionFileDescriptor>(pair->second.release()));
44+
std::make_unique<ConnectionFileDescriptor>(std::move(pair->second)));
4545
comm.SetCloseOnEOF(true);
4646

4747
if (use_read_thread) {
@@ -126,7 +126,7 @@ TEST_F(CommunicationTest, SynchronizeWhileClosing) {
126126

127127
ThreadedCommunication comm("test");
128128
comm.SetConnection(
129-
std::make_unique<ConnectionFileDescriptor>(pair->second.release()));
129+
std::make_unique<ConnectionFileDescriptor>(std::move(pair->second)));
130130
comm.SetCloseOnEOF(true);
131131
ASSERT_TRUE(comm.StartReadThread());
132132

lldb/unittests/Host/ConnectionFileDescriptorTest.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ class ConnectionFileDescriptorTest : public testing::Test {
2222
std::unique_ptr<TCPSocket> socket_a_up;
2323
std::unique_ptr<TCPSocket> socket_b_up;
2424
CreateTCPConnectedSockets(ip, &socket_a_up, &socket_b_up);
25-
auto *socket = socket_a_up.release();
26-
ConnectionFileDescriptor connection_file_descriptor(socket);
25+
uint16_t socket_a_remote_port = socket_a_up->GetRemotePortNumber();
26+
ConnectionFileDescriptor connection_file_descriptor(std::move(socket_a_up));
2727

2828
std::string uri(connection_file_descriptor.GetURI());
29-
EXPECT_EQ((URI{"connect", ip, socket->GetRemotePortNumber(), "/"}),
29+
EXPECT_EQ((URI{"connect", ip, socket_a_remote_port, "/"}),
3030
*URI::Parse(uri));
3131
}
3232
};

lldb/unittests/Process/gdb-remote/GDBRemoteClientBaseTest.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "GDBRemoteTestUtils.h"
1111
#include "Plugins/Process/Utility/LinuxSignals.h"
1212
#include "Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.h"
13+
#include "lldb/Host/ConnectionFileDescriptor.h"
1314
#include "lldb/Utility/GDBRemote.h"
1415
#include "lldb/Utility/Listener.h"
1516
#include "llvm/ADT/StringRef.h"
@@ -51,8 +52,12 @@ struct TestClient : public GDBRemoteClientBase {
5152
class GDBRemoteClientBaseTest : public GDBRemoteTest {
5253
public:
5354
void SetUp() override {
54-
ASSERT_THAT_ERROR(GDBRemoteCommunication::ConnectLocally(client, server),
55-
llvm::Succeeded());
55+
llvm::Expected<Socket::Pair> pair = Socket::CreatePair();
56+
ASSERT_THAT_EXPECTED(pair, llvm::Succeeded());
57+
client.SetConnection(
58+
std::make_unique<ConnectionFileDescriptor>(std::move(pair->first)));
59+
server.SetConnection(
60+
std::make_unique<ConnectionFileDescriptor>(std::move(pair->second)));
5661
ASSERT_EQ(TestClient::eBroadcastBitRunPacketSent,
5762
listener_sp->StartListeningForEvents(
5863
&client, TestClient::eBroadcastBitRunPacketSent));

lldb/unittests/Process/gdb-remote/GDBRemoteCommunicationClientTest.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h"
99
#include "GDBRemoteTestUtils.h"
1010
#include "lldb/Core/ModuleSpec.h"
11+
#include "lldb/Host/ConnectionFileDescriptor.h"
1112
#include "lldb/Host/XML.h"
1213
#include "lldb/Target/MemoryRegionInfo.h"
1314
#include "lldb/Utility/DataBuffer.h"
@@ -63,8 +64,12 @@ std::string one_register_hex = "41424344";
6364
class GDBRemoteCommunicationClientTest : public GDBRemoteTest {
6465
public:
6566
void SetUp() override {
66-
ASSERT_THAT_ERROR(GDBRemoteCommunication::ConnectLocally(client, server),
67-
llvm::Succeeded());
67+
llvm::Expected<Socket::Pair> pair = Socket::CreatePair();
68+
ASSERT_THAT_EXPECTED(pair, llvm::Succeeded());
69+
client.SetConnection(
70+
std::make_unique<ConnectionFileDescriptor>(std::move(pair->first)));
71+
server.SetConnection(
72+
std::make_unique<ConnectionFileDescriptor>(std::move(pair->second)));
6873
}
6974

7075
protected:

lldb/unittests/Process/gdb-remote/GDBRemoteCommunicationTest.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66
//
77
//===----------------------------------------------------------------------===//
8+
89
#include "GDBRemoteTestUtils.h"
10+
#include "lldb/Host/ConnectionFileDescriptor.h"
911
#include "llvm/Testing/Support/Error.h"
1012

1113
using namespace lldb_private::process_gdb_remote;
@@ -28,8 +30,12 @@ class TestClient : public GDBRemoteCommunication {
2830
class GDBRemoteCommunicationTest : public GDBRemoteTest {
2931
public:
3032
void SetUp() override {
31-
ASSERT_THAT_ERROR(GDBRemoteCommunication::ConnectLocally(client, server),
32-
llvm::Succeeded());
33+
llvm::Expected<Socket::Pair> pair = Socket::CreatePair();
34+
ASSERT_THAT_EXPECTED(pair, llvm::Succeeded());
35+
client.SetConnection(
36+
std::make_unique<ConnectionFileDescriptor>(std::move(pair->first)));
37+
server.SetConnection(
38+
std::make_unique<ConnectionFileDescriptor>(std::move(pair->second)));
3339
}
3440

3541
protected:

lldb/unittests/tools/lldb-server/tests/TestClient.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,8 @@ TestClient::launchCustom(StringRef Log, bool disable_stdio,
125125
listen_socket.Accept(2 * GetDefaultTimeout(), accept_socket)
126126
.takeError())
127127
return E;
128-
auto Conn = std::make_unique<ConnectionFileDescriptor>(accept_socket);
128+
auto Conn = std::make_unique<ConnectionFileDescriptor>(
129+
std::unique_ptr<Socket>(accept_socket));
129130
auto Client = std::unique_ptr<TestClient>(new TestClient(std::move(Conn)));
130131

131132
if (Error E = Client->initializeConnection())

0 commit comments

Comments
 (0)