<div dir="ltr">It's not that it relies on a specific thread being selected, because as you can see there are 2 threads in that trace. The problem is that the second frame is not even yet in the main function, it's in the startup code because of how early the attach process happens (which itsels is probably actually racy, since attach is user-initiated and might happen before or after main function has entered. But the test checks for main.c as the source file of the second frame, so this si where the probelm lies.</div><br><div class="gmail_quote"><div dir="ltr">On Thu, Aug 27, 2015 at 1:41 AM Pavel Labath <<a href="mailto:labath@google.com">labath@google.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">The main issue I see with all these APIs is that they are<br>
non-blocking. That is, the test executable cannot simply say "wait<br>
until a debugger attaches", but it will have to do something like:<br>
while (! attached) {<br>
sleep(X);<br>
attached = figure_out_if_i_am_attached_using_architecture_specific_methods();<br>
}<br>
<br>
This does not sound to me like it will be significantly more stable<br>
then the currently used method:<br>
while (! attached) sleep(X);<br>
where the debugger flips the variable after it attaches.<br>
<br>
However, I would definitely welcome providing a default implementation<br>
of wait_for_debugger_attach() (regardless of how it is implemented),<br>
which all tests can use, instead of each one rolling out its own.<br>
<br>
<br>
Another possible implementation would be to use some standard IPC<br>
mechanism (pipes, signals, sockets, ...) for waking up the inferior<br>
once the debugger is ready. The test inferior could e.g., wait on a<br>
pipe and the debugger will write a single byte there once it attaches.<br>
Since we control both the test runner and the test inferior, this is<br>
enough and you don't need any fancy APIs. The tricky part here would<br>
be to make sure this works during remote debugging.<br>
<br>
<br>
That said, I don't think the current issues with the attach tests are<br>
caused by this problem. The current protocol, however awkard it may<br>
be, should still work IMO, but we are still seeing flakyness in all<br>
tests that do attaches. I think we have some other issues here and I<br>
am suspecting races in other parts of the system. I was planning to<br>
take a look at these soon...<br>
<br>
<br>
> LLDB picks this up, and the result is that LLDB stops and waits for the user<br>
> to continue the inferior just as it would with any other breakpoint, and if<br>
> you were to get a backtrace you might see something like this:<br>
><br>
> looking at: Stack traces for SBProcess: pid = 12588, state = stopped,<br>
> threads = 2, executable = test_with_dwarf_and_attach_to_process_with_id_api<br>
> Stack trace for thread id=0x3428 name=None queue=None stop reason=none<br>
> frame #0: 0xffffffffffffffff ntdll.dll`DbgBreakPoint + 1<br>
<br>
This sounds like a pretty strange way to stop the inferior (I was<br>
quite surprised that ^C also injects a thread into a program), however<br>
it is fundamentally equivalent to what the other platforms do. When we<br>
attach on Linux, the inferior also comes out stopped. The difference<br>
is that we get a SIGSTOP as a stop reason, while on windows you get a<br>
breakpoint in a different thread. It sounds to me like the tests<br>
should not rely on a specific thread being selected after the attach.<br>
Most tests don't do backtraces right after attach since you're likely<br>
to get very unpredictable results on any platform. Those that do<br>
should be fixed to set a breakpoint on the place that interests them,<br>
resume and do a backtrace once they hit that breakpoint. I vaguelly<br>
recall some tests that actually do try to backtrace on attach on<br>
purpose (for example, to see if you can backtrace out of a syscall).<br>
If they exist, we should fix them to first select the right thread for<br>
the backtracing, so they don't try to use the DbgBreakPoint thread.<br>
</blockquote></div>