From: Tom Tromey Date: Wed, 3 May 2017 23:26:47 +0000 (-0600) Subject: Remove cleanups from mi-cmd-var.c X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=2d6960b4568869baaa3cb40f75caed4021938e1c;p=binutils-gdb.git 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 * 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". --- diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 867692c7a8a..2aaaabead73 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,10 @@ +2017-09-29 Tom Tromey + + * 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-29 Tom Tromey * mi/mi-cmd-break.c (mi_argv_to_format): Return std::string. diff --git a/gdb/mi/mi-cmd-var.c b/gdb/mi/mi-cmd-var.c index 8b22b2fcbd9..0215b1a8f51 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. */ diff --git a/gdb/varobj.c b/gdb/varobj.c index f6691809f28..2d850fb5e1a 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 e35c1b86e7f..0d4a537d7ed 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);