<div dir="ltr">If I do that my process does stop at main, but I think I'm hit with a race condition.  3 times out of 5 I saw the same results as you, where it doesn't print the backtrace but if I do bt it works fine.  The other 2 times out of 5 It does print the backtrace, but then I'm deadlocked.  I added a bunch of tracepoints so we can see the order of events.  here's what it looks like when it deadlocks.<div><div><br></div><div><div>Target::Launch about to call ProcessWindows::Launch</div><div>ProcessWindows::DoLaunch entering</div><div>ProcessWindows::DoLaunch about to call DebugLaunch</div><div>ProcessWindows::DoLaunch succeeded, waiting for initial stop</div><div>Application "\??\D:\src\llvm\tools\lldb\test\expression_command\formatters\a.out" found in cache</div><div><span style="line-height:1.5;font-size:13.1999998092651px">ProcessWindows::OnDebuggerConnected</span><br></div><div><span style="line-height:1.5;font-size:13.1999998092651px">ProcessWindows::OnDebugException</span><br></div><div>ProcessWindows got EXCEPTION_BREAKPOINT</div><div>ProcessWindows got initial stop, setting initial stop event</div><div>ProcessWindows::DoLaunch received initial stop, returning</div><div>ProcessWindows::DoLaunch finished launching process, exiting</div><div>Target::Launch returned from ProcessWindows::DoLaunch, eLaunchFlagStopAtEntry == false, about to call WaitForProcessToStop</div><div>Target::Launch, WaitForProcessToStop returned, new state = eStateStopped</div><div>Target::Launch about to call ProcessWindows::PrivateResume</div><div>ProcessWindows::DoResume resuming from active exception</div><div>ProcessWindows::DoResume couldn't find an active exception, setting state to eStateRunning</div><div><span style="line-height:1.5;font-size:13.1999998092651px">ProcessWindows::OnDebugException</span><br></div><div>ProcessWindows got EXCEPTION_BREAKPOINT</div><div>Target::Launch synchronous_execution is true, calling WaitForProcessToStop again</div></div><div><br></div><div>The interesting stuff is the last 2 lines.  It hits the breakpoint in main *before* calling WaitForProcessToStop, so WaitForProcessToStop never sees a "change".  </div></div><div><br></div><div>Here's what it looks like when it works.</div><div><br></div><div><div>Target::Launch about to call ProcessWindows::Launch</div><div>ProcessWindows::DoLaunch entering</div><div>ProcessWindows::DoLaunch about to call DebugLaunch</div><div>ProcessWindows::DoLaunch succeeded, waiting for initial stop</div><div>Application "\??\D:\src\llvm\tools\lldb\test\expression_command\formatters\a.out" found in cache</div><div><span style="line-height:1.5;font-size:13.1999998092651px">ProcessWindows::OnDebuggerConnected</span><br></div><div><span style="line-height:1.5;font-size:13.1999998092651px">ProcessWindows::OnDebugException</span><br></div><div>ProcessWindows got EXCEPTION_BREAKPOINT</div><div>ProcessWindows got initial stop, setting initial stop event</div><div>ProcessWindows::DoLaunch received initial stop, returning</div><div>ProcessWindows::DoLaunch finished launching process, exiting</div><div>ProcessWindows breakpoint handler set private state to eStateStopped</div><div>Target::Launch returned from ProcessWindows::DoLaunch, eLaunchFlagStopAtEntry == false, about to call WaitForProcessToStop</div><div>Target::Launch, WaitForProcessToStop returned, new state = eStateStopped</div><div>Target::Launch about to call ProcessWindows::PrivateResume</div><div>ProcessWindows::DoResume resuming from active exception</div><div>ProcessWindows::DoResume couldn't find an active exception, nothing to resume</div><div><span style="line-height:1.5;font-size:13.1999998092651px">ProcessWindows::OnDebugException</span><br></div><div>ProcessWindows got EXCEPTION_BREAKPOINT</div><div>Target::Launch synchronous_execution is true, calling WaitForProcessToStop again</div><div>ProcessWindows breakpoint handler set private state to eStateStopped</div><div>Target::Launch WaitForProcessToStop returned, yay!</div></div><div><br></div><div><br></div><div>The difference here is that "calling WaitForProcessToStop again" happens before the process plugin sets the private state.   Can you try repeating your test multiple times and seeing if you can get the deadlock to occur?</div><div><br></div></div><br><div class="gmail_quote">On Fri, Mar 20, 2015 at 4:49 PM <<a href="mailto:jingham@apple.com">jingham@apple.com</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I'm not sure it is deadlocking the debugger.  lldb is just waiting for a stop.  For instance ^C should interrupt it, or sending a signal externally to the process, or triggering a breakpoint or crash, etc.<br>
<br>
Actually, Greg must have fixed the bug I was remembering, because this works correctly for me with TOT lldb.<br>
<br>
What happens for you if your .lldbinit has:<br>
<br>
file a.out<br>
break set -n main<br>
run<br>
<br>
For me this stops at the breakpoint at main.  We still have a little clean up to do here, because I don't see the stop notification in this case.  I see:<br>
<br>
 > lldb -S cmds.lldb<br>
(lldb) command source -s 1 'cmds.lldb'<br>
4 locations added to breakpoint 1<br>
(lldb)<br>
<br>
but if I then do "bt" I'm sitting at main:<br>
<br>
(lldb) bt<br>
* thread #1: tid = 0x1bf8a4, function: main , stop reason = breakpoint 1.1<br>
  * frame #0: 0x0000000100018e87 Sketch`main at SKTMain.m:17<br>
    frame #1: 0x00007fff94f445ad libdyld.dylib`start<br>
    frame #2: 0x00007fff94f445ad libdyld.dylib`start<br>
<br>
Not sure what's up with the stutter at start either.  But that's a different rabbit to chase...<br>
<br>
Jim<br>
<br>
<br>
> On Mar 20, 2015, at 4:40 PM, Zachary Turner <<a href="mailto:zturner@google.com" target="_blank">zturner@google.com</a>> wrote:<br>
><br>
> If that's the case, then a .lldbinit file like this:<br>
><br>
> file a.out<br>
> run<br>
><br>
> Will deadlock the debugger, because the real stop never comes?<br>
><br>
> On Fri, Mar 20, 2015 at 4:35 PM <<a href="mailto:jingham@apple.com" target="_blank">jingham@apple.com</a>> wrote:<br>
> That's the stop at entry stop.  The code you quoted is in a block that starts with:<br>
><br>
>         if (launch_info.GetFlags().Test(<u></u>eLaunchFlagStopAtEntry) == false)<br>
>         {<br>
><br>
> So we've stopped at the entry point, but the user didn't want to know about that, so we resume and wait for a "real" stop.<br>
><br>
> Jim<br>
><br>
><br>
> > On Mar 20, 2015, at 4:30 PM, Zachary Turner <<a href="mailto:zturner@google.com" target="_blank">zturner@google.com</a>> wrote:<br>
> ><br>
> > I'm a little confused.  You said that in synchronous execution, Launch won't return until the process has stopped.  That makes sense, but it already checks that the process has stopped once regardless of whether synchronous execution is set.  Then, it calls PrivateResume() (even if synchronous_execution is set), and then waits for the process to stop again?  What would trigger this second stop?  Target::Launch already asked it to resume, so now it's happily running while Target::Launch is waiting for it to stop a second time.<br>
> ><br>
> > On Fri, Mar 20, 2015 at 4:23 PM <<a href="mailto:jingham@apple.com" target="_blank">jingham@apple.com</a>> wrote:<br>
> > In synchronous execution, the "Launch" command won't return till the process has stopped.  The point of synchronous execution is that you can do:<br>
> ><br>
> > break set -n foo<br>
> > run<br>
> > bt<br>
> ><br>
> > So "run" can't return till the breakpoint has been hit.  That is why it waits for the process to stop.  I'm not quite sure why this is done in Target::Launch, in other cases (e.g. in for "step" and "continue" the command object is the one that takes care of waiting for the stop.  Launch is a little funny however, because it can't use the normal process wait mechanism to do its job since the real process isn't alive when it has to start waiting...<br>
> ><br>
> > I think the reason you are hanging here is that the code that reads in all the init statements runs an event loop temporarily while it is reading them in, and the kills that and hands off the the real command execution loop, and this continuation gets lost in the handoff.  I thought Greg had already fixed that, but maybe it's still sitting in his queue.<br>
> ><br>
> > Jim<br>
> ><br>
> ><br>
> ><br>
> ><br>
> > > On Mar 20, 2015, at 3:57 PM, Zachary Turner <<a href="mailto:zturner@google.com" target="_blank">zturner@google.com</a>> wrote:<br>
> > ><br>
> > > I ran into an issue earlier where I tried to make a .lldbinit file with some lines like this:<br>
> > ><br>
> > > file a.out<br>
> > > run<br>
> > ><br>
> > ><br>
> > > When this happens the process runs, the breakpoint gets hit and I see the source listing, it returns to the lldb prompt, but then I can't type anything.  It appears LLDB is deadlocked inside of Target::Launch() at the following location:<br>
> > ><br>
> > >                 if (!synchronous_execution)<br>
> > >                     m_process_sp-><u></u>RestoreProcessEvents ();<br>
> > ><br>
> > >                 error = m_process_sp->PrivateResume();<br>
> > ><br>
> > >                 if (error.Success())<br>
> > >                 {<br>
> > >                     // there is a race condition where this thread will return up the call stack to the main command<br>
> > >                     // handler and show an (lldb) prompt before HandlePrivateEvent (from PrivateStateThread) has<br>
> > >                     // a chance to call PushProcessIOHandler()<br>
> > >                     m_process_sp->SyncIOHandler(<u></u>2000);<br>
> > ><br>
> > >                     if (synchronous_execution)<br>
> > >                     {<br>
> > ><br>
> > > state = m_process_sp-><u></u>WaitForProcessToStop (NULL, NULL, true, hijack_listener_sp.get(), stream);<br>
> > >                         const bool must_be_alive = false; // eStateExited is ok, so this must be false<br>
> > >                         if (!StateIsStoppedState(state, must_be_alive))<br>
> > >                         {<br>
> > >                             error.<u></u>SetErrorStringWithFormat("<u></u>process isn't stopped: %s", StateAsCString(state));<br>
> > >                         }<br>
> > >                     }<br>
> > >                 }<br>
> > ><br>
> > > Normally when I'm using LLDB and entering the commands myself, this synchronous_execution value is not set, and everything works as expected.  How is this supposed to work?  What does my plugin need to do differently in order to handle this case?  The process has already stopped once and resumed, so I'm not sure why it would need to stop again?  I see that it's not restoring process events in the case of synchronous execution, so maybe it should have never resumed in the first place? ______________________________<u></u>_________________<br>
> > > lldb-dev mailing list<br>
> > > <a href="mailto:lldb-dev@cs.uiuc.edu" target="_blank">lldb-dev@cs.uiuc.edu</a><br>
> > > <a href="http://lists.cs.uiuc.edu/mailman/listinfo/lldb-dev" target="_blank">http://lists.cs.uiuc.edu/<u></u>mailman/listinfo/lldb-dev</a><br>
> ><br>
><br>
<br>
</blockquote></div>