This patch fixes -gdb-exit for locally target. It includes the following changes:
- Fix Process::Finalize
- Use SBProcess::Destroy in -gdb-exit
Differential D8298
Fix -gdb-exit to detach if was attached or destroy otherwise (MI) ki.stfu on Mar 12 2015, 9:43 AM. Authored by
Details This patch fixes -gdb-exit for locally target. It includes the following changes:
Diff Detail Event TimelineComment Actions We should not add SBProcess::GetShouldDetach() and we should fix the Process::DoDestroy() functions to all look at the Process::GetShouldDetach() and each instance should do the right thing (detach or kill) based on that setting. This isn't something we should pass out of the API. See inlined comments above.
Comment Actions Process::Finalize() only gets called when the lldb_private::Process destructor is called. We should do similar logic in lldb_private::Process::Destroy(). Currently Process::Destroy() calls the virtual WillDestrory(), DoDestroy() and DidDestroy(), but we should probably fix Process::Destroy() to do more generic logic and check the GetShouldDetach() and call Process::Detach() first before calling the subclass DoDestroy()... Comment Actions Call Process::Detach from Process::Destroy if needed I'm not sure about this patch and I think it isn't ready. As I understood Detach() detaches without cleanup, Halt() kills a target without cleanup, but Destroy() detaches or kills a target (according to GetShouldDetach()) and performs a cleanup after that. Therefore I think Destroy should be like following: Destroy() { if (GetShouldDetach()) Detach(); else Halt(); CleanupObject(); } Comment Actions Remove the switch statement as mentioned in inline comments and we are good to go.
Comment Actions Hello @clayborg, I added the switch() back in Process::Finalize() in r233258, because it caused an error: $ bin/lldb (lldb) target create ~/p/hello Current executable set to '~/p/hello' (x86_64). (lldb) r Assertion failed: (!"bad_weak_ptr"), function shared_ptr, file /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/memory, line 5174. Abort trap: 6 backtrace: $ lldb bin/lldb -- ~/p/hello (lldb) target create "bin/lldb" Current executable set to 'bin/lldb' (x86_64). (lldb) settings set -- target.run-args "/Users/IliaK/p/hello" (lldb) r Process 50068 launched: '/Users/IliaK/p/llvm/build_ninja/bin/lldb' (x86_64) Process 50068 stopped * thread #1: tid = 0xbfd4c, 0x00007fff5fc0d28e, stop reason = signal SIGSTOP frame #0: 0x00007fff5fc0d28e -> 0x7fff5fc0d28e: pushq %rbp 0x7fff5fc0d28f: movq %rsp, %rbp 0x7fff5fc0d292: popq %rbp 0x7fff5fc0d293: retq (lldb) c Process 50068 resuming (lldb) target create "/Users/IliaK/p/hello" Current executable set to '/Users/IliaK/p/hello' (x86_64). (lldb) r Assertion failed: (!"bad_weak_ptr"), function shared_ptr, file /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/memory, line 5174. Process 50068 stopped * thread #1: tid = 0xbfd4c, 0x00007fff9b42f286 libsystem_kernel.dylib`__pthread_kill + 10, queue = 'com.apple.main-thread', stop reason = signal SIGABRT frame #0: 0x00007fff9b42f286 libsystem_kernel.dylib`__pthread_kill + 10 libsystem_kernel.dylib`__pthread_kill + 10: -> 0x7fff9b42f286: jae 0x7fff9b42f290 ; __pthread_kill + 20 0x7fff9b42f288: movq %rax, %rdi 0x7fff9b42f28b: jmp 0x7fff9b42ac53 ; cerror_nocancel 0x7fff9b42f290: retq (lldb) bt * thread #1: tid = 0xbfd4c, 0x00007fff9b42f286 libsystem_kernel.dylib`__pthread_kill + 10, queue = 'com.apple.main-thread', stop reason = signal SIGABRT * frame #0: 0x00007fff9b42f286 libsystem_kernel.dylib`__pthread_kill + 10 frame #1: 0x00007fff8f28c42f libsystem_pthread.dylib`pthread_kill + 90 frame #2: 0x00000001014f3d9b liblldb.3.7.0.dylib`raise(sig=6) + 27 at Signals.inc:524 frame #3: 0x00000001014f3e52 liblldb.3.7.0.dylib`abort + 18 at Signals.inc:541 frame #4: 0x00000001014f3e31 liblldb.3.7.0.dylib`__assert_rtn(func=0x0000000103c4e976, file=0x0000000103c4e981, line=5174, expr=0x0000000103c4e9f1) + 129 at Signals.inc:537 frame #5: 0x000000010002d3c3 liblldb.3.7.0.dylib`std::__1::shared_ptr<lldb_private::Process>::shared_ptr<lldb_private::Process>(this=0x00007fff5fbf9ec8, __r=0x0000000109293220, (null)=(__for_bool_ = 0)) + 163 at memory:5174 frame #6: 0x000000010002d313 liblldb.3.7.0.dylib`std::__1::shared_ptr<lldb_private::Process>::shared_ptr<lldb_private::Process>(this=0x00007fff5fbf9ec8, __r=0x0000000109293220, (null)=(__for_bool_ = 0)) + 35 at memory:5176 frame #7: 0x0000000101bd3121 liblldb.3.7.0.dylib`lldb_private::Process::SetPrivateState(lldb::StateType) [inlined] std::__1::enable_shared_from_this<lldb_private::Process>::shared_from_this(this=0x0000000109293220) + 51 at memory:5240 frame #8: 0x0000000101bd30ee liblldb.3.7.0.dylib`lldb_private::Process::SetPrivateState(this=0x0000000109293200, new_state=eStateDetached) + 862 at Process.cpp:1785 frame #9: 0x0000000101fe7266 liblldb.3.7.0.dylib`ProcessKDP::DoDetach(this=0x0000000109293200, keep_stopped=false) + 342 at ProcessKDP.cpp:663 frame #10: 0x0000000101fe7390 liblldb.3.7.0.dylib`ProcessKDP::DoDestroy(this=0x0000000109293200) + 48 at ProcessKDP.cpp:675 frame #11: 0x0000000101bce7a3 liblldb.3.7.0.dylib`lldb_private::Process::Destroy(this=0x0000000109293200) + 419 at Process.cpp:3959 frame #12: 0x0000000101bcdb86 liblldb.3.7.0.dylib`lldb_private::Process::Finalize(this=0x0000000109293200) + 54 at Process.cpp:826 frame #13: 0x0000000101fe4e3a liblldb.3.7.0.dylib`ProcessKDP::~ProcessKDP(this=0x0000000109293200) + 106 at ProcessKDP.cpp:203 frame #14: 0x0000000101fe4f05 liblldb.3.7.0.dylib`ProcessKDP::~ProcessKDP(this=0x0000000109293200) + 21 at ProcessKDP.cpp:197 frame #15: 0x0000000101fe4fb9 liblldb.3.7.0.dylib`ProcessKDP::~ProcessKDP(this=0x0000000109293200) + 25 at ProcessKDP.cpp:197 frame #16: 0x0000000101feaa0c liblldb.3.7.0.dylib`std::__1::__shared_ptr_pointer<ProcessKDP*, std::__1::default_delete<ProcessKDP>, std::__1::allocator<ProcessKDP> >::__on_zero_shared() [inlined] std::__1::default_delete<ProcessKDP>::operator(this=0x000000010aa626a8, this=0x000000010aa626a8, this=0x000000010aa626a8, this=0x000000010aa626a8, this=0x000000010aa626a8, __ptr=0x0000000109293200)(ProcessKDP*) const + 156 at memory:2426 frame #17: 0x0000000101fea9e1 liblldb.3.7.0.dylib`std::__1::__shared_ptr_pointer<ProcessKDP*, std::__1::default_delete<ProcessKDP>, std::__1::allocator<ProcessKDP> >::__on_zero_shared(this=0x000000010aa62690) + 113 at memory:3669 frame #18: 0x00007fff9797e8a6 libc++.1.dylib`std::__1::__shared_weak_count::__release_shared() + 44 frame #19: 0x000000010002d2df liblldb.3.7.0.dylib`std::__1::shared_ptr<lldb_private::Process>::~shared_ptr(this=0x00007fff5fbfa948) + 47 at memory:4448 frame #20: 0x000000010002bf15 liblldb.3.7.0.dylib`std::__1::shared_ptr<lldb_private::Process>::~shared_ptr(this=0x00007fff5fbfa948) + 21 at memory:4446 frame #21: 0x0000000101bcb7fa liblldb.3.7.0.dylib`lldb_private::Process::FindPlugin(lldb_private::Target&, char const*, lldb_private::Listener&, lldb_private::FileSpec const*) [inlined] std::__1::shared_ptr<lldb_private::Process>::reset(this=0x00007fff5fbfab88) + 2378 at memory:4577 frame #22: 0x0000000101bcb6de liblldb.3.7.0.dylib`lldb_private::Process::FindPlugin(target=0x0000000109820e00, plugin_name=0x0000000000000000, listener=0x000000010903d278, crash_file_path=0x0000000000000000) + 2094 at Process.cpp:679 frame #23: 0x0000000101c3b56e liblldb.3.7.0.dylib`lldb_private::Target::CreateProcess(this=0x0000000109820e00, listener=0x000000010903d278, plugin_name=0x0000000000000000, crash_file=0x0000000000000000) + 142 at Target.cpp:206 frame #24: 0x0000000101e8473d liblldb.3.7.0.dylib`PlatformPOSIX::Attach(this=0x000000010881b640, attach_info=0x00007fff5fbfb270, debugger=0x000000010903d000, target=0x0000000109820e00, error=0x00007fff5fbfbd68) + 1325 at PlatformPOSIX.cpp:785 frame #25: 0x0000000101bbc204 liblldb.3.7.0.dylib`lldb_private::Platform::DebugProcess(this=0x000000010881b640, launch_info=0x00000001088abc28, debugger=0x000000010903d000, target=0x0000000109820e00, error=0x00007fff5fbfbd68) + 644 at Platform.cpp:1289 frame #26: 0x0000000101e84fe4 liblldb.3.7.0.dylib`PlatformPOSIX::DebugProcess(this=0x000000010881b640, launch_info=0x00000001088abc28, debugger=0x000000010903d000, target=0x0000000109820e00, error=0x00007fff5fbfbd68) + 244 at PlatformPOSIX.cpp:827 frame #27: 0x0000000101c4bae1 liblldb.3.7.0.dylib`lldb_private::Target::Launch(this=0x0000000109820e00, launch_info=0x00000001088abc28, stream=0x00007fff5fbfbd88) + 1953 at Target.cpp:2560 frame #28: 0x00000001015ba7dd liblldb.3.7.0.dylib`CommandObjectProcessLaunch::DoExecute(this=0x00000001088abab0, launch_args=0x00007fff5fbfc038, result=0x00007fff5fbfed20) + 1357 at CommandObjectProcess.cpp:263 frame #29: 0x0000000101a06e99 liblldb.3.7.0.dylib`lldb_private::CommandObjectParsed::Execute(this=0x00000001088abab0, args_string=0x00007fff5fbfc891, result=0x00007fff5fbfed20) + 537 at CommandObject.cpp:1081 frame #30: 0x00000001019dd82e liblldb.3.7.0.dylib`lldb_private::CommandInterpreter::HandleCommand(this=0x00000001088a11e0, command_line=0x00007fff5fbfeec9, lazy_add_to_history=eLazyBoolCalculate, result=0x00007fff5fbfed20, override_context=0x0000000000000000, repeat_on_empty_command=true, no_context_switching=false) + 23358 at CommandInterpreter.cpp:1966 frame #31: 0x00000001019e7409 liblldb.3.7.0.dylib`lldb_private::CommandInterpreter::IOHandlerInputComplete(this=0x00000001088a11e0, io_handler=0x0000000108d03370, line=0x00007fff5fbfeec8) + 1161 at CommandInterpreter.cpp:3151 frame #32: 0x00000001019e7ac7 liblldb.3.7.0.dylib`non-virtual thunk to lldb_private::CommandInterpreter::IOHandlerInputComplete(this=0x00000001088a12b0, io_handler=0x0000000108d03370, line=0x00007fff5fbfeec8) + 55 at CommandInterpreter.cpp:3230 frame #33: 0x00000001017d8a67 liblldb.3.7.0.dylib`lldb_private::IOHandlerEditline::Run(this=0x0000000108d03370) + 1575 at IOHandler.cpp:729 frame #34: 0x000000010179266e liblldb.3.7.0.dylib`lldb_private::Debugger::ExecuteIOHandlers(this=0x000000010903d000) + 142 at Debugger.cpp:920 frame #35: 0x00000001019e8567 liblldb.3.7.0.dylib`lldb_private::CommandInterpreter::RunCommandInterpreter(this=0x00000001088a11e0, auto_handle_events=true, spawn_thread=false, options=0x00007fff5fbff210) + 199 at CommandInterpreter.cpp:3388 frame #36: 0x0000000100048809 liblldb.3.7.0.dylib`lldb::SBDebugger::RunCommandInterpreter(this=0x00007fff5fbff9f8, auto_handle_events=true, spawn_thread=false) + 137 at SBDebugger.cpp:975 frame #37: 0x0000000100008abe lldb`Driver::MainLoop(this=0x00007fff5fbff9d8) + 5502 at Driver.cpp:1152 frame #38: 0x0000000100009077 lldb`main(argc=2, argv=0x00007fff5fbffb20, envp=0x00007fff5fbffb38) + 359 at Driver.cpp:1252 frame #39: 0x00007fff94f3b5c9 libdyld.dylib`start + 1 (lldb) quit Quitting LLDB will kill one or more processes. Do you really want to proceed: [Y/n] y Thanks, |
This switch is no longer needed, just replace with: