[Lldb-commits] [PATCH] D130037: [lldb] [gdb-remote] Fix process ID after following forked child

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


This revision was automatically updated to reflect the committed changes.
Closed by commit rGb61b8efcf31b: [lldb] [gdb-remote] Fix process ID after following forked child (authored by mgorny).
Herald added a project: LLDB.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D130037/new/

https://reviews.llvm.org/D130037

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


Index: lldb/test/API/functionalities/gdb_remote_client/TestFork.py
===================================================================
--- lldb/test/API/functionalities/gdb_remote_client/TestFork.py
+++ 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 @@
           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)
Index: lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
===================================================================
--- lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
+++ lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
@@ -5307,8 +5307,11 @@
 
   // 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 @@
                 error.AsCString() ? error.AsCString() : "<unknown error>");
       return;
   }
+
+  if (GetFollowForkMode() == eFollowChild) {
+    // Update our PID
+    SetID(child_pid);
+  }
 }
 
 void ProcessGDBRemote::DidVForkDone() {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D130037.446509.patch
Type: text/x-patch
Size: 2507 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20220721/505da122/attachment.bin>


More information about the lldb-commits mailing list