Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Luis Machado <lgustavo@codesourcery.com>
To: "Maciej W. Rozycki" <macro@linux-mips.org>
Cc: <gdb-patches@sourceware.org>, <linux-mips@linux-mips.org>
Subject: Re: [PATCH] Expect SI_KERNEL si_code for a MIPS software breakpoint trap
Date: Tue, 09 Feb 2016 14:30:00 -0000	[thread overview]
Message-ID: <56B9F7E6.5010006@codesourcery.com> (raw)
In-Reply-To: <alpine.LFD.2.20.1509181729100.10647@eddie.linux-mips.org>

Hi Maciej,

I'm finally getting back to this. Sorry for the delay.

On 09/18/2015 01:56 PM, Maciej W. Rozycki wrote:
> Hi Luis,
>
>> I tracked this down to the lack of a proper definition of what MIPS' kernel
>> returns in the si_code for a software breakpoint trap.
>>
>> Though i did not find documentation about this, tests showed that we should
>> check for SI_KERNEL, just like i386. I've cc-ed Maciej, just to be sure this
>> is indeed correct.
>
>   Hmm, the MIPS/Linux port does not set any particular code for SIGTRAP,
> all such signals will have the SI_KERNEL default, so you may well return
> TRUE unconditionally.
>

That is unfortunate. It would be nice to have a well defined standard of 
communicating these events from kernels to debuggers. All is not lost 
though, since that can be improved.

>   I'm not convinced however that it is safe to assume all SIGTRAPs come
> from breakpoints -- this signal is sent by the kernel for both BREAK and
> trap (multiple mnemonics, e.g. TEQ, TGEI, etc.) instructions which may
> have been placed throughout code for some reason, for example to serve as
> cheap assertion checks.
>
>   Is there a separate check made afterwards like `bpstat_explains_signal'
> to validate the source of the signal here?
>

In my specific example we are dealing with two breakpoint hits by 
different threads. The first one is reported just fine and the one we 
have problems with is the queued one that is reported afterwards when we 
attempt to move the other thread.

We do rely on bpstat_explains_signal when gdbserver/the remote target 
notifies gdb about a stop. In the case of a queued breakpoint hit, it 
doesn't even get reported back to gdb and is just ignored by gdbserver 
if it is recognized as a breakpoint hit.

With the proposed change, even the hardcoded traps will initially be 
recognized as breakpoints, albeit maybe recognized as permanent 
breakpoints for some opcodes. It may cause gdbserver to ignore a second 
hardcoded trap hit, which is not desirable.

>   Perhaps we should make it a part of the ABI and teach MIPS/Linux about
> the breakpoint encoding used by GDB, which is `BREAK 5' (aka BRK_SSTEPBP
> in kernel-speak, a misnomer I'm afraid), and make it set `si_code' to
> TRAP_BRKPT, as expected.  This won't fix history of course, but at least
> it will make debugging a little bit easier to handle in the future.
> Cc-ing `linux-mips' for further input.

This is the best solution in my opinion and will definitely make the 
debugger's life easier if it can tell the difference between multiple 
seemingly equivalent SIGTRAP's.

Does this involve handling BRK_SSTEPBP inside 
arch/mips/kernel/traps.c:do_trap_or_bp?

>
>   I was wondering where these SIGTRAPs come from too BTW, thanks for
> investigating it.  And thanks for the heads-up!

You're welcome.


  parent reply	other threads:[~2016-02-09 14:30 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-18 16:11 Luis Machado
2015-09-18 16:56 ` Maciej W. Rozycki
2015-09-18 17:04   ` David Daney
2015-09-18 18:36     ` Maciej W. Rozycki
2016-02-09 14:30   ` Luis Machado [this message]
2016-02-09 21:01     ` Maciej W. Rozycki
2016-02-10 12:53       ` Luis Machado
2016-02-15 23:50         ` Maciej W. Rozycki
2016-02-16  0:30           ` Pedro Alves
2016-02-19 16:21             ` Maciej W. Rozycki
2016-02-24 11:52               ` Pedro Alves
2016-02-16  0:57         ` 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=56B9F7E6.5010006@codesourcery.com \
    --to=lgustavo@codesourcery.com \
    --cc=gdb-patches@sourceware.org \
    --cc=linux-mips@linux-mips.org \
    --cc=macro@linux-mips.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