(Ada) C++fy conditional string when catching exception.

This commit C++fy the conditional string used when catching Ada exception.

gdb/ChangeLog:

        * ada-lang.c (catch_ada_exception_command_split)
        (create_ada_exception_catchpoint) <cond_string>: Change parameter
        type.  Update code accordingly.
        (catch_ada_exception_command, catch_ada_handlers_command): Use
        C++ string instead of char* for conditional var.
        (catch_ada_assert_command_split) <cond_string>: Change parameter
        type.  Update code accordingly.
        (catch_assert_command): Use C++ string instead of char* for
        conditional var.
        * ada-lang.h (create_ada_exception_catchpoint) <cond_string>:
        Update declaration.
        * mi/mi-cmd-catch.c (mi_cmd_catch_assert, mi_cmd_catch_exception):
        Use std::string instead of char* for condition string.

Tested on x86_64-linux.
This commit is contained in:
Xavier Roirand 2018-01-25 11:09:23 +01:00
parent 4fa955b25e
commit 56ecd069f0
3 changed files with 22 additions and 27 deletions

View File

@ -13142,7 +13142,7 @@ catch_ada_exception_command_split (const char *args,
bool is_catch_handlers_cmd, bool is_catch_handlers_cmd,
enum ada_exception_catchpoint_kind *ex, enum ada_exception_catchpoint_kind *ex,
char **excep_string, char **excep_string,
char **cond_string) std::string &cond_string)
{ {
struct cleanup *old_chain = make_cleanup (null_cleanup, NULL); struct cleanup *old_chain = make_cleanup (null_cleanup, NULL);
char *exception_name; char *exception_name;
@ -13209,7 +13209,8 @@ catch_ada_exception_command_split (const char *args,
*ex = ada_catch_exception; *ex = ada_catch_exception;
*excep_string = exception_name; *excep_string = exception_name;
} }
*cond_string = cond; if (cond != NULL)
cond_string.assign (cond);
} }
/* Return the name of the symbol on which we should break in order to /* Return the name of the symbol on which we should break in order to
@ -13400,7 +13401,7 @@ void
create_ada_exception_catchpoint (struct gdbarch *gdbarch, create_ada_exception_catchpoint (struct gdbarch *gdbarch,
enum ada_exception_catchpoint_kind ex_kind, enum ada_exception_catchpoint_kind ex_kind,
char *excep_string, char *excep_string,
char *cond_string, const std::string &cond_string,
int tempflag, int tempflag,
int disabled, int disabled,
int from_tty) int from_tty)
@ -13415,8 +13416,8 @@ create_ada_exception_catchpoint (struct gdbarch *gdbarch,
ops, tempflag, disabled, from_tty); ops, tempflag, disabled, from_tty);
c->excep_string = excep_string; c->excep_string = excep_string;
create_excep_cond_exprs (c.get (), ex_kind); create_excep_cond_exprs (c.get (), ex_kind);
if (cond_string != NULL) if (!cond_string.empty ())
set_breakpoint_condition (c.get (), cond_string, from_tty); set_breakpoint_condition (c.get (), cond_string.c_str (), from_tty);
install_breakpoint (0, std::move (c), 1); install_breakpoint (0, std::move (c), 1);
} }
@ -13431,14 +13432,14 @@ catch_ada_exception_command (const char *arg_entry, int from_tty,
int tempflag; int tempflag;
enum ada_exception_catchpoint_kind ex_kind; enum ada_exception_catchpoint_kind ex_kind;
char *excep_string = NULL; char *excep_string = NULL;
char *cond_string = NULL; std::string cond_string;
tempflag = get_cmd_context (command) == CATCH_TEMPORARY; tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
if (!arg) if (!arg)
arg = ""; arg = "";
catch_ada_exception_command_split (arg, false, &ex_kind, &excep_string, catch_ada_exception_command_split (arg, false, &ex_kind, &excep_string,
&cond_string); cond_string);
create_ada_exception_catchpoint (gdbarch, ex_kind, create_ada_exception_catchpoint (gdbarch, ex_kind,
excep_string, cond_string, excep_string, cond_string,
tempflag, 1 /* enabled */, tempflag, 1 /* enabled */,
@ -13456,14 +13457,14 @@ catch_ada_handlers_command (const char *arg_entry, int from_tty,
int tempflag; int tempflag;
enum ada_exception_catchpoint_kind ex_kind; enum ada_exception_catchpoint_kind ex_kind;
char *excep_string = NULL; char *excep_string = NULL;
char *cond_string = NULL; std::string cond_string;
tempflag = get_cmd_context (command) == CATCH_TEMPORARY; tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
if (!arg) if (!arg)
arg = ""; arg = "";
catch_ada_exception_command_split (arg, true, &ex_kind, &excep_string, catch_ada_exception_command_split (arg, true, &ex_kind, &excep_string,
&cond_string); cond_string);
create_ada_exception_catchpoint (gdbarch, ex_kind, create_ada_exception_catchpoint (gdbarch, ex_kind,
excep_string, cond_string, excep_string, cond_string,
tempflag, 1 /* enabled */, tempflag, 1 /* enabled */,
@ -13479,7 +13480,7 @@ catch_ada_handlers_command (const char *arg_entry, int from_tty,
(the memory needs to be deallocated after use). */ (the memory needs to be deallocated after use). */
static void static void
catch_ada_assert_command_split (const char *args, char **cond_string) catch_ada_assert_command_split (const char *args, std::string &cond_string)
{ {
args = skip_spaces (args); args = skip_spaces (args);
@ -13491,7 +13492,7 @@ catch_ada_assert_command_split (const char *args, char **cond_string)
args = skip_spaces (args); args = skip_spaces (args);
if (args[0] == '\0') if (args[0] == '\0')
error (_("condition missing after `if' keyword")); error (_("condition missing after `if' keyword"));
*cond_string = xstrdup (args); cond_string.assign (args);
} }
/* Otherwise, there should be no other argument at the end of /* Otherwise, there should be no other argument at the end of
@ -13509,13 +13510,13 @@ catch_assert_command (const char *arg_entry, int from_tty,
const char *arg = arg_entry; const char *arg = arg_entry;
struct gdbarch *gdbarch = get_current_arch (); struct gdbarch *gdbarch = get_current_arch ();
int tempflag; int tempflag;
char *cond_string = NULL; std::string cond_string;
tempflag = get_cmd_context (command) == CATCH_TEMPORARY; tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
if (!arg) if (!arg)
arg = ""; arg = "";
catch_ada_assert_command_split (arg, &cond_string); catch_ada_assert_command_split (arg, cond_string);
create_ada_exception_catchpoint (gdbarch, ada_catch_assert, create_ada_exception_catchpoint (gdbarch, ada_catch_assert,
NULL, cond_string, NULL, cond_string,
tempflag, 1 /* enabled */, tempflag, 1 /* enabled */,

View File

@ -379,8 +379,8 @@ extern std::string ada_name_for_lookup (const char *name);
extern void create_ada_exception_catchpoint extern void create_ada_exception_catchpoint
(struct gdbarch *gdbarch, enum ada_exception_catchpoint_kind ex_kind, (struct gdbarch *gdbarch, enum ada_exception_catchpoint_kind ex_kind,
char *excep_string, char *cond_string, int tempflag, int disabled, char *excep_string, const std::string &cond_string, int tempflag,
int from_tty); int disabled, int from_tty);
/* Some information about a given Ada exception. */ /* Some information about a given Ada exception. */

View File

@ -32,7 +32,7 @@ void
mi_cmd_catch_assert (const char *cmd, char *argv[], int argc) mi_cmd_catch_assert (const char *cmd, char *argv[], int argc)
{ {
struct gdbarch *gdbarch = get_current_arch(); struct gdbarch *gdbarch = get_current_arch();
char *condition = NULL; std::string condition;
int enabled = 1; int enabled = 1;
int temp = 0; int temp = 0;
@ -62,7 +62,7 @@ mi_cmd_catch_assert (const char *cmd, char *argv[], int argc)
switch ((enum opt) opt) switch ((enum opt) opt)
{ {
case OPT_CONDITION: case OPT_CONDITION:
condition = oarg; condition.assign (oarg);
break; break;
case OPT_DISABLED: case OPT_DISABLED:
enabled = 0; enabled = 0;
@ -79,10 +79,6 @@ mi_cmd_catch_assert (const char *cmd, char *argv[], int argc)
error (_("Invalid argument: %s"), argv[oind]); error (_("Invalid argument: %s"), argv[oind]);
scoped_restore restore_breakpoint_reporting = setup_breakpoint_reporting (); scoped_restore restore_breakpoint_reporting = setup_breakpoint_reporting ();
/* create_ada_exception_catchpoint needs CONDITION to be xstrdup'ed,
and will assume control of its lifetime. */
if (condition != NULL)
condition = xstrdup (condition);
create_ada_exception_catchpoint (gdbarch, ada_catch_assert, create_ada_exception_catchpoint (gdbarch, ada_catch_assert,
NULL, condition, temp, enabled, 0); NULL, condition, temp, enabled, 0);
} }
@ -93,7 +89,7 @@ void
mi_cmd_catch_exception (const char *cmd, char *argv[], int argc) mi_cmd_catch_exception (const char *cmd, char *argv[], int argc)
{ {
struct gdbarch *gdbarch = get_current_arch(); struct gdbarch *gdbarch = get_current_arch();
char *condition = NULL; std::string condition;
int enabled = 1; int enabled = 1;
char *exception_name = NULL; char *exception_name = NULL;
int temp = 0; int temp = 0;
@ -128,7 +124,7 @@ mi_cmd_catch_exception (const char *cmd, char *argv[], int argc)
switch ((enum opt) opt) switch ((enum opt) opt)
{ {
case OPT_CONDITION: case OPT_CONDITION:
condition = oarg; condition.assign (oarg);
break; break;
case OPT_DISABLED: case OPT_DISABLED:
enabled = 0; enabled = 0;
@ -156,12 +152,10 @@ mi_cmd_catch_exception (const char *cmd, char *argv[], int argc)
error (_("\"-e\" and \"-u\" are mutually exclusive")); error (_("\"-e\" and \"-u\" are mutually exclusive"));
scoped_restore restore_breakpoint_reporting = setup_breakpoint_reporting (); scoped_restore restore_breakpoint_reporting = setup_breakpoint_reporting ();
/* create_ada_exception_catchpoint needs EXCEPTION_NAME and CONDITION /* create_ada_exception_catchpoint needs EXCEPTION_NAME to be
to be xstrdup'ed, and will assume control of their lifetime. */ xstrdup'ed, and will assume control of its lifetime. */
if (exception_name != NULL) if (exception_name != NULL)
exception_name = xstrdup (exception_name); exception_name = xstrdup (exception_name);
if (condition != NULL)
condition = xstrdup (condition);
create_ada_exception_catchpoint (gdbarch, ex_kind, create_ada_exception_catchpoint (gdbarch, ex_kind,
exception_name, condition, exception_name, condition,
temp, enabled, 0); temp, enabled, 0);