Skip to content

[lldb] Fixed the error unable to launch a GDB server in API tests #98833

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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});
}
Expand Down
10 changes: 6 additions & 4 deletions lldb/tools/lldb-server/lldb-platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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
Expand Down
Loading