[Lldb-commits] [lldb] [lldb] Have lldb-server assign ports to children in platform mode (PR #88845)
Anthony Ha via lldb-commits
lldb-commits at lists.llvm.org
Tue Apr 16 17:49:33 PDT 2024
================
@@ -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 {
----------------
Awfa wrote:
In the else branch, the connection to the platform will just be dropped, and an error printed to stderr.
This is a recoverable error in the sense that when a child platform process dies, a port will become available again - so it's desirable not to crash `lldb-server`.
https://github.com/llvm/llvm-project/pull/88845
More information about the lldb-commits
mailing list