[lldb] Error when there are no ports to launch a gdbserver on
authorDavid Spickett <david.spickett@linaro.org>
Tue, 17 Nov 2020 15:41:04 +0000 (15:41 +0000)
committerDavid Spickett <david.spickett@linaro.org>
Mon, 30 Nov 2020 10:19:14 +0000 (10:19 +0000)
commit98e87f76d0f486122d76b334232102e0d7a9254d
treefe51f71ff83bb0eb70c2a79110dad74382c2bc96
parentb5fbc60e4de45f2b56331281a706b78ff52bd286
[lldb] Error when there are no ports to launch a gdbserver on

Previously if you did:
$ lldb-server platform --server <...> --min-gdbserver-port 12346
--max-gdbserver-port 12347
(meaning only use port 12346 for gdbservers)

Then tried to launch two gdbservers on the same connection,
the second one would return port 65535. Which is a real port
number but it actually means lldb-server didn't find one it was
allowed to use.

send packet: $qLaunchGDBServer;<...>
read packet: $pid:1919;port:12346;#c0
<...>
send packet: $qLaunchGDBServer;<...>
read packet: $pid:1927;port:65535;#c7

This situation should be an error even if port 65535 does happen
to be available on the current machine.

To fix this make PortMap it's own class within
GDBRemoteCommunicationServerPlatform.

This almost the same as the old typedef but for
GetNextAvailablePort() returning an llvm::Expected.
This means we have to handle not finding a port,
by returning an error packet.

Also add unit tests for this new PortMap class.

Reviewed By: labath

Differential Revision: https://reviews.llvm.org/D91634
lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.h
lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp
lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.h
lldb/tools/lldb-server/lldb-platform.cpp
lldb/unittests/Process/gdb-remote/CMakeLists.txt
lldb/unittests/Process/gdb-remote/PortMapTest.cpp [new file with mode: 0644]