Skip to content

Commit c9977d6

Browse files
committed
riscv/crt0: Use a jal instruction to jump to _ctrap
This ensures that running `b _ctrap; c; bt` inside gdb shows the right backtrace. If we jump without setting ra gdb gets confused about the backtrace since we don't have the right cfi directives inside ctrap. This does not result in any downsides since ra has already been saved. Previously we had to set a breakpoint just before this jump to get a correct backtrace, now it's possible to set a breakpoint in _ctrap instead: ``` Reading symbols from test/test-fopen... Breakpoint 1 at 0x80000058: file ../../picolibc/picocrt/machine/riscv/crt0.c, line 84. Remote debugging using :1234 0x0000000000001000 in ?? () Continuing. Breakpoint 1, _ctrap (fault=0x805feee8) at ../../picolibc/picocrt/machine/riscv/crt0.c:84 84 printf("RISCV fault\n"); #0 _ctrap (fault=0x805feee8) at ../../picolibc/picocrt/machine/riscv/crt0.c:84 #1 0x00000000800001c4 in _trap () at ../../picolibc/picocrt/machine/riscv/crt0.c:168 #2 0x00000000800013d0 in fclose (f=0x804008c0) at ../../picolibc/newlib/libc/tinystdio/fclose.c:39 #3 0x0000000080000680 in main () at ../../picolibc/test/test-fopen.c:85 (gdb) ```
1 parent 4a97063 commit c9977d6

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

picocrt/machine/riscv/crt0.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ _trap(void)
161161
"csrw mstatus, t0\n"
162162
"csrwi fcsr, 0");
163163
#endif
164-
__asm__("j _ctrap");
164+
__asm__("jal _ctrap");
165165
}
166166
#endif
167167

0 commit comments

Comments
 (0)