Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Marc Khouzam <marc.khouzam@ericsson.com>
To: "'gdb-patches@sourceware.org'" <gdb-patches@sourceware.org>
Subject: RE: [MI][patch] broken -target-detach
Date: Thu, 30 Sep 2010 10:25:00 -0000	[thread overview]
Message-ID: <F7CE05678329534C957159168FA70DEC571AB036DD@EUSAACMS0703.eamcs.ericsson.se> (raw)
In-Reply-To: <F7CE05678329534C957159168FA70DEC571AA1B55A@EUSAACMS0703.eamcs.ericsson.se>

More on this below.

On September 27, 2010 Marc Khouzam wrote:
> 
> Hi,
> 
> with GDB 7.2, the MI command -target-detach is not working very well.
> It still assumes that the thread-group id is a pid, instead of the
> new thread-group id format which starts with an 'i'.
> Also, the usage printout does not correspond to the documentation:
> 
> Usage: -target-detach [thread-group]
> vs
> -target-detach [ pid | gid ]
> 
> I have a patch that fixes things to parse both a pid or a thread-group.
> I've added it at the bottom, but I'm not sure it is the right approach.

After giving it some thought, I believe this is the right approach.

> With the new global MI flag --thread-group, I wonder if -target-detach
> should take a thread-group as a parameter anymore.

Using the --thread-group flag (alike -thread and --frame) tells the MI
command to focus on the thread-group specified and then execute the
command.  

-target-detach with no parameter means to detach from the process
currently in focus.  The --thread-group flags is meant exactly for such cases,
to avoid having to use a separate command to change the process in focus
and then issuing -target-detach.

On the other hand, it also makes sense to use -target-detach <thread-group>
to specify which thread-group to detach from, instead of the current one.

So, although "-target-detach --thread-group <gid>" and
"-target-detach <gid>" have the same effect, they both make sense
for a frontend.  Even "-target-detach --thread-group <gid> <gid2>",
makes sense, since a frontend may be focused on one process but may
want to detach from another.

Therefore the patch below seems like the right approach, which is to allow
-target-detach to work as it is documented:

-target-detach [pid | gid ]

I think this fix should go into the 7.2 branch as well.

What do you say?

Thanks

Marc


> You can see the error in the session below:
> 
> GNU gdb (GDB) 7.2.50.20100927-cvs
> (gdb) interpreter-exec mi "-target-attach --thread-group i1 12283"
> ^done,frame={addr="0x00f2b422",func="__kernel_vsyscall",args=[]}
> (gdb)
> (gdb)  interpreter-exec mi "-list-thread-groups"
> ^done,groups=[{id="i1",type="process",pid="12283",executable="/home/lmckhou/testing/a1",cores=["0"]}]
> (gdb)
> (gdb) interpreter-exec mi "-target-detach a a"
> ^error,msg="Usage: -target-detach [thread-group]"
> (gdb)
> (gdb) interpreter-exec mi "-target-detach i1"
> ^error,msg="Cannot parse thread group id 'i1'"
> (gdb) interpreter-exec mi "-target-detach --thread-group i1"
> ^done
> 
> Patch:


### Eclipse Workspace Patch 1.0
#P src
Index: gdb/mi/mi-main.c
===================================================================
RCS file: /cvs/src/src/gdb/mi/mi-main.c,v
retrieving revision 1.181
diff -u -r1.181 mi-main.c
--- gdb/mi/mi-main.c    1 Sep 2010 19:03:54 -0000       1.181
+++ gdb/mi/mi-main.c    27 Sep 2010 17:18:21 -0000
@@ -418,19 +418,36 @@
 mi_cmd_target_detach (char *command, char **argv, int argc)
 {
   if (argc != 0 && argc != 1)
-    error ("Usage: -target-detach [thread-group]");
+    error ("Usage: -target-detach [pid | thread-group]");

   if (argc == 1)
     {
       struct thread_info *tp;
       char *end = argv[0];
+      /* First see if we are dealing with a pid */
       int pid = strtol (argv[0], &end, 10);

       if (*end != '\0')
-       error (_("Cannot parse thread group id '%s'"), argv[0]);
+       {
+         int id;
+         struct inferior *inf;
+         /* We are not dealing with a pid.  Check for group id */
+         if (*(argv[0]) != 'i')
+           error (_("Invalid pid or thread-group id '%s'"), argv[0]);
+
+         id = strtoul (argv[0] + 1, &end, 0);
+         if (*end != '\0')
+           error (_("Invalid syntax of group id '%s'"), argv[0]);
+
+         inf = find_inferior_id (id);
+         if (!inf)
+           error (_("Non-existent thread-group id '%d'"), id);
+
+         pid = inf->pid;
+       }

       /* Pick any thread in the desired process.  Current
-        target_detach deteches from the parent of inferior_ptid.  */
+      target_detach detaches from the parent of inferior_ptid.  */
       tp = iterate_over_threads (find_thread_of_process, &pid);
       if (!tp)
        error (_("Thread group is empty"));


  reply	other threads:[~2010-09-30  1:36 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-09-28  9:21 Marc Khouzam
2010-09-30 10:25 ` Marc Khouzam [this message]
2010-10-12 22:51   ` Tom Tromey
2010-10-15 23:47 ` Pedro Alves
2010-11-12 16:02   ` Marc Khouzam
2010-11-12 16:43     ` Pedro Alves
2010-11-12 19:07       ` Marc Khouzam

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=F7CE05678329534C957159168FA70DEC571AB036DD@EUSAACMS0703.eamcs.ericsson.se \
    --to=marc.khouzam@ericsson.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox