From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7873) id C9D39384B124; Sat, 25 Jun 2022 02:18:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C9D39384B124 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Tiezhu Yang To: gdb-cvs@sourceware.org Subject: [binutils-gdb] gdb: LoongArch: Implement loongarch_linux_syscall_next_pc() X-Act-Checkin: binutils-gdb X-Git-Author: Tiezhu Yang X-Git-Refname: refs/heads/master X-Git-Oldrev: 0757a50396e3638434f806aec2ee8c8f79a7026c X-Git-Newrev: af6e3f77e939ecf85e18720925a4d8f355f90ee1 Message-Id: <20220625021822.C9D39384B124@sourceware.org> Date: Sat, 25 Jun 2022 02:18:22 +0000 (GMT) X-BeenThere: gdb-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 25 Jun 2022 02:18:22 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3Daf6e3f77e939= ecf85e18720925a4d8f355f90ee1 commit af6e3f77e939ecf85e18720925a4d8f355f90ee1 Author: Tiezhu Yang Date: Sat Jun 25 09:21:16 2022 +0800 gdb: LoongArch: Implement loongarch_linux_syscall_next_pc() =20 When FRAME is at a syscall instruction, return the PC of the next instruction to be executed. =20 Signed-off-by: Tiezhu Yang Diff: --- gdb/loongarch-linux-tdep.c | 26 ++++++++++++++++++++++++++ gdb/loongarch-tdep.c | 7 +++++++ gdb/loongarch-tdep.h | 3 +++ 3 files changed, 36 insertions(+) diff --git a/gdb/loongarch-linux-tdep.c b/gdb/loongarch-linux-tdep.c index 5da48a4e0a5..21fc67f9323 100644 --- a/gdb/loongarch-linux-tdep.c +++ b/gdb/loongarch-linux-tdep.c @@ -161,11 +161,35 @@ loongarch_iterate_over_regset_sections (struct gdbarc= h *gdbarch, LOONGARCH_LINUX_NUM_GREGSET * regsize, &loongarch_gregset, NULL, cb_= data); } =20 +/* The following value is derived from __NR_rt_sigreturn in + from the Linux source tree. */ + +#define LOONGARCH_NR_rt_sigreturn 139 + +/* When FRAME is at a syscall instruction, return the PC of the next + instruction to be executed. */ + +static CORE_ADDR +loongarch_linux_syscall_next_pc (struct frame_info *frame) +{ + const CORE_ADDR pc =3D get_frame_pc (frame); + ULONGEST a7 =3D get_frame_register_unsigned (frame, LOONGARCH_A7_REGNUM); + + /* If we are about to make a sigreturn syscall, use the unwinder to + decode the signal frame. */ + if (a7 =3D=3D LOONGARCH_NR_rt_sigreturn) + return frame_unwind_caller_pc (frame); + + return pc + 4; +} + /* Initialize LoongArch Linux ABI info. */ =20 static void loongarch_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarc= h) { + loongarch_gdbarch_tdep *tdep =3D (loongarch_gdbarch_tdep *) gdbarch_tdep= (gdbarch); + linux_init_abi (info, gdbarch, 0); =20 set_solib_svr4_fetch_link_map_offsets (gdbarch, @@ -187,6 +211,8 @@ loongarch_linux_init_abi (struct gdbarch_info info, str= uct gdbarch *gdbarch) =20 /* Core file support. */ set_gdbarch_iterate_over_regset_sections (gdbarch, loongarch_iterate_ove= r_regset_sections); + + tdep->syscall_next_pc =3D loongarch_linux_syscall_next_pc; } =20 /* Initialize LoongArch Linux target support. */ diff --git a/gdb/loongarch-tdep.c b/gdb/loongarch-tdep.c index 3c02449a5e6..f2f4e3be909 100644 --- a/gdb/loongarch-tdep.c +++ b/gdb/loongarch-tdep.c @@ -224,6 +224,8 @@ loongarch_skip_prologue (struct gdbarch *gdbarch, CORE_= ADDR pc) static CORE_ADDR loongarch_next_pc (struct regcache *regcache, CORE_ADDR cur_pc) { + struct gdbarch *gdbarch =3D regcache->arch (); + loongarch_gdbarch_tdep *tdep =3D (loongarch_gdbarch_tdep *) gdbarch_tdep= (gdbarch); insn_t insn =3D loongarch_fetch_instruction (cur_pc); size_t insn_len =3D loongarch_insn_length (insn); CORE_ADDR next_pc =3D cur_pc + insn_len; @@ -307,6 +309,11 @@ loongarch_next_pc (struct regcache *regcache, CORE_ADD= R cur_pc) if (rj !=3D 0) next_pc =3D cur_pc + loongarch_decode_imm ("0:5|10:16<<2", insn, 1); } + else if ((insn & 0xffff8000) =3D=3D 0x002b0000) /* syscall */ + { + if (tdep->syscall_next_pc !=3D nullptr) + next_pc =3D tdep->syscall_next_pc (get_current_frame ()); + } =20 return next_pc; } diff --git a/gdb/loongarch-tdep.h b/gdb/loongarch-tdep.h index f3efa4601ef..54b34af1d66 100644 --- a/gdb/loongarch-tdep.h +++ b/gdb/loongarch-tdep.h @@ -48,6 +48,9 @@ struct loongarch_gdbarch_tdep : gdbarch_tdep { /* Features about the abi that impact how the gdbarch is configured. */ struct loongarch_gdbarch_features abi_features; + + /* Return the expected next PC if FRAME is stopped at a syscall instruct= ion. */ + CORE_ADDR (*syscall_next_pc) (struct frame_info *frame) =3D nullptr; }; =20 #endif /* LOONGARCH_TDEP_H */