This patch fixes lldb core crash in Listener waiting for process ended and operates with already invalid data if lldb-mi requested process destroy in -exec-abort command handler without getting process stopped at first.
To avoid crash in existing code MI user should do process stop explicitly:
-exec-interrupt
-exec-abort
After investigation it was revealed what cause was in Process::HaltForDestroyOrDetach() - WaitForProcessToStop() used improperly - without hijacked listener created. Default listener argument is NULL (see WaitForProcessToStop default params). So initial workaround patch in lldb-MI module -exec-abort handler not needed anymore with patched Target\Process.cpp:
-exec-run .... -exec-abort ^done (gdb) =thread-exited,id="1",group-id="i1" =thread-exited,id="2",group-id="i1" =thread-exited,id="3",group-id="i1" =thread-exited,id="4",group-id="i1" =thread-exited,id="5",group-id="i1" =thread-exited,id="6",group-id="i1" (gdb) (gdb) =thread-exited,id="1",group-id="i1" =thread-group-exited,id="i1",exit-code="0" *stopped,reason="exited-normally" (gdb) -gdb-exit ^exit =thread-group-exited,id="i1" (gdb)
Backtrace corresponding to crash if process running and MI user invoked -exec-abort without getting target stop:
Process: lldb-mi-3.8.0 [13039] Path: /Users/USER/*/lldb-mi-3.8.0 Identifier: lldb-mi-3.8.0 Version: 0 Code Type: X86-64 (Native) Parent Process: ??? [13038] Responsible: lldb-mi-3.8.0 [13039] User ID: 501 Date/Time: 2015-07-24 15:08:07.807 +0300 OS Version: Mac OS X 10.11 (15A226f) Report Version: 11 Time Awake Since Boot: 170000 seconds Crashed Thread: 0 Dispatch queue: com.apple.main-thread Exception Type: EXC_BAD_ACCESS (SIGSEGV) Exception Codes: KERN_INVALID_ADDRESS at 0x0000008200000092 Exception Note: EXC_CORPSE_NOTIFY VM Regions Near 0x8200000092: Process Corpse Info 0000000135abc000-0000000135cbc000 [ 2048K] rw-/rwx SM=COW --> STACK GUARD 0000700000000000-0000700000001000 [ 4K] ---/rwx SM=NUL stack guard for thread 1 Thread 0 Crashed:: Dispatch queue: com.apple.main-thread 0 liblldb.3.8.0.dylib 0x0000000104b952d4 EventMatcher::operator()(std::__1::shared_ptr<lldb_private::Event> const&) const + 52 (memory:3954) 1 liblldb.3.8.0.dylib 0x0000000104b90dc4 lldb_private::Listener::FindNextEventInternal(lldb_private::Broadcaster*, lldb_private::ConstString const*, unsigned int, unsigned int, std::__1::shared_ptr<lldb_private::Event>&, bool) + 1188 (algorithm:878) 2 liblldb.3.8.0.dylib 0x0000000104b9173a lldb_private::Listener::GetNextEventInternal(lldb_private::Broadcaster*, lldb_private::ConstString const*, unsigned int, unsigned int, std::__1::shared_ptr<lldb_private::Event>&) + 74 (Listener.cpp:373) 3 liblldb.3.8.0.dylib 0x0000000104b91a5b lldb_private::Listener::WaitForEventsInternal(lldb_private::TimeValue const*, lldb_private::Broadcaster*, lldb_private::ConstString const*, unsigned int, unsigned int, std::__1::shared_ptr<lldb_private::Event>&) + 571 (Listener.cpp:419) 4 liblldb.3.8.0.dylib 0x0000000104b91ee3 lldb_private::Listener::WaitForEventForBroadcasterWithType(lldb_private::TimeValue const*, lldb_private::Broadcaster*, unsigned int, std::__1::shared_ptr<lldb_private::Event>&) + 83 (Listener.cpp:469) 5 liblldb.3.8.0.dylib 0x0000000104f8391a lldb_private::Process::WaitForStateChangedEvents(lldb_private::TimeValue const*, std::__1::shared_ptr<lldb_private::Event>&, lldb_private::Listener*) + 202 (Process.cpp:1328) 6 liblldb.3.8.0.dylib 0x0000000104f834cc lldb_private::Process::WaitForProcessToStop(lldb_private::TimeValue const*, std::__1::shared_ptr<lldb_private::Event>*, bool, lldb_private::Listener*, lldb_private::Stream*) + 908 (Process.cpp:1012) 7 liblldb.3.8.0.dylib 0x0000000104f93acd lldb_private::Process::HaltForDestroyOrDetach(std::__1::shared_ptr<lldb_private::Event>&) + 333 (Process.cpp:3936) 8 liblldb.3.8.0.dylib 0x0000000104f820e2 lldb_private::Process::Destroy(bool) + 322 (Process.cpp:4060) 9 liblldb.3.8.0.dylib 0x00000001031e9e49 lldb::SBProcess::Destroy() + 169 (SBProcess.cpp:793) 10 lldb-mi-3.8.0 0x0000000102f89539 CMICmdCmdExecAbort::Execute() + 777 (MICmdCmdExec.cpp:1249) 11 lldb-mi-3.8.0 0x0000000102f898cc non-virtual thunk to CMICmdCmdExecAbort::Execute() + 28 (MICmdCmdExec.cpp:1239) 12 lldb-mi-3.8.0 0x0000000102fcec0f CMICmdInvoker::CmdExecute(CMICmdBase&) + 255 (MICmdInvoker.cpp:204) 13 lldb-mi-3.8.0 0x0000000102fd3b55 CMICmdMgr::CmdExecute(SMICmdData const&) + 805 (MICmdMgr.cpp:199) 14 lldb-mi-3.8.0 0x0000000103023326 CMIDriver::ExecuteCommand(SMICmdData const&) + 38 (MIDriver.cpp:990) 15 lldb-mi-3.8.0 0x00000001030212ea CMIDriver::InterpretCommandThisDriver(CMIUtilString const&, bool&) + 234 (MIDriver.cpp:942) 16 lldb-mi-3.8.0 0x00000001030208ee CMIDriver::InterpretCommand(CMIUtilString const&) + 62 (MIDriver.cpp:828) 17 lldb-mi-3.8.0 0x000000010301f7c7 CMIDriver::DoMainLoop() + 1431 (MIDriver.cpp:575) 18 lldb-mi-3.8.0 0x00000001030209cc non-virtual thunk to CMIDriver::DoMainLoop() + 28 (MIDriver.cpp:526) 19 lldb-mi-3.8.0 0x000000010302e094 CMIDriverMgr::DriverMainLoop() + 68 (MIDriverMgr.cpp:294) 20 lldb-mi-3.8.0 0x000000010302bf9d main + 237 (MIDriverMain.cpp:174) 21 libdyld.dylib 0x00007fff8d93a5ad start + 1 ...