Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tankut Baris Aktemur <tankut.baris.aktemur@intel.com>
To: gdb-patches@sourceware.org
Cc: simon.marchi@efficios.com
Subject: [PATCH v2 02/11] gdbserver: use inheritance to define tracepoint contexts
Date: Mon, 30 Dec 2024 11:49:43 +0100	[thread overview]
Message-ID: <20241230-upstream-gdbserver-regcache-v2-2-020a9514fcf0@intel.com> (raw)
In-Reply-To: <20241230-upstream-gdbserver-regcache-v2-0-020a9514fcf0@intel.com>

Use inheritance in the definition of tracepoint contexts.  This is a
refactoring that aims to improve the code.  No behavior should be
altered.
---
 gdbserver/tracepoint.cc | 107 ++++++++++++++++++++++--------------------------
 1 file changed, 48 insertions(+), 59 deletions(-)

diff --git a/gdbserver/tracepoint.cc b/gdbserver/tracepoint.cc
index 81104b02c8321fcb4cb247a6166be10ba04aea8c..fc0586a5c5ace6edc1fc72d24511c6f36e97f759 100644
--- a/gdbserver/tracepoint.cc
+++ b/gdbserver/tracepoint.cc
@@ -1274,7 +1274,7 @@ static char *tracing_stop_note;
 
 /* Functions local to this file.  */
 
-/* Base "class" for tracepoint type specific data to be passed down to
+/* Base class for tracepoint type specific data to be passed down to
    collect_data_at_tracepoint.  */
 struct tracepoint_hit_ctx
 {
@@ -1285,23 +1285,13 @@ struct tracepoint_hit_ctx
 
 /* Fast/jump tracepoint specific data to be passed down to
    collect_data_at_tracepoint.  */
-struct fast_tracepoint_ctx
+struct fast_tracepoint_ctx : public tracepoint_hit_ctx
 {
-  struct tracepoint_hit_ctx base;
-
-  struct regcache regcache;
-  int regcache_initted;
-  unsigned char *regspace;
-
-  unsigned char *regs;
-  struct tracepoint *tpoint;
-};
-
-/* Static tracepoint specific data to be passed down to
-   collect_data_at_tracepoint.  */
-struct static_tracepoint_ctx
-{
-  struct tracepoint_hit_ctx base;
+  fast_tracepoint_ctx (unsigned char *_regs)
+    : regcache_initted (0), regs (_regs)
+  {
+    type = fast_tracepoint;
+  }
 
   /* The regcache corresponding to the registers state at the time of
      the tracepoint hit.  Initialized lazily, from REGS.  */
@@ -1314,25 +1304,41 @@ struct static_tracepoint_ctx
   unsigned char *regspace;
 
   /* The register buffer as passed on by lttng/ust.  */
-  struct registers *regs;
+  unsigned char *regs;
+
+  /* The GDB tracepoint matching the probed marker that was "hit".  */
+  struct tracepoint *tpoint;
+};
+
+/* Static tracepoint specific data to be passed down to
+   collect_data_at_tracepoint.  */
+struct static_tracepoint_ctx : public fast_tracepoint_ctx
+{
+  static_tracepoint_ctx (unsigned char *_regs,
+			 const char *_fmt, va_list *_args)
+    : fast_tracepoint_ctx (_regs), fmt (_fmt), args (_args)
+  {
+    type = static_tracepoint;
+  }
 
   /* The "printf" formatter and the args the user passed to the marker
      call.  We use this to be able to collect "static trace data"
      ($_sdata).  */
   const char *fmt;
   va_list *args;
-
-  /* The GDB tracepoint matching the probed marker that was "hit".  */
-  struct tracepoint *tpoint;
 };
 
 #else
 
 /* Static tracepoint specific data to be passed down to
    collect_data_at_tracepoint.  */
-struct trap_tracepoint_ctx
+struct trap_tracepoint_ctx : public tracepoint_hit_ctx
 {
-  struct tracepoint_hit_ctx base;
+  trap_tracepoint_ctx (struct regcache *_regcache)
+    : regcache (_regcache)
+  {
+    type = trap_tracepoint;
+  }
 
   struct regcache *regcache;
 };
@@ -4345,7 +4351,6 @@ tracepoint_finished_step (thread_info *tinfo, CORE_ADDR stop_pc)
   struct tracepoint *tpoint;
   struct wstep_state *wstep;
   struct wstep_state **wstep_link;
-  struct trap_tracepoint_ctx ctx;
 
   /* Pull in fast tracepoint trace frames from the inferior lib buffer into
      our buffer.  */
@@ -4375,8 +4380,7 @@ tracepoint_finished_step (thread_info *tinfo, CORE_ADDR stop_pc)
 	       target_pid_to_str (tinfo->id).c_str (),
 	       wstep->tp_number, paddress (wstep->tp_address));
 
-  ctx.base.type = trap_tracepoint;
-  ctx.regcache = get_thread_regcache (tinfo);
+  trap_tracepoint_ctx ctx (get_thread_regcache (tinfo));
 
   while (wstep != NULL)
     {
@@ -4398,8 +4402,7 @@ tracepoint_finished_step (thread_info *tinfo, CORE_ADDR stop_pc)
       ++wstep->current_step;
 
       /* Collect data.  */
-      collect_data_at_step ((struct tracepoint_hit_ctx *) &ctx,
-			    stop_pc, tpoint, wstep->current_step);
+      collect_data_at_step (&ctx, stop_pc, tpoint, wstep->current_step);
 
       if (wstep->current_step >= tpoint->step_count)
 	{
@@ -4530,14 +4533,12 @@ tracepoint_was_hit (thread_info *tinfo, CORE_ADDR stop_pc)
 {
   struct tracepoint *tpoint;
   int ret = 0;
-  struct trap_tracepoint_ctx ctx;
 
   /* Not tracing, don't handle.  */
   if (!tracing)
     return 0;
 
-  ctx.base.type = trap_tracepoint;
-  ctx.regcache = get_thread_regcache (tinfo);
+  trap_tracepoint_ctx ctx (get_thread_regcache (tinfo));
 
   for (tpoint = tracepoints; tpoint; tpoint = tpoint->next)
     {
@@ -4556,10 +4557,8 @@ tracepoint_was_hit (thread_info *tinfo, CORE_ADDR stop_pc)
 
 	  /* Test the condition if present, and collect if true.  */
 	  if (!tpoint->cond
-	      || (condition_true_at_tracepoint
-		  ((struct tracepoint_hit_ctx *) &ctx, tpoint)))
-	    collect_data_at_tracepoint ((struct tracepoint_hit_ctx *) &ctx,
-					stop_pc, tpoint);
+	      || (condition_true_at_tracepoint (&ctx, tpoint)))
+	    collect_data_at_tracepoint (&ctx, stop_pc, tpoint);
 
 	  if (stopping_tracepoint
 	      || trace_buffer_is_full
@@ -4696,7 +4695,8 @@ get_context_regcache (struct tracepoint_hit_ctx *ctx)
 
   if (ctx->type == fast_tracepoint)
     {
-      struct fast_tracepoint_ctx *fctx = (struct fast_tracepoint_ctx *) ctx;
+      auto fctx = static_cast<fast_tracepoint_ctx *> (ctx);
+
       if (!fctx->regcache_initted)
 	{
 	  fctx->regcache_initted = 1;
@@ -4709,8 +4709,7 @@ get_context_regcache (struct tracepoint_hit_ctx *ctx)
 #ifdef HAVE_UST
   if (ctx->type == static_tracepoint)
     {
-      struct static_tracepoint_ctx *sctx
-	= (struct static_tracepoint_ctx *) ctx;
+      auto sctx = static_cast <static_tracepoint_ctx *> (ctx);
 
       if (!sctx->regcache_initted)
 	{
@@ -4730,7 +4729,7 @@ get_context_regcache (struct tracepoint_hit_ctx *ctx)
 #else
   if (ctx->type == trap_tracepoint)
     {
-      struct trap_tracepoint_ctx *tctx = (struct trap_tracepoint_ctx *) ctx;
+      auto tctx = static_cast<trap_tracepoint_ctx *> (ctx);
       regcache = tctx->regcache;
     }
 #endif
@@ -4881,7 +4880,7 @@ condition_true_at_tracepoint (struct tracepoint_hit_ctx *ctx,
 #ifdef IN_PROCESS_AGENT
   if (tpoint->compiled_cond)
     {
-      struct fast_tracepoint_ctx *fctx = (struct fast_tracepoint_ctx *) ctx;
+      auto fctx = static_cast<fast_tracepoint_ctx *> (ctx);
       err = ((condfn) (uintptr_t) (tpoint->compiled_cond)) (fctx->regs, &value);
     }
   else
@@ -5763,7 +5762,6 @@ IP_AGENT_EXPORT_FUNC void gdb_collect (struct tracepoint *tpoint,
 IP_AGENT_EXPORT_FUNC void
 gdb_collect (struct tracepoint *tpoint, unsigned char *regs)
 {
-  struct fast_tracepoint_ctx ctx;
   const struct target_desc *ipa_tdesc;
 
   /* Don't do anything until the trace run is completely set up.  */
@@ -5771,9 +5769,8 @@ gdb_collect (struct tracepoint *tpoint, unsigned char *regs)
     return;
 
   ipa_tdesc = get_ipa_tdesc (ipa_tdesc_idx);
-  ctx.base.type = fast_tracepoint;
-  ctx.regs = regs;
-  ctx.regcache_initted = 0;
+  fast_tracepoint_ctx ctx (regs);
+
   /* Wrap the regblock in a register cache (in the stack, we don't
      want to malloc here).  */
   ctx.regspace = (unsigned char *) alloca (ipa_tdesc->registers_size);
@@ -5797,11 +5794,10 @@ gdb_collect (struct tracepoint *tpoint, unsigned char *regs)
 
       /* Test the condition if present, and collect if true.  */
       if (ctx.tpoint->cond == NULL
-	  || condition_true_at_tracepoint ((struct tracepoint_hit_ctx *) &ctx,
-					   ctx.tpoint))
+	  || condition_true_at_tracepoint (&ctx, ctx.tpoint))
 	{
-	  collect_data_at_tracepoint ((struct tracepoint_hit_ctx *) &ctx,
-				      ctx.tpoint->address, ctx.tpoint);
+	  collect_data_at_tracepoint (&ctx, ctx.tpoint->address,
+				      ctx.tpoint);
 
 	  /* Note that this will cause original insns to be written back
 	     to where we jumped from, but that's OK because we're jumping
@@ -6651,7 +6647,6 @@ gdb_probe (const struct marker *mdata, void *probe_private,
 	   const char *fmt, va_list *args)
 {
   struct tracepoint *tpoint;
-  struct static_tracepoint_ctx ctx;
   const struct target_desc *ipa_tdesc;
 
   /* Don't do anything until the trace run is completely set up.  */
@@ -6662,11 +6657,7 @@ gdb_probe (const struct marker *mdata, void *probe_private,
     }
 
   ipa_tdesc = get_ipa_tdesc (ipa_tdesc_idx);
-  ctx.base.type = static_tracepoint;
-  ctx.regcache_initted = 0;
-  ctx.regs = regs;
-  ctx.fmt = fmt;
-  ctx.args = args;
+  static_tracepoint_ctx ctx (regs, fmt, args)
 
   /* Wrap the regblock in a register cache (in the stack, we don't
      want to malloc here).  */
@@ -6702,11 +6693,9 @@ gdb_probe (const struct marker *mdata, void *probe_private,
 
   /* Test the condition if present, and collect if true.  */
   if (tpoint->cond == NULL
-      || condition_true_at_tracepoint ((struct tracepoint_hit_ctx *) &ctx,
-				       tpoint))
+      || condition_true_at_tracepoint (&ctx, tpoint))
     {
-      collect_data_at_tracepoint ((struct tracepoint_hit_ctx *) &ctx,
-				  tpoint->address, tpoint);
+      collect_data_at_tracepoint (&ctx, tpoint->address, tpoint);
 
       if (stopping_tracepoint
 	  || trace_buffer_is_full
@@ -6737,7 +6726,7 @@ static void
 collect_ust_data_at_tracepoint (struct tracepoint_hit_ctx *ctx,
 				struct traceframe *tframe)
 {
-  struct static_tracepoint_ctx *umd = (struct static_tracepoint_ctx *) ctx;
+  auto umd = static_cast<static_tracepoint_ctx *> (ctx);
   unsigned char *bufspace;
   int size;
   va_list copy;

-- 
2.34.1

Intel Deutschland GmbH
Registered Address: Am Campeon 10, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de
Managing Directors: Sean Fennelly, Jeffrey Schneiderman, Tiffany Doon Silva
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928

  parent reply	other threads:[~2024-12-30 10:53 UTC|newest]

Thread overview: 93+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-28 11:27 [PATCH 00/26] gdbserver: refactor regcache and allow gradually populating Tankut Baris Aktemur via Gdb-patches
2023-02-28 11:27 ` [PATCH 01/26] gdbserver: convert init_register_cache into regcache::initialize Tankut Baris Aktemur via Gdb-patches
2023-12-21 20:12   ` Simon Marchi
2023-02-28 11:28 ` [PATCH 02/26] gdbserver: convert new_register_cache into a regcache constructor Tankut Baris Aktemur via Gdb-patches
2023-12-21 20:19   ` Simon Marchi
2023-02-28 11:28 ` [PATCH 03/26] gdbserver: by-pass regcache to access tdesc only Tankut Baris Aktemur via Gdb-patches
2023-12-21 20:22   ` Simon Marchi
2023-02-28 11:28 ` [PATCH 04/26] gdbserver: boolify and defaultize the 'fetch' parameter of get_thread_regcache Tankut Baris Aktemur via Gdb-patches
2023-12-21 20:24   ` Simon Marchi
2023-02-28 11:28 ` [PATCH 05/26] gdbserver: add a pointer to the owner thread in regcache Tankut Baris Aktemur via Gdb-patches
2023-12-21 20:28   ` Simon Marchi
2023-02-28 11:28 ` [PATCH 06/26] gdbserver: turn part of get_thread_regcache into regcache::fetch Tankut Baris Aktemur via Gdb-patches
2023-12-21 20:48   ` Simon Marchi
2023-02-28 11:28 ` [PATCH 07/26] gdbserver: convert regcache_cpy into regcache::copy_from Tankut Baris Aktemur via Gdb-patches
2023-12-21 20:50   ` Simon Marchi
2023-02-28 11:28 ` [PATCH 08/26] gdbserver: convert free_register_cache into a destructor of regcache Tankut Baris Aktemur via Gdb-patches
2023-12-21 20:57   ` Simon Marchi
2023-02-28 11:28 ` [PATCH 09/26] gdbserver: extract out regcache::invalidate and regcache::discard Tankut Baris Aktemur via Gdb-patches
2023-12-21 21:08   ` Simon Marchi
2023-02-28 11:28 ` [PATCH 10/26] gdbserver: convert registers_to_string into regcache::registers_to_string Tankut Baris Aktemur via Gdb-patches
2023-12-21 21:13   ` Simon Marchi
2023-12-21 21:19     ` Simon Marchi
2023-02-28 11:28 ` [PATCH 11/26] gdbserver: convert registers_from_string into regcache::registers_from_string Tankut Baris Aktemur via Gdb-patches
2023-02-28 11:28 ` [PATCH 12/26] gdbserver: convert supply_regblock to regcache::supply_regblock Tankut Baris Aktemur via Gdb-patches
2023-12-21 21:23   ` Simon Marchi
2023-02-28 11:28 ` [PATCH 13/26] gdbserver: convert register_data into regcache::register_data Tankut Baris Aktemur via Gdb-patches
2023-12-21 21:26   ` Simon Marchi
2023-02-28 11:28 ` [PATCH 14/26] gdbserver: introduce and use regcache::set_register_status Tankut Baris Aktemur via Gdb-patches
2023-12-21 21:30   ` Simon Marchi
2023-02-28 11:28 ` [PATCH 15/26] gdbserver: check for nullptr condition in regcache::get_register_status Tankut Baris Aktemur via Gdb-patches
2023-12-21 21:32   ` Simon Marchi
2023-12-21 21:34   ` Simon Marchi
2023-02-28 11:28 ` [PATCH 16/26] gdbserver: boolify regcache fields Tankut Baris Aktemur via Gdb-patches
2023-12-22  3:20   ` Simon Marchi
2023-02-28 11:28 ` [PATCH 17/26] gdbserver: rename regcache's registers_valid to registers_fetched Tankut Baris Aktemur via Gdb-patches
2023-12-22  3:23   ` Simon Marchi
2023-02-28 11:28 ` [PATCH 18/26] gdbsupport: fix a typo in a comment in common-regcache.h Tankut Baris Aktemur via Gdb-patches
2023-12-22  3:24   ` Simon Marchi
2023-02-28 11:28 ` [PATCH 19/26] gdbserver: fix the declared type of register_status in regcache Tankut Baris Aktemur via Gdb-patches
2023-12-22  3:35   ` Simon Marchi
2023-02-28 11:28 ` [PATCH 20/26] gdbserver: make some regcache fields private Tankut Baris Aktemur via Gdb-patches
2023-12-22  3:39   ` Simon Marchi
2023-02-28 11:28 ` [PATCH 21/26] gdbserver: use REG_UNKNOWN for a regcache's register statuses Tankut Baris Aktemur via Gdb-patches
2023-12-22  4:32   ` Simon Marchi
2023-02-28 11:28 ` [PATCH 22/26] gdbserver: zero-out register values in regcache-discard Tankut Baris Aktemur via Gdb-patches
2023-12-22  4:36   ` Simon Marchi
2023-02-28 11:28 ` [PATCH 23/26] gdbserver: set register statuses in registers_from_string Tankut Baris Aktemur via Gdb-patches
2023-12-22  4:40   ` Simon Marchi
2023-02-28 11:28 ` [PATCH 24/26] gdbserver: return tracked register status in regcache_raw_read_unsigned Tankut Baris Aktemur via Gdb-patches
2023-12-22  4:42   ` Simon Marchi
2023-02-28 11:28 ` [PATCH 25/26] gdbserver: refuse null argument in regcache::supply_regblock Tankut Baris Aktemur via Gdb-patches
2023-12-22  4:54   ` Simon Marchi
2023-02-28 11:28 ` [PATCH 26/26] gdbserver: allow gradually populating and selectively storing a regcache Tankut Baris Aktemur via Gdb-patches
2023-12-22 16:25   ` Simon Marchi
2024-06-28 12:17     ` Aktemur, Tankut Baris
2023-03-07 20:39 ` [PATCH 00/26] gdbserver: refactor regcache and allow gradually populating Tom Tromey
2023-03-13 14:33   ` Aktemur, Tankut Baris via Gdb-patches
2023-03-28 13:42 ` Aktemur, Tankut Baris via Gdb-patches
2023-06-20 12:58 ` Aktemur, Tankut Baris via Gdb-patches
2024-12-17  8:18 ` [PUSHED 0/8] Some gdbserver regcache cleanup Tankut Baris Aktemur
2024-12-17  8:18   ` [PUSHED 1/8] gdbserver: by-pass regcache to access tdesc only Tankut Baris Aktemur
2024-12-17  8:18   ` [PUSHED 2/8] gdbserver: boolify and defaultize the 'fetch' parameter of get_thread_regcache Tankut Baris Aktemur
2024-12-17  8:18   ` [PUSHED 3/8] gdbserver: convert regcache_cpy into regcache::copy_from Tankut Baris Aktemur
2024-12-17  8:18   ` [PUSHED 4/8] gdbserver: check for nullptr condition in regcache::get_register_status Tankut Baris Aktemur
2024-12-17  8:18   ` [PUSHED 5/8] gdbserver: boolify regcache fields Tankut Baris Aktemur
2024-12-17  8:18   ` [PUSHED 6/8] gdbserver: rename regcache's registers_valid to registers_fetched Tankut Baris Aktemur
2024-12-17  8:18   ` [PUSHED 7/8] gdbsupport: fix a typo in a comment in common-regcache.h Tankut Baris Aktemur
2024-12-17  8:18   ` [PUSHED 8/8] gdbserver: return tracked register status in regcache_raw_read_unsigned Tankut Baris Aktemur
2024-12-30 10:49 ` [PATCH v2 00/11] gdbserver: refactor regcache Tankut Baris Aktemur
2024-12-30 10:49   ` [PATCH v2 01/11] gdbserver: dump 'xx...x' in collect_register_as_string for unavailable register Tankut Baris Aktemur
2025-01-06 21:28     ` Simon Marchi
2025-01-09  8:35       ` Aktemur, Tankut Baris
2024-12-30 10:49   ` Tankut Baris Aktemur [this message]
2025-01-06 21:46     ` [PATCH v2 02/11] gdbserver: use inheritance to define tracepoint contexts Simon Marchi
2024-12-30 10:49   ` [PATCH v2 03/11] gdbserver: use inheritance more " Tankut Baris Aktemur
2025-01-07  4:40     ` Simon Marchi
2024-12-30 10:49   ` [PATCH v2 04/11] gdbserver: convert init_register_cache and new_register_cache into constructors Tankut Baris Aktemur
2025-01-07  4:51     ` Simon Marchi
2024-12-30 10:49   ` [PATCH v2 05/11] gdbserver: convert free_register_cache into a destructor of regcache Tankut Baris Aktemur
2025-01-07  4:53     ` Simon Marchi
2025-01-07  4:54     ` Simon Marchi
2024-12-30 10:49   ` [PATCH v2 06/11] gdbserver: use unique_ptr for thread_info's regcache Tankut Baris Aktemur
2024-12-30 10:49   ` [PATCH v2 07/11] gdbserver: introduce and use regcache::set_register_status Tankut Baris Aktemur
2025-01-07  5:01     ` Simon Marchi
2025-01-09 12:49       ` Aktemur, Tankut Baris
2024-12-30 10:49   ` [PATCH v2 08/11] gdbserver: use REG_UNKNOWN for a regcache's register statuses Tankut Baris Aktemur
2025-01-07  5:17     ` Simon Marchi
2024-12-30 10:49   ` [PATCH v2 09/11] gdbserver: define and use regcache::reset Tankut Baris Aktemur
2025-01-07  5:27     ` Simon Marchi
2024-12-30 10:49   ` [PATCH v2 10/11] gdbserver: refactor the definition and uses of supply_regblock Tankut Baris Aktemur
2025-01-07  5:34     ` Simon Marchi
2024-12-30 10:49   ` [PATCH v2 11/11] gdbserver: fix the declared type of register_status in regcache Tankut Baris Aktemur
2025-01-07  5:40     ` Simon Marchi

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=20241230-upstream-gdbserver-regcache-v2-2-020a9514fcf0@intel.com \
    --to=tankut.baris.aktemur@intel.com \
    --cc=gdb-patches@sourceware.org \
    --cc=simon.marchi@efficios.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