[Lldb-commits] [lldb] [lldb] Removed gdbserver ports map from lldb-server (PR #104238)

Dmitry Vasilyev via lldb-commits lldb-commits at lists.llvm.org
Fri Sep 6 06:12:07 PDT 2024


================
@@ -150,12 +153,17 @@ static void client_handle(GDBRemoteCommunicationServerPlatform &platform,
   printf("Disconnected.\n");
 }
 
-static GDBRemoteCommunicationServerPlatform::PortMap gdbserver_portmap;
-static std::mutex gdbserver_portmap_mutex;
-
 static void spawn_process_reaped(lldb::pid_t pid, int signal, int status) {
-  std::lock_guard<std::mutex> guard(gdbserver_portmap_mutex);
-  gdbserver_portmap.FreePortForProcess(pid);
+  if (g_single_pid != LLDB_INVALID_PROCESS_ID && g_single_pid == pid) {
+    // If not running as a server and the platform connection is closed
+    if (!g_terminate) {
+      g_terminate = true;
----------------
slydiman wrote:

The child monitor callback is used in 2 places:

* lldb-platform.cpp: In case of non-server mode we need to exit after disconnecting (when the child process handling the platform connection exited). In theory we should be in the middle of MainLoop except the case when an assert happened somewhere. So access g_main_loop is safe here. But the safest way is to use a terminate flag and a dummy connection instead of accesing g_main_loop. We can pass a reference to MainLoop as a callback argument but it changes nothing. A global variable is much clear here.

* The child process handling the platform connection uses the single instance of GDBRemoteCommunicationServerPlatform, which uses a list of PIDs g_spawned_pids. This process will exit after disconnecting and the child process monitor callback is most dangerous point. Any processes may exit at any time. We need the PIDs list only for Handle_qKillSpawnedProcess response. It would be better to try to kill the process anyway and just check somehow that this PID is still alive. I think the best solution here is the static g_spawned_pids. Any other solutions are out the scope of this patch.

https://github.com/llvm/llvm-project/pull/104238


More information about the lldb-commits mailing list