diff options
author | Pedro Alves <palves@redhat.com> | 2016-11-08 15:26:47 +0000 |
---|---|---|
committer | Pedro Alves <palves@redhat.com> | 2016-11-08 15:26:47 +0000 |
commit | 2f408ecb929bd56613e94cf1e84ace4692c78257 (patch) | |
tree | 5b0e71bb60037a2e47b8eabb233beac31c4a17b2 /gdb/ada-varobj.c | |
parent | d2af8993a7cac29eaa5a4efd47c9117bbd175068 (diff) | |
download | binutils-gdb-2f408ecb929bd56613e94cf1e84ace4692c78257.tar.gz |
Use ui_file_as_string throughout more
This replaces most of the remaining ui_file_xstrdup calls with
ui_file_as_string calls. Whenever a call was replaced, that led to a
cascade of other necessary adjustments throughout, to make the code
use std::string instead of raw pointers. And then whenever I added a
std::string as member of a struct, I needed to adjust
allocation/destruction of said struct to use new/delete instead of
xmalloc/xfree.
The stopping point was once gdb built again. These doesn't seem to be
a way to reasonably split this out further.
Maybe-not-obvious changes:
- demangle_for_lookup returns a cleanup today. To get rid of that,
and avoid unnecessary string dupping/copying, this introduces a
demangle_result_storage type that the caller instantiates and
passes to demangle_for_lookup.
- Many methods returned a "char *" to indicate that the caller owns
the memory and must free it. Those are switched to return a
std::string instead. Methods that return a "view" into some
internal string return a "const char *" instead. I.e., we only
copy/allocate when necessary.
gdb/ChangeLog:
2016-11-08 Pedro Alves <palves@redhat.com>
* ada-lang.c (ada_name_for_lookup, type_as_string): Use and return
std::string.
(type_as_string_and_cleanup): Delete.
(ada_lookup_struct_elt_type): Use type_as_string.
* ada-lang.h (ada_name_for_lookup): Now returns std::string.
* ada-varobj.c (ada_varobj_scalar_image): Return a std::string.
(ada_varobj_describe_child): Make 'child_name' and
'child_path_expr' parameters std::string pointers.
(ada_varobj_describe_struct_child, ada_varobj_describe_ptr_child):
Likewise, and use string_printf.
(ada_varobj_describe_simple_array_child)
(ada_varobj_describe_child): Likewise.
(ada_varobj_get_name_of_child, ada_varobj_get_path_expr_of_child)
(ada_varobj_get_value_image)
(ada_varobj_get_value_of_array_variable)
(ada_varobj_get_value_of_variable, ada_name_of_variable)
(ada_name_of_child, ada_path_expr_of_child)
(ada_value_of_variable): Now returns std::string. Use
string_printf.
(ada_value_of_child): Adjust.
* break-catch-throw.c (check_status_exception_catchpoint): Adjust
to use std::string.
* breakpoint.c (watch_command_1): Adjust to use std::string.
* c-lang.c (c_get_string): Adjust to use std::string.
* c-typeprint.c (print_name_maybe_canonical): Use std::string.
* c-varobj.c (varobj_is_anonymous_child): Use ==/!= std::string
operators.
(c_name_of_variable): Now returns a std::string.
(c_describe_child): The 'cname' and 'cfull_expression' output
parameters are now std::string pointers. Adjust.
(c_name_of_child, c_path_expr_of_child, c_value_of_variable)
(cplus_number_of_children): Adjust to use std::string and
string_printf.
(cplus_name_of_variable): Now returns a std::string.
(cplus_describe_child): The 'cname' and 'cfull_expression' output
parameters are now std::string pointers. Adjust.
(cplus_name_of_child, cplus_path_expr_of_child)
(cplus_value_of_variable): Now returns a std::string.
* cp-abi.c (cplus_typename_from_type_info): Return std::string.
* cp-abi.h (cplus_typename_from_type_info): Return std::string.
(struct cp_abi_ops) <get_typename_from_type_info>: Return
std::string.
* cp-support.c (inspect_type): Use std::string.
(cp_canonicalize_string_full, cp_canonicalize_string_no_typedefs)
(cp_canonicalize_string): Return std::string and adjust.
* cp-support.h (cp_canonicalize_string)
(cp_canonicalize_string_no_typedefs, cp_canonicalize_string_full):
Return std::string.
* dbxread.c (read_dbx_symtab): Use std::string.
* dwarf2read.c (dwarf2_canonicalize_name): Adjust to use std::string.
* gdbcmd.h (lookup_struct_elt_type): Adjust to use std::string.
* gnu-v3-abi.c (gnuv3_get_typeid): Use std::string.
(gnuv3_get_typename_from_type_info): Return a std::string and
adjust.
(gnuv3_get_type_from_type_info): Adjust to use std::string.
* guile/guile.c (gdbscm_execute_gdb_command): Adjust to use
std::string.
* infcmd.c (print_return_value_1): Adjust to use std::string.
* linespec.c (find_linespec_symbols): Adjust to
demangle_for_lookup API change. Use std::string.
* mi/mi-cmd-var.c (print_varobj, mi_cmd_var_set_format)
(mi_cmd_var_info_type, mi_cmd_var_info_path_expression)
(mi_cmd_var_info_expression, mi_cmd_var_evaluate_expression)
(mi_cmd_var_assign, varobj_update_one): Adjust to use std::string.
* minsyms.c (lookup_minimal_symbol): Use std::string.
* python/py-varobj.c (py_varobj_iter_next): Use new instead of
XNEW. vitem->name is a std::string now, adjust.
* rust-exp.y (convert_ast_to_type, convert_name): Adjust to use
std::string.
* stabsread.c (define_symbol): Adjust to use std::string.
* symtab.c (demangle_for_lookup): Now returns 'const char *'. Add
a demangle_result_storage parameter. Use it for storage.
(lookup_symbol_in_language)
(lookup_symbol_in_objfile_from_linkage_name): Adjust to new
demangle_for_lookup API.
* symtab.h (struct demangle_result_storage): New type.
(demangle_for_lookup): Now returns 'const char *'. Add a
demangle_result_storage parameter.
* typeprint.c (type_to_string): Return std::string and use
ui_file_as_string.
* value.h (type_to_string): Change return type to std::string.
* varobj-iter.h (struct varobj_item) <name>: Now a std::string.
(varobj_iter_delete): Use delete instead of xfree.
* varobj.c (create_child): Return std::string instead of char * in
output parameter.
(name_of_variable, name_of_child, my_value_of_variable): Return
std::string instead of char *.
(varobj_create, varobj_get_handle): Constify 'objname' parameter.
Adjust to std::string fields.
(varobj_get_objname): Return a const char * instead of a char *.
(varobj_get_expression): Return a std::string.
(varobj_list_children): Adjust to use std::string.
(varobj_get_type): Return a std::string.
(varobj_get_path_expr): Return a const char * instead of a char *.
Adjust to std::string fields.
(varobj_get_formatted_value, varobj_get_value): Return a
std::string.
(varobj_set_value): Change type of 'expression' parameter to
std::string. Use std::string.
(install_new_value): Use std::string.
(delete_variable_1): Adjust to use std::string.
(create_child): Change the 'name' parameter to a std::string
reference. Swap it into the new item's name.
(create_child_with_value): Swap item's name into the new child's
name. Use string_printf.
(new_variable): Use new instead of XNEW.
(free_variable): Don't xfree fields that are now std::string.
(name_of_variable, name_of_child): Now returns std::string.
(value_of_root): Adjust to use std::string.
(my_value_of_variable, varobj_value_get_print_value): Return
and use std::string.
(varobj_value_get_print_value): Adjust to use ui_file_as_string
and std::string.
* varobj.h (struct varobj) <name, path_expr, obj_name,
print_value>: Now std::string's.
<name_of_variable, name_of_child, path_expr_of_child,
value_of_variable>: Return std::string.
(varobj_create, varobj_get_handle): Constify 'objname' parameter.
(varobj_get_objname): Return a const char * instead of a char *.
(varobj_get_expression, varobj_get_type): Return a std::string.
(varobj_get_path_expr): Return a const char * instead of a char *.
(varobj_get_formatted_value, varobj_get_value): Return a
std::string.
(varobj_set_value): Constify 'expression' parameter.
(varobj_value_get_print_value): Return a std::string.
Diffstat (limited to 'gdb/ada-varobj.c')
-rw-r--r-- | gdb/ada-varobj.c | 130 |
1 files changed, 53 insertions, 77 deletions
diff --git a/gdb/ada-varobj.c b/gdb/ada-varobj.c index 19028907f1b..ae46ca220e6 100644 --- a/gdb/ada-varobj.c +++ b/gdb/ada-varobj.c @@ -74,19 +74,16 @@ ada_varobj_decode_var (struct value **value_ptr, struct type **type_ptr) /* Return a string containing an image of the given scalar value. VAL is the numeric value, while TYPE is the value's type. This is useful for plain integers, of course, but even more - so for enumerated types. + so for enumerated types. */ - The result should be deallocated by xfree after use. */ - -static char * +static std::string ada_varobj_scalar_image (struct type *type, LONGEST val) { struct ui_file *buf = mem_fileopen (); struct cleanup *cleanups = make_cleanup_ui_file_delete (buf); - char *result; ada_print_scalar (type, val, buf); - result = ui_file_xstrdup (buf, NULL); + std::string result = ui_file_as_string (buf); do_cleanups (cleanups); return result; @@ -404,10 +401,10 @@ static void ada_varobj_describe_child (struct value *parent_value, const char *parent_name, const char *parent_path_expr, int child_index, - char **child_name, + std::string *child_name, struct value **child_value, struct type **child_type, - char **child_path_expr); + std::string *child_path_expr); /* Same as ada_varobj_describe_child, but limited to struct/union objects. */ @@ -418,10 +415,10 @@ ada_varobj_describe_struct_child (struct value *parent_value, const char *parent_name, const char *parent_path_expr, int child_index, - char **child_name, + std::string *child_name, struct value **child_value, struct type **child_type, - char **child_path_expr) + std::string *child_path_expr) { int fieldno; int childno = 0; @@ -506,7 +503,7 @@ ada_varobj_describe_struct_child (struct value *parent_value, const char *field_name = TYPE_FIELD_NAME (parent_type, fieldno); int child_name_len = ada_name_prefix_len (field_name); - *child_name = xstrprintf ("%.*s", child_name_len, field_name); + *child_name = string_printf ("%.*s", child_name_len, field_name); } if (child_value && parent_value) @@ -527,8 +524,8 @@ ada_varobj_describe_struct_child (struct value *parent_value, int child_name_len = ada_name_prefix_len (field_name); *child_path_expr = - xstrprintf ("(%s).%.*s", parent_path_expr, - child_name_len, field_name); + string_printf ("(%s).%.*s", parent_path_expr, + child_name_len, field_name); } return; @@ -556,13 +553,13 @@ ada_varobj_describe_ptr_child (struct value *parent_value, const char *parent_name, const char *parent_path_expr, int child_index, - char **child_name, + std::string *child_name, struct value **child_value, struct type **child_type, - char **child_path_expr) + std::string *child_path_expr) { if (child_name) - *child_name = xstrprintf ("%s.all", parent_name); + *child_name = string_printf ("%s.all", parent_name); if (child_value && parent_value) ada_varobj_ind (parent_value, parent_type, child_value, NULL); @@ -571,7 +568,7 @@ ada_varobj_describe_ptr_child (struct value *parent_value, ada_varobj_ind (parent_value, parent_type, NULL, child_type); if (child_path_expr) - *child_path_expr = xstrprintf ("(%s).all", parent_path_expr); + *child_path_expr = string_printf ("(%s).all", parent_path_expr); } /* Same as ada_varobj_describe_child, limited to simple array objects @@ -586,10 +583,10 @@ ada_varobj_describe_simple_array_child (struct value *parent_value, const char *parent_name, const char *parent_path_expr, int child_index, - char **child_name, + std::string *child_name, struct value **child_value, struct type **child_type, - char **child_path_expr) + std::string *child_path_expr) { struct type *index_type; int real_index; @@ -612,8 +609,7 @@ ada_varobj_describe_simple_array_child (struct value *parent_value, if (child_path_expr) { - char *index_img = ada_varobj_scalar_image (index_type, real_index); - struct cleanup *cleanups = make_cleanup (xfree, index_img); + std::string index_img = ada_varobj_scalar_image (index_type, real_index); /* Enumeration litterals by themselves are potentially ambiguous. For instance, consider the following package spec: @@ -647,13 +643,12 @@ ada_varobj_describe_simple_array_child (struct value *parent_value, if (index_type_name != NULL) *child_path_expr = - xstrprintf ("(%s)(%.*s'(%s))", parent_path_expr, - ada_name_prefix_len (index_type_name), - index_type_name, index_img); + string_printf ("(%s)(%.*s'(%s))", parent_path_expr, + ada_name_prefix_len (index_type_name), + index_type_name, index_img.c_str ()); else *child_path_expr = - xstrprintf ("(%s)(%s)", parent_path_expr, index_img); - do_cleanups (cleanups); + string_printf ("(%s)(%s)", parent_path_expr, index_img.c_str ()); } } @@ -665,10 +660,10 @@ ada_varobj_describe_child (struct value *parent_value, const char *parent_name, const char *parent_path_expr, int child_index, - char **child_name, + std::string *child_name, struct value **child_value, struct type **child_type, - char **child_path_expr) + std::string *child_path_expr) { /* We cannot compute the child's path expression without the parent's path expression. This is a pre-condition @@ -680,13 +675,13 @@ ada_varobj_describe_child (struct value *parent_value, ada_varobj_adjust_for_child_access (&parent_value, &parent_type); if (child_name) - *child_name = NULL; + *child_name = std::string (); if (child_value) *child_value = NULL; if (child_type) *child_type = NULL; if (child_path_expr) - *child_path_expr = NULL; + *child_path_expr = std::string (); if (ada_is_array_descriptor_type (parent_type) && TYPE_CODE (parent_type) == TYPE_CODE_TYPEDEF) @@ -731,20 +726,18 @@ ada_varobj_describe_child (struct value *parent_value, /* It should never happen. But rather than crash, report dummy names and return a NULL child_value. */ if (child_name) - *child_name = xstrdup ("???"); + *child_name = "???"; } /* Return the name of the child number CHILD_INDEX of the (PARENT_VALUE, - PARENT_TYPE) pair. PARENT_NAME is the name of the PARENT. - - The result should be deallocated after use with xfree. */ + PARENT_TYPE) pair. PARENT_NAME is the name of the PARENT. */ -static char * +static std::string ada_varobj_get_name_of_child (struct value *parent_value, struct type *parent_type, const char *parent_name, int child_index) { - char *child_name; + std::string child_name; ada_varobj_describe_child (parent_value, parent_type, parent_name, NULL, child_index, &child_name, NULL, @@ -755,18 +748,16 @@ ada_varobj_get_name_of_child (struct value *parent_value, /* Return the path expression of the child number CHILD_INDEX of the (PARENT_VALUE, PARENT_TYPE) pair. PARENT_NAME is the name of the parent, and PARENT_PATH_EXPR is the parent's path expression. - Both must be non-NULL. + Both must be non-NULL. */ - The result must be deallocated after use with xfree. */ - -static char * +static std::string ada_varobj_get_path_expr_of_child (struct value *parent_value, struct type *parent_type, const char *parent_name, const char *parent_path_expr, int child_index) { - char *child_path_expr; + std::string child_path_expr; ada_varobj_describe_child (parent_value, parent_type, parent_name, parent_path_expr, child_index, NULL, @@ -813,11 +804,10 @@ ada_varobj_get_type_of_child (struct value *parent_value, The resulting string must be deallocated after use with xfree. */ -static char * +static std::string ada_varobj_get_value_image (struct value *value, struct value_print_options *opts) { - char *result; struct ui_file *buffer; struct cleanup *old_chain; @@ -825,7 +815,7 @@ ada_varobj_get_value_image (struct value *value, old_chain = make_cleanup_ui_file_delete (buffer); common_val_print (value, buffer, 0, opts, current_language); - result = ui_file_xstrdup (buffer, NULL); + std::string result = ui_file_as_string (buffer); do_cleanups (old_chain); return result; @@ -841,7 +831,7 @@ ada_varobj_get_value_image (struct value *value, The result should be deallocated after use using xfree. */ -static char * +static std::string ada_varobj_get_value_of_array_variable (struct value *value, struct type *type, struct value_print_options *opts) @@ -857,50 +847,36 @@ ada_varobj_get_value_of_array_variable (struct value *value, && ada_is_string_type (type) && (opts->format == 0 || opts->format == 's')) { - char *str; - struct cleanup *old_chain; - - str = ada_varobj_get_value_image (value, opts); - old_chain = make_cleanup (xfree, str); - result = xstrprintf ("[%d] %s", numchild, str); - do_cleanups (old_chain); + std::string str = ada_varobj_get_value_image (value, opts); + return string_printf ("[%d] %s", numchild, str.c_str ()); } else - result = xstrprintf ("[%d]", numchild); - - return result; + return string_printf ("[%d]", numchild); } /* Return a string representation of the (VALUE, TYPE) pair, using the given print options OPTS as our formatting options. */ -static char * +static std::string ada_varobj_get_value_of_variable (struct value *value, struct type *type, struct value_print_options *opts) { - char *result = NULL; - ada_varobj_decode_var (&value, &type); switch (TYPE_CODE (type)) { case TYPE_CODE_STRUCT: case TYPE_CODE_UNION: - result = xstrdup ("{...}"); - break; + return "{...}"; case TYPE_CODE_ARRAY: - result = ada_varobj_get_value_of_array_variable (value, type, opts); - break; + return ada_varobj_get_value_of_array_variable (value, type, opts); default: if (!value) - result = xstrdup (""); + return ""; else - result = ada_varobj_get_value_image (value, opts); - break; + return ada_varobj_get_value_image (value, opts); } - - return result; } /* Ada specific callbacks for VAROBJs. */ @@ -911,20 +887,20 @@ ada_number_of_children (const struct varobj *var) return ada_varobj_get_number_of_children (var->value, var->type); } -static char * +static std::string ada_name_of_variable (const struct varobj *parent) { return c_varobj_ops.name_of_variable (parent); } -static char * +static std::string ada_name_of_child (const struct varobj *parent, int index) { return ada_varobj_get_name_of_child (parent->value, parent->type, - parent->name, index); + parent->name.c_str (), index); } -static char* +static std::string ada_path_expr_of_child (const struct varobj *child) { const struct varobj *parent = child->parent; @@ -932,7 +908,7 @@ ada_path_expr_of_child (const struct varobj *child) return ada_varobj_get_path_expr_of_child (parent->value, parent->type, - parent->name, + parent->name.c_str (), parent_path_expr, child->index); } @@ -941,7 +917,7 @@ static struct value * ada_value_of_child (const struct varobj *parent, int index) { return ada_varobj_get_value_of_child (parent->value, parent->type, - parent->name, index); + parent->name.c_str (), index); } static struct type * @@ -951,7 +927,7 @@ ada_type_of_child (const struct varobj *parent, int index) index); } -static char * +static std::string ada_value_of_variable (const struct varobj *var, enum varobj_display_formats format) { @@ -1019,9 +995,9 @@ ada_value_has_mutated (const struct varobj *var, struct value *new_val, varobj_restrict_range (var->children, &from, &to); for (i = from; i < to; i++) - if (strcmp (ada_varobj_get_name_of_child (new_val, new_type, - var->name, i), - VEC_index (varobj_p, var->children, i)->name) != 0) + if (ada_varobj_get_name_of_child (new_val, new_type, + var->name.c_str (), i) + != VEC_index (varobj_p, var->children, i)->name) return 1; return 0; |