[Lldb-commits] [lldb] [lldb] Fixed the error `unable to launch a GDB server` in API tests (PR #98833)
via lldb-commits
lldb-commits at lists.llvm.org
Sun Jul 14 12:45:03 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-lldb
Author: Dmitry Vasilyev (slydiman)
<details>
<summary>Changes</summary>
TestPlatformLaunchGDBServer.py runs ldb-server w/o parameters `--min-gdbserver-port`, `--max-gdbserver-port` or `--gdbserver-port`. So `gdbserver_portmap` is empty and `gdbserver_portmap.GetNextAvailablePort()` will return 0. Do not pass 0 to `portmap_for_child` in this case. Added few asserts in `GDBRemoteCommunicationServerPlatform::PortMap` to avoid such issue in the future.
This patch fixes #<!-- -->97537.
It seems StartDebugserverProcess() ignores the port anyway and parameters `--min-gdbserver-port`, `--max-gdbserver-port` and `--gdbserver-port` are useless at all, but it is out of scope of this patch.
---
Full diff: https://github.com/llvm/llvm-project/pull/98833.diff
2 Files Affected:
- (modified) lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp (+2)
- (modified) lldb/tools/lldb-server/lldb-platform.cpp (+6-4)
``````````diff
diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp
index 5285ec1d3db4e..65f1cc12ba307 100644
--- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp
@@ -46,11 +46,13 @@ using namespace lldb_private;
GDBRemoteCommunicationServerPlatform::PortMap::PortMap(uint16_t min_port,
uint16_t max_port) {
+ assert(min_port);
for (; min_port < max_port; ++min_port)
m_port_map[min_port] = LLDB_INVALID_PROCESS_ID;
}
void GDBRemoteCommunicationServerPlatform::PortMap::AllowPort(uint16_t port) {
+ assert(port);
// Do not modify existing mappings
m_port_map.insert({port, LLDB_INVALID_PROCESS_ID});
}
diff --git a/lldb/tools/lldb-server/lldb-platform.cpp b/lldb/tools/lldb-server/lldb-platform.cpp
index cfd0a3797d810..7148a1d2a3094 100644
--- a/lldb/tools/lldb-server/lldb-platform.cpp
+++ b/lldb/tools/lldb-server/lldb-platform.cpp
@@ -313,9 +313,11 @@ int main_platform(int argc, char *argv[]) {
GDBRemoteCommunicationServerPlatform::PortMap portmap_for_child;
llvm::Expected<uint16_t> available_port =
gdbserver_portmap.GetNextAvailablePort();
- if (available_port)
- portmap_for_child.AllowPort(*available_port);
- else {
+ if (available_port) {
+ // GetNextAvailablePort() may return 0 if gdbserver_portmap is empty.
+ if (*available_port)
+ portmap_for_child.AllowPort(*available_port);
+ } else {
llvm::consumeError(available_port.takeError());
fprintf(stderr,
"no available gdbserver port for connection - dropping...\n");
@@ -352,7 +354,7 @@ int main_platform(int argc, char *argv[]) {
if (platform.IsConnected()) {
if (inferior_arguments.GetArgumentCount() > 0) {
lldb::pid_t pid = LLDB_INVALID_PROCESS_ID;
- std::optional<uint16_t> port = 0;
+ std::optional<uint16_t> port;
std::string socket_name;
Status error = platform.LaunchGDBServer(inferior_arguments,
"", // hostname
``````````
</details>
https://github.com/llvm/llvm-project/pull/98833
More information about the lldb-commits
mailing list