This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

MI attach stop reason


At the end of the email is a trace for a simple test of attaching to an
already running process using the MI interface using the "-target-attach
<pid>" command syntax.

After sending the -target-attach gdb replies with a "*stopped" message,
this seems fine, however, there's no reason field given.

Now, obviously, the reason for the stop is the attach, however, it seems
like including a reason field would provide a more consistent interface, do
folk generally agree or disagree with this?

Next I had a look down the reason list that's here:

  http://sourceware.org/gdb/current/onlinedocs/gdb/GDB_002fMI-Async-Records.html

and I think there are only two options, one would be to reuse the
"signal-received" reason, though I'm not sure this is great, or I could add
a new reason "attached".  Or is there something on the list that I've not
though of?

Finally, I include a straw-man patch for people to comment on, this patch
is just to find the correct place report the reason field, so for now I'm
re-using the signal reason.  Any final patch will need to add documentation
and tests.  Please let me know if this looks like the correct place to
add this new code, or if not suggestions are welcome.

Thanks,

Andrew

## START EXAMPLE ##

[xl-cam-20]tests> cat sleepy.c
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>

int 
main ()
{
  printf ("pid = %d\n", getpid ());

  while (1)
    sleep (10);
  
  return 0;
}
[xl-cam-20]tests> gcc -Wall -Werror -g -o sleepy.x sleepy.c
[xl-cam-20]tests> ./sleepy.x &
[2] 17608
pid = 17608
[xl-cam-20]tests> gdb --interpreter=mi2
=thread-group-added,id="i1"
~"GNU gdb (GDB) 7.4\n"
~"Copyright (C) 2012 Free Software Foundation, Inc.\n"
~"License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>\nThis is free software: you are free to change and redistribute it.\nThere is NO WARRANTY, to the extent permitted by law.  Type \"show copying\"\nand \"show warranty\" for details.\n"
~"This GDB was configured as \"x86_64-unknown-linux-gnu\".\nFor bug reporting instructions, please see:\n"
~"<http://www.gnu.org/software/gdb/bugs/>.\n"
(gdb) 
-target-attach 17608
=thread-group-started,id="i1",pid="17608"
=thread-created,id="1",group-id="i1"
=library-loaded,id="/lib64/libc.so.6",target-name="/lib64/libc.so.6",host-name="/lib64/libc.so.6",symbols-loaded="0",thread-group="i1"
=library-loaded,id="/lib64/ld-linux-x86-64.so.2",target-name="/lib64/ld-linux-x86-64.so.2",host-name="/lib64/ld-linux-x86-64.so.2",symbols-loaded="0",thread-group="i1"
&"warning: no loadable sections found in added symbol-file system-supplied DSO at 0x7fffb3d82000\n"
*stopped,frame={addr="0x000000367a49a510",func="__nanosleep_nocancel",args=[],from="/lib64/libc.so.6"},thread-id="1",stopped-threads="all",core="9"
^done

## END EXAMPLE ##

## START PATCH ##

diff --git a/gdb/infcmd.c b/gdb/infcmd.c
index af6a4db..f29e8eb 100644
--- a/gdb/infcmd.c
+++ b/gdb/infcmd.c
@@ -57,6 +57,7 @@
 #include "continuations.h"
 #include "linespec.h"
 #include "cli/cli-utils.h"
+#include "mi/mi-common.h"
 
 /* Local functions: */
 
@@ -2479,6 +2480,8 @@ attach_command_post_wait (char *args, int from_tty, int as
     }
   else
     {
+      struct ui_out *uiout = current_uiout;
+
       /* The user requested a plain `attach', so be sure to leave
         the inferior stopped.  */
 
@@ -2495,6 +2498,13 @@ attach_command_post_wait (char *args, int from_tty, int a
       if (non_stop)
        target_stop (pid_to_ptid (inferior->pid));
 
+      if (ui_out_is_mi_like_p (uiout))
+        {
+          ui_out_field_string (uiout, "reason",
+                               async_reason_lookup (EXEC_ASYNC_SIGNAL_RECEIVED)
+         ui_out_text (uiout, "\n");
+        }
+
       /* Tell the user/frontend where we're stopped.  */
       normal_stop ();
       if (deprecated_attach_hook)

## END PATCH ##


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]