================ @@ -301,13 +294,31 @@ int main_platform(int argc, char *argv[]) { exit(socket_error); } printf("Connection established.\n"); + + std::optional<uint16_t> port = 0; if (g_server) { // Collect child zombie processes. #if !defined(_WIN32) - while (waitpid(-1, nullptr, WNOHANG) > 0) - ; + auto waitResult = waitpid(-1, nullptr, WNOHANG); + while (waitResult > 0) { + // waitResult is the child pid + gdbserver_portmap.FreePortForProcess(waitResult); + waitResult = waitpid(-1, nullptr, WNOHANG); + } #endif - if (fork()) { + llvm::Expected<uint16_t> available_port = + gdbserver_portmap.GetNextAvailablePort(); + if (available_port) + port = *available_port; + + else { ---------------- DavidSpickett wrote:
This needs to do something with the failed expected otherwise there'll be an error at runtime. See `GDBRemoteCommunicationServerPlatform::LaunchGDBServer`. I think you can just do `llvm::consumeError(port.takeError())` here. That runtime error may need asserts to be enabled, pass `-DLLVM_ENABLE_ASSERTIONS=True` to cmake. 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