Skip to content

Commit 1268fa3

Browse files
committed
[lldb] Removed gdbserver ports map from lldb-server
Listen to gdbserver-port, accept the connection and run lldb-server gdbserver --fd on all platforms. Parameters --min-gdbserver-port and --max-gdbserver-port are deprecated now. This is the part 2 of llvm#101283. Depends on llvm#106955. Fixes llvm#97537, fixes llvm#101475.
1 parent ba52a09 commit 1268fa3

24 files changed

+1043
-1304
lines changed

lldb/docs/man/lldb-server.rst

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -147,15 +147,8 @@ GDB-SERVER CONNECTIONS
147147

148148
.. option:: --gdbserver-port <port>
149149

150-
Define a port to be used for gdb-server connections. Can be specified multiple
151-
times to allow multiple ports. Has no effect if --min-gdbserver-port
152-
and --max-gdbserver-port are specified.
153-
154-
.. option:: --min-gdbserver-port <port>
155-
.. option:: --max-gdbserver-port <port>
156-
157-
Specify the range of ports that can be used for gdb-server connections. Both
158-
options need to be specified simultaneously. Overrides --gdbserver-port.
150+
Define a port to be used for gdb-server connections. This port is used for
151+
multiple connections.
159152

160153
.. option:: --port-offset <offset>
161154

lldb/docs/resources/qemu-testing.rst

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -149,30 +149,21 @@ to the host (refer to QEMU's manuals for the specific options).
149149
* At least one to connect to the intial ``lldb-server``.
150150
* One more if you want to use ``lldb-server`` in ``platform mode``, and have it
151151
start a ``gdbserver`` instance for you.
152-
* A bunch more if you want to run tests against the ``lldb-server`` platform.
153152

154153
If you are doing either of the latter 2 you should also restrict what ports
155154
``lldb-server tries`` to use, otherwise it will randomly pick one that is almost
156155
certainly not forwarded. An example of this is shown below.
157156

158157
::
159158

160-
$ lldb-server plaform --server --listen 0.0.0.0:54321 \
161-
--min-gdbserver-port 49140 --max-gdbserver-port 49150
159+
$ lldb-server plaform --server --listen 0.0.0.0:54321 --gdbserver-port 49140
162160

163161
The result of this is that:
164162

165163
* ``lldb-server`` platform mode listens externally on port ``54321``.
166164

167-
* When it is asked to start a new gdbserver mode instance, it will use a port
168-
in the range ``49140`` to ``49150``.
165+
* When it is asked to start a new gdbserver mode instance, it will use the port
166+
``49140``.
169167

170-
Your VM configuration should have ports ``54321``, and ``49140`` to ``49150``
171-
forwarded for this to work.
172-
173-
.. note::
174-
These options are used to create a "port map" within ``lldb-server``.
175-
Unfortunately this map is not cleaned up on Windows on connection close,
176-
and across a few uses you may run out of valid ports. To work around this,
177-
restart the platform every so often, especially after running a set of tests.
178-
This is tracked here: https://github.com/llvm/llvm-project/issues/90923
168+
Your VM configuration should have ports ``54321`` and ``49140`` forwarded for
169+
this to work.
Lines changed: 71 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,71 @@
1-
//===-- TCPSocket.h ---------------------------------------------*- C++ -*-===//
2-
//
3-
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4-
// See https://llvm.org/LICENSE.txt for license information.
5-
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6-
//
7-
//===----------------------------------------------------------------------===//
8-
9-
#ifndef LLDB_HOST_COMMON_TCPSOCKET_H
10-
#define LLDB_HOST_COMMON_TCPSOCKET_H
11-
12-
#include "lldb/Host/Socket.h"
13-
#include "lldb/Host/SocketAddress.h"
14-
#include <map>
15-
16-
namespace lldb_private {
17-
class TCPSocket : public Socket {
18-
public:
19-
TCPSocket(bool should_close, bool child_processes_inherit);
20-
TCPSocket(NativeSocket socket, bool should_close,
21-
bool child_processes_inherit);
22-
~TCPSocket() override;
23-
24-
// returns port number or 0 if error
25-
uint16_t GetLocalPortNumber() const;
26-
27-
// returns ip address string or empty string if error
28-
std::string GetLocalIPAddress() const;
29-
30-
// must be connected
31-
// returns port number or 0 if error
32-
uint16_t GetRemotePortNumber() const;
33-
34-
// must be connected
35-
// returns ip address string or empty string if error
36-
std::string GetRemoteIPAddress() const;
37-
38-
int SetOptionNoDelay();
39-
int SetOptionReuseAddress();
40-
41-
Status Connect(llvm::StringRef name) override;
42-
Status Listen(llvm::StringRef name, int backlog) override;
43-
Status Accept(Socket *&conn_socket) override;
44-
45-
Status CreateSocket(int domain);
46-
47-
bool IsValid() const override;
48-
49-
std::string GetRemoteConnectionURI() const override;
50-
51-
private:
52-
TCPSocket(NativeSocket socket, const TCPSocket &listen_socket);
53-
54-
void CloseListenSockets();
55-
56-
std::map<int, SocketAddress> m_listen_sockets;
57-
};
58-
}
59-
60-
#endif // LLDB_HOST_COMMON_TCPSOCKET_H
1+
//===-- TCPSocket.h ---------------------------------------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLDB_HOST_COMMON_TCPSOCKET_H
10+
#define LLDB_HOST_COMMON_TCPSOCKET_H
11+
12+
#include "lldb/Host/MainLoopBase.h"
13+
#include "lldb/Host/Socket.h"
14+
#include "lldb/Host/SocketAddress.h"
15+
#include <map>
16+
17+
namespace lldb_private {
18+
class TCPSocket : public Socket {
19+
public:
20+
TCPSocket(bool should_close, bool child_processes_inherit);
21+
TCPSocket(NativeSocket socket, bool should_close,
22+
bool child_processes_inherit);
23+
~TCPSocket() override;
24+
25+
// returns port number or 0 if error
26+
uint16_t GetLocalPortNumber() const;
27+
28+
// returns ip address string or empty string if error
29+
std::string GetLocalIPAddress() const;
30+
31+
// must be connected
32+
// returns port number or 0 if error
33+
uint16_t GetRemotePortNumber() const;
34+
35+
// must be connected
36+
// returns ip address string or empty string if error
37+
std::string GetRemoteIPAddress() const;
38+
39+
int SetOptionNoDelay();
40+
int SetOptionReuseAddress();
41+
42+
Status Connect(llvm::StringRef name) override;
43+
Status Listen(llvm::StringRef name, int backlog) override;
44+
45+
// Use the provided main loop instance to accept new connections. The callback
46+
// will be called (from MainLoop::Run) for each new connection. This function
47+
// does not block.
48+
llvm::Expected<std::vector<MainLoopBase::ReadHandleUP>>
49+
Accept(MainLoopBase &loop,
50+
std::function<void(std::unique_ptr<TCPSocket> socket)> sock_cb);
51+
52+
// Accept a single connection and "return" it in the pointer argument. This
53+
// function blocks until the connection arrives.
54+
Status Accept(Socket *&conn_socket) override;
55+
56+
Status CreateSocket(int domain);
57+
58+
bool IsValid() const override;
59+
60+
std::string GetRemoteConnectionURI() const override;
61+
62+
private:
63+
TCPSocket(NativeSocket socket, const TCPSocket &listen_socket);
64+
65+
void CloseListenSockets();
66+
67+
std::map<int, SocketAddress> m_listen_sockets;
68+
};
69+
} // namespace lldb_private
70+
71+
#endif // LLDB_HOST_COMMON_TCPSOCKET_H

0 commit comments

Comments
 (0)