Patchwork [3/4] (Ada) C++fy conditional string when catching exception.

login
register
mail settings
Submitter Xavier Roirand
Date Jan. 30, 2018, 9:23 a.m.
Message ID <1517304232-15552-1-git-send-email-roirand@adacore.com>
Download mbox | patch
Permalink /patch/25688/
State New
Headers show

Comments

Xavier Roirand - Jan. 30, 2018, 9:23 a.m.
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.
---
 gdb/ada-lang.c        | 27 ++++++++++++++-------------
 gdb/ada-lang.h        |  4 ++--
 gdb/mi/mi-cmd-catch.c | 18 ++++++------------
 3 files changed, 22 insertions(+), 27 deletions(-)
Joel Brobecker - Jan. 31, 2018, 4:40 a.m.
> 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.

Approved.

Thank you,

Patch

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 3ff7169..0da58d9 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -13142,7 +13142,7 @@  catch_ada_exception_command_split (const char *args,
 				   bool is_catch_handlers_cmd,
                                    enum ada_exception_catchpoint_kind *ex,
 				   char **excep_string,
-				   char **cond_string)
+				   std::string &cond_string)
 {
   struct cleanup *old_chain = make_cleanup (null_cleanup, NULL);
   char *exception_name;
@@ -13209,7 +13209,8 @@  catch_ada_exception_command_split (const char *args,
       *ex = ada_catch_exception;
       *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
@@ -13400,7 +13401,7 @@  void
 create_ada_exception_catchpoint (struct gdbarch *gdbarch,
 				 enum ada_exception_catchpoint_kind ex_kind,
 				 char *excep_string,
-				 char *cond_string,
+				 const std::string &cond_string,
 				 int tempflag,
 				 int disabled,
 				 int from_tty)
@@ -13415,8 +13416,8 @@  create_ada_exception_catchpoint (struct gdbarch *gdbarch,
 				 ops, tempflag, disabled, from_tty);
   c->excep_string = excep_string;
   create_excep_cond_exprs (c.get (), ex_kind);
-  if (cond_string != NULL)
-    set_breakpoint_condition (c.get (), cond_string, from_tty);
+  if (!cond_string.empty ())
+    set_breakpoint_condition (c.get (), cond_string.c_str (), from_tty);
   install_breakpoint (0, std::move (c), 1);
 }
 
@@ -13431,14 +13432,14 @@  catch_ada_exception_command (const char *arg_entry, int from_tty,
   int tempflag;
   enum ada_exception_catchpoint_kind ex_kind;
   char *excep_string = NULL;
-  char *cond_string = NULL;
+  std::string cond_string;
 
   tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
 
   if (!arg)
     arg = "";
   catch_ada_exception_command_split (arg, false, &ex_kind, &excep_string,
-				     &cond_string);
+				     cond_string);
   create_ada_exception_catchpoint (gdbarch, ex_kind,
 				   excep_string, cond_string,
 				   tempflag, 1 /* enabled */,
@@ -13456,14 +13457,14 @@  catch_ada_handlers_command (const char *arg_entry, int from_tty,
   int tempflag;
   enum ada_exception_catchpoint_kind ex_kind;
   char *excep_string = NULL;
-  char *cond_string = NULL;
+  std::string cond_string;
 
   tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
 
   if (!arg)
     arg = "";
   catch_ada_exception_command_split (arg, true, &ex_kind, &excep_string,
-				     &cond_string);
+				     cond_string);
   create_ada_exception_catchpoint (gdbarch, ex_kind,
 				   excep_string, cond_string,
 				   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).  */
 
 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);
 
@@ -13491,7 +13492,7 @@  catch_ada_assert_command_split (const char *args, char **cond_string)
       args = skip_spaces (args);
       if (args[0] == '\0')
         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
@@ -13509,13 +13510,13 @@  catch_assert_command (const char *arg_entry, int from_tty,
   const char *arg = arg_entry;
   struct gdbarch *gdbarch = get_current_arch ();
   int tempflag;
-  char *cond_string = NULL;
+  std::string cond_string;
 
   tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
 
   if (!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,
 				   NULL, cond_string,
 				   tempflag, 1 /* enabled */,
diff --git a/gdb/ada-lang.h b/gdb/ada-lang.h
index bac6c06..1f6ea77 100644
--- a/gdb/ada-lang.h
+++ b/gdb/ada-lang.h
@@ -379,8 +379,8 @@  extern std::string ada_name_for_lookup (const char *name);
 
 extern void create_ada_exception_catchpoint
   (struct gdbarch *gdbarch, enum ada_exception_catchpoint_kind ex_kind,
-   char *excep_string, char *cond_string, int tempflag, int disabled,
-   int from_tty);
+   char *excep_string, const std::string &cond_string, int tempflag,
+   int disabled, int from_tty);
 
 /* Some information about a given Ada exception.  */
 
diff --git a/gdb/mi/mi-cmd-catch.c b/gdb/mi/mi-cmd-catch.c
index 38b96cc..a0f311a 100644
--- a/gdb/mi/mi-cmd-catch.c
+++ b/gdb/mi/mi-cmd-catch.c
@@ -32,7 +32,7 @@  void
 mi_cmd_catch_assert (const char *cmd, char *argv[], int argc)
 {
   struct gdbarch *gdbarch = get_current_arch();
-  char *condition = NULL;
+  std::string condition;
   int enabled = 1;
   int temp = 0;
 
@@ -62,7 +62,7 @@  mi_cmd_catch_assert (const char *cmd, char *argv[], int argc)
       switch ((enum opt) opt)
         {
 	case OPT_CONDITION:
-	  condition = oarg;
+	  condition.assign (oarg);
 	  break;
 	case OPT_DISABLED:
 	  enabled = 0;
@@ -79,10 +79,6 @@  mi_cmd_catch_assert (const char *cmd, char *argv[], int argc)
     error (_("Invalid argument: %s"), argv[oind]);
 
   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,
 				   NULL, condition, temp, enabled, 0);
 }
@@ -93,7 +89,7 @@  void
 mi_cmd_catch_exception (const char *cmd, char *argv[], int argc)
 {
   struct gdbarch *gdbarch = get_current_arch();
-  char *condition = NULL;
+  std::string condition;
   int enabled = 1;
   char *exception_name = NULL;
   int temp = 0;
@@ -128,7 +124,7 @@  mi_cmd_catch_exception (const char *cmd, char *argv[], int argc)
       switch ((enum opt) opt)
         {
 	case OPT_CONDITION:
-	  condition = oarg;
+	  condition.assign (oarg);
 	  break;
 	case OPT_DISABLED:
 	  enabled = 0;
@@ -156,12 +152,10 @@  mi_cmd_catch_exception (const char *cmd, char *argv[], int argc)
     error (_("\"-e\" and \"-u\" are mutually exclusive"));
 
   scoped_restore restore_breakpoint_reporting = setup_breakpoint_reporting ();
-  /* create_ada_exception_catchpoint needs EXCEPTION_NAME and CONDITION
-     to be xstrdup'ed, and will assume control of their lifetime.  */
+  /* create_ada_exception_catchpoint needs EXCEPTION_NAME to be
+     xstrdup'ed, and will assume control of its lifetime.  */
   if (exception_name != NULL)
     exception_name = xstrdup (exception_name);
-  if (condition != NULL)
-    condition = xstrdup (condition);
   create_ada_exception_catchpoint (gdbarch, ex_kind,
 				   exception_name, condition,
 				   temp, enabled, 0);