diff options
author | Lancelot SIX <lsix@lancelotsix.com> | 2021-07-16 22:10:08 +0000 |
---|---|---|
committer | Lancelot SIX <lsix@lancelotsix.com> | 2021-07-16 22:10:08 +0000 |
commit | e843807b2df9f99b8172bfaf4daa3a42461cdbfa (patch) | |
tree | fdce54aa31c1f7bb740dc766c5d7bc13d0428299 /gdb/riscv-linux-tdep.c | |
parent | 47357fdc1db04240be98c683de776b3a351e945b (diff) | |
download | fsf-binutils-gdb-e843807b2df9f99b8172bfaf4daa3a42461cdbfa.zip fsf-binutils-gdb-e843807b2df9f99b8172bfaf4daa3a42461cdbfa.tar.gz fsf-binutils-gdb-e843807b2df9f99b8172bfaf4daa3a42461cdbfa.tar.bz2 |
gdb: Support stepping out from signal handler on riscv*-linux
Currently, gdb cannot step outside of a signal handler on RISC-V
platforms. This causes multiple failures in gdb.base/sigstep.exp:
FAIL: gdb.base/sigstep.exp: continue to handler, nothing in handler, step from handler: leave handler (timeout)
FAIL: gdb.base/sigstep.exp: continue to handler, si+advance in handler, step from handler: leave handler (timeout)
FAIL: gdb.base/sigstep.exp: continue to handler, nothing in handler, next from handler: leave handler (timeout)
FAIL: gdb.base/sigstep.exp: continue to handler, si+advance in handler, next from handler: leave handler (timeout)
FAIL: gdb.base/sigstep.exp: stepi from handleri: leave signal trampoline
FAIL: gdb.base/sigstep.exp: nexti from handleri: leave signal trampoline
=== gdb Summary ===
# of expected passes 587
# of unexpected failures 6
This patch adds support for stepping outside of a signal handler on
riscv*-*-linux*.
Implementation is heavily inspired from mips_linux_syscall_next_pc and
surroundings as advised by Pedro Alves.
After this patch, all tests in gdb.base/sigstep.exp pass.
Build and tested on riscv64-linux-gnu.
Diffstat (limited to 'gdb/riscv-linux-tdep.c')
-rw-r--r-- | gdb/riscv-linux-tdep.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/gdb/riscv-linux-tdep.c b/gdb/riscv-linux-tdep.c index ca97a60..49dc75b 100644 --- a/gdb/riscv-linux-tdep.c +++ b/gdb/riscv-linux-tdep.c @@ -27,6 +27,11 @@ #include "trad-frame.h" #include "gdbarch.h" +/* The following value is derived from __NR_rt_sigreturn in + <include/uapi/asm-generic/unistd.h> from the Linux source tree. */ + +#define RISCV_NR_rt_sigreturn 139 + /* Define the general register mapping. The kernel puts the PC at offset 0, gdb puts it at offset 32. Register x0 is always 0 and can be ignored. Registers x1 to x31 are in the same place. */ @@ -154,11 +159,28 @@ riscv_linux_sigframe_init (const struct tramp_frame *self, trad_frame_set_id (this_cache, frame_id_build (frame_sp, func)); } +/* When FRAME is at a syscall instruction (ECALL), return the PC of the next + instruction to be executed. */ + +static CORE_ADDR +riscv_linux_syscall_next_pc (struct frame_info *frame) +{ + const CORE_ADDR pc = get_frame_pc (frame); + const ULONGEST a7 = get_frame_register_unsigned (frame, RISCV_A7_REGNUM); + + if (a7 == RISCV_NR_rt_sigreturn) + return frame_unwind_caller_pc (frame); + + return pc + 4 /* Length of the ECALL insn. */; +} + /* Initialize RISC-V Linux ABI info. */ static void riscv_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) { + struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); + linux_init_abi (info, gdbarch, 0); set_gdbarch_software_single_step (gdbarch, riscv_software_single_step); @@ -182,6 +204,8 @@ riscv_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) (gdbarch, riscv_linux_iterate_over_regset_sections); tramp_frame_prepend_unwinder (gdbarch, &riscv_linux_sigframe); + + tdep->syscall_next_pc = riscv_linux_syscall_next_pc; } /* Initialize RISC-V Linux target support. */ |