<div dir="ltr"><div>Hi,</div><div><br></div><div>I am revising our lldb automation tests into async mode. However, I found it randomly crashes depends on timing. And the crash happens mostly while launching lldb twice in a row. I have narrowed down the code into a simple repro below. Any assumption I made wrong with the LLDB API here?</div><div><br></div><div>The crash stack seems to be not consistently. In the small repro below, the crash stack is:</div><div><div>Crashed Thread:        0  Dispatch queue: com.apple.main-thread</div><div><br></div><div>Exception Type:        EXC_BAD_ACCESS (SIGSEGV)</div><div>Exception Codes:       EXC_I386_GPFLT</div><div><br></div><div>Thread 0 Crashed:: Dispatch queue: com.apple.main-thread</div><div>0   _lldb.so                      <span class="" style="white-space:pre">   </span>0x00000001088c7179 EventMatcher::operator()(std::__1::shared_ptr<lldb_private::Event> const&) const + 21</div><div>1   _lldb.so                      <span class="" style="white-space:pre">   </span>0x00000001088c65d2 lldb_private::Listener::FindNextEventInternal(lldb_private::Broadcaster*, lldb_private::ConstString const*, unsigned int, unsigned int, std::__1::shared_ptr<lldb_private::Event>&, bool) + 176</div><div>2   _lldb.so                      <span class="" style="white-space:pre"> </span>0x00000001088c6952 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>&) + 134</div><div>3   _lldb.so                      <span class="" style="white-space:pre">       </span>0x00000001088c6ae9 lldb_private::Listener::WaitForEventForBroadcasterWithType(lldb_private::TimeValue const*, lldb_private::Broadcaster*, unsigned int, std::__1::shared_ptr<lldb_private::Event>&) + 27</div><div>4   _lldb.so                      <span class="" style="white-space:pre">   </span>0x0000000108abce6c lldb_private::Process::WaitForStateChangedEvents(lldb_private::TimeValue const*, std::__1::shared_ptr<lldb_private::Event>&, lldb_private::Listener*) + 112</div><div>5   _lldb.so                      <span class="" style="white-space:pre">     </span>0x0000000108abcc95 lldb_private::Process::WaitForProcessToStop(lldb_private::TimeValue const*, std::__1::shared_ptr<lldb_private::Event>*, bool, lldb_private::Listener*, lldb_private::Stream*) + 377</div><div>6   _lldb.so                      <span class="" style="white-space:pre"> </span>0x0000000108ac516a lldb_private::Process::HaltForDestroyOrDetach(std::__1::shared_ptr<lldb_private::Event>&) + 216</div><div>7   _lldb.so                      <span class="" style="white-space:pre"> </span>0x0000000108abc8b0 lldb_private::Process::Destroy(bool) + 146</div><div>8   _lldb.so                      <span class="" style="white-space:pre">        </span>0x0000000108abc56d lldb_private::Process::Finalize() + 91</div><div>9   _lldb.so                      <span class="" style="white-space:pre">    </span>0x00000001088b63c4 lldb_private::Debugger::Clear() + 148</div><div>10  _lldb.so                      <span class="" style="white-space:pre">     </span>0x00000001088b61fd lldb_private::Debugger::Destroy(std::__1::shared_ptr<lldb_private::Debugger>&) + 37</div><div>11  _lldb.so                      <span class="" style="white-space:pre">     </span>0x0000000106bdb144 lldb::SBDebugger::Destroy(lldb::SBDebugger&) + 116</div><div>12  _lldb.so                      <span class="" style="white-space:pre">    </span>0x0000000106c23daf _wrap_SBDebugger_Destroy(_object*, _object*) + 120</div><div>13  org.python.python             <span class="" style="white-space:pre">     </span>0x00000001058dd75f PyEval_EvalFrameEx + 12761</div></div><div><br></div><div>while in the real unit test it is crashing at:</div><div><div>Thread 12 Crashed:</div><div>0   libsystem_kernel.dylib        <span class="" style="white-space:pre"> </span>0x00007fff8635a286 __pthread_kill + 10</div><div>1   libsystem_c.dylib             <span class="" style="white-space:pre">    </span>0x00007fff919409b3 abort + 129</div><div>2   libc++abi.dylib               <span class="" style="white-space:pre">   </span>0x00007fff8a94ea21 abort_message + 257</div><div>3   libc++abi.dylib               <span class="" style="white-space:pre">   </span>0x00007fff8a9769d1 default_terminate_handler() + 267</div><div>4   libobjc.A.dylib               <span class="" style="white-space:pre">     </span>0x00007fff935e77eb _objc_terminate() + 124</div><div>5   libc++abi.dylib               <span class="" style="white-space:pre">       </span>0x00007fff8a9740a1 std::__terminate(void (*)()) + 8</div><div>6   libc++abi.dylib               <span class="" style="white-space:pre">      </span>0x00007fff8a973b30 __cxa_throw + 121</div><div>7   com.apple.LLDB.framework      <span class="" style="white-space:pre"> </span>0x000000010b994c6b std::__1::shared_ptr<lldb_private::Process>::shared_ptr<lldb_private::Process>(std::__1::weak_ptr<lldb_private::Process> const&, std::__1::enable_if<is_convertible<lldb_private::Process*, lldb_private::Process*>::value, std::__1::shared_ptr<lldb_private::Process>::__nat>::type) + 99</div><div>8   com.apple.LLDB.framework      <span class="" style="white-space:pre">       </span>0x000000010b8ac762 lldb_private::Process::AppendSTDOUT(char const*, unsigned long) + 86</div><div>9   com.apple.LLDB.framework      <span class="" style="white-space:pre">      </span>0x000000010b6951d7 lldb_private::Communication::ReadThread(void*) + 287</div><div>10  libsystem_pthread.dylib       <span class="" style="white-space:pre">      </span>0x00007fff8d92c05a _pthread_body + 131</div><div>11  libsystem_pthread.dylib       <span class="" style="white-space:pre">       </span>0x00007fff8d92bfd7 _pthread_start + 176</div></div><div><br></div><div><br></div><div>================Repro Code====================</div><div><br></div><div>def wait_for_process_stop(process):</div><div>    while not process.is_stopped:</div><div>        time.sleep(0.1)</div><div><br></div><div>def launch_debugging(debugger, stop_at_entry):</div><div>    error = lldb.SBError()</div><div>    listener = lldb.SBListener('Chrome Dev Tools Listener')</div><div>    target = debugger.GetSelectedTarget()</div><div>    process = target.Launch (listener,</div><div>                    None,      # argv</div><div>                    None,      # envp</div><div>                    None,      # stdin_path</div><div>                    None,      # stdout_path</div><div>                    None,      # stderr_path</div><div>                    None,      # working directory</div><div>                    0,         # launch flags</div><div>                    stop_at_entry,      # Stop at entry</div><div>                    error)     # error</div><div>    print 'Launch result: %s' % str(error)</div><div>    event_thread = LLDBListenerThread(debugger)</div><div>    event_thread.start()</div><div>    return process</div><div><br></div><div>def do_test():</div><div>    debugger = lldb.SBDebugger.Create()</div><div>    debugger.SetAsync(True)</div><div>    target = debugger.CreateTargetWithFileAndArch(executable_path, lldb.LLDB_ARCH_DEFAULT)</div><div><br></div><div>    process = launch_debugging(debugger, stop_at_entry=True)</div><div><br></div><div>    wait_for_process_stop(process) # wait for entry breakpoint.</div><div>    target.BreakpointCreateByName('main')</div><div>    process.Continue()</div><div>    wait_for_process_stop(process) # wait for main breakpoint.</div><div>    lldb.SBDebugger.Destroy(debugger)</div><div><br></div><div>def main():</div><div>    do_test()</div><div>    do_test()</div></div>