Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Pedro Alves <palves@redhat.com>
To: Ulrich Weigand <uweigand@de.ibm.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [RFC] Fix SW breakpoint handling for Cell multi-arch
Date: Thu, 27 Aug 2015 16:44:00 -0000	[thread overview]
Message-ID: <55DF3E6D.20706@redhat.com> (raw)
In-Reply-To: <20150827162324.33ACF39FA@oc7340732750.ibm.com>

On 08/27/2015 05:23 PM, Ulrich Weigand wrote:
> Pedro Alves wrote:
>> On 08/27/2015 12:54 PM, Ulrich Weigand wrote:
>>> Hi Pedro,
>>>
>>> a second major issue with Cell multi-arch debugging right now is related
>>> to the new target-side SW breakpoint handling.  Cell uses linux-nat as
>>> primary target for the PowerPC side, which now returns true from the
>>> to_supports_stopped_by_sw_breakpoint hook.
>>>
>>> This works fine for the PowerPC side.  However, when a breakpoint on the
>>> SPU side is hit, the kernel does *not* provide a siginfo with TRAP_BRKPT,
>>> but instead simply delivers a SIGTRAP without siginfo.
>>
>> Does si_code indicate that it was a kernel-generated SIGTRAP (that is,
>> SI_KERNEL)?  Wondering whether that would still be distinguishable
>> from trace/single-step traps and user sent SIGTRAPs.  See comment and
>> table about x86's si_code in nat/linux-nat.h.  I don't know whether
>> the SPU has to care about all the cases there, but I suspect
>> not (e.g., I'd assume SPU code can't exec?).
> 
> That's an interesting idea.  Indeed the kernel uses SI_KERNEL for
> SIGTRAPs indicating SW breakpoints on SPU, but nowhere else in all
> of PowerPC code.  This means simply accepting either TRAP_BRKPT or
> SI_KERNEL should work.  And indeed the patch appended below works
> just as well as the original patch for me.

Excellent!

> Index: binutils-gdb/gdb/gdbserver/linux-low.c
> ===================================================================
> --- binutils-gdb.orig/gdb/gdbserver/linux-low.c
> +++ binutils-gdb/gdb/gdbserver/linux-low.c
> @@ -651,7 +651,7 @@ check_stopped_by_breakpoint (struct lwp_
>      {
>        if (siginfo.si_signo == SIGTRAP)
>  	{
> -	  if (siginfo.si_code == GDB_ARCH_TRAP_BRKPT)
> +	  if (GDB_ARCH_IS_TRAP_BRKPT (siginfo.si_code))
>  	    {
>  	      if (debug_threads)
>  		{
> Index: binutils-gdb/gdb/linux-nat.c
> ===================================================================
> --- binutils-gdb.orig/gdb/linux-nat.c
> +++ binutils-gdb/gdb/linux-nat.c
> @@ -2801,7 +2801,7 @@ check_stopped_by_breakpoint (struct lwp_
>      {
>        if (siginfo.si_signo == SIGTRAP)
>  	{
> -	  if (siginfo.si_code == GDB_ARCH_TRAP_BRKPT)
> +	  if (GDB_ARCH_IS_TRAP_BRKPT (siginfo.si_code))
>  	    {
>  	      if (debug_linux_nat)
>  		fprintf_unfiltered (gdb_stdlog,
> Index: binutils-gdb/gdb/nat/linux-ptrace.h
> ===================================================================
> --- binutils-gdb.orig/gdb/nat/linux-ptrace.h
> +++ binutils-gdb/gdb/nat/linux-ptrace.h
> @@ -135,12 +135,19 @@ struct buffer;
>     running to a breakpoint and checking what comes out of
>     siginfo->si_code.
>  
> -   The generic Linux target code should use GDB_ARCH_TRAP_BRKPT
> -   instead of TRAP_BRKPT to abstract out this x86 peculiarity.  */
> +   The ppc kernel does use TRAP_BRKPT for software breakpoints
> +   in PowerPC code, but it uses SI_KERNEL for software breakpoints
> +   in SPU code on a Cell/B.E.  However, SI_KERNEL is never seen
> +   on a SIGTRAP for any other reason.
> +
> +   The generic Linux target code should use GDB_ARCH_IS_TRAP_BRKPT
> +   instead of TRAP_BRKPT to abstract out these peculiarities.  */
>  #if defined __i386__ || defined __x86_64__
> -# define GDB_ARCH_TRAP_BRKPT SI_KERNEL
> +# define GDB_ARCH_IS_TRAP_BRKPT(X) ((X) == SI_KERNEL)
> +#elif defined __powerpc__
> +# define GDB_ARCH_IS_TRAP_BRKPT(X) ((X) == SI_KERNEL || (X) == TRAP_BRKPT)
>  #else
> -# define GDB_ARCH_TRAP_BRKPT TRAP_BRKPT
> +# define GDB_ARCH_IS_TRAP_BRKPT(X) ((X) == TRAP_BRKPT)
>  #endif
>  
>  #ifndef TRAP_HWBKPT
> 

LGTM.

Thanks,
Pedro Alves


  reply	other threads:[~2015-08-27 16:44 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-27 11:54 Ulrich Weigand
2015-08-27 15:43 ` Pedro Alves
2015-08-27 16:23   ` Ulrich Weigand
2015-08-27 16:44     ` Pedro Alves [this message]
2015-08-27 17:40       ` Ulrich Weigand

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=55DF3E6D.20706@redhat.com \
    --to=palves@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=uweigand@de.ibm.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