public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Pedro Alves <palves@redhat.com>
To: Simon Marchi <simon.marchi@ericsson.com>, gdb-patches@sourceware.org
Subject: Re: [PATCH 1/3] Remove args from target detach
Date: Thu, 18 Jan 2018 15:57:00 -0000	[thread overview]
Message-ID: <14e51528-6323-a8b1-43ab-534095ea19d1@redhat.com> (raw)
In-Reply-To: <1514699454-18587-1-git-send-email-simon.marchi@ericsson.com>

On 12/31/2017 05:50 AM, Simon Marchi wrote:
> I was looking into adding a parameter to target_detach, and was
> wondering what the args parameter was.  It seems like in the distant
> past, it was possible to specify a signal number when detaching.  That
> signal was injected in the process before it was detached.  There is an
> example of code handling this in linux_nat_detach.  With today's GDB, I
> can't get this to work.  Doing "detach 15" (15 == SIGTERM) doesn't work,
> because detach is a prefix command and doesn't recognize the sub-command
> 15.  Doing "detach inferiors 15" doesn't work because it expects a list
> of inferior id to detach.  Therefore, I don't think there's a way of
> invoking detach_command with a non-NULL args.  I also didn't find any
> documentation related to this feature.
> 
> I assume that this feature stopped working when detach was made a prefix
> command, which is in f73adfeb8bae36885e6ea248d12223ab0d5eb9cb (sorry,
> there's no commit title) from 2006.  Given that this feature was broken
> for such a long time and we haven't heard anything (AFAIK, I did not
> find any related bug), I think it's safe to remove it, as well as the
> args parameter to target_detach.  If someone wants to re-introduce it, I
> would suggest rethinking the user interface, and in particular would
> suggest using signal name instead of numbers.
> 
> I tried to fix all the impacted code, but I might have forgotten some
> spots.  It shouldn't be hard to fix if that's the case.  I also couldn't
> build-test everything I changed, especially the nto and solaris stuff.
> 

Eh.  I knew about "detach SIG", from touching the detach-related
code many times before.  Had no idea that it was broken.

I think the main use cases are/were:

 - To be able to detach without passing the just-intercepted signal
   to the program.  I.e., "detach 0" was to "detach", like "signal 0"
   is to "continue".

 - To be able to attach to a program (maybe job-stopped), debug it
   a bit, and then detach it, leaving it job-stopped.  I.e., queue
   a SIGSTOP when you detach, with "detach SIGTOP".

I think you can do the former today with either:
  "handle SIGFOO nopass" + "detach"
  "queue-signal 0" + "detach"

and the latter with either:
  "queue-signal SIGSTOP" + "detach"
  "shell kill -SIGSTOP $PID" + "detach"

The "shell kill" variant is a bit more cumbersome, of
course, and only works with native debugging.

We're probably missing testcases for the above scenarios.
IWBN to add them, of course.

The patch looks fine to me.  One nit:

>  static void
> -procfs_detach (struct target_ops *ops, const char *args, int from_tty)
> +procfs_detach (struct target_ops *ops, int from_tty)
>  {
> -  int sig = 0;
>    int pid = ptid_get_pid (inferior_ptid);
>  
> -  if (args)
> -    sig = atoi (args);
> -
>    if (from_tty)
>      {
>        const char *exec_file;
> @@ -1945,7 +1941,7 @@ procfs_detach (struct target_ops *ops, const char *args, int from_tty)
>        gdb_flush (gdb_stdout);
>      }
>  
> -  do_detach (sig);
> +  do_detach (0);

I think the 'signo' parameter of do_detach is now always
0, so it could be removed.  I understand that you might
want to avoid breaking the port (too much), but it looks
very easy to remove.

>  
>    inferior_ptid = null_ptid;
>    detach_inferior (pid);

Thanks,
Pedro Alves

      parent reply	other threads:[~2018-01-18 15:57 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-31  5:56 Simon Marchi
2017-12-31  5:58 ` [PATCH 2/3] Pass inferior down to target_detach and to_detach Simon Marchi
2018-01-18 16:41   ` Pedro Alves
2018-01-19  3:17     ` Simon Marchi
2017-12-31  6:01 ` [PATCH 3/3] Make linux_nat_detach/thread_db_detach use the inferior parameter Simon Marchi
2018-01-18 17:06   ` Pedro Alves
2018-01-19  3:26     ` Simon Marchi
2018-01-18 15:57 ` Pedro Alves [this message]

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=14e51528-6323-a8b1-43ab-534095ea19d1@redhat.com \
    --to=palves@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=simon.marchi@ericsson.com \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).