Invoke lldb against some target e.g. /bin/sleep, set a breakpoint, run, then detach when the breakpoint is hit. The inferior dumps core with SIGTRAP. (LLDB r201577) Typescript: joule% bin/lldb /bin/sleep 60 Current executable set to '/bin/sleep' (x86_64). (lldb) b main Breakpoint 1: where = sleep`main + 20 at sleep.c:75, address = 0x0000000000400964 (lldb) run Process 26485 launching Process 26485 stopped (lldb) Process 26485 launched: '/bin/sleep' (x86_64) Process 26485 stopped * thread #1: tid = 100436, 0x0000000000400964 sleep`main(argc=<unavailable>, argv=0x00007fffffffd730) + 20 at sleep.c:75, stop reason = breakpoint 1.1 frame #0: 0x0000000000400964 sleep`main(argc=<unavailable>, argv=0x00007fffffffd730) + 20 at sleep.c:75 72 if (argc != 2) 73 usage(); 74 -> 75 if (sscanf(argv[1], "%lf%1s", &d, buf) != 1) 76 usage(); 77 if (d > INT_MAX) 78 usage(); (lldb) detach Process 26485 detached (lldb) Detaching from process 26485 (lldb) quit joule% ls sleep.core sleep.core joule% bin/lldb /bin/sleep -c sleep.core Core file '/data/emaste/src/llvm/build/sleep.core' (x86_64) was loaded. Process 0 stopped * thread #1: tid = 0, 0x0000000000400965 sleep`main(argc=<unavailable>, argv=0x00007fffffffd730) + 21 at sleep.c:75, name = 'sleep', stop reason = signal SIGTRAP frame #0: 0x0000000000400965 sleep`main(argc=<unavailable>, argv=0x00007fffffffd730) + 21 at sleep.c:75 72 if (argc != 2) 73 usage(); 74 -> 75 if (sscanf(argv[1], "%lf%1s", &d, buf) != 1) 76 usage(); 77 if (d > INT_MAX) 78 usage(); (lldb)
the breakpoint is not cleaned up upon detach (lldb) log enable lldb break (lldb) log enable freebsd ptrace (lldb) b main Target::CreateBreakpoint (internal = no) => break_id = 1: name = 'main' Added location: 1.1: module = /bin/ls compile unit = ls.c function = main location = /tank/emaste/src/freebsd-stable-9/bin/ls/ls.c:166 address = 0x0000000000403069 resolved = false hit count = 0 Breakpoint 1: where = ls`main + 9 at ls.c:166, address = 0x0000000000403069 (lldb) run ptrace(PT_TRACE_ME, 0, 0x0, 0) called from file ../tools/lldb/source/Plugins/Process/FreeBSD/ProcessMonitor.cpp line 990 Process 50631 launching Target::CreateBreakpoint (internal = yes) => break_id = -1: address = 0x0000000000401dc0 Process::EnableSoftwareBreakpoint (site_id = 1) addr = 0x401dc0 ptrace(PT_IO, 50631, 0x7fffff9fce08, 0) called from file ../tools/lldb/source/Plugins/Process/FreeBSD/ProcessMonitor.cpp line 160 PT_IO: op=READ_D offs=401dc0 size=1 ptrace(PT_IO, 50631, 0x7fffff9fce08, 0) called from file ../tools/lldb/source/Plugins/Process/FreeBSD/ProcessMonitor.cpp line 176 PT_IO: op=WRITE_D offs=401dc0 size=1 ptrace(PT_IO, 50631, 0x7fffff9fce08, 0) called from file ../tools/lldb/source/Plugins/Process/FreeBSD/ProcessMonitor.cpp line 160 PT_IO: op=READ_D offs=401dc0 size=1 Process::EnableSoftwareBreakpoint (site_id = 1) addr = 0x401dc0 -- SUCCESS Process::EnableSoftwareBreakpoint (site_id = 2) addr = 0x403069 ptrace(PT_IO, 50631, 0x7fffff9fce08, 0) called from file ../tools/lldb/source/Plugins/Process/FreeBSD/ProcessMonitor.cpp line 160 PT_IO: op=READ_D offs=403069 size=1 ptrace(PT_IO, 50631, 0x7fffff9fce08, 0) called from file ../tools/lldb/source/Plugins/Process/FreeBSD/ProcessMonitor.cpp line 176 PT_IO: op=WRITE_D offs=403069 size=1 ptrace(PT_IO, 50631, 0x7fffff9fce08, 0) called from file ../tools/lldb/source/Plugins/Process/FreeBSD/ProcessMonitor.cpp line 160 PT_IO: op=READ_D offs=403069 size=1 Process::EnableSoftwareBreakpoint (site_id = 2) addr = 0x403069 -- SUCCESS ... ptrace(PT_GETREGS, 103027, 0x7fffff9fcdd0, 0) called from file ../tools/lldb/source/Plugins/Process/FreeBSD/ProcessMonitor.cpp line 309 PT_GETREGS: ip=0x403069 PT_GETREGS: sp=0x7fffffffd510 PT_GETREGS: bp=0x7fffffffd550 PT_GETREGS: ax=0xffffffffffffffff frame #0: 0x0000000000403069 ls`main(argc=1, argv=0x00007fffffffd578) + 9 at ls.c:166 163 char *bp = tcapbuf; 164 #endif 165 -> 166 (void)setlocale(LC_ALL, ""); 167 168 /* Terminal defaults to -Cq, non-terminal defaults to -1. */ 169 if (isatty(STDOUT_FILENO)) { (lldb) detach ptrace(PT_DETACH, 45195, 0x0, 0) called from file ../tools/lldb/source/Plugins/Process/FreeBSD/ProcessMonitor.cpp line 747 Process 45195 detached (lldb) (lldb) Detaching from process 45195 (lldb)
Initial fix in 201724 There is still an issue when quitting LLDB.
quitting while stopped at a breakpoint looks like this (with log enable freebsd ptrace & lldb process): (lldb) quit Quitting LLDB will kill one or more processes. Do you really want to proceed: [Y/n] y ptrace(PT_IO, 74686, 0x7fffff9fce08, 0) called from file ../tools/lldb/source/Plugins/Process/FreeBSD/ProcessMonitor.cpp line 166 PT_IO: op=READ_D offs=400480 size=1 ptrace(PT_IO, 74686, 0x7fffff9fce08, 0) called from file ../tools/lldb/source/Plugins/Process/FreeBSD/ProcessMonitor.cpp line 182 PT_IO: op=WRITE_D offs=400480 size=1 ptrace(PT_IO, 74686, 0x7fffff9fce08, 0) called from file ../tools/lldb/source/Plugins/Process/FreeBSD/ProcessMonitor.cpp line 166 PT_IO: op=READ_D offs=400480 size=1 ptrace(PT_IO, 74686, 0x7fffff9fce08, 0) called from file ../tools/lldb/source/Plugins/Process/FreeBSD/ProcessMonitor.cpp line 166 PT_IO: op=READ_D offs=4005b0 size=1 ptrace(PT_IO, 74686, 0x7fffff9fce08, 0) called from file ../tools/lldb/source/Plugins/Process/FreeBSD/ProcessMonitor.cpp line 182 PT_IO: op=WRITE_D offs=4005b0 size=1 ptrace(PT_IO, 74686, 0x7fffff9fce08, 0) called from file ../tools/lldb/source/Plugins/Process/FreeBSD/ProcessMonitor.cpp line 166 PT_IO: op=READ_D offs=4005b0 size=1 ptrace(PT_IO, 74686, 0x7fffff9fce08, 0) called from file ../tools/lldb/source/Plugins/Process/FreeBSD/ProcessMonitor.cpp line 166 PT_IO: op=READ_D offs=800602d20 size=1 ptrace(PT_IO, 74686, 0x7fffff9fce08, 0) called from file ../tools/lldb/source/Plugins/Process/FreeBSD/ProcessMonitor.cpp line 182 PT_IO: op=WRITE_D offs=800602d20 size=1 ptrace(PT_IO, 74686, 0x7fffff9fce08, 0) called from file ../tools/lldb/source/Plugins/Process/FreeBSD/ProcessMonitor.cpp line 166 PT_IO: op=READ_D offs=800602d20 size=1 Process::SetPrivateState (exited) Process::SetPrivateState (exited) stop_id = 5 Process::ControlPrivateStateThread (signal = 1) Sending control event of type: 1. Process::ShouldBroadcastEvent (0x808cdee20) => new state: exited, last broadcast state: exited - YES Process::HandlePrivateEvent (pid = 74686) broadcasting new state exited (old state stopped) to public Process::RunPrivateStateThread (arg = 0x808aed500, pid = 74686) about to exit with internal state exited... Process::RunPrivateStateThread (arg = 0x808aed500, pid = 74686) thread exiting... The control event killed the private state thread without having to cancel. <pause here for a moment> Went to stop the private state thread, but it was already invalid.
It seems ProcessPOSIX::DoDestroy is incomplete; this PoC patch addresses the aborting debugees and the delayed quit: --- a/source/Plugins/Process/POSIX/ProcessPOSIX.cpp +++ b/source/Plugins/Process/POSIX/ProcessPOSIX.cpp @@ -351,6 +351,8 @@ ProcessPOSIX::DoDestroy() return error; } + error = m_monitor->Detach(GetID()); + SetPrivateState(eStateExited); } After this there are two new failures, related to "process kill": test_state_after_continue_with_dwarf (TestThreadStates.ThreadStateTestCase) test_state_after_expression_with_dwarf (TestThreadStates.ThreadStateTestCase) Need to determine exactly what is appropriate for DoDestroy.
Change committed to FreeBSD in http://svnweb.freebsd.org/changeset/base/263678
Committed in r205315 and r205337