[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


================
@@ -5681,7 +5685,10 @@ void ProcessGDBRemote::DidVForkDone() {
 void ProcessGDBRemote::DidExec() {
   // If we are following children, vfork is finished by exec (rather than
   // vforkdone that is submitted for parent).
-  if (GetFollowForkMode() == eFollowChild)
-    m_vfork_in_progress = false;
+  if (GetFollowForkMode() == eFollowChild) {
+    assert(m_vfork_in_progress_count > 0);
+    if (m_vfork_in_progress_count > 0)
+      --m_vfork_in_progress_count;
----------------
clayborg wrote:

We need to verify this is needed here. Usually someone does a `fork()` or `vfork()` and then they do an `exec*()` call (there are many different flavors of exec:
```
int execl(const char *path, const char *arg0, ..., /*, (char *)0, */);
int execle(const char *path, const char *arg0, ..., /* (char *)0 char *const envp[] */);
int execlp(const char *file, const char *arg0, ..., /*, (char *)0, */);
int execv(const char *path, char *const argv[]);
int execvp(const char *file, char *const argv[]);
int execvP(const char *file, const char *search_path, char *const argv[]);
```
So we need to verify in our test case that if we do a `fork() + exec*()` or `vfork() + exec*()` call that we don't run both `ProcessGDBRemote::DidVForkDone()` _and_ `ProcessGDBRemote::DidExec()` because if we do this assertion will fire.


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


More information about the lldb-commits mailing list