public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] gdb/riscv: add systemtap support
@ 2023-03-20  8:18 Andrew Burgess
  2023-03-20 13:43 ` Tom Tromey
  0 siblings, 1 reply; 6+ messages in thread
From: Andrew Burgess @ 2023-03-20  8:18 UTC (permalink / raw)
  To: gdb-patches; +Cc: Andrew Burgess

This commit is initial support for SystemTap for RISC-V Linux.  The
following two tests exercise SystemTap functionality, and are showing
many failures, which are all fixed by this commit:

  gdb.cp/exceptprint.exp
  gdb.base/stap-probe.exp

One thing I wasn't sure about is if the SystemTap support should be
Linux specific, or architecture specific.  For aarch64, arm, ia64, and
ppc, the SystemTap support seems to libe in the ARCH-linux-tdep.c
file, while for amd64, i386, and s390 the implementation lives in
ARCH-tdep.c.  I have no idea which of these is the better choice -- or
maybe both choices are correct in the right circumstances, and I'm
just not aware of how to choose between them.

Anyway, for this patch I selected riscv-linux-tdep.c (though clearly,
moving the changes to riscv-tdep.c is trivial if anyone can why that's
a more appropriate location).  It makes sense to me that SystemTap
might be a Linux only tool, which is why I picked the Linux tdep file.

The stap-probe.exp file tests immediate, register, and register
indirect operands, all of which appear to be working fine with this
commit.  The generic expression support doesn't appear to be
architecture specific, so I'd expect that to work fine too.
---
 gdb/riscv-linux-tdep.c | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)

diff --git a/gdb/riscv-linux-tdep.c b/gdb/riscv-linux-tdep.c
index 292d7a4ef7c..f1a8dbbb71e 100644
--- a/gdb/riscv-linux-tdep.c
+++ b/gdb/riscv-linux-tdep.c
@@ -26,6 +26,7 @@
 #include "tramp-frame.h"
 #include "trad-frame.h"
 #include "gdbarch.h"
+#include "safe-ctype.h"
 
 /* The following value is derived from __NR_rt_sigreturn in
    <include/uapi/asm-generic/unistd.h> from the Linux source tree.  */
@@ -174,6 +175,33 @@ riscv_linux_syscall_next_pc (frame_info_ptr frame)
   return pc + 4 /* Length of the ECALL insn.  */;
 }
 
+/* Implementation of `gdbarch_stap_is_single_operand', as defined in
+   gdbarch.h.  */
+
+static int
+riscv_stap_is_single_operand (struct gdbarch *gdbarch, const char *s)
+{
+  return (ISDIGIT (*s) /* Literal number.  */
+	  || *s == '(' /* Register indirection.  */
+	  || ISALPHA (*s)); /* Register value.  */
+}
+
+/* String that appears before a register name in a SystemTap register
+   indirect expression.  */
+
+static const char *const stap_register_indirection_prefixes[] =
+{
+  "(", nullptr
+};
+
+/* String that appears after a register name in a SystemTap register
+   indirect expression.  */
+
+static const char *const stap_register_indirection_suffixes[] =
+{
+  ")", nullptr
+};
+
 /* Initialize RISC-V Linux ABI info.  */
 
 static void
@@ -206,6 +234,13 @@ riscv_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
   tramp_frame_prepend_unwinder (gdbarch, &riscv_linux_sigframe);
 
   tdep->syscall_next_pc = riscv_linux_syscall_next_pc;
+
+  /* SystemTap Support.  */
+  set_gdbarch_stap_is_single_operand (gdbarch, riscv_stap_is_single_operand);
+  set_gdbarch_stap_register_indirection_prefixes
+    (gdbarch, stap_register_indirection_prefixes);
+  set_gdbarch_stap_register_indirection_suffixes
+    (gdbarch, stap_register_indirection_suffixes);
 }
 
 /* Initialize RISC-V Linux target support.  */

base-commit: 57d67e5883732ec5bc14f02c312d2000d75c1a10
-- 
2.25.4


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

* Re: [PATCH] gdb/riscv: add systemtap support
  2023-03-20  8:18 [PATCH] gdb/riscv: add systemtap support Andrew Burgess
@ 2023-03-20 13:43 ` Tom Tromey
  2023-03-20 20:47   ` Andrew Burgess
  0 siblings, 1 reply; 6+ messages in thread
From: Tom Tromey @ 2023-03-20 13:43 UTC (permalink / raw)
  To: Andrew Burgess via Gdb-patches; +Cc: Andrew Burgess

>>>>> "Andrew" == Andrew Burgess via Gdb-patches <gdb-patches@sourceware.org> writes:

Andrew> One thing I wasn't sure about is if the SystemTap support should be
Andrew> Linux specific, or architecture specific.  For aarch64, arm, ia64, and
Andrew> ppc, the SystemTap support seems to libe in the ARCH-linux-tdep.c
Andrew> file, while for amd64, i386, and s390 the implementation lives in
Andrew> ARCH-tdep.c.  I have no idea which of these is the better choice -- or
Andrew> maybe both choices are correct in the right circumstances, and I'm
Andrew> just not aware of how to choose between them.

It's really an ELF feature, but in practice AFAIK it is only used on
Linux.  Putting it in the arch tdep file seems fine to me, but nothing
bad will happen if it is in the linux-tdep file.

Andrew> Anyway, for this patch I selected riscv-linux-tdep.c (though clearly,
Andrew> moving the changes to riscv-tdep.c is trivial if anyone can why that's
Andrew> a more appropriate location).  It makes sense to me that SystemTap
Andrew> might be a Linux only tool, which is why I picked the Linux tdep file.

Yeah, they are called SystemTap probes but really they are just
implemented as a single header file that could be used elsewhere.

Tom

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

* Re: [PATCH] gdb/riscv: add systemtap support
  2023-03-20 13:43 ` Tom Tromey
@ 2023-03-20 20:47   ` Andrew Burgess
  2023-03-20 21:54     ` [PATCHv2] " Andrew Burgess
  0 siblings, 1 reply; 6+ messages in thread
From: Andrew Burgess @ 2023-03-20 20:47 UTC (permalink / raw)
  To: Tom Tromey, Andrew Burgess via Gdb-patches

Tom Tromey <tom@tromey.com> writes:

>>>>>> "Andrew" == Andrew Burgess via Gdb-patches <gdb-patches@sourceware.org> writes:
>
> Andrew> One thing I wasn't sure about is if the SystemTap support should be
> Andrew> Linux specific, or architecture specific.  For aarch64, arm, ia64, and
> Andrew> ppc, the SystemTap support seems to libe in the ARCH-linux-tdep.c
> Andrew> file, while for amd64, i386, and s390 the implementation lives in
> Andrew> ARCH-tdep.c.  I have no idea which of these is the better choice -- or
> Andrew> maybe both choices are correct in the right circumstances, and I'm
> Andrew> just not aware of how to choose between them.
>
> It's really an ELF feature, but in practice AFAIK it is only used on
> Linux.  Putting it in the arch tdep file seems fine to me, but nothing
> bad will happen if it is in the linux-tdep file.

Thanks for the insight.  I'll move the changes over to riscv-tdep.c and
update the commit message.

Thanks,
Andrew

>
> Andrew> Anyway, for this patch I selected riscv-linux-tdep.c (though clearly,
> Andrew> moving the changes to riscv-tdep.c is trivial if anyone can why that's
> Andrew> a more appropriate location).  It makes sense to me that SystemTap
> Andrew> might be a Linux only tool, which is why I picked the Linux tdep file.
>
> Yeah, they are called SystemTap probes but really they are just
> implemented as a single header file that could be used elsewhere.
>
> Tom


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

* [PATCHv2] gdb/riscv: add systemtap support
  2023-03-20 20:47   ` Andrew Burgess
@ 2023-03-20 21:54     ` Andrew Burgess
  2023-03-21 14:15       ` Tom Tromey
  0 siblings, 1 reply; 6+ messages in thread
From: Andrew Burgess @ 2023-03-20 21:54 UTC (permalink / raw)
  To: Tom Tromey, Andrew Burgess via Gdb-patches


Here's a V2 with the changes in riscv-tdep.c rather than
riscv-linux-tdep.c.  Nothing else has changed.

Thanks,
Andrew

---

commit f0288ff3d6468fb6c42c69a027f391d3460f790b
Author: Andrew Burgess <aburgess@redhat.com>
Date:   Sat Mar 18 15:15:49 2023 +0000

    gdb/riscv: add systemtap support
    
    This commit is initial support for SystemTap for RISC-V Linux.  The
    following two tests exercise SystemTap functionality, and are showing
    many failures, which are all fixed by this commit:
    
      gdb.cp/exceptprint.exp
      gdb.base/stap-probe.exp
    
    One thing I wasn't sure about is if the SystemTap support should be
    Linux specific, or architecture specific.  For aarch64, arm, ia64, and
    ppc, the SystemTap support seems to libe in the ARCH-linux-tdep.c
    file, while for amd64, i386, and s390 the implementation lives in
    ARCH-tdep.c.  I have no idea which of these is the better choice -- or
    maybe both choices are correct in the right circumstances, and I'm
    just not aware of how to choose between them.
    
    Anyway, for this patch I selected riscv-tdep.c (though clearly, moving
    the changes to riscv-linux-tdep.c is trivial if anyone thinks that's a
    more appropriate location).
    
    The stap-probe.exp file tests immediate, register, and register
    indirect operands, all of which appear to be working fine with this
    commit.  The generic expression support doesn't appear to be
    architecture specific, so I'd expect that to work fine too.

diff --git a/gdb/riscv-tdep.c b/gdb/riscv-tdep.c
index 771d892df26..d01ba9bfa6a 100644
--- a/gdb/riscv-tdep.c
+++ b/gdb/riscv-tdep.c
@@ -56,6 +56,7 @@
 #include "prologue-value.h"
 #include "arch/riscv.h"
 #include "riscv-ravenscar-thread.h"
+#include "safe-ctype.h"
 
 /* The stack must be 16-byte aligned.  */
 #define SP_ALIGNMENT 16
@@ -4039,6 +4040,33 @@ riscv_gnu_triplet_regexp (struct gdbarch *gdbarch)
   return "riscv(32|64)?";
 }
 
+/* Implementation of `gdbarch_stap_is_single_operand', as defined in
+   gdbarch.h.  */
+
+static int
+riscv_stap_is_single_operand (struct gdbarch *gdbarch, const char *s)
+{
+  return (ISDIGIT (*s) /* Literal number.  */
+	  || *s == '(' /* Register indirection.  */
+	  || ISALPHA (*s)); /* Register value.  */
+}
+
+/* String that appears before a register name in a SystemTap register
+   indirect expression.  */
+
+static const char *const stap_register_indirection_prefixes[] =
+{
+  "(", nullptr
+};
+
+/* String that appears after a register name in a SystemTap register
+   indirect expression.  */
+
+static const char *const stap_register_indirection_suffixes[] =
+{
+  ")", nullptr
+};
+
 /* Initialize the current architecture based on INFO.  If possible,
    re-use an architecture from ARCHES, which is a list of
    architectures already created during this debugging session.
@@ -4277,6 +4305,13 @@ riscv_gdbarch_init (struct gdbarch_info info,
 					  disassembler_options_riscv ());
   set_gdbarch_disassembler_options (gdbarch, &riscv_disassembler_options);
 
+  /* SystemTap Support.  */
+  set_gdbarch_stap_is_single_operand (gdbarch, riscv_stap_is_single_operand);
+  set_gdbarch_stap_register_indirection_prefixes
+    (gdbarch, stap_register_indirection_prefixes);
+  set_gdbarch_stap_register_indirection_suffixes
+    (gdbarch, stap_register_indirection_suffixes);
+
   /* Hook in OS ABI-specific overrides, if they have been registered.  */
   gdbarch_init_osabi (info, gdbarch);
 


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

* Re: [PATCHv2] gdb/riscv: add systemtap support
  2023-03-20 21:54     ` [PATCHv2] " Andrew Burgess
@ 2023-03-21 14:15       ` Tom Tromey
  2023-03-23  7:20         ` Andrew Burgess
  0 siblings, 1 reply; 6+ messages in thread
From: Tom Tromey @ 2023-03-21 14:15 UTC (permalink / raw)
  To: Andrew Burgess via Gdb-patches; +Cc: Tom Tromey, Andrew Burgess

>>>>> "Andrew" == Andrew Burgess via Gdb-patches <gdb-patches@sourceware.org> writes:

Andrew> Here's a V2 with the changes in riscv-tdep.c rather than
Andrew> riscv-linux-tdep.c.  Nothing else has changed.

Thanks, it looks good to me.
Reviewed-By: Tom Tromey <tom@tromey.com>

Tom

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

* Re: [PATCHv2] gdb/riscv: add systemtap support
  2023-03-21 14:15       ` Tom Tromey
@ 2023-03-23  7:20         ` Andrew Burgess
  0 siblings, 0 replies; 6+ messages in thread
From: Andrew Burgess @ 2023-03-23  7:20 UTC (permalink / raw)
  To: Tom Tromey, Andrew Burgess via Gdb-patches; +Cc: Tom Tromey

Tom Tromey <tom@tromey.com> writes:

>>>>>> "Andrew" == Andrew Burgess via Gdb-patches <gdb-patches@sourceware.org> writes:
>
> Andrew> Here's a V2 with the changes in riscv-tdep.c rather than
> Andrew> riscv-linux-tdep.c.  Nothing else has changed.
>
> Thanks, it looks good to me.
> Reviewed-By: Tom Tromey <tom@tromey.com>

I pushed this patch.

Thanks,
Andrew


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

end of thread, other threads:[~2023-03-23  7:20 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-20  8:18 [PATCH] gdb/riscv: add systemtap support Andrew Burgess
2023-03-20 13:43 ` Tom Tromey
2023-03-20 20:47   ` Andrew Burgess
2023-03-20 21:54     ` [PATCHv2] " Andrew Burgess
2023-03-21 14:15       ` Tom Tromey
2023-03-23  7:20         ` Andrew Burgess

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