Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Yao Qi <yao@codesourcery.com>
To: Pedro Alves <palves@redhat.com>
Cc: <gdb-patches@sourceware.org>
Subject: Re: [PATCH] [RFC, docs RFA] gdbserver and gdb.threads/attach-into-signal.exp.
Date: Thu, 23 Feb 2012 04:07:00 -0000	[thread overview]
Message-ID: <4F45B324.2080609@codesourcery.com> (raw)
In-Reply-To: <20120222171937.29946.56976.stgit@hit-nxdomain.opendns.com>

On 02/23/2012 01:19 AM, Pedro Alves wrote:
> The issue is that when GDBserver detaches the inferior, it forgets the
> SIGALRM signal it had found when it attached, so the inferior doesn't
> get the signal (it is suppressed) and reaches the abort.  The fix is
> to make sure we forward the pending signals to the inferior on detach,
> like gdb/linux-nat.c does.  gdb/linux-nat.c does not pass down to the
> inferior signals that are in the "handle SIG nopass" state, however.
> GDBserver has no idea currently about the pass/nopass state of
> signals, so in order for GDBserver to do the same GDB, we need to make
> GDB tell GDBserver about the pass/nopass state of all signals.  This
> is recorded in GDB in the infrun.c:signal_program array.  The patch
> adds a new RSP packet QProgramSignals (similar to QPassSignals, though
> with different semantics) to do exactly that.
> 

Can we install target_ops hook to_program_signals in linux-nat, and move
existings code in it?  As you said, this problem doesn't exit on
linux-nat, and a new target_ops hook to_program_signals is created, so
it is natural to move existing linux-nat code to
linux_nat_program_signals (it is to be created).


> diff --git a/gdb/gdbserver/linux-low.c b/gdb/gdbserver/linux-low.c
> index ab34d84..5353cff 100644
> --- a/gdb/gdbserver/linux-low.c
> +++ b/gdb/gdbserver/linux-low.c
> @@ -928,36 +928,125 @@ linux_kill (int pid)
>    return 0;
>  }
>  
> +/* Get pending signal of LP, for detaching purposes.  */
                            ^^ "THREAD"
Can we remove the 2nd half of this setense "for detaching purpose".
IIUC, this routine is quite general, so it might be used for other
purpose in the future.

> +
> +static int
> +get_pending_signal (struct thread_info *thread)

> +
>  static int
>  linux_detach_one_lwp (struct inferior_list_entry *entry, void *args)
>  {
>    struct thread_info *thread = (struct thread_info *) entry;
>    struct lwp_info *lwp = get_thread_lwp (thread);
>    int pid = * (int *) args;
> +  int sig;
>  
>    if (ptid_get_pid (entry->id) != pid)
>      return 0;
>  
> -  /* If this process is stopped but is expecting a SIGSTOP, then make
> -     sure we take care of that now.  This isn't absolutely guaranteed
> -     to collect the SIGSTOP, but is fairly likely to.  */
> +  /* If there is a pending SIGSTOP, get rid of it.  */
>    if (lwp->stop_expected)
>      {
> -      int wstat;
> -      /* Clear stop_expected, so that the SIGSTOP will be reported.  */
> +      if (debug_threads)
> +	fprintf (stderr,
> +		 "Sending SIGCONT to %s\n",
> +		 target_pid_to_str (ptid_of (lwp)));
> +
> +      kill_lwp (lwpid_of (lwp), SIGCONT);
>        lwp->stop_expected = 0;
> -      linux_resume_one_lwp (lwp, 0, 0, NULL);
> -      linux_wait_for_event (lwp->head.id, &wstat, __WALL);
>      }
>  

As described in changelog entry,

	(linux_detach_one_lwp): Get rid of a pending SIGSTOP with SIGCONT.
	Pass on pending signals to PTRACE_DETACH.

Pending SIGSTOP is replaced with (pending?) SIGCONT.  In original code,
resume lwp -> wait -> PTRACE_DETACH (0).  With this patch, it changed to
PTRACE_DETACH (SIGCONT) directly, IIUC.  I am wondering it may the
status of program after detach, especiall when attach to a `T (stopped)'
process at the beginning of debug session.  I am unable to find a test
case to proof, so I may be wrong.  Just rise this question here.

>    /* Flush any pending changes to the process's registers.  */
>    regcache_invalidate_one ((struct inferior_list_entry *)
>  			   get_lwp_thread (lwp));
>
> +  /* Pass on any pending signal for this thread.  */
> +  sig = get_pending_signal (thread);
> +
>    /* Finally, let it resume.  */
>    if (the_low_target.prepare_to_resume != NULL)
>      the_low_target.prepare_to_resume (lwp);
> -  ptrace (PTRACE_DETACH, lwpid_of (lwp), 0, 0);
> +  if (ptrace (PTRACE_DETACH, lwpid_of (lwp), 0, sig) < 0)
> +    error (_("Can't detach %s: %s"),
> +	   target_pid_to_str (ptid_of (lwp)),
> +	   strerror (errno));
>
>    delete_lwp (lwp);
>    return 0;

-- 
Yao (齐尧)


  reply	other threads:[~2012-02-23  3:32 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-22 19:29 Pedro Alves
2012-02-23  4:07 ` Yao Qi [this message]
2012-02-24 21:29   ` Pedro Alves
2012-02-25 12:19     ` Yao Qi
2012-03-06 18:26 ` Pedro Alves
2012-03-06 19:04   ` Eli Zaretskii
2012-03-07 18:25     ` Pedro Alves
2012-03-07 18:53       ` Eli Zaretskii
2012-03-07 19:20         ` NEWS: Add subtitle for new z0/z1 conditional breakpoint extensions Pedro Alves
2012-03-07 19:28         ` [PATCH] [RFC, docs RFA] gdbserver and gdb.threads/attach-into-signal.exp Pedro Alves

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=4F45B324.2080609@codesourcery.com \
    --to=yao@codesourcery.com \
    --cc=gdb-patches@sourceware.org \
    --cc=palves@redhat.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