Skip to content

Commit 13eb5b3

Browse files
committed
[lldb] [llgs] Add a test for detach-all packet
Add a test verifying that plain 'D' packet correctly detaches all processes. Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.llvm.org/D127291
1 parent 313d9c1 commit 13eb5b3

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3375,6 +3375,7 @@ GDBRemoteCommunicationServerLLGS::Handle_vRun(
33753375

33763376
GDBRemoteCommunication::PacketResult
33773377
GDBRemoteCommunicationServerLLGS::Handle_D(StringExtractorGDBRemote &packet) {
3378+
Log *log = GetLog(LLDBLog::Process);
33783379
StopSTDIOForwarding();
33793380

33803381
lldb::pid_t pid = LLDB_INVALID_PROCESS_ID;
@@ -3398,6 +3399,9 @@ GDBRemoteCommunicationServerLLGS::Handle_D(StringExtractorGDBRemote &packet) {
33983399
for (auto it = m_debugged_processes.begin();
33993400
it != m_debugged_processes.end();) {
34003401
if (pid == LLDB_INVALID_PROCESS_ID || pid == it->first) {
3402+
LLDB_LOGF(log,
3403+
"GDBRemoteCommunicationServerLLGS::%s detaching %" PRId64,
3404+
__FUNCTION__, it->first);
34013405
if (llvm::Error e = it->second->Detach().ToError())
34023406
detach_error = llvm::joinErrors(std::move(detach_error), std::move(e));
34033407
else {

lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,3 +222,43 @@ def test_detach_current(self):
222222
"send packet: $E44#00",
223223
], True)
224224
self.expect_gdbremote_sequence()
225+
226+
@add_test_categories(["fork"])
227+
def test_detach_all(self):
228+
self.build()
229+
self.prep_debug_monitor_and_inferior(inferior_args=["fork"])
230+
self.add_qSupported_packets(["multiprocess+",
231+
"fork-events+"])
232+
ret = self.expect_gdbremote_sequence()
233+
self.assertIn("fork-events+", ret["qSupported_response"])
234+
self.reset_test_sequence()
235+
236+
# continue and expect fork
237+
self.test_sequence.add_log_lines([
238+
"read packet: $c#00",
239+
{"direction": "send", "regex": self.fork_regex.format("fork"),
240+
"capture": self.fork_capture},
241+
], True)
242+
ret = self.expect_gdbremote_sequence()
243+
parent_pid = ret["parent_pid"]
244+
parent_tid = ret["parent_tid"]
245+
child_pid = ret["child_pid"]
246+
child_tid = ret["child_tid"]
247+
self.reset_test_sequence()
248+
249+
self.test_sequence.add_log_lines([
250+
# double-check our PIDs
251+
"read packet: $Hgp{}.{}#00".format(parent_pid, parent_tid),
252+
"send packet: $OK#00",
253+
"read packet: $Hgp{}.{}#00".format(child_pid, child_tid),
254+
"send packet: $OK#00",
255+
# detach all processes
256+
"read packet: $D#00",
257+
"send packet: $OK#00",
258+
# verify that both PIDs are invalid now
259+
"read packet: $Hgp{}.{}#00".format(parent_pid, parent_tid),
260+
"send packet: $Eff#00",
261+
"read packet: $Hgp{}.{}#00".format(child_pid, child_tid),
262+
"send packet: $Eff#00",
263+
], True)
264+
self.expect_gdbremote_sequence()

0 commit comments

Comments
 (0)