Mirror of the gdb mailing list
 help / color / mirror / Atom feed
From: Tim Newsome <tim@sifive.com>
To: Jim Wilson <jimw@sifive.com>
Cc: gdb <gdb@sourceware.org>, Andrew Burgess <andrew.burgess@embecosm.com>
Subject: Re: RISC-V: decr_pc_after_break causing problems
Date: Tue, 26 Jun 2018 19:15:00 -0000	[thread overview]
Message-ID: <CAGDihe=9SGEDaXZeYhDGBz-_d39TLDsQ4JTsFmQhUqoDq7JdAg@mail.gmail.com> (raw)
In-Reply-To: <CAFyWVaYoF8LmH=RGEZTrMWqaYF0i3GERZG-B_rDxtTt2LQs9gw@mail.gmail.com>

As another point of reference, the gdb we use with OpenOCD does not have
the set_gdbarch_decr_pc_after_break line at all.

Tim

On Mon, Jun 25, 2018 at 7:54 PM, Jim Wilson <jimw@sifive.com> wrote:

> The RISC-V port in the riscv-tdep.c file has
>   set_gdbarch_decr_pc_after_break (gdbarch, (has_compressed_isa ? 2 : 4));
>
> The privileged architecture spec v1.10 states in section 3.2.1 that
> the ebreak instruction causes the receiving privilege mode's epc
> register to be set to the address of the ebreak instruction, not the
> address of the following instruction.  So gdb should not be
> decrementing from the pc after a breakpoint is hit.
>
> It isn't clear why this code is even here, as it isn't present in the
> original gdb port in the github riscv/riscv-binutils-gdb tree.
>
> Curiously, there is a corresponding bug in the riscv linux kernel
> sources, where it is adding 4 to the sepc in the breakpoint trap
> handling code for no apparent reason.  This might be OK if this was a
> 4-byte breakpoint instruction, but is not OK if this is a 2-byte
> breakpoint instruction.
>
> In order to get compressed breakpoints working on a SiFive HiFive
> Unleashed board running linux, I need both the gdb and the linux
> kernel bugs fixed.  The 4-byte breakpoint instruction works OK now,
> but is not safe to use in code compiled with compressed instructions.
> A good example is in the shared library support where _dl_debug_state
> is a 2-byte function located 2-bytes before _dl_debug_initialize, so
> placing a 4-byte breakpoint at _dl_debug_state overwrites the first
> two bytes of the first instruction of _dl_debug_initialize causing it
> to segfault.
>
> I can submit patches for gdb and the linux kernel, but it would be
> useful to know why gdb is trying to subtract from the pc after a
> break.  Maybe someone has a part that doesn't conform to the v1.10
> privilege architecture spec?  I noticed that this epc == breakpoint
> address is not stated in earlier versions of the spec, which makes
> earlier spec versions potentially ambiguous.  If we need to support
> parts that don't conform to v1.10 priv spec then that makes the fix
> more complicated.  It isn't clear how gdb is supposed to detect
> whether a part conforms or not.  Maybe we can add an option to turn
> this decrementing on
> or off?  Maybe a configure option to select whether it is on/off by
> default?
>
> There is another problem here incidentally that there is an option to
> turn on/off compressed breakpoints, but it doesn't affect the amount
> we subtract from the pc, which means this option can't work as
> currently written.  This problem goes away if we stop decrementing the
> pc in gdb.  If we have to keep the code that decrements the pc for
> some targets, then maybe we should just eliminate the option.  It
> isn't safe to use 4-byte breakpoints in code with compressed
> instructions anyways.  And there is no point in using 2-byte
> breakpoints in code with no compressed instructions.
>
> Jim
>


  reply	other threads:[~2018-06-26 19:15 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-26  2:54 Jim Wilson
2018-06-26 19:15 ` Tim Newsome [this message]
2018-07-04  0:17 ` Jim Wilson
2018-07-04  0:35   ` Palmer Dabbelt
2018-07-05 22:54     ` John Baldwin
2018-07-11 14:52       ` Andrew Burgess
2018-07-11 17:47 ` Andrew Burgess
2018-07-11 18:20   ` Jim Wilson
2018-07-16 22:09     ` Jim Wilson

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='CAGDihe=9SGEDaXZeYhDGBz-_d39TLDsQ4JTsFmQhUqoDq7JdAg@mail.gmail.com' \
    --to=tim@sifive.com \
    --cc=andrew.burgess@embecosm.com \
    --cc=gdb@sourceware.org \
    --cc=jimw@sifive.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