From: Tom Tromey Date: Thu, 3 May 2018 16:23:55 +0000 (-0600) Subject: Return std::string from ada_exception_catchpoint_cond_string X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=cb7de75eb33b2ceda391c903cac5e5ed63933b99;p=binutils-gdb.git Return std::string from ada_exception_catchpoint_cond_string This changes ada_exception_catchpoint_cond_string to return a std::string, allowing for the removal of a cleanup in create_excep_cond_exprs. ChangeLog 2018-05-04 Tom Tromey * ada-lang.c (create_excep_cond_exprs): Update. (ada_exception_catchpoint_cond_string): Use std::string. --- diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 4edd754338f..1a86a210716 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,8 @@ +2018-05-04 Tom Tromey + + * ada-lang.c (create_excep_cond_exprs): Update. + (ada_exception_catchpoint_cond_string): Use std::string. + 2018-05-04 Tom Tromey * ada-lang.c (xget_renaming_scope): Return std::string. diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index d0862404592..1af09bc00ec 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -12431,7 +12431,7 @@ ada_exception_name_addr (enum ada_exception_catchpoint_kind ex, return result; } -static char *ada_exception_catchpoint_cond_string +static std::string ada_exception_catchpoint_cond_string (const char *excep_string, enum ada_exception_catchpoint_kind ex); @@ -12499,9 +12499,7 @@ static void create_excep_cond_exprs (struct ada_catchpoint *c, enum ada_exception_catchpoint_kind ex) { - struct cleanup *old_chain; struct bp_location *bl; - char *cond_string; /* Nothing to do if there's no specific exception to catch. */ if (c->excep_string == NULL) @@ -12513,8 +12511,8 @@ create_excep_cond_exprs (struct ada_catchpoint *c, /* Compute the condition expression in text form, from the specific expection we want to catch. */ - cond_string = ada_exception_catchpoint_cond_string (c->excep_string, ex); - old_chain = make_cleanup (xfree, cond_string); + std::string cond_string + = ada_exception_catchpoint_cond_string (c->excep_string, ex); /* Iterate over all the catchpoint's locations, and parse an expression for each. */ @@ -12528,7 +12526,7 @@ create_excep_cond_exprs (struct ada_catchpoint *c, { const char *s; - s = cond_string; + s = cond_string.c_str (); TRY { exp = parse_exp_1 (&s, bl->address, @@ -12546,8 +12544,6 @@ create_excep_cond_exprs (struct ada_catchpoint *c, ada_loc->excep_cond_expr = std::move (exp); } - - do_cleanups (old_chain); } /* ada_catchpoint destructor. */ @@ -13248,29 +13244,25 @@ ada_exception_breakpoint_ops (enum ada_exception_catchpoint_kind ex) being raised with the exception that the user wants to catch. This assumes that this condition is used when the inferior just triggered an exception catchpoint. - EX: the type of catchpoints used for catching Ada exceptions. - - The string returned is a newly allocated string that needs to be - deallocated later. */ + EX: the type of catchpoints used for catching Ada exceptions. */ -static char * +static std::string ada_exception_catchpoint_cond_string (const char *excep_string, enum ada_exception_catchpoint_kind ex) { int i; bool is_standard_exc = false; - const char *actual_exc_expr; - char *ref_exc_expr; + std::string result; if (ex == ada_catch_handlers) { /* For exception handlers catchpoints, the condition string does not use the same parameter as for the other exceptions. */ - actual_exc_expr = ("long_integer (GNAT_GCC_exception_Access" - "(gcc_exception).all.occurrence.id)"); + result = ("long_integer (GNAT_GCC_exception_Access" + "(gcc_exception).all.occurrence.id)"); } else - actual_exc_expr = "long_integer (e)"; + result = "long_integer (e)"; /* The standard exceptions are a special case. They are defined in runtime units that have been compiled without debugging info; if @@ -13300,13 +13292,13 @@ ada_exception_catchpoint_cond_string (const char *excep_string, } } + result += " = "; + if (is_standard_exc) - ref_exc_expr = xstrprintf ("long_integer (&standard.%s)", excep_string); + string_appendf (result, "long_integer (&standard.%s)", excep_string); else - ref_exc_expr = xstrprintf ("long_integer (&%s)", excep_string); + string_appendf (result, "long_integer (&%s)", excep_string); - char *result = xstrprintf ("%s = %s", actual_exc_expr, ref_exc_expr); - xfree (ref_exc_expr); return result; }