From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 116887 invoked by alias); 11 Feb 2016 16:30:28 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 116657 invoked by uid 89); 11 Feb 2016 16:30:15 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.6 required=5.0 tests=AWL,BAYES_00,RP_MATCHES_RCVD,SPF_PASS autolearn=ham version=3.3.2 spammy=*action, ACTION, Base, Want X-HELO: xyzzy.0x04.net Received: from xyzzy.0x04.net (HELO xyzzy.0x04.net) (109.74.193.254) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 11 Feb 2016 16:30:12 +0000 Received: from hogfather.0x04.net (89-65-66-135.dynamic.chello.pl [89.65.66.135]) by xyzzy.0x04.net (Postfix) with ESMTPS id 80C703FEC0; Thu, 11 Feb 2016 17:30:55 +0100 (CET) Received: by hogfather.0x04.net (Postfix, from userid 1000) id 358BD58008A; Thu, 11 Feb 2016 17:30:05 +0100 (CET) From: =?UTF-8?q?Marcin=20Ko=C5=9Bcielnicki?= To: palves@redhat.com Cc: gdb-patches@sourceware.org, antoine.tremblay@ericsson.com, =?UTF-8?q?Marcin=20Ko=C5=9Bcielnicki?= Subject: [PATCH] gdbserver: Remove tracepoint_action ops. Date: Thu, 11 Feb 2016 16:30:00 -0000 Message-Id: <1455208203-28310-1-git-send-email-koriakin@0x04.net> In-Reply-To: <56A60CD3.6060704@redhat.com> References: <56A60CD3.6060704@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-IsSubscribed: yes X-SW-Source: 2016-02/txt/msg00368.txt.bz2 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-06-27 Wei-cheng Wang 2016-02-11 Marcin Kościelnicki * tracepoint.c (struct tracepoint_action_ops): Removed. (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. --- Hey, This is a fixed-up version of Wei-cheng's patch at https://sourceware.org/ml/gdb-patches/2015-03/msg00995.html . This version, in addition to fixing a few trivial conflicts, also removes the definition of struct tracepoint_action_ops, which is now unused, but was left in by the original patch. I'm also not sure if I got the changelog format right... OK to push? gdb/gdbserver/tracepoint.c | 119 +++++++++++++++++++-------------------------- 1 file changed, 50 insertions(+), 69 deletions(-) diff --git a/gdb/gdbserver/tracepoint.c b/gdb/gdbserver/tracepoint.c index 0671999..ca77487 100644 --- a/gdb/gdbserver/tracepoint.c +++ b/gdb/gdbserver/tracepoint.c @@ -462,28 +462,10 @@ static int write_inferior_data_ptr (CORE_ADDR where, CORE_ADDR ptr); #endif -/* Operations on various types of tracepoint actions. */ - -struct tracepoint_action; - -struct tracepoint_action_ops -{ - /* Download tracepoint action ACTION to IPA. Return the address of action - in IPA/inferior. */ - CORE_ADDR (*download) (const struct tracepoint_action *action); - - /* Send ACTION to agent via command buffer started from BUFFER. Return - updated head of command buffer. */ - char* (*send) (char *buffer, const struct tracepoint_action *action); -}; - /* Base action. Concrete actions inherit this. */ struct tracepoint_action { -#ifndef IN_PROCESS_AGENT - const struct tracepoint_action_ops *ops; -#endif char type; }; @@ -523,12 +505,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)); - CORE_ADDR ipa_action = target_malloc (size_in_ipa); + CORE_ADDR ipa_action = target_malloc (sizeof (struct collect_memory_action)); - write_inferior_memory (ipa_action, (unsigned char *) &action->type, - size_in_ipa); + write_inferior_memory (ipa_action, (unsigned char *) action, + sizeof (struct collect_memory_action)); return ipa_action; } @@ -545,21 +525,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)); - CORE_ADDR ipa_action = target_malloc (size_in_ipa); + CORE_ADDR ipa_action = target_malloc (sizeof (struct collect_registers_action)); - write_inferior_memory (ipa_action, (unsigned char *) &action->type, - size_in_ipa); + write_inferior_memory (ipa_action, (unsigned char *) action, + sizeof (struct collect_registers_action)); return ipa_action; } @@ -570,27 +542,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)); - CORE_ADDR ipa_action = target_malloc (size_in_ipa); + CORE_ADDR ipa_action = target_malloc (sizeof (struct eval_expr_action)); 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_data_ptr (ipa_action + offsetof (struct eval_expr_action, expr) - - offsetof (struct tracepoint_action, type), + write_inferior_memory (ipa_action, (unsigned char *) action, + sizeof (struct eval_expr_action)); + expr = download_agent_expr (((struct eval_expr_action *) action)->expr); + write_inferior_data_ptr (ipa_action + + offsetof (struct eval_expr_action, expr), expr); return ipa_action; @@ -628,21 +592,14 @@ 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)); - CORE_ADDR ipa_action = target_malloc (size_in_ipa); + CORE_ADDR ipa_action = + target_malloc (sizeof (struct collect_static_trace_data_action)); - write_inferior_memory (ipa_action, (unsigned char *) &action->type, - size_in_ipa); + write_inferior_memory (ipa_action, (unsigned char *) action, + sizeof (struct collect_static_trace_data_action)); return ipa_action; } @@ -653,11 +610,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) +{ + 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) { - l_tracepoint_action_download, - l_tracepoint_action_send, -}; + 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 +1929,6 @@ add_tracepoint_action (struct tracepoint *tpoint, char *packet) int is_neg; maction->base.type = *act; - maction->base.ops = &m_tracepoint_action_ops; action = &maction->base; ++act; @@ -1970,7 +1954,6 @@ add_tracepoint_action (struct tracepoint *tpoint, char *packet) XNEW (struct collect_registers_action); raction->base.type = *act; - raction->base.ops = &r_tracepoint_action_ops; action = &raction->base; trace_debug ("Want to collect registers"); @@ -1986,7 +1969,6 @@ add_tracepoint_action (struct tracepoint *tpoint, char *packet) XNEW (struct collect_static_trace_data_action); raction->base.type = *act; - raction->base.ops = &l_tracepoint_action_ops; action = &raction->base; trace_debug ("Want to collect static trace data"); @@ -2002,7 +1984,6 @@ add_tracepoint_action (struct tracepoint *tpoint, char *packet) struct eval_expr_action *xaction = XNEW (struct eval_expr_action); xaction->base.type = *act; - xaction->base.ops = &x_tracepoint_action_ops; action = &xaction->base; trace_debug ("Want to evaluate expression"); @@ -6066,7 +6047,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_ptr @@ -6116,7 +6097,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 (); -- 2.7.0