[Lldb-commits] [lldb] [lldb] Have lldb-server assign ports to children in platform mode (PR #88845)
David Spickett via lldb-commits
lldb-commits at lists.llvm.org
Thu Apr 18 01:52:05 PDT 2024
================
@@ -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:
llvm::consumeError can do this iirc.
https://github.com/llvm/llvm-project/pull/88845
More information about the lldb-commits
mailing list