mgorny created this revision.
mgorny added reviewers: labath, krytarowski, emaste, jingham.
Herald added a subscriber: arichardson.
Herald added a project: All.
mgorny requested review of this revision.
Update the process ID after handling fork/vfork to ensure that
the process plugin reports the correct PID immediately.
Sponsored by: The FreeBSD Foundation
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
@@ -5319,8 +5319,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) {
@@ -5373,6 +5376,11 @@
error.AsCString() ? error.AsCString() : "<unknown error>");
return;
}
+
+ if (GetFollowForkMode() == eFollowChild) {
+ // Update our PID
+ SetID(child_pid);
+ }
}
void ProcessGDBRemote::DidVForkDone() {
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
@@ -5319,8 +5319,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) {
@@ -5373,6 +5376,11 @@
error.AsCString() ? error.AsCString() : "<unknown error>");
return;
}
+
+ if (GetFollowForkMode() == eFollowChild) {
+ // Update our PID
+ SetID(child_pid);
+ }
}
void ProcessGDBRemote::DidVForkDone() {
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits