This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[RFA 03/11] Remove cleanups from mi-cmd-var.c


This removes some cleanups from mi-cmd-var.c.  varobj_gen_name now
returns a string, simplifying mi_cmd_var_create.  In
mi_cmd_var_delete, a string copy is apparently unnecessary, so it's
simply removed.

ChangeLog
2017-09-12  Tom Tromey  <tom@tromey.com>

	* varobj.h (varobj_gen_name): Return std::string.
	* varobj.c (varobj_gen_name): Return std::string.
	* mi/mi-cmd-var.c (mi_cmd_var_create): Use std::string.
	(mi_cmd_var_delete): Don't copy "name".
---
 gdb/ChangeLog       |  7 +++++++
 gdb/mi/mi-cmd-var.c | 43 +++++++++++--------------------------------
 gdb/varobj.c        |  7 ++-----
 gdb/varobj.h        |  2 +-
 4 files changed, 21 insertions(+), 38 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 15a19bb8..b1fdcda 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,12 @@
 2017-09-12  Tom Tromey  <tom@tromey.com>
 
+	* varobj.h (varobj_gen_name): Return std::string.
+	* varobj.c (varobj_gen_name): Return std::string.
+	* mi/mi-cmd-var.c (mi_cmd_var_create): Use std::string.
+	(mi_cmd_var_delete): Don't copy "name".
+
+2017-09-12  Tom Tromey  <tom@tromey.com>
+
 	* mi/mi-cmd-break.c (mi_argv_to_format): Return std::string.
 	(mi_cmd_break_insert_1): Update.
 
diff --git a/gdb/mi/mi-cmd-var.c b/gdb/mi/mi-cmd-var.c
index 8b22b2f..b628814 100644
--- a/gdb/mi/mi-cmd-var.c
+++ b/gdb/mi/mi-cmd-var.c
@@ -95,32 +95,21 @@ mi_cmd_var_create (const char *command, char **argv, int argc)
   struct ui_out *uiout = current_uiout;
   CORE_ADDR frameaddr = 0;
   struct varobj *var;
-  char *name;
   char *frame;
   char *expr;
-  struct cleanup *old_cleanups;
   enum varobj_type var_type;
 
   if (argc != 3)
     error (_("-var-create: Usage: NAME FRAME EXPRESSION."));
 
-  name = xstrdup (argv[0]);
-  /* Add cleanup for name. Must be free_current_contents as name can
-     be reallocated.  */
-  old_cleanups = make_cleanup (free_current_contents, &name);
-
-  frame = xstrdup (argv[1]);
-  make_cleanup (xfree, frame);
+  std::string name = argv[0];
 
-  expr = xstrdup (argv[2]);
-  make_cleanup (xfree, expr);
+  frame = argv[1];
+  expr = argv[2];
 
-  if (strcmp (name, "-") == 0)
-    {
-      xfree (name);
-      name = varobj_gen_name ();
-    }
-  else if (!isalpha (*name))
+  if (name == "-")
+    name = varobj_gen_name ();
+  else if (!isalpha (name[0]))
     error (_("-var-create: name of object must begin with a letter"));
 
   if (strcmp (frame, "*") == 0)
@@ -135,10 +124,10 @@ mi_cmd_var_create (const char *command, char **argv, int argc)
 
   if (varobjdebug)
     fprintf_unfiltered (gdb_stdlog,
-		    "Name=\"%s\", Frame=\"%s\" (%s), Expression=\"%s\"\n",
-			name, frame, hex_string (frameaddr), expr);
+			"Name=\"%s\", Frame=\"%s\" (%s), Expression=\"%s\"\n",
+			name.c_str (), frame, hex_string (frameaddr), expr);
 
-  var = varobj_create (name, expr, frameaddr, var_type);
+  var = varobj_create (name.c_str (), expr, frameaddr, var_type);
 
   if (var == NULL)
     error (_("-var-create: unable to create variable object"));
@@ -146,8 +135,6 @@ mi_cmd_var_create (const char *command, char **argv, int argc)
   print_varobj (var, PRINT_ALL_VALUES, 0 /* don't print expression */);
 
   uiout->field_int ("has_more", varobj_has_more (var, 0));
-
-  do_cleanups (old_cleanups);
 }
 
 void
@@ -157,16 +144,12 @@ mi_cmd_var_delete (const char *command, char **argv, int argc)
   struct varobj *var;
   int numdel;
   int children_only_p = 0;
-  struct cleanup *old_cleanups;
   struct ui_out *uiout = current_uiout;
 
   if (argc < 1 || argc > 2)
     error (_("-var-delete: Usage: [-c] EXPRESSION."));
 
-  name = xstrdup (argv[0]);
-  /* Add cleanup for name. Must be free_current_contents as name can
-     be reallocated.  */
-  old_cleanups = make_cleanup (free_current_contents, &name);
+  name = argv[0];
 
   /* If we have one single argument it cannot be '-c' or any string
      starting with '-'.  */
@@ -186,9 +169,7 @@ mi_cmd_var_delete (const char *command, char **argv, int argc)
       if (strcmp (name, "-c") != 0)
 	error (_("-var-delete: Invalid option."));
       children_only_p = 1;
-      do_cleanups (old_cleanups);
-      name = xstrdup (argv[1]);
-      old_cleanups = make_cleanup (free_current_contents, &name);
+      name = argv[1];
     }
 
   /* If we didn't error out, now NAME contains the name of the
@@ -199,8 +180,6 @@ mi_cmd_var_delete (const char *command, char **argv, int argc)
   numdel = varobj_delete (var, children_only_p);
 
   uiout->field_int ("ndeleted", numdel);
-
-  do_cleanups (old_cleanups);
 }
 
 /* Parse a string argument into a format value.  */
diff --git a/gdb/varobj.c b/gdb/varobj.c
index f669180..2d850fb 100644
--- a/gdb/varobj.c
+++ b/gdb/varobj.c
@@ -435,17 +435,14 @@ varobj_create (const char *objname,
 
 /* Generates an unique name that can be used for a varobj.  */
 
-char *
+std::string
 varobj_gen_name (void)
 {
   static int id = 0;
-  char *obj_name;
 
   /* Generate a name for this object.  */
   id++;
-  obj_name = xstrprintf ("var%d", id);
-
-  return obj_name;
+  return string_printf ("var%d", id);
 }
 
 /* Given an OBJNAME, returns the pointer to the corresponding varobj.  Call
diff --git a/gdb/varobj.h b/gdb/varobj.h
index e35c1b8..0d4a537 100644
--- a/gdb/varobj.h
+++ b/gdb/varobj.h
@@ -233,7 +233,7 @@ extern struct varobj *varobj_create (const char *objname,
 				     const char *expression, CORE_ADDR frame,
 				     enum varobj_type type);
 
-extern char *varobj_gen_name (void);
+extern std::string varobj_gen_name (void);
 
 extern struct varobj *varobj_get_handle (const char *name);
 
-- 
2.9.4


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]