================ @@ -301,13 +294,35 @@ int main_platform(int argc, char *argv[]) { exit(socket_error); } printf("Connection established.\n"); + if (g_server) { // Collect child zombie processes. #if !defined(_WIN32) - while (waitpid(-1, nullptr, WNOHANG) > 0) - ; + ::pid_t waitResult; + while ((waitResult = waitpid(-1, nullptr, WNOHANG)) > 0) { + // waitResult is the child pid + gdbserver_portmap.FreePortForProcess(waitResult); + } #endif - if (fork()) { + // TODO: Clean up portmap for Windows when children die + + // After collecting zombie ports, get the next available + GDBRemoteCommunicationServerPlatform::PortMap portmap_for_child; + llvm::Expected<uint16_t> available_port = + gdbserver_portmap.GetNextAvailablePort(); + if (available_port) + portmap_for_child.AllowPort(*available_port); + else { + fprintf(stderr, + "no available gdbserver port for connection - dropping...\n"); ---------------- DavidSpickett wrote:
The else path needs to consume the error from llvm::Expected<uint16_t> otherwise when the Expected destructs we'll get an assertion failure. https://github.com/llvm/llvm-project/pull/88845 _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits