[Lldb-commits] [lldb] [RISCV][LLDB] Add RISC-V Architecture plugin for trap validation (PR #207675)

Sudharsan Veeravalli via lldb-commits lldb-commits at lists.llvm.org
Mon Jul 6 22:02:02 PDT 2026


svs-quic wrote:

> Does the generic implementation not work fine for RISC-V? I thought you only needed to override it when the instruction had an immediate?

We have this set for RISCV in `lldb/source/Host/common/NativeProcessProtocol.cpp`

```
  case llvm::Triple::riscv32:
  case llvm::Triple::riscv64:  
  case llvm::Triple::loongarch32:
  case llvm::Triple::loongarch64:
    // On these architectures the PC doesn't get updated for breakpoint hits.
    return 0;
```

The test that fails looks like:

```
#include <stdio.h>
int global = 0;
int main() {
  global = 5; // Set a breakpoint here
  puts("");
  __builtin_debugtrap();
  global = 10;
  __builtin_trap();
  global = 15;
  return global;
}
```

When we run in lldb this is what we see:

```
(lldb) b main.c:4
Breakpoint 1: where = dtrap.o`main + 12 at main.c:4:10, address = 0x08048136
(lldb) gdb-remote 1234
(lldb) Process 430709 stopped
* thread #1, stop reason = signal SIGTRAP
       frame #0: 0x08048166 dtrap.o`_start
dtrap.o`_start:
->  0x8048166 <+0>:  auipc  gp, 0x3
    0x804816a <+4>:  addi   gp, gp, 0x776
    0x804816e <+8>:  auipc  a0, 0xf7fb8
    0x8048172 <+12>: addi   a0, a0, -0x16e
c
Process 430709 resuming
(lldb) Process 430709 stopped
* thread #1, stop reason = breakpoint 1.1
       frame #0: 0x08048136 dtrap.o`main at main.c:4:10
   1   	#include <stdio.h>
   2   	int global = 0;
   3   	int main() {
-> 4   	  global = 5; // Set a breakpoint here
   5   	  puts("");
   6   	  __builtin_debugtrap();
   7   	  global = 10;
c
Process 430709 resuming
(lldb) Process 430709 stopped
* thread #1, stop reason = signal SIGTRAP
       frame #0: 0x08048150 dtrap.o`main at main.c:6:3
   3   	int main() {
   4   	  global = 5; // Set a breakpoint here
   5   	  puts("");
-> 6   	  __builtin_debugtrap();
   7   	  global = 10;
   8   	  __builtin_trap();
   9   	  global = 15;
dis
dtrap.o`main:
    0x804812a <+0>:  addi   sp, sp, -0x10
    0x804812c <+2>:  sw     ra, 0xc(sp)
    0x804812e <+4>:  sw     s0, 0x8(sp)
    0x8048130 <+6>:  addi   s0, sp, 0x10
    0x8048132 <+8>:  li     a0, 0x0
    0x8048134 <+10>: sw     a0, 0x4(sp)
    0x8048136 <+12>: auipc  a0, 0x3
    0x804813a <+16>: addi   a1, a0, -0x5a
    0x804813e <+20>: sw     a1, 0x0(sp)
    0x8048140 <+22>: li     a0, 0x5
    0x8048142 <+24>: sw     a0, 0x0(a1)
    0x8048144 <+26>: auipc  a0, 0x1
    0x8048148 <+30>: addi   a0, a0, -0x24
    0x804814c <+34>: jal    0x80483c0
    0x804814e <+36>: lw     a0, 0x0(sp)
->  0x8048150 <+38>: ebreak 
    0x8048152 <+40>: li     a1, 0xa
```

When we continue from here on the SIGTRAP LLDB does not know EBREAK is a valid TRAP instruction and so a continue stays on the same instruction:

```
(lldb) c
Process 430709 resuming
(lldb) Process 430709 stopped
* thread #1, stop reason = signal SIGTRAP
       frame #0: 0x08048150 dtrap.o`main at main.c:6:3
   3   	int main() {
   4   	  global = 5; // Set a breakpoint here
   5   	  puts("");
-> 6   	  __builtin_debugtrap();
   7   	  global = 10;
   8   	  __builtin_trap();
   9   	  global = 15;
dis
dtrap.o`main:
    0x804812a <+0>:  addi   sp, sp, -0x10
    0x804812c <+2>:  sw     ra, 0xc(sp)
    0x804812e <+4>:  sw     s0, 0x8(sp)
    0x8048130 <+6>:  addi   s0, sp, 0x10
    0x8048132 <+8>:  li     a0, 0x0
    0x8048134 <+10>: sw     a0, 0x4(sp)
    0x8048136 <+12>: auipc  a0, 0x3
    0x804813a <+16>: addi   a1, a0, -0x5a
    0x804813e <+20>: sw     a1, 0x0(sp)
    0x8048140 <+22>: li     a0, 0x5
    0x8048142 <+24>: sw     a0, 0x0(a1)
    0x8048144 <+26>: auipc  a0, 0x1
    0x8048148 <+30>: addi   a0, a0, -0x24
    0x804814c <+34>: jal    0x80483c0
    0x804814e <+36>: lw     a0, 0x0(sp)
->  0x8048150 <+38>: ebreak 
    0x8048152 <+40>: li     a1, 0xa
    0x8048154 <+42>: sw     a1, 0x0(a0)
```

Hope this helps.



https://github.com/llvm/llvm-project/pull/207675


More information about the lldb-commits mailing list