public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] gdb: LoongArch: prepend tramp frame unwinder for signal
@ 2022-03-31 12:01 Tiezhu Yang
  2022-04-04 16:43 ` Tom Tromey
  0 siblings, 1 reply; 4+ messages in thread
From: Tiezhu Yang @ 2022-03-31 12:01 UTC (permalink / raw)
  To: gdb-patches

Implement the "init" method of struct tramp_frame to prepend tramp
frame unwinder for signal on LoongArch.

With this patch, the following failed testcases can be fixed:

  FAIL: gdb.base/annota1.exp: backtrace @ signal handler (timeout)
  FAIL: gdb.base/annota3.exp: backtrace @ signal handler (pattern 2)

Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
---
 gdb/loongarch-linux-tdep.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 50 insertions(+)

diff --git a/gdb/loongarch-linux-tdep.c b/gdb/loongarch-linux-tdep.c
index 6c040c3..7e219c4 100644
--- a/gdb/loongarch-linux-tdep.c
+++ b/gdb/loongarch-linux-tdep.c
@@ -25,6 +25,8 @@
 #include "loongarch-tdep.h"
 #include "solib-svr4.h"
 #include "target-descriptions.h"
+#include "trad-frame.h"
+#include "tramp-frame.h"
 
 /* Unpack an elf_gregset_t into GDB's register cache.  */
 
@@ -117,6 +119,50 @@ const struct regset loongarch_gregset =
   loongarch_fill_gregset,
 };
 
+/* Implement the "init" method of struct tramp_frame.  */
+
+#define LOONGARCH_RT_SIGFRAME_UCONTEXT_OFFSET	128
+#define LOONGARCH_UCONTEXT_SIGCONTEXT_OFFSET	176
+
+static void
+loongarch_linux_rt_sigframe_init (const struct tramp_frame *self,
+				  struct frame_info *this_frame,
+				  struct trad_frame_cache *this_cache,
+				  CORE_ADDR func)
+{
+  struct gdbarch *gdbarch = get_frame_arch (this_frame);
+  loongarch_gdbarch_tdep *tdep = (loongarch_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  auto regs = tdep->regs;
+
+  CORE_ADDR frame_sp = get_frame_sp (this_frame);
+  CORE_ADDR sigcontext_base = (frame_sp + LOONGARCH_RT_SIGFRAME_UCONTEXT_OFFSET
+			       + LOONGARCH_UCONTEXT_SIGCONTEXT_OFFSET);
+
+  trad_frame_set_reg_addr (this_cache, regs.pc, sigcontext_base);
+  for (int i = 0; i < 32; i++)
+    trad_frame_set_reg_addr (this_cache, regs.r + i, sigcontext_base + 8 + i * 8);
+
+  trad_frame_set_id (this_cache, frame_id_build (frame_sp, func));
+}
+
+/* li.w    a7, __NR_rt_sigreturn  */
+#define LOONGARCH_INST_LIW_A7_RT_SIGRETURN	0x03822c0b
+/* syscall 0  */
+#define LOONGARCH_INST_SYSCALL			0x002b0000
+
+static const struct tramp_frame loongarch_linux_rt_sigframe =
+{
+  SIGTRAMP_FRAME,
+  4,
+  {
+    { LOONGARCH_INST_LIW_A7_RT_SIGRETURN, ULONGEST_MAX },
+    { LOONGARCH_INST_SYSCALL, ULONGEST_MAX },
+    { TRAMP_SENTINEL_INSN, ULONGEST_MAX }
+  },
+  loongarch_linux_rt_sigframe_init,
+  NULL
+};
+
 /* Initialize LoongArch Linux ABI info.  */
 
 static void
@@ -134,8 +180,12 @@ loongarch_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 
   /* GNU/Linux uses the dynamic linker included in the GNU C Library.  */
   set_gdbarch_skip_solib_resolver (gdbarch, glibc_skip_solib_resolver);
+
   /* Enable TLS support.  */
   set_gdbarch_fetch_tls_load_module_address (gdbarch, svr4_fetch_objfile_link_map);
+
+  /* Prepend tramp frame unwinder for signal.  */
+  tramp_frame_prepend_unwinder (gdbarch, &loongarch_linux_rt_sigframe);
 }
 
 /* Initialize LoongArch Linux target support.  */
-- 
2.1.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] gdb: LoongArch: prepend tramp frame unwinder for signal
  2022-03-31 12:01 [PATCH] gdb: LoongArch: prepend tramp frame unwinder for signal Tiezhu Yang
@ 2022-04-04 16:43 ` Tom Tromey
  2022-04-06  3:18   ` Tiezhu Yang
  0 siblings, 1 reply; 4+ messages in thread
From: Tom Tromey @ 2022-04-04 16:43 UTC (permalink / raw)
  To: Tiezhu Yang; +Cc: gdb-patches

>>>>> Tiezhu Yang <yangtiezhu@loongson.cn> writes:

> Implement the "init" method of struct tramp_frame to prepend tramp
> frame unwinder for signal on LoongArch.

> With this patch, the following failed testcases can be fixed:

>   FAIL: gdb.base/annota1.exp: backtrace @ signal handler (timeout)
>   FAIL: gdb.base/annota3.exp: backtrace @ signal handler (pattern 2)

Thank you for the patch.  This is ok, though as loongarch maintainer you
can self-approve patches that only touch this port's files.

Because LoongArch is a new port, I think it's fine if you want to apply
this to the gdb 12 branch as well.

Tom

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] gdb: LoongArch: prepend tramp frame unwinder for signal
  2022-04-04 16:43 ` Tom Tromey
@ 2022-04-06  3:18   ` Tiezhu Yang
  2022-04-06 14:56     ` Tom Tromey
  0 siblings, 1 reply; 4+ messages in thread
From: Tiezhu Yang @ 2022-04-06  3:18 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches



On 04/05/2022 12:43 AM, Tom Tromey wrote:
>>>>>> Tiezhu Yang <yangtiezhu@loongson.cn> writes:
>
>> Implement the "init" method of struct tramp_frame to prepend tramp
>> frame unwinder for signal on LoongArch.
>
>> With this patch, the following failed testcases can be fixed:
>
>>   FAIL: gdb.base/annota1.exp: backtrace @ signal handler (timeout)
>>   FAIL: gdb.base/annota3.exp: backtrace @ signal handler (pattern 2)
>
> Thank you for the patch.  This is ok, though as loongarch maintainer you
> can self-approve patches that only touch this port's files.

Hi Tom,

Thank you very much, I will push this patch later.

If I am understanding you correctly, what you said means that
if the patches only touch files related with LoongArch, I can
push them to the master first, and then send the patches with
"COMMITTED" in the subject line to gdb-patches@sourceware.org,
right?

>
> Because LoongArch is a new port, I think it's fine if you want to apply
> this to the gdb 12 branch as well.
>
> Tom
>

I think it is enough to apply the patches to the master, thank
you.

Thanks,
Tiezhu


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] gdb: LoongArch: prepend tramp frame unwinder for signal
  2022-04-06  3:18   ` Tiezhu Yang
@ 2022-04-06 14:56     ` Tom Tromey
  0 siblings, 0 replies; 4+ messages in thread
From: Tom Tromey @ 2022-04-06 14:56 UTC (permalink / raw)
  To: Tiezhu Yang; +Cc: Tom Tromey, gdb-patches

> If I am understanding you correctly, what you said means that
> if the patches only touch files related with LoongArch, I can
> push them to the master first, and then send the patches with
> "COMMITTED" in the subject line to gdb-patches@sourceware.org,
> right?

Yes.  Normally I send the email first, then push.  But it really doesn't
matter hugely since email is asynchronous.

thanks,
Tom

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-04-06 14:58 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-31 12:01 [PATCH] gdb: LoongArch: prepend tramp frame unwinder for signal Tiezhu Yang
2022-04-04 16:43 ` Tom Tromey
2022-04-06  3:18   ` Tiezhu Yang
2022-04-06 14:56     ` Tom Tromey

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).