public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug sim/31915] New: gdb sim for riscv mishandle breakpoints, skips original instruction under ebreak
@ 2024-06-20  1:17 zelenski at cs dot stanford.edu
  2024-06-20  1:17 ` [Bug sim/31915] " zelenski at cs dot stanford.edu
  2024-06-20  1:34 ` zelenski at cs dot stanford.edu
  0 siblings, 2 replies; 3+ messages in thread
From: zelenski at cs dot stanford.edu @ 2024-06-20  1:17 UTC (permalink / raw)
  To: gdb-prs

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

            Bug ID: 31915
           Summary: gdb sim for riscv mishandle breakpoints, skips
                    original instruction under ebreak
           Product: gdb
           Version: 14.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: sim
          Assignee: unassigned at sourceware dot org
          Reporter: zelenski at cs dot stanford.edu
                CC: vapier at gentoo dot org
  Target Milestone: ---

Created attachment 15585
  --> https://sourceware.org/bugzilla/attachment.cgi?id=15585&action=edit
Script show broken gdb and fixed version

gdb sim debugging bare-metal riscv program. Set breakpoint at address 0xblah.
When breakpoint is hit, the original instruction at address 0xblah is skipped.
I believe this is due to ebreak overwrite at 0xblah. When hit ebreak, expected
handling would restore the original at 0xblah and reissue instruction, but sim
mistakenly advances to 0xblah+4 which skips execution of original. This bug in
simulator seems to affect any use of breakpoints (severity of consequences vary
based on content of skipped instruction)

Excerpt from sim/riscv/sim-main.c below.
Edit line 628 to remove the "+4" seems to correct problem.

   625      case MATCH_EBREAK:
   626        TRACE_INSN (cpu, "ebreak;");
   627        /* GDB expects us to step over EBREAK.  */
   628        sim_engine_halt (sd, cpu, NULL, riscv_cpu->pc+4, sim_stopped,
   629                         SIM_SIGTRAP);
   630        break;

Attachment shows gdb skipping instruction at breakpoint and again with above
fix applied showing that instruction is correctly executed

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

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

* [Bug sim/31915] gdb sim for riscv mishandle breakpoints, skips original instruction under ebreak
  2024-06-20  1:17 [Bug sim/31915] New: gdb sim for riscv mishandle breakpoints, skips original instruction under ebreak zelenski at cs dot stanford.edu
@ 2024-06-20  1:17 ` zelenski at cs dot stanford.edu
  2024-06-20  1:34 ` zelenski at cs dot stanford.edu
  1 sibling, 0 replies; 3+ messages in thread
From: zelenski at cs dot stanford.edu @ 2024-06-20  1:17 UTC (permalink / raw)
  To: gdb-prs

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

Julie Zelenski <zelenski at cs dot stanford.edu> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |zelenski at cs dot stanford.edu

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

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

* [Bug sim/31915] gdb sim for riscv mishandle breakpoints, skips original instruction under ebreak
  2024-06-20  1:17 [Bug sim/31915] New: gdb sim for riscv mishandle breakpoints, skips original instruction under ebreak zelenski at cs dot stanford.edu
  2024-06-20  1:17 ` [Bug sim/31915] " zelenski at cs dot stanford.edu
@ 2024-06-20  1:34 ` zelenski at cs dot stanford.edu
  1 sibling, 0 replies; 3+ messages in thread
From: zelenski at cs dot stanford.edu @ 2024-06-20  1:34 UTC (permalink / raw)
  To: gdb-prs

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

--- Comment #1 from Julie Zelenski <zelenski at cs dot stanford.edu> ---
diff --git a/sim/riscv/sim-main.c b/sim/riscv/sim-main.c
index 250791634a1..ef81dfc1750 100644
--- a/sim/riscv/sim-main.c
+++ b/sim/riscv/sim-main.c
@@ -625,7 +625,7 @@ execute_i (SIM_CPU *cpu, unsigned_word iw, const struct
riscv_opcode *op)
     case MATCH_EBREAK:
       TRACE_INSN (cpu, "ebreak;");
       /* GDB expects us to step over EBREAK.  */
-      sim_engine_halt (sd, cpu, NULL, riscv_cpu->pc + 4, sim_stopped,
+      sim_engine_halt (sd, cpu, NULL, riscv_cpu->pc, sim_stopped,
                       SIM_SIGTRAP);
       break;
     case MATCH_ECALL:

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

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

end of thread, other threads:[~2024-06-20  1:34 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-06-20  1:17 [Bug sim/31915] New: gdb sim for riscv mishandle breakpoints, skips original instruction under ebreak zelenski at cs dot stanford.edu
2024-06-20  1:17 ` [Bug sim/31915] " zelenski at cs dot stanford.edu
2024-06-20  1:34 ` zelenski at cs dot stanford.edu

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