[Lldb-commits] [lldb] b61b8ef - [lldb] [gdb-remote] Fix process ID after following forked child

Michał Górny via lldb-commits lldb-commits at lists.llvm.org
Thu Jul 21 08:11:50 PDT 2022


Author: Michał Górny
Date: 2022-07-21T17:11:38+02:00
New Revision: b61b8efcf31b3d53377b9cf6cb3eb87742602ff6

URL: https://github.com/llvm/llvm-project/commit/b61b8efcf31b3d53377b9cf6cb3eb87742602ff6
DIFF: https://github.com/llvm/llvm-project/commit/b61b8efcf31b3d53377b9cf6cb3eb87742602ff6.diff

LOG: [lldb] [gdb-remote] Fix process ID after following forked child

Update the process ID after handling fork/vfork to ensure that
the process plugin reports the correct PID immediately.

Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.llvm.org/D130037

Added: 
    

Modified: 
    lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
    lldb/test/API/functionalities/gdb_remote_client/TestFork.py

Removed: 
    


################################################################################
diff  --git a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
index fe6a3f9ed6c19..5f18706f67e5d 100644
--- a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
@@ -5307,8 +5307,11 @@ void ProcessGDBRemote::DidFork(lldb::pid_t child_pid, lldb::tid_t child_tid) {
 
   // Hardware breakpoints/watchpoints are not inherited implicitly,
   // so we need to readd them if we're following child.
-  if (GetFollowForkMode() == eFollowChild)
+  if (GetFollowForkMode() == eFollowChild) {
     DidForkSwitchHardwareTraps(true);
+    // Update our PID
+    SetID(child_pid);
+  }
 }
 
 void ProcessGDBRemote::DidVFork(lldb::pid_t child_pid, lldb::tid_t child_tid) {
@@ -5361,6 +5364,11 @@ void ProcessGDBRemote::DidVFork(lldb::pid_t child_pid, lldb::tid_t child_tid) {
                 error.AsCString() ? error.AsCString() : "<unknown error>");
       return;
   }
+
+  if (GetFollowForkMode() == eFollowChild) {
+    // Update our PID
+    SetID(child_pid);
+  }
 }
 
 void ProcessGDBRemote::DidVForkDone() {

diff  --git a/lldb/test/API/functionalities/gdb_remote_client/TestFork.py b/lldb/test/API/functionalities/gdb_remote_client/TestFork.py
index 79fa520fe22dd..bf66f25a55186 100644
--- a/lldb/test/API/functionalities/gdb_remote_client/TestFork.py
+++ b/lldb/test/API/functionalities/gdb_remote_client/TestFork.py
@@ -9,7 +9,7 @@
 
 class TestMultiprocess(GDBRemoteTestBase):
 
-    def base_test(self, variant):
+    def base_test(self, variant, follow_child=False):
         class MyResponder(MockGDBServerResponder):
             def __init__(self):
                 super().__init__()
@@ -43,12 +43,24 @@ def D(self, packet):
           self.runCmd("log enable gdb-remote packets")
           self.addTearDownHook(
                 lambda: self.runCmd("log disable gdb-remote packets"))
+        if follow_child:
+            self.runCmd("settings set target.process.follow-fork-mode child")
         process = self.connect(target)
+        self.assertEqual(process.GetProcessID(), 1024)
         process.Continue()
-        self.assertRegex(self.server.responder.detached, r"D;0*401")
+        self.assertRegex(self.server.responder.detached,
+                         r"D;0*400" if follow_child else r"D;0*401")
+        self.assertEqual(process.GetProcessID(),
+                         1025 if follow_child else 1024)
 
     def test_fork(self):
         self.base_test("fork")
 
     def test_vfork(self):
         self.base_test("vfork")
+
+    def test_fork_follow_child(self):
+        self.base_test("fork", follow_child=True)
+
+    def test_vfork_follow_child(self):
+        self.base_test("vfork", follow_child=True)


        


More information about the lldb-commits mailing list