Non-stop attach misses stopped events

Marc Khouzam
Fri Jan 14 21:32:00 GMT 2011


I got a bug report on Eclipse that I believe I can 'blame' on GDB :-)

When using the 'attach' command to attach to a process in non-stop mode
on Linux, all threads are stopped automatically, but only the first
thread reports a *stopped event.  So Eclipse reports all but one
thread as running, when they are actually all stopped.
I will need to work around this for Eclipse, but I still think
it would be nice to fix GDB.

GDB session below showing this.

I believe I tracked it down to the logic in 
where it says:

      /* At least the current thread is already stopped.  */

      /* In all-stop, by definition, all threads have to be already
	 stopped at this point.  In non-stop, however, although the
	 selected thread is stopped, others may still be executing.
	 Be sure to explicitly stop all threads of the process.  This
	 should have no effect on already stopped threads.  */
      if (non_stop)
	  target_stop (pid_to_ptid (inferior->pid));

So the problem is that _all_ threads are already stopped, unlike
what the comment suggests, and therefore we don't force a stop
on any threads, and don't see any *stopped events (except the
default one).

Here are the options I'm thinking of:

1- have the attach procedure somehow trigger normal_stop() for 
each thread, which will eventually cause the *stopped event.
That seems intrusive, and very low-level.

2- have the single *stopped event report "all" as the stopped
thread list.  I like this, but I'm not sure it is possible
to tell the MI code that even in non-stop, it should use
the "all" tag for just this case.

3- actually resume all threads (like when doing an async attach
('attach&')) and then stop all of them again.  This is very
easy, and it makes Eclipse work well, but it causes extra
*running events, and feels like a hack.

I can submit a patch for option 3 if that does seem like a way

Any opinions?


> gdb -i mi
~"GNU gdb (GDB)\n"
(gdb) set target-async on
&"set target-async on\n"
(gdb) set non-stop on
&"set non-stop on\n"
(gdb) attach 5285

=== This inferior has two threads ===

&"attach 5285\n"
~"Attaching to process 5285\n"
~"Reading symbols from /home/lmckhou/runtime-TestDSF/QuickTests/Debug/QuickTests..."
~"Reading symbols from /lib/tls/i686/cmov/"
~"(no debugging symbols found)...done.\n"
~"[Thread debugging using libthread_db enabled]\n"
~"[New Thread 0xb7863b70 (LWP 5286)]\n"
~"Loaded symbols for /lib/tls/i686/cmov/\n"
~"Reading symbols from /usr/lib/"
~"(no debugging symbols found)...done.\n"

=== only one *stopped event, and it is for the first thread ===
=== notice also the missing (gdb) prompt and ^done, but that is probably another issue ===

-list-thread-groups i1
^done,threads=[{id="2",target-id="Thread 0xb7863b70 (LWP 5286)",
{id="1",target-id="Thread 0xb7865b30 (LWP 5285)",

=== Both threads are actually stopped ===

More information about the Gdb mailing list