public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
From: Tiezhu Yang <yangtiezhu@sourceware.org>
To: gdb-cvs@sourceware.org
Subject: [binutils-gdb] gdb: LoongArch: Implement loongarch_linux_syscall_next_pc()
Date: Sat, 25 Jun 2022 02:18:22 +0000 (GMT)	[thread overview]
Message-ID: <20220625021822.C9D39384B124@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=af6e3f77e939ecf85e18720925a4d8f355f90ee1

commit af6e3f77e939ecf85e18720925a4d8f355f90ee1
Author: Tiezhu Yang <yangtiezhu@loongson.cn>
Date:   Sat Jun 25 09:21:16 2022 +0800

    gdb: LoongArch: Implement loongarch_linux_syscall_next_pc()
    
    When FRAME is at a syscall instruction, return the PC of the next
    instruction to be executed.
    
    Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>

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 gdbarch *gdbarch,
       LOONGARCH_LINUX_NUM_GREGSET * regsize, &loongarch_gregset, NULL, cb_data);
 }
 
+/* The following value is derived from __NR_rt_sigreturn in
+   <include/uapi/asm-generic/unistd.h> 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 = get_frame_pc (frame);
+  ULONGEST a7 = 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 == LOONGARCH_NR_rt_sigreturn)
+    return frame_unwind_caller_pc (frame);
+
+  return pc + 4;
+}
+
 /* Initialize LoongArch Linux ABI info.  */
 
 static void
 loongarch_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
+  loongarch_gdbarch_tdep *tdep = (loongarch_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+
   linux_init_abi (info, gdbarch, 0);
 
   set_solib_svr4_fetch_link_map_offsets (gdbarch,
@@ -187,6 +211,8 @@ loongarch_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 
   /* Core file support.  */
   set_gdbarch_iterate_over_regset_sections (gdbarch, loongarch_iterate_over_regset_sections);
+
+  tdep->syscall_next_pc = loongarch_linux_syscall_next_pc;
 }
 
 /* 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 = regcache->arch ();
+  loongarch_gdbarch_tdep *tdep = (loongarch_gdbarch_tdep *) gdbarch_tdep (gdbarch);
   insn_t insn = loongarch_fetch_instruction (cur_pc);
   size_t insn_len = loongarch_insn_length (insn);
   CORE_ADDR next_pc = cur_pc + insn_len;
@@ -307,6 +309,11 @@ loongarch_next_pc (struct regcache *regcache, CORE_ADDR cur_pc)
       if (rj != 0)
 	next_pc = cur_pc + loongarch_decode_imm ("0:5|10:16<<2", insn, 1);
     }
+  else if ((insn & 0xffff8000) == 0x002b0000)		/* syscall  */
+    {
+      if (tdep->syscall_next_pc != nullptr)
+	next_pc = tdep->syscall_next_pc (get_current_frame ());
+    }
 
   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 instruction.  */
+  CORE_ADDR (*syscall_next_pc) (struct frame_info *frame) = nullptr;
 };
 
 #endif /* LOONGARCH_TDEP_H  */


                 reply	other threads:[~2022-06-25  2:18 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220625021822.C9D39384B124@sourceware.org \
    --to=yangtiezhu@sourceware.org \
    --cc=gdb-cvs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).