diff --git a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp --- a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp +++ b/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() : ""); 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 --- 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 @@ 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)