aboutsummaryrefslogtreecommitdiff
path: root/gdb/mi
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2017-05-03 17:26:47 -0600
committerTom Tromey <tom@tromey.com>2017-09-29 21:12:12 -0600
commit2d6960b4568869baaa3cb40f75caed4021938e1c (patch)
tree79b3e0b7d8941661ab76757be74adf5d8b68953b /gdb/mi
parent784c453a4f1aeee237203dd6257a6ed24bee28c3 (diff)
downloadgdb-2d6960b4568869baaa3cb40f75caed4021938e1c.zip
gdb-2d6960b4568869baaa3cb40f75caed4021938e1c.tar.gz
gdb-2d6960b4568869baaa3cb40f75caed4021938e1c.tar.bz2
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. gdb/ChangeLog 2017-09-29 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".
Diffstat (limited to 'gdb/mi')
-rw-r--r--gdb/mi/mi-cmd-var.c38
1 files changed, 10 insertions, 28 deletions
diff --git a/gdb/mi/mi-cmd-var.c b/gdb/mi/mi-cmd-var.c
index 8b22b2f..0215b1a 100644
--- a/gdb/mi/mi-cmd-var.c
+++ b/gdb/mi/mi-cmd-var.c
@@ -95,32 +95,24 @@ 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);
-
- expr = xstrdup (argv[2]);
- make_cleanup (xfree, expr);
+ frame = argv[1];
+ expr = argv[2];
+ const char *name = argv[0];
+ std::string gen_name;
if (strcmp (name, "-") == 0)
{
- xfree (name);
- name = varobj_gen_name ();
+ gen_name = varobj_gen_name ();
+ name = gen_name.c_str ();
}
- else if (!isalpha (*name))
+ else if (!isalpha (name[0]))
error (_("-var-create: name of object must begin with a letter"));
if (strcmp (frame, "*") == 0)
@@ -135,7 +127,7 @@ 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=\"%s\", Frame=\"%s\" (%s), Expression=\"%s\"\n",
name, frame, hex_string (frameaddr), expr);
var = varobj_create (name, expr, frameaddr, var_type);
@@ -146,8 +138,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 +147,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 +172,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 +183,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. */