This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[PATCH 1/5] Remove global variable tracepoint_list and stepping_list.
- From: Yao Qi <yao at codesourcery dot com>
- To: <gdb-patches at sourceware dot org>
- Date: Fri, 7 Jun 2013 21:08:09 +0800
- Subject: [PATCH 1/5] Remove global variable tracepoint_list and stepping_list.
- References: <1370610493-26468-1-git-send-email-yao at codesourcery dot com>
This patch is a refactor patch. Simply, it removes two global
variables tracepoint_list and stepping_list.
gdb:
2013-06-07 Pedro Alves <pedro@codesourcery.com>
Yao Qi <yao@codesourcery.com>
* tracepoint.c (tracepoint_list, stepping_list): Remove.
(do_clear_collection_list, init_collection_list): New.
(encode_actions): Change the type of the second and third
parameter from 'char ***' to 'struct collection_list *'.
(encode_actions): Rename to encode_actions_rsp, and rewrite on top
of the new encode_actions implementation.
(encode_actions): New function.
(_initialize_tracepoint): Delete references to 'tracepoint_list'
and 'stepping_list'.
* tracepoint.h (encode_actions): Remove declaration.
(encode_actions_rsp): Add declaration.
* remote.c (remote_download_tracepoint): Caller update.
---
gdb/remote.c | 2 +-
gdb/tracepoint.c | 112 ++++++++++++++++++++++++++++++-----------------------
gdb/tracepoint.h | 4 +-
3 files changed, 66 insertions(+), 52 deletions(-)
diff --git a/gdb/remote.c b/gdb/remote.c
index 080d048..d06b1ed 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -10524,7 +10524,7 @@ remote_download_tracepoint (struct bp_location *loc)
struct breakpoint *b = loc->owner;
struct tracepoint *t = (struct tracepoint *) b;
- encode_actions (loc, &tdp_actions, &stepping_actions);
+ encode_actions_rsp (loc, &tdp_actions, &stepping_actions);
old_chain = make_cleanup (free_actions_list_cleanup_wrapper,
tdp_actions);
(void) make_cleanup (free_actions_list_cleanup_wrapper,
diff --git a/gdb/tracepoint.c b/gdb/tracepoint.c
index 5bad3e8..03f9230 100644
--- a/gdb/tracepoint.c
+++ b/gdb/tracepoint.c
@@ -873,8 +873,7 @@ struct collection_list
/* True is the user requested a collection of "$_sdata", "static
tracepoint data". */
int strace_data;
- }
-tracepoint_list, stepping_list;
+ };
/* MEMRANGE functions: */
@@ -1239,6 +1238,35 @@ clear_collection_list (struct collection_list *list)
list->next_aexpr_elt = 0;
memset (list->regs_mask, 0, sizeof (list->regs_mask));
list->strace_data = 0;
+
+ xfree (list->aexpr_list);
+ xfree (list->list);
+}
+
+/* Wrapper to function clear_collection_list. */
+
+static void
+do_clear_collection_list (void *list)
+{
+ struct collection_list *l = list;
+
+ clear_collection_list (l);
+}
+
+/* Initialize collection_list CLIST. */
+
+static void
+init_collection_list (struct collection_list *clist)
+{
+ memset (clist, 0, sizeof *clist);
+
+ clist->listsize = 128;
+ clist->list = xcalloc (clist->listsize,
+ sizeof (struct memrange));
+
+ clist->aexpr_listsize = 128;
+ clist->aexpr_list = xcalloc (clist->aexpr_listsize,
+ sizeof (struct agent_expr *));
}
/* Reduce a collection list to string form (for gdb protocol). */
@@ -1606,37 +1634,50 @@ encode_actions_1 (struct command_line *action,
} /* for */
}
-/* Render all actions into gdb protocol. */
-
-void
-encode_actions (struct bp_location *tloc, char ***tdp_actions,
- char ***stepping_actions)
+static void
+encode_actions (struct bp_location *tloc,
+ struct collection_list *tracepoint_list,
+ struct collection_list *stepping_list)
{
- char *default_collect_line = NULL;
- struct command_line *actions;
- struct command_line *default_collect_action = NULL;
int frame_reg;
LONGEST frame_offset;
- struct cleanup *back_to;
-
- back_to = make_cleanup (null_cleanup, NULL);
+ struct command_line *actions;
+ struct cleanup *old_chain;
- clear_collection_list (&tracepoint_list);
- clear_collection_list (&stepping_list);
+ old_chain = make_cleanup (null_cleanup, NULL);
- *tdp_actions = NULL;
- *stepping_actions = NULL;
+ actions = all_tracepoint_actions_and_cleanup (tloc->owner);
gdbarch_virtual_frame_pointer (tloc->gdbarch,
tloc->address, &frame_reg, &frame_offset);
- actions = all_tracepoint_actions_and_cleanup (tloc->owner);
-
encode_actions_1 (actions, tloc, frame_reg, frame_offset,
- &tracepoint_list, &stepping_list);
+ tracepoint_list, stepping_list);
+
+ do_cleanups (old_chain);
+
+ memrange_sortmerge (tracepoint_list);
+ memrange_sortmerge (stepping_list);
+}
+
+/* Render all actions into gdb protocol. */
+
+void
+encode_actions_rsp (struct bp_location *tloc,
+ char ***tdp_actions, char ***stepping_actions)
+{
+ struct cleanup *back_to;
+ struct collection_list tracepoint_list, stepping_list;
+
+ back_to = make_cleanup (null_cleanup, NULL);
- memrange_sortmerge (&tracepoint_list);
- memrange_sortmerge (&stepping_list);
+ init_collection_list (&tracepoint_list);
+ init_collection_list (&stepping_list);
+
+ make_cleanup (do_clear_collection_list, &tracepoint_list);
+ make_cleanup (do_clear_collection_list, &stepping_list);
+
+ encode_actions (tloc, &tracepoint_list, &stepping_list);
*tdp_actions = stringify_collection_list (&tracepoint_list);
*stepping_actions = stringify_collection_list (&stepping_list);
@@ -5673,33 +5714,6 @@ _initialize_tracepoint (void)
traceframe_number = -1;
tracepoint_number = -1;
- if (tracepoint_list.list == NULL)
- {
- tracepoint_list.listsize = 128;
- tracepoint_list.list = xmalloc
- (tracepoint_list.listsize * sizeof (struct memrange));
- }
- if (tracepoint_list.aexpr_list == NULL)
- {
- tracepoint_list.aexpr_listsize = 128;
- tracepoint_list.aexpr_list = xmalloc
- (tracepoint_list.aexpr_listsize * sizeof (struct agent_expr *));
- }
-
- if (stepping_list.list == NULL)
- {
- stepping_list.listsize = 128;
- stepping_list.list = xmalloc
- (stepping_list.listsize * sizeof (struct memrange));
- }
-
- if (stepping_list.aexpr_list == NULL)
- {
- stepping_list.aexpr_listsize = 128;
- stepping_list.aexpr_list = xmalloc
- (stepping_list.aexpr_listsize * sizeof (struct agent_expr *));
- }
-
add_info ("scope", scope_info,
_("List the variables local to a scope"));
diff --git a/gdb/tracepoint.h b/gdb/tracepoint.h
index 3b09ca8..5ecf1fb 100644
--- a/gdb/tracepoint.h
+++ b/gdb/tracepoint.h
@@ -357,8 +357,8 @@ void free_actions (struct breakpoint *);
extern const char *decode_agent_options (const char *exp, int *trace_string);
-extern void encode_actions (struct bp_location *tloc,
- char ***tdp_actions, char ***stepping_actions);
+extern void encode_actions_rsp (struct bp_location *tloc,
+ char ***tdp_actions, char ***stepping_actions);
extern void validate_actionline (const char *, struct breakpoint *);
extern void validate_trace_state_variable_name (const char *name);
--
1.7.7.6