public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Wei-cheng Wang <cole945@gmail.com>
To: uweigand@de.ibm.com,	gdb-patches@sourceware.org
Cc: Wei-cheng Wang <cole945@gmail.com>
Subject: [PATCH 7/7 v3] Remove tracepoint_action ops.
Date: Mon, 30 Mar 2015 16:31:00 -0000	[thread overview]
Message-ID: <1427733032-64989-7-git-send-email-cole945@gmail.com> (raw)
In-Reply-To: <1427733032-64989-1-git-send-email-cole945@gmail.com>

This patch removes 'ops' in tracepoint, and uses helper functions to
call action handler instead.

The object layout of tracepoint_action may differ in gdbserver and
inferior depend on the alignment rule of target ABI, so gdbserver cannot
simply copy the object from its memory to inferior memory.

For example,

  struct collect_memory_action
  {
    struct tracepoint_action base;
    {
      #ifndef IN_PROCESS_AGENT
      const struct tracepoint_action_ops *ops;
      #if
  -   char type;
  | }
  | ULONGEST addr;
  | ULONGEST len;
  - int32_t basereg;
  };

and on PowerPC,

     Wihtout ops           with ops
      0   1   2   3         0   1   2   3
   0 |type| PADDING...    0 |ops-------------|
   4 .................    4 |type|PADDING....|
   8 |addr------------    8 |addr-------------
   c ----------------|    c -----------------|
  10 |len-------------   10 |len--------------
  14 ----------------|   14 -----------------|
  18 |basereg--------|   18 |basereg---------|

so we cannot directly copy the object.

In this patch, 'ops' is removed in order to make the objects identical.

gdbserver/ChangeLog

2015-03-30  Wei-cheng Wang  <cole945@gmail.com>

	* tracepoint.c (struct tracepoint_action): Remove ops.
	(m_tracepoint_action_download, r_tracepoint_action_download,
	x_tracepoint_action_download, l_tracepoint_action_download): Adjust
	size and offset accordingly.
	(m_tracepoint_action_ops, r_tracepoint_action_ops,
	x_tracepoint_action_ops, l_tracepoint_action_ops): Delete
	(tracepoint_action_send, tracepoint_action_download): New functions.
	Helpers for tracetion action handlers.
	(add_tracepoint_action): Remove setup actions ops.
	(download_tracepoint_1, tracepoint_send_agent): Call helper functions.
---
 gdb/gdbserver/tracepoint.c | 94 ++++++++++++++++++++++------------------------
 1 file changed, 44 insertions(+), 50 deletions(-)

diff --git a/gdb/gdbserver/tracepoint.c b/gdb/gdbserver/tracepoint.c
index ff66434..31c7fdf 100644
--- a/gdb/gdbserver/tracepoint.c
+++ b/gdb/gdbserver/tracepoint.c
@@ -483,9 +483,6 @@ struct tracepoint_action_ops
 
 struct tracepoint_action
 {
-#ifndef IN_PROCESS_AGENT
-  const struct tracepoint_action_ops *ops;
-#endif
   char type;
 };
 
@@ -525,12 +522,10 @@ struct collect_static_trace_data_action
 static CORE_ADDR
 m_tracepoint_action_download (const struct tracepoint_action *action)
 {
-  int size_in_ipa = (sizeof (struct collect_memory_action)
-		     - offsetof (struct tracepoint_action, type));
+  int size_in_ipa = (sizeof (struct collect_memory_action));
   CORE_ADDR ipa_action = target_malloc (size_in_ipa);
 
-  write_inferior_memory (ipa_action, (unsigned char *) &action->type,
-			 size_in_ipa);
+  write_inferior_memory (ipa_action, (unsigned char *) action, size_in_ipa);
 
   return ipa_action;
 }
@@ -547,21 +542,13 @@ m_tracepoint_action_send (char *buffer, const struct tracepoint_action *action)
   return buffer;
 }
 
-static const struct tracepoint_action_ops m_tracepoint_action_ops =
-{
-  m_tracepoint_action_download,
-  m_tracepoint_action_send,
-};
-
 static CORE_ADDR
 r_tracepoint_action_download (const struct tracepoint_action *action)
 {
-  int size_in_ipa = (sizeof (struct collect_registers_action)
-		     - offsetof (struct tracepoint_action, type));
+  int size_in_ipa = (sizeof (struct collect_registers_action));
   CORE_ADDR ipa_action  = target_malloc (size_in_ipa);
 
-  write_inferior_memory (ipa_action, (unsigned char *) &action->type,
-			size_in_ipa);
+  write_inferior_memory (ipa_action, (unsigned char *) action, size_in_ipa);
 
   return ipa_action;
 }
@@ -572,28 +559,19 @@ r_tracepoint_action_send (char *buffer, const struct tracepoint_action *action)
   return buffer;
 }
 
-static const struct tracepoint_action_ops r_tracepoint_action_ops =
-{
-  r_tracepoint_action_download,
-  r_tracepoint_action_send,
-};
-
 static CORE_ADDR download_agent_expr (struct agent_expr *expr);
 
 static CORE_ADDR
 x_tracepoint_action_download (const struct tracepoint_action *action)
 {
-  int size_in_ipa = (sizeof (struct eval_expr_action)
-		     - offsetof (struct tracepoint_action, type));
+  int size_in_ipa = (sizeof (struct eval_expr_action));
   CORE_ADDR ipa_action = target_malloc (size_in_ipa);
   CORE_ADDR expr;
 
-  write_inferior_memory (ipa_action, (unsigned char *) &action->type,
-			 size_in_ipa);
-  expr = download_agent_expr (((struct eval_expr_action *)action)->expr);
+  write_inferior_memory (ipa_action, (unsigned char *) action, size_in_ipa);
+  expr = download_agent_expr (((struct eval_expr_action *) action)->expr);
   write_inferior_data_pointer (ipa_action
-			       + offsetof (struct eval_expr_action, expr)
-			       - offsetof (struct tracepoint_action, type),
+			       + offsetof (struct eval_expr_action, expr),
 			       expr);
 
   return ipa_action;
@@ -631,21 +609,13 @@ x_tracepoint_action_send ( char *buffer, const struct tracepoint_action *action)
   return agent_expr_send (buffer, eaction->expr);
 }
 
-static const struct tracepoint_action_ops x_tracepoint_action_ops =
-{
-  x_tracepoint_action_download,
-  x_tracepoint_action_send,
-};
-
 static CORE_ADDR
 l_tracepoint_action_download (const struct tracepoint_action *action)
 {
-  int size_in_ipa = (sizeof (struct collect_static_trace_data_action)
-		     - offsetof (struct tracepoint_action, type));
+  int size_in_ipa = (sizeof (struct collect_static_trace_data_action));
   CORE_ADDR ipa_action = target_malloc (size_in_ipa);
 
-  write_inferior_memory (ipa_action, (unsigned char *) &action->type,
-			 size_in_ipa);
+  write_inferior_memory (ipa_action, (unsigned char *) action, size_in_ipa);
 
   return ipa_action;
 }
@@ -656,11 +626,39 @@ l_tracepoint_action_send (char *buffer, const struct tracepoint_action *action)
   return buffer;
 }
 
-static const struct tracepoint_action_ops l_tracepoint_action_ops =
+static char *
+tracepoint_action_send (char *buffer, const struct tracepoint_action *action)
 {
-  l_tracepoint_action_download,
-  l_tracepoint_action_send,
-};
+  switch (action->type)
+    {
+    case 'M':
+      return m_tracepoint_action_send (buffer, action);
+    case 'R':
+      return r_tracepoint_action_send (buffer, action);
+    case 'X':
+      return x_tracepoint_action_send (buffer, action);
+    case 'L':
+      return l_tracepoint_action_send (buffer, action);
+    }
+  error ("Unknown trace action '%c'.", action->type);
+}
+
+static CORE_ADDR
+tracepoint_action_download (const struct tracepoint_action *action)
+{
+  switch (action->type)
+    {
+    case 'M':
+      return m_tracepoint_action_download (action);
+    case 'R':
+      return r_tracepoint_action_download (action);
+    case 'X':
+      return x_tracepoint_action_download (action);
+    case 'L':
+      return l_tracepoint_action_download (action);
+    }
+  error ("Unknown trace action '%c'.", action->type);
+}
 #endif
 
 /* This structure describes a piece of the source-level definition of
@@ -1944,7 +1942,6 @@ add_tracepoint_action (struct tracepoint *tpoint, char *packet)
 
 	    maction = xmalloc (sizeof *maction);
 	    maction->base.type = *act;
-	    maction->base.ops = &m_tracepoint_action_ops;
 	    action = &maction->base;
 
 	    ++act;
@@ -1970,7 +1967,6 @@ add_tracepoint_action (struct tracepoint *tpoint, char *packet)
 
 	    raction = xmalloc (sizeof *raction);
 	    raction->base.type = *act;
-	    raction->base.ops = &r_tracepoint_action_ops;
 	    action = &raction->base;
 
 	    trace_debug ("Want to collect registers");
@@ -1986,7 +1982,6 @@ add_tracepoint_action (struct tracepoint *tpoint, char *packet)
 
 	    raction = xmalloc (sizeof *raction);
 	    raction->base.type = *act;
-	    raction->base.ops = &l_tracepoint_action_ops;
 	    action = &raction->base;
 
 	    trace_debug ("Want to collect static trace data");
@@ -2003,7 +1998,6 @@ add_tracepoint_action (struct tracepoint *tpoint, char *packet)
 
 	    xaction = xmalloc (sizeof (*xaction));
 	    xaction->base.type = *act;
-	    xaction->base.ops = &x_tracepoint_action_ops;
 	    action = &xaction->base;
 
 	    trace_debug ("Want to evaluate expression");
@@ -6046,7 +6040,7 @@ download_tracepoint_1 (struct tracepoint *tpoint)
       for (i = 0; i < tpoint->numactions; i++)
 	{
 	  struct tracepoint_action *action = tpoint->actions[i];
-	  CORE_ADDR ipa_action = action->ops->download (action);
+	  CORE_ADDR ipa_action = tracepoint_action_download (action);
 
 	  if (ipa_action != 0)
 	    write_inferior_data_pointer
@@ -6096,7 +6090,7 @@ tracepoint_send_agent (struct tracepoint *tpoint)
       struct tracepoint_action *action = tpoint->actions[i];
 
       p[0] = action->type;
-      p = action->ops->send (&p[1], action);
+      p = tracepoint_action_send (&p[1], action);
     }
 
   get_jump_space_head ();
-- 
1.9.1

  parent reply	other threads:[~2015-03-30 16:31 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-30 16:31 [PATCH 1/7 v3] powerpc: Support z-point type in gdbserver Wei-cheng Wang
2015-03-30 16:31 ` [PATCH 4/7 v3] Allow target to decide where to map jump-pad Wei-cheng Wang
2015-04-08 17:04   ` Ulrich Weigand
2015-03-30 16:31 ` [PATCH 3/7 v3] Add testcases for ppc64 tracepoint Wei-cheng Wang
2015-04-08 17:02   ` Ulrich Weigand
2015-03-30 16:31 ` Wei-cheng Wang [this message]
2015-04-08 17:09   ` [PATCH 7/7 v3] Remove tracepoint_action ops Ulrich Weigand
2015-03-30 16:31 ` [PATCH 5/7 v3] Replace write_inferior_data_ptr with write_inferior_data_pointer Wei-cheng Wang
2015-04-08 17:06   ` Ulrich Weigand
2015-03-30 16:31 ` [PATCH 2/7 v3] Tracepoint for ppc64 Wei-cheng Wang
2015-04-08 16:57   ` Ulrich Weigand
2015-06-27 17:48     ` Wei-cheng Wang
2015-07-03 16:42       ` Ulrich Weigand
2015-03-30 16:31 ` [PATCH 6/7 v3] Build unavailable-stack frames for tracepoint Wei-cheng Wang
2015-04-08 17:07   ` Ulrich Weigand
2016-02-22  5:28   ` Marcin Kościelnicki
2016-02-23 18:58     ` Ulrich Weigand
2016-02-24  3:18       ` Marcin Kościelnicki
2016-02-24 20:44         ` Sergio Durigan Junior
2016-02-24 21:06           ` [PATCH] [OBV] gdb/rs6000: Fix maybe-uninitialized warning Marcin Kościelnicki
2015-04-08 16:56 ` [PATCH 1/7 v3] powerpc: Support z-point type in gdbserver Ulrich Weigand

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=1427733032-64989-7-git-send-email-cole945@gmail.com \
    --to=cole945@gmail.com \
    --cc=gdb-patches@sourceware.org \
    --cc=uweigand@de.ibm.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).