public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug gdb/28486] New: [riscv64] GDB doesn't allow stepping over cbreak trap instruction
@ 2021-10-21 20:25 kip at thevertigo dot com
  2021-10-21 22:38 ` [Bug gdb/28486] " wilson at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: kip at thevertigo dot com @ 2021-10-21 20:25 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=28486

            Bug ID: 28486
           Summary: [riscv64] GDB doesn't allow stepping over cbreak trap
                    instruction
           Product: gdb
           Version: 10.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: gdb
          Assignee: unassigned at sourceware dot org
          Reporter: kip at thevertigo dot com
  Target Milestone: ---

While trying to create a #define macro to programmatically generate a
breakpoint on RISC-V using the cbreak instruction in the ISA, I noticed GDB
halts execution as it should, but it doesn't allow stepping over it.

This behaviour is unusual because on other architectures that have similar trap
instructions, GDB allows the user to step over it.

On mips I use "teq $0, $0"; POWER it's "twge %r2, %r2"; on x86 it's "int
$0x03"; on arm64 it's "brk #0", etc. They all halt as they should, and then
allow the user to step over the breakpoint.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug gdb/28486] [riscv64] GDB doesn't allow stepping over cbreak trap instruction
  2021-10-21 20:25 [Bug gdb/28486] New: [riscv64] GDB doesn't allow stepping over cbreak trap instruction kip at thevertigo dot com
@ 2021-10-21 22:38 ` wilson at gcc dot gnu.org
  2021-10-22  5:43 ` kip at thevertigo dot com
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: wilson at gcc dot gnu.org @ 2021-10-21 22:38 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=28486

Jim Wilson <wilson at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |wilson at gcc dot gnu.org

--- Comment #1 from Jim Wilson <wilson at gcc dot gnu.org> ---
RISC-V doesn't have a breakpoint instruction.  ebreak is a generic trap
instruction used for multiple purposes.  The compiler uses it for program
ending traps for instance.  gdb does use ebreak, but gdb will only recognize an
ebreak it emitted itself as an actual breakpoint.  Any others are program
ending traps.

Note that the MIPS break instruction accepts an argument, and MIPS has defined
one specific value to indicate a breakpoint.  However, on RISC-V, ebreak does
not take an argument, so we can't use that method to distinguish a program
ending trap from a breakpoint.

The semihosting spec uses ebreak, but it uses a specific sequence of
instructions to indicate that this is a semihosting call and not a program
ending trap.  It does this because ebreak does not take an argument, and hence
there is no other way to specify that this is a semihosting call.  See
https://github.com/riscv/riscv-semihosting-spec/blob/main/riscv-semihosting-spec.adoc#11-semihosting-trap-instruction-sequence

Because an ebreak instruction is ambiguous, I'm concerned that it would be
dangerous to let the debugger step over it by default.  We could maybe add an
option to allow someone to step over ebreak if they really want to, and leave
it off by default.  Or we could define a sequence of instructions that is meant
to be a user breakpoint like was done for the semihosting spec, and then teach
gdb to respect that.

Or maybe it is normal for gdb to let users step over a trap instruction, even
though program state may be undefined at that point?

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug gdb/28486] [riscv64] GDB doesn't allow stepping over cbreak trap instruction
  2021-10-21 20:25 [Bug gdb/28486] New: [riscv64] GDB doesn't allow stepping over cbreak trap instruction kip at thevertigo dot com
  2021-10-21 22:38 ` [Bug gdb/28486] " wilson at gcc dot gnu.org
@ 2021-10-22  5:43 ` kip at thevertigo dot com
  2021-10-25 20:53 ` wilson at gcc dot gnu.org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: kip at thevertigo dot com @ 2021-10-22  5:43 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=28486

--- Comment #2 from Kip Warner <kip at thevertigo dot com> ---
Hey Jim,

Sorry, there was a typo in my original post. I meant ebreak, not cbreak.

I tried the semihosting trap instruction sequence and I still had the same
result on the ebreak instruction:

    asm volatile("slli x0, x0, 0x1f; ebreak; srai x0, x0, 7");

While folks figure out whether this is a bug in GDB or intentional, do you have
a suggested workaround for what I'm trying to achieve? I'm aware of the kill()
and raise() functions, but they require an #include, whereas inline asm rolled
into a #define macro does not.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug gdb/28486] [riscv64] GDB doesn't allow stepping over cbreak trap instruction
  2021-10-21 20:25 [Bug gdb/28486] New: [riscv64] GDB doesn't allow stepping over cbreak trap instruction kip at thevertigo dot com
  2021-10-21 22:38 ` [Bug gdb/28486] " wilson at gcc dot gnu.org
  2021-10-22  5:43 ` kip at thevertigo dot com
@ 2021-10-25 20:53 ` wilson at gcc dot gnu.org
  2021-10-25 21:14 ` kip at thevertigo dot com
  2022-04-09 15:03 ` [Bug tdep/28486] " tromey at sourceware dot org
  4 siblings, 0 replies; 6+ messages in thread
From: wilson at gcc dot gnu.org @ 2021-10-25 20:53 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=28486

--- Comment #3 from Jim Wilson <wilson at gcc dot gnu.org> ---
On IRC, Jessica Clarke suggested that gcc could use unimp for a program ending
trap, thus leaving ebreak for user breakpoints.  I think we are already using
unimp for something else (padding bytes in text?), but that probably doesn't
conflict with the new proposed use.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug gdb/28486] [riscv64] GDB doesn't allow stepping over cbreak trap instruction
  2021-10-21 20:25 [Bug gdb/28486] New: [riscv64] GDB doesn't allow stepping over cbreak trap instruction kip at thevertigo dot com
                   ` (2 preceding siblings ...)
  2021-10-25 20:53 ` wilson at gcc dot gnu.org
@ 2021-10-25 21:14 ` kip at thevertigo dot com
  2022-04-09 15:03 ` [Bug tdep/28486] " tromey at sourceware dot org
  4 siblings, 0 replies; 6+ messages in thread
From: kip at thevertigo dot com @ 2021-10-25 21:14 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=28486

--- Comment #4 from Kip Warner <kip at thevertigo dot com> ---
The problem with using an unimp (non-)instruction is it creates a SIGILL when
the intention is to try and create a bona fide SIGTRAP.

Something I found interesting is I tried a little experiment on my RISC-V
machine. If I use ::raise(SIGTRAP); it works as expected. But if I stepi
through each instruction, no SIGTRAP exception is ever raised.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug tdep/28486] [riscv64] GDB doesn't allow stepping over cbreak trap instruction
  2021-10-21 20:25 [Bug gdb/28486] New: [riscv64] GDB doesn't allow stepping over cbreak trap instruction kip at thevertigo dot com
                   ` (3 preceding siblings ...)
  2021-10-25 21:14 ` kip at thevertigo dot com
@ 2022-04-09 15:03 ` tromey at sourceware dot org
  4 siblings, 0 replies; 6+ messages in thread
From: tromey at sourceware dot org @ 2022-04-09 15:03 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=28486

Tom Tromey <tromey at sourceware dot org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |tromey at sourceware dot org
          Component|gdb                         |tdep

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-04-09 15:03 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-21 20:25 [Bug gdb/28486] New: [riscv64] GDB doesn't allow stepping over cbreak trap instruction kip at thevertigo dot com
2021-10-21 22:38 ` [Bug gdb/28486] " wilson at gcc dot gnu.org
2021-10-22  5:43 ` kip at thevertigo dot com
2021-10-25 20:53 ` wilson at gcc dot gnu.org
2021-10-25 21:14 ` kip at thevertigo dot com
2022-04-09 15:03 ` [Bug tdep/28486] " tromey at sourceware dot org

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).