[Lldb-commits] [lldb] Fix lldb crash while handling concurrent vfork() (PR #81564)

Greg Clayton via lldb-commits lldb-commits at lists.llvm.org
Fri Feb 23 09:57:28 PST 2024


================
@@ -0,0 +1,70 @@
+#include <iostream>
+#include <mutex>
+#include <sys/wait.h>
+#include <thread>
+#include <unistd.h>
+#include <vector>
+
+pid_t g_pid = 0;
+std::mutex g_child_pids_mutex;
+std::vector<pid_t> g_child_pids;
+
+int call_vfork(int index) {
+  pid_t child_pid = vfork();
+
+  if (child_pid == -1) {
+    // Error handling
+    perror("vfork");
+    return 1;
+  } else if (child_pid == 0) {
+    // This code is executed by the child process
+    g_pid = getpid();
+    printf("Child process: %d\n", g_pid);
----------------
clayborg wrote:

Add code to call `exec*()` here:
```
if (call_exec)
  execl(exec_path, exec_path, NULL); // Call this program through exec() with no args.
else
  _exit(index + 10); // Exit the child process
```

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


More information about the lldb-commits mailing list