Skip to content

Commit 1799cf9

Browse files
committed
Refactored after llvm#108188.
1 parent 792cb17 commit 1799cf9

File tree

6 files changed

+152
-235
lines changed

6 files changed

+152
-235
lines changed

lldb/docs/man/lldb-server.rst

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,12 +150,6 @@ GDB-SERVER CONNECTIONS
150150
Define a port to be used for gdb-server connections. This port is used for
151151
multiple connections.
152152

153-
.. option:: --port-offset <offset>
154-
155-
Add the specified offset to port numbers returned by server. This is useful
156-
if the server is running behind a firewall, and a range of ports is redirected
157-
to it with an offset.
158-
159153
EXAMPLES
160154
--------
161155

lldb/include/lldb/Host/Socket.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,9 @@ class Socket : public IOObject {
9292
static llvm::Error Initialize();
9393
static void Terminate();
9494

95-
static std::unique_ptr<Socket> Create(const SocketProtocol protocol,
96-
bool child_processes_inherit,
97-
Status &error);
95+
static std::unique_ptr<Socket>
96+
Create(const SocketProtocol protocol, bool child_processes_inherit,
97+
Status &error, NativeSocket sockfd = kInvalidSocketValue);
9898

9999
virtual Status Connect(llvm::StringRef name) = 0;
100100
virtual Status Listen(llvm::StringRef name, int backlog) = 0;
@@ -154,7 +154,7 @@ class Socket : public IOObject {
154154

155155
protected:
156156
Socket(SocketProtocol protocol, bool should_close,
157-
bool m_child_process_inherit);
157+
bool child_processes_inherit);
158158

159159
virtual size_t Send(const void *buf, const size_t num_bytes);
160160

lldb/source/Host/common/Socket.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,30 +215,32 @@ void Socket::Terminate() {
215215

216216
std::unique_ptr<Socket> Socket::Create(const SocketProtocol protocol,
217217
bool child_processes_inherit,
218-
Status &error) {
218+
Status &error, NativeSocket sockfd) {
219219
error.Clear();
220220

221221
std::unique_ptr<Socket> socket_up;
222222
switch (protocol) {
223223
case ProtocolTcp:
224224
socket_up =
225-
std::make_unique<TCPSocket>(true, child_processes_inherit);
225+
std::make_unique<TCPSocket>(sockfd, true, child_processes_inherit);
226226
break;
227227
case ProtocolUdp:
228+
assert(sockfd == kInvalidSocketValue);
228229
socket_up =
229230
std::make_unique<UDPSocket>(true, child_processes_inherit);
230231
break;
231232
case ProtocolUnixDomain:
232233
#if LLDB_ENABLE_POSIX
233234
socket_up =
234-
std::make_unique<DomainSocket>(true, child_processes_inherit);
235+
std::make_unique<DomainSocket>(sockfd, true, child_processes_inherit);
235236
#else
236237
error = Status::FromErrorString(
237238
"Unix domain sockets are not supported on this platform.");
238239
#endif
239240
break;
240241
case ProtocolUnixAbstract:
241242
#ifdef __linux__
243+
assert(sockfd == kInvalidSocketValue);
242244
socket_up =
243245
std::make_unique<AbstractSocket>(child_processes_inherit);
244246
#else

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

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ std::set<lldb::pid_t> GDBRemoteCommunicationServerPlatform::g_spawned_pids;
5151
GDBRemoteCommunicationServerPlatform::GDBRemoteCommunicationServerPlatform(
5252
const Socket::SocketProtocol socket_protocol, uint16_t gdbserver_port)
5353
: GDBRemoteCommunicationServerCommon(), m_socket_protocol(socket_protocol),
54-
m_gdbserver_port(gdbserver_port), m_port_offset(0) {
54+
m_gdbserver_port(gdbserver_port) {
5555

5656
RegisterMemberFunctionHandler(
5757
StringExtractorGDBRemote::eServerPacketType_qC,
@@ -185,8 +185,7 @@ GDBRemoteCommunicationServerPlatform::Handle_qLaunchGDBServer(
185185

186186
StreamGDBRemote response;
187187
uint16_t gdbserver_port = socket_name.empty() ? m_gdbserver_port : 0;
188-
response.Printf("pid:%" PRIu64 ";port:%u;", debugserver_pid,
189-
gdbserver_port + m_port_offset);
188+
response.Printf("pid:%" PRIu64 ";port:%u;", debugserver_pid, gdbserver_port);
190189
if (!socket_name.empty()) {
191190
response.PutCString("socket_name:");
192191
response.PutStringAsRawHex8(socket_name);
@@ -494,10 +493,6 @@ GDBRemoteCommunicationServerPlatform::GetDomainSocketPath(const char *prefix) {
494493
return FileSpec(socket_path.c_str());
495494
}
496495

497-
void GDBRemoteCommunicationServerPlatform::SetPortOffset(uint16_t port_offset) {
498-
m_port_offset = port_offset;
499-
}
500-
501496
void GDBRemoteCommunicationServerPlatform::SetPendingGdbServer(
502497
const std::string &socket_name) {
503498
m_pending_gdb_server_socket_name = socket_name;

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ class GDBRemoteCommunicationServerPlatform
3232

3333
Status LaunchProcess() override;
3434

35-
void SetPortOffset(uint16_t port_offset);
36-
3735
void SetInferiorArguments(const lldb_private::Args &args);
3836

3937
Status LaunchGDBServer(const lldb_private::Args &args, lldb::pid_t &pid,
@@ -47,7 +45,6 @@ class GDBRemoteCommunicationServerPlatform
4745
static std::set<lldb::pid_t> g_spawned_pids;
4846

4947
uint16_t m_gdbserver_port;
50-
uint16_t m_port_offset;
5148
std::optional<std::string> m_pending_gdb_server_socket_name;
5249

5350
PacketResult Handle_qLaunchGDBServer(StringExtractorGDBRemote &packet);

0 commit comments

Comments
 (0)