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.
This commit is contained in:
Tom Tromey
2017-04-10 15:47:21 -06:00
parent d28cd78ad8
commit 16e802b9c0
5 changed files with 40 additions and 75 deletions

View File

@@ -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. */