diff options
author | Tom Tromey <tom@tromey.com> | 2017-04-10 15:47:21 -0600 |
---|---|---|
committer | Tom Tromey <tom@tromey.com> | 2017-04-12 11:16:19 -0600 |
commit | 16e802b9c085ce354b1ab9e2fd25d00bf7626fa8 (patch) | |
tree | 7745d7708fd31fe748a6807242a3a6e58201f892 | |
parent | d28cd78ad820e3a40ac5064b6a30f3a12ce70bf0 (diff) | |
download | fsf-binutils-gdb-16e802b9c085ce354b1ab9e2fd25d00bf7626fa8.zip fsf-binutils-gdb-16e802b9c085ce354b1ab9e2fd25d00bf7626fa8.tar.gz fsf-binutils-gdb-16e802b9c085ce354b1ab9e2fd25d00bf7626fa8.tar.bz2 |
Add a constructor and destructor to linespec_result
linespec_result is only ever allocated on the stack, so it's
relatively easy to convert to having a constructor and a destructor.
This patch makes this change. This removes some cleanups.
gdb/ChangeLog
2017-04-12 Tom Tromey <tom@tromey.com>
* linespec.h (struct linespec_result): Add constructor and
destructor.
(init_linespec_result, destroy_linespec_result)
(make_cleanup_destroy_linespec_result): Don't declare.
* linespec.c (init_linespec_result): Remove.
(linespec_result::~linespec_result): Rename from
destroy_linespec_result. Update.
(cleanup_linespec_result, make_cleanup_destroy_linespec_result):
Remove.
* breakpoint.c (create_breakpoint, break_range_command)
(decode_location_default): Update.
* ax-gdb.c (agent_command_1): Update.
-rw-r--r-- | gdb/ChangeLog | 15 | ||||
-rw-r--r-- | gdb/ax-gdb.c | 5 | ||||
-rw-r--r-- | gdb/breakpoint.c | 19 | ||||
-rw-r--r-- | gdb/linespec.c | 35 | ||||
-rw-r--r-- | gdb/linespec.h | 41 |
5 files changed, 40 insertions, 75 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog index d2de99f..7ddac5b 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,20 @@ 2017-04-12 Tom Tromey <tom@tromey.com> + * linespec.h (struct linespec_result): Add constructor and + destructor. + (init_linespec_result, destroy_linespec_result) + (make_cleanup_destroy_linespec_result): Don't declare. + * linespec.c (init_linespec_result): Remove. + (linespec_result::~linespec_result): Rename from + destroy_linespec_result. Update. + (cleanup_linespec_result, make_cleanup_destroy_linespec_result): + Remove. + * breakpoint.c (create_breakpoint, break_range_command) + (decode_location_default): Update. + * ax-gdb.c (agent_command_1): Update. + +2017-04-12 Tom Tromey <tom@tromey.com> + * remote.c (remote_download_tracepoint): Update. * python/py-breakpoint.c (bppy_get_location): Update. * guile/scm-breakpoint.c (bpscm_print_breakpoint_smob) diff --git a/gdb/ax-gdb.c b/gdb/ax-gdb.c index 7206022..fae2e2d 100644 --- a/gdb/ax-gdb.c +++ b/gdb/ax-gdb.c @@ -2603,15 +2603,13 @@ agent_command_1 (char *exp, int eval) struct linespec_result canonical; int ix; struct linespec_sals *iter; - struct cleanup *old_chain; exp = skip_spaces (exp); - init_linespec_result (&canonical); + event_location_up location = new_linespec_location (&exp); decode_line_full (location.get (), DECODE_LINE_FUNFIRSTLINE, NULL, (struct symtab *) NULL, 0, &canonical, NULL, NULL); - old_chain = make_cleanup_destroy_linespec_result (&canonical); exp = skip_spaces (exp); if (exp[0] == ',') { @@ -2625,7 +2623,6 @@ agent_command_1 (char *exp, int eval) for (i = 0; i < iter->sals.nelts; i++) agent_eval_command_one (exp, eval, iter->sals.sals[i].pc); } - do_cleanups (old_chain); } else agent_eval_command_one (exp, eval, get_frame_pc (get_current_frame ())); diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index afc8309..42f344a 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -9726,7 +9726,6 @@ create_breakpoint (struct gdbarch *gdbarch, unsigned flags) { struct linespec_result canonical; - struct cleanup *old_chain; struct cleanup *bkpt_chain = NULL; int pending = 0; int task = 0; @@ -9738,8 +9737,6 @@ create_breakpoint (struct gdbarch *gdbarch, if (extra_string != NULL && *extra_string == '\0') extra_string = NULL; - init_linespec_result (&canonical); - TRY { ops->create_sals_from_location (location, &canonical, type_wanted); @@ -9779,9 +9776,6 @@ create_breakpoint (struct gdbarch *gdbarch, if (!pending && VEC_empty (linespec_sals, canonical.sals)) return 0; - /* Create a chain of things that always need to be cleaned up. */ - old_chain = make_cleanup_destroy_linespec_result (&canonical); - /* ----------------------------- SNIP ----------------------------- Anything added to the cleanup chain beyond this point is assumed to be part of a breakpoint. If the breakpoint create succeeds @@ -9922,8 +9916,6 @@ create_breakpoint (struct gdbarch *gdbarch, /* That's it. Discard the cleanups for data inserted into the breakpoint. */ discard_cleanups (bkpt_chain); - /* But cleanup everything else. */ - do_cleanups (old_chain); /* error call may happen here - have BKPT_CHAIN already discarded. */ update_global_location_list (UGLL_MAY_INSERT); @@ -10372,13 +10364,10 @@ break_range_command (char *arg, int from_tty) if (arg == NULL || arg[0] == '\0') error(_("No address range specified.")); - init_linespec_result (&canonical_start); - arg_start = arg; event_location_up start_location = string_to_event_location (&arg, current_language); parse_breakpoint_sals (start_location.get (), &canonical_start); - cleanup_bkpt = make_cleanup_destroy_linespec_result (&canonical_start); if (arg[0] != ',') error (_("Too few arguments.")); @@ -10393,14 +10382,13 @@ break_range_command (char *arg, int from_tty) sal_start = lsal_start->sals.sals[0]; addr_string_start = savestring (arg_start, arg - arg_start); - make_cleanup (xfree, addr_string_start); + cleanup_bkpt = make_cleanup (xfree, addr_string_start); arg++; /* Skip the comma. */ arg = skip_spaces (arg); /* Parse the end location. */ - init_linespec_result (&canonical_end); arg_start = arg; /* We call decode_line_full directly here instead of using @@ -10414,8 +10402,6 @@ break_range_command (char *arg, int from_tty) sal_start.symtab, sal_start.line, &canonical_end, NULL, NULL); - make_cleanup_destroy_linespec_result (&canonical_end); - if (VEC_empty (linespec_sals, canonical_end.sals)) error (_("Could not find location of the end of the range.")); @@ -14487,7 +14473,6 @@ decode_location_default (struct breakpoint *b, { struct linespec_result canonical; - init_linespec_result (&canonical); decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, search_pspace, (struct symtab *) NULL, 0, &canonical, multiple_symbols_all, @@ -14506,8 +14491,6 @@ decode_location_default (struct breakpoint *b, contents. */ lsal->sals.sals = NULL; } - - destroy_linespec_result (&canonical); } /* Prepare the global context for a re-set of breakpoint B. */ diff --git a/gdb/linespec.c b/gdb/linespec.c index bccabaf..51fa128 100644 --- a/gdb/linespec.c +++ b/gdb/linespec.c @@ -3887,45 +3887,18 @@ symbol_to_sal (struct symtab_and_line *result, return 0; } -/* See the comment in linespec.h. */ - -void -init_linespec_result (struct linespec_result *lr) -{ - memset (lr, 0, sizeof (*lr)); -} - -/* See the comment in linespec.h. */ - -void -destroy_linespec_result (struct linespec_result *ls) +linespec_result::~linespec_result () { int i; struct linespec_sals *lsal; - delete_event_location (ls->location); - for (i = 0; VEC_iterate (linespec_sals, ls->sals, i, lsal); ++i) + delete_event_location (location); + for (i = 0; VEC_iterate (linespec_sals, sals, i, lsal); ++i) { xfree (lsal->canonical); xfree (lsal->sals.sals); } - VEC_free (linespec_sals, ls->sals); -} - -/* Cleanup function for a linespec_result. */ - -static void -cleanup_linespec_result (void *a) -{ - destroy_linespec_result ((struct linespec_result *) a); -} - -/* See the comment in linespec.h. */ - -struct cleanup * -make_cleanup_destroy_linespec_result (struct linespec_result *ls) -{ - return make_cleanup (cleanup_linespec_result, ls); + VEC_free (linespec_sals, sals); } /* Return the quote characters permitted by the linespec parser. */ diff --git a/gdb/linespec.h b/gdb/linespec.h index 4e69895..5ea8f6f 100644 --- a/gdb/linespec.h +++ b/gdb/linespec.h @@ -41,12 +41,12 @@ struct linespec_sals { /* This is the location corresponding to the sals contained in this object. It can be passed as the FILTER argument to future calls - to decode_line_full. This is freed by - destroy_linespec_result. */ + to decode_line_full. This is freed by the linespec_result + destructor. */ char *canonical; - /* Sals. The 'sals' field is destroyed by - destroy_linespec_result. */ + /* Sals. The 'sals' field is destroyed by the linespec_result + destructor. */ struct symtabs_and_lines sals; }; @@ -54,12 +54,23 @@ typedef struct linespec_sals linespec_sals; DEF_VEC_O (linespec_sals); /* An instance of this may be filled in by decode_line_1. The caller - must call init_linespec_result to initialize it and - destroy_linespec_result to destroy it. The caller must make copies - of any data that it needs to keep. */ + must make copies of any data that it needs to keep. */ struct linespec_result { + linespec_result () + : special_display (0), + pre_expanded (0), + location (NULL), + sals (NULL) + { + } + + ~linespec_result (); + + linespec_result (const linespec_result &) = delete; + linespec_result &operator= (const linespec_result &) = delete; + /* If non-zero, the linespec should be displayed to the user. This is used by "unusual" linespecs where the ordinary `info break' display mechanism would do the wrong thing. */ @@ -75,24 +86,10 @@ struct linespec_result by the user. This will be freed by destroy_linespec_result. */ struct event_location *location; - /* The sals. The vector will be freed by - destroy_linespec_result. */ + /* The sals. The vector will be freed by the destructor. */ VEC (linespec_sals) *sals; }; -/* Initialize a linespec_result. */ - -extern void init_linespec_result (struct linespec_result *); - -/* Destroy a linespec_result. */ - -extern void destroy_linespec_result (struct linespec_result *); - -/* Return a cleanup that destroys a linespec_result. */ - -extern struct cleanup * - make_cleanup_destroy_linespec_result (struct linespec_result *); - /* Decode a linespec using the provided default symtab and line. */ extern struct symtabs_and_lines |