Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Jiangshuai Li via Gdb-patches <gdb-patches@sourceware.org>
To: gdb-patches@sourceware.org
Cc: Jiangshuai Li <jiangshuai_li@linux.alibaba.com>
Subject: [PATCH] gdb/csky add unwinder for sigtramp frame when kernel 4.x and later
Date: Mon,  8 Aug 2022 14:00:00 +0800	[thread overview]
Message-ID: <20220808060000.10587-1-jiangshuai_li@linux.alibaba.com> (raw)

When kernel veriosn >= V4.x, the characteristic values used to determine
whether it is a signal function call are:
	movi r7, 139
	trap 0

Registers are saved at (sp + CSKY_SIGINFO_OFFSET + CSKY_SIGINFO_SIZE
+ CSKY_UCONTEXT_SIGCONTEXT + CSKY_SIGCONTEXT_PT_REGS_TLS). The order is
described in csky_linux_rt_sigreturn_init_pt_regs.
---
 gdb/csky-linux-tdep.c | 47 +++++++++++++++++++++++++++++++++++++++++++
 gdb/csky-tdep.h       |  6 ++++++
 2 files changed, 53 insertions(+)

diff --git a/gdb/csky-linux-tdep.c b/gdb/csky-linux-tdep.c
index 106f629b8b0..89d3a60c43c 100644
--- a/gdb/csky-linux-tdep.c
+++ b/gdb/csky-linux-tdep.c
@@ -353,6 +353,51 @@ csky_linux_rt_sigreturn_tramp_frame = {
   csky_linux_rt_sigreturn_init
 };
 
+static void
+csky_linux_rt_sigreturn_init_pt_regs (const struct tramp_frame *self,
+				      struct frame_info *this_frame,
+				      struct trad_frame_cache *this_cache,
+				      CORE_ADDR func)
+{
+  int i;
+  CORE_ADDR sp = get_frame_register_unsigned (this_frame, CSKY_SP_REGNUM);
+
+  CORE_ADDR base = sp + CSKY_SIGINFO_OFFSET + CSKY_SIGINFO_SIZE
+		   + CSKY_UCONTEXT_SIGCONTEXT
+		   + CSKY_SIGCONTEXT_PT_REGS_TLS;
+
+  /* LR */
+  trad_frame_set_reg_addr (this_cache, CSKY_R15_REGNUM, base);
+
+  /* PC */
+  trad_frame_set_reg_addr (this_cache, CSKY_PC_REGNUM, base + 4);
+
+  /* PSR */
+  trad_frame_set_reg_addr (this_cache, CSKY_CR0_REGNUM, base + 8);
+
+  /* SP */
+  trad_frame_set_reg_addr (this_cache, CSKY_SP_REGNUM, base + 12);
+
+  /* Set addrs of R0 ~ R13.  */
+  for (i = 0; i < 14; i++)
+    trad_frame_set_reg_addr (this_cache, i, base + i * 4 + 20);
+
+  trad_frame_set_id (this_cache, frame_id_build (sp, func));
+}
+
+
+static struct tramp_frame
+csky_linux_rt_sigreturn_tramp_frame_kernel_4x = {
+  SIGTRAMP_FRAME,
+  4,
+  {
+    { CSKY_MOVI_R7_139, ULONGEST_MAX },
+    { CSKY_TRAP_0, ULONGEST_MAX },
+    { TRAMP_SENTINEL_INSN }
+  },
+  csky_linux_rt_sigreturn_init_pt_regs
+};
+
 /* Hook function for gdbarch_register_osabi.  */
 
 static void
@@ -378,6 +423,8 @@ csky_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 
   tramp_frame_prepend_unwinder (gdbarch,
 				&csky_linux_rt_sigreturn_tramp_frame);
+  tramp_frame_prepend_unwinder (gdbarch,
+				&csky_linux_rt_sigreturn_tramp_frame_kernel_4x);
 }
 
 void _initialize_csky_linux_tdep ();
diff --git a/gdb/csky-tdep.h b/gdb/csky-tdep.h
index 3ee50fc5931..f845b9ab744 100644
--- a/gdb/csky-tdep.h
+++ b/gdb/csky-tdep.h
@@ -379,4 +379,10 @@ enum csky_regnum
 #define CSKY_MOVI_R7_173 0x00adea07
 #define CSKY_TRAP_0 0x2020c000
 
+/* Sizeof (tls) */
+#define CSKY_SIGCONTEXT_PT_REGS_TLS  4
+
+/* Macro for kernel 4.x  */
+#define CSKY_MOVI_R7_139 0x008bea07
+
 #endif
-- 
2.25.1


                 reply	other threads:[~2022-08-08  6:00 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=20220808060000.10587-1-jiangshuai_li@linux.alibaba.com \
    --to=gdb-patches@sourceware.org \
    --cc=jiangshuai_li@linux.alibaba.com \
    /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