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.
This commit is contained in:
Pedro Alves 2016-11-08 15:26:47 +00:00
parent d2af8993a7
commit 2f408ecb92
31 changed files with 608 additions and 615 deletions

View file

@ -1,3 +1,131 @@
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.
2016-11-08 Pedro Alves <palves@redhat.com> 2016-11-08 Pedro Alves <palves@redhat.com>
* language.c (add_language): Use ui_file_as_string and adjust to * language.c (add_language): Use ui_file_as_string and adjust to

View file

@ -5871,28 +5871,21 @@ ada_iterate_over_symbols (const struct block *block,
} }
/* If NAME is the name of an entity, return a string that should /* If NAME is the name of an entity, return a string that should
be used to look that entity up in Ada units. This string should be used to look that entity up in Ada units.
be deallocated after use using xfree.
NAME can have any form that the "break" or "print" commands might NAME can have any form that the "break" or "print" commands might
recognize. In other words, it does not have to be the "natural" recognize. In other words, it does not have to be the "natural"
name, or the "encoded" name. */ name, or the "encoded" name. */
char * std::string
ada_name_for_lookup (const char *name) ada_name_for_lookup (const char *name)
{ {
char *canon;
int nlen = strlen (name); int nlen = strlen (name);
if (name[0] == '<' && name[nlen - 1] == '>') if (name[0] == '<' && name[nlen - 1] == '>')
{ return std::string (name + 1, nlen - 2);
canon = (char *) xmalloc (nlen - 1);
memcpy (canon, name + 1, nlen - 2);
canon[nlen - 2] = '\0';
}
else else
canon = xstrdup (ada_encode (ada_fold_name (name))); return ada_encode (ada_fold_name (name));
return canon;
} }
/* The result is as for ada_lookup_symbol_list with FULL_SEARCH set /* The result is as for ada_lookup_symbol_list with FULL_SEARCH set

View file

@ -370,7 +370,7 @@ extern char *ada_breakpoint_rewrite (char *, int *);
extern char *ada_main_name (void); extern char *ada_main_name (void);
extern char *ada_name_for_lookup (const char *name); extern std::string ada_name_for_lookup (const char *name);
extern void create_ada_exception_catchpoint extern void create_ada_exception_catchpoint
(struct gdbarch *gdbarch, enum ada_exception_catchpoint_kind ex_kind, (struct gdbarch *gdbarch, enum ada_exception_catchpoint_kind ex_kind,

View file

@ -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. /* Return a string containing an image of the given scalar value.
VAL is the numeric value, while TYPE is the value's type. VAL is the numeric value, while TYPE is the value's type.
This is useful for plain integers, of course, but even more 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 std::string
static char *
ada_varobj_scalar_image (struct type *type, LONGEST val) ada_varobj_scalar_image (struct type *type, LONGEST val)
{ {
struct ui_file *buf = mem_fileopen (); struct ui_file *buf = mem_fileopen ();
struct cleanup *cleanups = make_cleanup_ui_file_delete (buf); struct cleanup *cleanups = make_cleanup_ui_file_delete (buf);
char *result;
ada_print_scalar (type, val, buf); ada_print_scalar (type, val, buf);
result = ui_file_xstrdup (buf, NULL); std::string result = ui_file_as_string (buf);
do_cleanups (cleanups); do_cleanups (cleanups);
return result; return result;
@ -404,10 +401,10 @@ static void ada_varobj_describe_child (struct value *parent_value,
const char *parent_name, const char *parent_name,
const char *parent_path_expr, const char *parent_path_expr,
int child_index, int child_index,
char **child_name, std::string *child_name,
struct value **child_value, struct value **child_value,
struct type **child_type, struct type **child_type,
char **child_path_expr); std::string *child_path_expr);
/* Same as ada_varobj_describe_child, but limited to struct/union /* Same as ada_varobj_describe_child, but limited to struct/union
objects. */ objects. */
@ -418,10 +415,10 @@ ada_varobj_describe_struct_child (struct value *parent_value,
const char *parent_name, const char *parent_name,
const char *parent_path_expr, const char *parent_path_expr,
int child_index, int child_index,
char **child_name, std::string *child_name,
struct value **child_value, struct value **child_value,
struct type **child_type, struct type **child_type,
char **child_path_expr) std::string *child_path_expr)
{ {
int fieldno; int fieldno;
int childno = 0; 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); const char *field_name = TYPE_FIELD_NAME (parent_type, fieldno);
int child_name_len = ada_name_prefix_len (field_name); 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) if (child_value && parent_value)
@ -527,7 +524,7 @@ ada_varobj_describe_struct_child (struct value *parent_value,
int child_name_len = ada_name_prefix_len (field_name); int child_name_len = ada_name_prefix_len (field_name);
*child_path_expr = *child_path_expr =
xstrprintf ("(%s).%.*s", parent_path_expr, string_printf ("(%s).%.*s", parent_path_expr,
child_name_len, field_name); child_name_len, field_name);
} }
@ -556,13 +553,13 @@ ada_varobj_describe_ptr_child (struct value *parent_value,
const char *parent_name, const char *parent_name,
const char *parent_path_expr, const char *parent_path_expr,
int child_index, int child_index,
char **child_name, std::string *child_name,
struct value **child_value, struct value **child_value,
struct type **child_type, struct type **child_type,
char **child_path_expr) std::string *child_path_expr)
{ {
if (child_name) if (child_name)
*child_name = xstrprintf ("%s.all", parent_name); *child_name = string_printf ("%s.all", parent_name);
if (child_value && parent_value) if (child_value && parent_value)
ada_varobj_ind (parent_value, parent_type, child_value, NULL); 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); ada_varobj_ind (parent_value, parent_type, NULL, child_type);
if (child_path_expr) 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 /* 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_name,
const char *parent_path_expr, const char *parent_path_expr,
int child_index, int child_index,
char **child_name, std::string *child_name,
struct value **child_value, struct value **child_value,
struct type **child_type, struct type **child_type,
char **child_path_expr) std::string *child_path_expr)
{ {
struct type *index_type; struct type *index_type;
int real_index; int real_index;
@ -612,8 +609,7 @@ ada_varobj_describe_simple_array_child (struct value *parent_value,
if (child_path_expr) if (child_path_expr)
{ {
char *index_img = ada_varobj_scalar_image (index_type, real_index); std::string index_img = ada_varobj_scalar_image (index_type, real_index);
struct cleanup *cleanups = make_cleanup (xfree, index_img);
/* Enumeration litterals by themselves are potentially ambiguous. /* Enumeration litterals by themselves are potentially ambiguous.
For instance, consider the following package spec: 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) if (index_type_name != NULL)
*child_path_expr = *child_path_expr =
xstrprintf ("(%s)(%.*s'(%s))", parent_path_expr, string_printf ("(%s)(%.*s'(%s))", parent_path_expr,
ada_name_prefix_len (index_type_name), ada_name_prefix_len (index_type_name),
index_type_name, index_img); index_type_name, index_img.c_str ());
else else
*child_path_expr = *child_path_expr =
xstrprintf ("(%s)(%s)", parent_path_expr, index_img); string_printf ("(%s)(%s)", parent_path_expr, index_img.c_str ());
do_cleanups (cleanups);
} }
} }
@ -665,10 +660,10 @@ ada_varobj_describe_child (struct value *parent_value,
const char *parent_name, const char *parent_name,
const char *parent_path_expr, const char *parent_path_expr,
int child_index, int child_index,
char **child_name, std::string *child_name,
struct value **child_value, struct value **child_value,
struct type **child_type, struct type **child_type,
char **child_path_expr) std::string *child_path_expr)
{ {
/* We cannot compute the child's path expression without /* We cannot compute the child's path expression without
the parent's path expression. This is a pre-condition 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); ada_varobj_adjust_for_child_access (&parent_value, &parent_type);
if (child_name) if (child_name)
*child_name = NULL; *child_name = std::string ();
if (child_value) if (child_value)
*child_value = NULL; *child_value = NULL;
if (child_type) if (child_type)
*child_type = NULL; *child_type = NULL;
if (child_path_expr) if (child_path_expr)
*child_path_expr = NULL; *child_path_expr = std::string ();
if (ada_is_array_descriptor_type (parent_type) if (ada_is_array_descriptor_type (parent_type)
&& TYPE_CODE (parent_type) == TYPE_CODE_TYPEDEF) && 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 /* It should never happen. But rather than crash, report dummy names
and return a NULL child_value. */ and return a NULL child_value. */
if (child_name) if (child_name)
*child_name = xstrdup ("???"); *child_name = "???";
} }
/* Return the name of the child number CHILD_INDEX of the (PARENT_VALUE, /* Return the name of the child number CHILD_INDEX of the (PARENT_VALUE,
PARENT_TYPE) pair. PARENT_NAME is the name of the PARENT. PARENT_TYPE) pair. PARENT_NAME is the name of the PARENT. */
The result should be deallocated after use with xfree. */ static std::string
static char *
ada_varobj_get_name_of_child (struct value *parent_value, ada_varobj_get_name_of_child (struct value *parent_value,
struct type *parent_type, struct type *parent_type,
const char *parent_name, int child_index) const char *parent_name, int child_index)
{ {
char *child_name; std::string child_name;
ada_varobj_describe_child (parent_value, parent_type, parent_name, ada_varobj_describe_child (parent_value, parent_type, parent_name,
NULL, child_index, &child_name, NULL, 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 /* Return the path expression of the child number CHILD_INDEX of
the (PARENT_VALUE, PARENT_TYPE) pair. PARENT_NAME is the name the (PARENT_VALUE, PARENT_TYPE) pair. PARENT_NAME is the name
of the parent, and PARENT_PATH_EXPR is the parent's path expression. 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 std::string
static char *
ada_varobj_get_path_expr_of_child (struct value *parent_value, ada_varobj_get_path_expr_of_child (struct value *parent_value,
struct type *parent_type, struct type *parent_type,
const char *parent_name, const char *parent_name,
const char *parent_path_expr, const char *parent_path_expr,
int child_index) int child_index)
{ {
char *child_path_expr; std::string child_path_expr;
ada_varobj_describe_child (parent_value, parent_type, parent_name, ada_varobj_describe_child (parent_value, parent_type, parent_name,
parent_path_expr, child_index, NULL, 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. */ The resulting string must be deallocated after use with xfree. */
static char * static std::string
ada_varobj_get_value_image (struct value *value, ada_varobj_get_value_image (struct value *value,
struct value_print_options *opts) struct value_print_options *opts)
{ {
char *result;
struct ui_file *buffer; struct ui_file *buffer;
struct cleanup *old_chain; struct cleanup *old_chain;
@ -825,7 +815,7 @@ ada_varobj_get_value_image (struct value *value,
old_chain = make_cleanup_ui_file_delete (buffer); old_chain = make_cleanup_ui_file_delete (buffer);
common_val_print (value, buffer, 0, opts, current_language); 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); do_cleanups (old_chain);
return result; return result;
@ -841,7 +831,7 @@ ada_varobj_get_value_image (struct value *value,
The result should be deallocated after use using xfree. */ The result should be deallocated after use using xfree. */
static char * static std::string
ada_varobj_get_value_of_array_variable (struct value *value, ada_varobj_get_value_of_array_variable (struct value *value,
struct type *type, struct type *type,
struct value_print_options *opts) struct value_print_options *opts)
@ -857,50 +847,36 @@ ada_varobj_get_value_of_array_variable (struct value *value,
&& ada_is_string_type (type) && ada_is_string_type (type)
&& (opts->format == 0 || opts->format == 's')) && (opts->format == 0 || opts->format == 's'))
{ {
char *str; std::string str = ada_varobj_get_value_image (value, opts);
struct cleanup *old_chain; return string_printf ("[%d] %s", numchild, str.c_str ());
str = ada_varobj_get_value_image (value, opts);
old_chain = make_cleanup (xfree, str);
result = xstrprintf ("[%d] %s", numchild, str);
do_cleanups (old_chain);
} }
else else
result = xstrprintf ("[%d]", numchild); return string_printf ("[%d]", numchild);
return result;
} }
/* Return a string representation of the (VALUE, TYPE) pair, using /* Return a string representation of the (VALUE, TYPE) pair, using
the given print options OPTS as our formatting options. */ the given print options OPTS as our formatting options. */
static char * static std::string
ada_varobj_get_value_of_variable (struct value *value, ada_varobj_get_value_of_variable (struct value *value,
struct type *type, struct type *type,
struct value_print_options *opts) struct value_print_options *opts)
{ {
char *result = NULL;
ada_varobj_decode_var (&value, &type); ada_varobj_decode_var (&value, &type);
switch (TYPE_CODE (type)) switch (TYPE_CODE (type))
{ {
case TYPE_CODE_STRUCT: case TYPE_CODE_STRUCT:
case TYPE_CODE_UNION: case TYPE_CODE_UNION:
result = xstrdup ("{...}"); return "{...}";
break;
case TYPE_CODE_ARRAY: case TYPE_CODE_ARRAY:
result = ada_varobj_get_value_of_array_variable (value, type, opts); return ada_varobj_get_value_of_array_variable (value, type, opts);
break;
default: default:
if (!value) if (!value)
result = xstrdup (""); return "";
else else
result = ada_varobj_get_value_image (value, opts); return ada_varobj_get_value_image (value, opts);
break;
} }
return result;
} }
/* Ada specific callbacks for VAROBJs. */ /* 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); return ada_varobj_get_number_of_children (var->value, var->type);
} }
static char * static std::string
ada_name_of_variable (const struct varobj *parent) ada_name_of_variable (const struct varobj *parent)
{ {
return c_varobj_ops.name_of_variable (parent); return c_varobj_ops.name_of_variable (parent);
} }
static char * static std::string
ada_name_of_child (const struct varobj *parent, int index) ada_name_of_child (const struct varobj *parent, int index)
{ {
return ada_varobj_get_name_of_child (parent->value, parent->type, 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) ada_path_expr_of_child (const struct varobj *child)
{ {
const struct varobj *parent = child->parent; 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, return ada_varobj_get_path_expr_of_child (parent->value,
parent->type, parent->type,
parent->name, parent->name.c_str (),
parent_path_expr, parent_path_expr,
child->index); child->index);
} }
@ -941,7 +917,7 @@ static struct value *
ada_value_of_child (const struct varobj *parent, int index) ada_value_of_child (const struct varobj *parent, int index)
{ {
return ada_varobj_get_value_of_child (parent->value, parent->type, return ada_varobj_get_value_of_child (parent->value, parent->type,
parent->name, index); parent->name.c_str (), index);
} }
static struct type * static struct type *
@ -951,7 +927,7 @@ ada_type_of_child (const struct varobj *parent, int index)
index); index);
} }
static char * static std::string
ada_value_of_variable (const struct varobj *var, ada_value_of_variable (const struct varobj *var,
enum varobj_display_formats format) 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); varobj_restrict_range (var->children, &from, &to);
for (i = from; i < to; i++) for (i = from; i < to; i++)
if (strcmp (ada_varobj_get_name_of_child (new_val, new_type, if (ada_varobj_get_name_of_child (new_val, new_type,
var->name, i), var->name.c_str (), i)
VEC_index (varobj_p, var->children, i)->name) != 0) != VEC_index (varobj_p, var->children, i)->name)
return 1; return 1;
return 0; return 0;

View file

@ -162,7 +162,7 @@ check_status_exception_catchpoint (struct bpstats *bs)
{ {
struct exception_catchpoint *self struct exception_catchpoint *self
= (struct exception_catchpoint *) bs->breakpoint_at; = (struct exception_catchpoint *) bs->breakpoint_at;
char *type_name = NULL; std::string type_name;
bkpt_breakpoint_ops.check_status (bs); bkpt_breakpoint_ops.check_status (bs);
if (bs->stop == 0) if (bs->stop == 0)
@ -174,17 +174,14 @@ check_status_exception_catchpoint (struct bpstats *bs)
TRY TRY
{ {
struct value *typeinfo_arg; struct value *typeinfo_arg;
char *canon; std::string canon;
fetch_probe_arguments (NULL, &typeinfo_arg); fetch_probe_arguments (NULL, &typeinfo_arg);
type_name = cplus_typename_from_type_info (typeinfo_arg); type_name = cplus_typename_from_type_info (typeinfo_arg);
canon = cp_canonicalize_string (type_name); canon = cp_canonicalize_string (type_name.c_str ());
if (canon != NULL) if (!canon.empty ())
{ std::swap (type_name, canon);
xfree (type_name);
type_name = canon;
}
} }
CATCH (e, RETURN_MASK_ERROR) CATCH (e, RETURN_MASK_ERROR)
{ {
@ -192,12 +189,10 @@ check_status_exception_catchpoint (struct bpstats *bs)
} }
END_CATCH END_CATCH
if (type_name != NULL) if (!type_name.empty ())
{ {
if (regexec (self->pattern, type_name, 0, NULL, 0) != 0) if (regexec (self->pattern, type_name.c_str (), 0, NULL, 0) != 0)
bs->stop = 0; bs->stop = 0;
xfree (type_name);
} }
} }

View file

@ -11390,14 +11390,13 @@ watch_command_1 (const char *arg, int accessflag, int from_tty,
{ {
struct type *t = value_type (val); struct type *t = value_type (val);
CORE_ADDR addr = value_as_address (val); CORE_ADDR addr = value_as_address (val);
char *name;
t = check_typedef (TYPE_TARGET_TYPE (check_typedef (t))); t = check_typedef (TYPE_TARGET_TYPE (check_typedef (t)));
name = type_to_string (t);
w->exp_string_reparse = xstrprintf ("* (%s *) %s", name, std::string name = type_to_string (t);
w->exp_string_reparse = xstrprintf ("* (%s *) %s", name.c_str (),
core_addr_to_string (addr)); core_addr_to_string (addr));
xfree (name);
w->exp_string = xstrprintf ("-location %.*s", w->exp_string = xstrprintf ("-location %.*s",
(int) (exp_end - exp_start), exp_start); (int) (exp_end - exp_start), exp_start);

View file

@ -356,14 +356,11 @@ c_get_string (struct value *value, gdb_byte **buffer,
error: error:
{ {
char *type_str; std::string type_str = type_to_string (type);
if (!type_str.empty ())
type_str = type_to_string (type);
if (type_str)
{ {
make_cleanup (xfree, type_str);
error (_("Trying to read string with inappropriate type `%s'."), error (_("Trying to read string with inappropriate type `%s'."),
type_str); type_str.c_str ());
} }
else else
error (_("Trying to read string with inappropriate type.")); error (_("Trying to read string with inappropriate type."));

View file

@ -60,15 +60,14 @@ print_name_maybe_canonical (const char *name,
const struct type_print_options *flags, const struct type_print_options *flags,
struct ui_file *stream) struct ui_file *stream)
{ {
char *s = NULL; std::string s;
if (!flags->raw) if (!flags->raw)
s = cp_canonicalize_string_full (name, s = cp_canonicalize_string_full (name,
find_typedef_for_canonicalize, find_typedef_for_canonicalize,
(void *) flags); (void *) flags);
fputs_filtered (s ? s : name, stream); fputs_filtered (!s.empty () ? s.c_str () : name, stream);
xfree (s);
} }

View file

@ -37,8 +37,8 @@ static void cplus_class_num_children (struct type *type, int children[3]);
int int
varobj_is_anonymous_child (const struct varobj *child) varobj_is_anonymous_child (const struct varobj *child)
{ {
return (strcmp (child->name, ANONYMOUS_STRUCT_NAME) == 0 return (child->name == ANONYMOUS_STRUCT_NAME
|| strcmp (child->name, ANONYMOUS_UNION_NAME) == 0); || child->name == ANONYMOUS_UNION_NAME);
} }
/* Given the value and the type of a variable object, /* Given the value and the type of a variable object,
@ -231,10 +231,10 @@ c_number_of_children (const struct varobj *var)
return children; return children;
} }
static char * static std::string
c_name_of_variable (const struct varobj *parent) c_name_of_variable (const struct varobj *parent)
{ {
return xstrdup (parent->name); return parent->name;
} }
/* Return the value of element TYPE_INDEX of a structure /* Return the value of element TYPE_INDEX of a structure
@ -279,27 +279,27 @@ value_struct_element_index (struct value *value, int type_index)
If any of CNAME, CVALUE, or CTYPE is not null, but the corresponding If any of CNAME, CVALUE, or CTYPE is not null, but the corresponding
information cannot be determined, set *CNAME, *CVALUE, or *CTYPE information cannot be determined, set *CNAME, *CVALUE, or *CTYPE
to NULL. */ to empty. */
static void static void
c_describe_child (const struct varobj *parent, int index, c_describe_child (const struct varobj *parent, int index,
char **cname, struct value **cvalue, struct type **ctype, std::string *cname, struct value **cvalue,
char **cfull_expression) struct type **ctype, std::string *cfull_expression)
{ {
struct value *value = parent->value; struct value *value = parent->value;
struct type *type = varobj_get_value_type (parent); struct type *type = varobj_get_value_type (parent);
char *parent_expression = NULL; std::string parent_expression;
int was_ptr; int was_ptr;
if (cname) if (cname)
*cname = NULL; *cname = std::string ();
if (cvalue) if (cvalue)
*cvalue = NULL; *cvalue = NULL;
if (ctype) if (ctype)
*ctype = NULL; *ctype = NULL;
if (cfull_expression) if (cfull_expression)
{ {
*cfull_expression = NULL; *cfull_expression = std::string ();
parent_expression parent_expression
= varobj_get_path_expr (varobj_get_path_expr_parent (parent)); = varobj_get_path_expr (varobj_get_path_expr_parent (parent));
} }
@ -309,10 +309,9 @@ c_describe_child (const struct varobj *parent, int index,
{ {
case TYPE_CODE_ARRAY: case TYPE_CODE_ARRAY:
if (cname) if (cname)
*cname *cname = int_string (index
= xstrdup (int_string (index
+ TYPE_LOW_BOUND (TYPE_INDEX_TYPE (type)), + TYPE_LOW_BOUND (TYPE_INDEX_TYPE (type)),
10, 1, 0, 0)); 10, 1, 0, 0);
if (cvalue && value) if (cvalue && value)
{ {
@ -333,7 +332,7 @@ c_describe_child (const struct varobj *parent, int index,
if (cfull_expression) if (cfull_expression)
*cfull_expression = *cfull_expression =
xstrprintf ("(%s)[%s]", parent_expression, string_printf ("(%s)[%s]", parent_expression.c_str (),
int_string (index int_string (index
+ TYPE_LOW_BOUND (TYPE_INDEX_TYPE (type)), + TYPE_LOW_BOUND (TYPE_INDEX_TYPE (type)),
10, 1, 0, 0)); 10, 1, 0, 0));
@ -355,24 +354,25 @@ c_describe_child (const struct varobj *parent, int index,
{ {
if (TYPE_CODE (TYPE_FIELD_TYPE (type, index)) if (TYPE_CODE (TYPE_FIELD_TYPE (type, index))
== TYPE_CODE_STRUCT) == TYPE_CODE_STRUCT)
*cname = xstrdup (ANONYMOUS_STRUCT_NAME); *cname = ANONYMOUS_STRUCT_NAME;
else else
*cname = xstrdup (ANONYMOUS_UNION_NAME); *cname = ANONYMOUS_UNION_NAME;
} }
if (cfull_expression) if (cfull_expression)
*cfull_expression = xstrdup (""); *cfull_expression = "";
} }
else else
{ {
if (cname) if (cname)
*cname = xstrdup (field_name); *cname = field_name;
if (cfull_expression) if (cfull_expression)
{ {
const char *join = was_ptr ? "->" : "."; const char *join = was_ptr ? "->" : ".";
*cfull_expression = xstrprintf ("(%s)%s%s", parent_expression, *cfull_expression = string_printf ("(%s)%s%s",
parent_expression.c_str (),
join, field_name); join, field_name);
} }
} }
@ -390,7 +390,7 @@ c_describe_child (const struct varobj *parent, int index,
case TYPE_CODE_PTR: case TYPE_CODE_PTR:
if (cname) if (cname)
*cname = xstrprintf ("*%s", parent->name); *cname = string_printf ("*%s", parent->name.c_str ());
if (cvalue && value) if (cvalue && value)
{ {
@ -413,33 +413,32 @@ c_describe_child (const struct varobj *parent, int index,
*ctype = TYPE_TARGET_TYPE (type); *ctype = TYPE_TARGET_TYPE (type);
if (cfull_expression) if (cfull_expression)
*cfull_expression = xstrprintf ("*(%s)", parent_expression); *cfull_expression = string_printf ("*(%s)", parent_expression.c_str ());
break; break;
default: default:
/* This should not happen. */ /* This should not happen. */
if (cname) if (cname)
*cname = xstrdup ("???"); *cname = "???";
if (cfull_expression) if (cfull_expression)
*cfull_expression = xstrdup ("???"); *cfull_expression = "???";
/* Don't set value and type, we don't know then. */ /* Don't set value and type, we don't know then. */
} }
} }
static char * static std::string
c_name_of_child (const struct varobj *parent, int index) c_name_of_child (const struct varobj *parent, int index)
{ {
char *name; std::string name;
c_describe_child (parent, index, &name, NULL, NULL, NULL); c_describe_child (parent, index, &name, NULL, NULL, NULL);
return name; return name;
} }
static char * static std::string
c_path_expr_of_child (const struct varobj *child) c_path_expr_of_child (const struct varobj *child)
{ {
char *path_expr; std::string path_expr;
c_describe_child (child->parent, child->index, NULL, NULL, NULL, c_describe_child (child->parent, child->index, NULL, NULL, NULL,
&path_expr); &path_expr);
@ -479,7 +478,7 @@ get_type (const struct varobj *var)
return type; return type;
} }
static char * static std::string
c_value_of_variable (const struct varobj *var, c_value_of_variable (const struct varobj *var,
enum varobj_display_formats format) enum varobj_display_formats format)
{ {
@ -496,16 +495,11 @@ c_value_of_variable (const struct varobj *var,
{ {
case TYPE_CODE_STRUCT: case TYPE_CODE_STRUCT:
case TYPE_CODE_UNION: case TYPE_CODE_UNION:
return xstrdup ("{...}"); return "{...}";
/* break; */ /* break; */
case TYPE_CODE_ARRAY: case TYPE_CODE_ARRAY:
{ return string_printf ("[%d]", var->num_children);
char *number;
number = xstrprintf ("[%d]", var->num_children);
return (number);
}
/* break; */ /* break; */
default: default:
@ -515,7 +509,7 @@ c_value_of_variable (const struct varobj *var,
/* This can happen if we attempt to get the value of a struct /* This can happen if we attempt to get the value of a struct
member when the parent is an invalid pointer. This is an member when the parent is an invalid pointer. This is an
error condition, so we should tell the caller. */ error condition, so we should tell the caller. */
return NULL; return std::string ();
} }
else else
{ {
@ -523,7 +517,7 @@ c_value_of_variable (const struct varobj *var,
/* Frozen variable and no value yet. We don't /* Frozen variable and no value yet. We don't
implicitly fetch the value. MI response will implicitly fetch the value. MI response will
use empty string for the value, which is OK. */ use empty string for the value, which is OK. */
return NULL; return std::string ();
gdb_assert (varobj_value_is_changeable_p (var)); gdb_assert (varobj_value_is_changeable_p (var));
gdb_assert (!value_lazy (var->value)); gdb_assert (!value_lazy (var->value));
@ -531,7 +525,7 @@ c_value_of_variable (const struct varobj *var,
/* If the specified format is the current one, /* If the specified format is the current one,
we can reuse print_value. */ we can reuse print_value. */
if (format == var->format) if (format == var->format)
return xstrdup (var->print_value); return var->print_value;
else else
return varobj_value_get_print_value (var->value, format, var); return varobj_value_get_print_value (var->value, format, var);
} }
@ -629,9 +623,9 @@ cplus_number_of_children (const struct varobj *var)
adjust_value_for_child_access (&value, &type, NULL, lookup_actual_type); adjust_value_for_child_access (&value, &type, NULL, lookup_actual_type);
cplus_class_num_children (type, kids); cplus_class_num_children (type, kids);
if (strcmp (var->name, "public") == 0) if (var->name == "public")
children = kids[v_public]; children = kids[v_public];
else if (strcmp (var->name, "private") == 0) else if (var->name == "private")
children = kids[v_private]; children = kids[v_private];
else else
children = kids[v_protected]; children = kids[v_protected];
@ -677,7 +671,7 @@ cplus_class_num_children (struct type *type, int children[3])
} }
} }
static char * static std::string
cplus_name_of_variable (const struct varobj *parent) cplus_name_of_variable (const struct varobj *parent)
{ {
return c_name_of_variable (parent); return c_name_of_variable (parent);
@ -704,25 +698,25 @@ match_accessibility (struct type *type, int index, enum accessibility acc)
static void static void
cplus_describe_child (const struct varobj *parent, int index, cplus_describe_child (const struct varobj *parent, int index,
char **cname, struct value **cvalue, struct type **ctype, std::string *cname, struct value **cvalue, struct type **ctype,
char **cfull_expression) std::string *cfull_expression)
{ {
struct value *value; struct value *value;
struct type *type; struct type *type;
int was_ptr; int was_ptr;
int lookup_actual_type = 0; int lookup_actual_type = 0;
char *parent_expression = NULL; const char *parent_expression = NULL;
const struct varobj *var; const struct varobj *var;
struct value_print_options opts; struct value_print_options opts;
if (cname) if (cname)
*cname = NULL; *cname = std::string ();
if (cvalue) if (cvalue)
*cvalue = NULL; *cvalue = NULL;
if (ctype) if (ctype)
*ctype = NULL; *ctype = NULL;
if (cfull_expression) if (cfull_expression)
*cfull_expression = NULL; *cfull_expression = std::string ();
get_user_print_options (&opts); get_user_print_options (&opts);
@ -758,9 +752,9 @@ cplus_describe_child (const struct varobj *parent, int index,
const char *field_name; const char *field_name;
vptr_fieldno = get_vptr_fieldno (type, &basetype); vptr_fieldno = get_vptr_fieldno (type, &basetype);
if (strcmp (parent->name, "private") == 0) if (parent->name == "private")
acc = private_field; acc = private_field;
else if (strcmp (parent->name, "protected") == 0) else if (parent->name == "protected")
acc = protected_field; acc = protected_field;
while (index >= 0) while (index >= 0)
@ -783,23 +777,23 @@ cplus_describe_child (const struct varobj *parent, int index,
{ {
if (TYPE_CODE (TYPE_FIELD_TYPE (type, type_index)) if (TYPE_CODE (TYPE_FIELD_TYPE (type, type_index))
== TYPE_CODE_STRUCT) == TYPE_CODE_STRUCT)
*cname = xstrdup (ANONYMOUS_STRUCT_NAME); *cname = ANONYMOUS_STRUCT_NAME;
else if (TYPE_CODE (TYPE_FIELD_TYPE (type, type_index)) else if (TYPE_CODE (TYPE_FIELD_TYPE (type, type_index))
== TYPE_CODE_UNION) == TYPE_CODE_UNION)
*cname = xstrdup (ANONYMOUS_UNION_NAME); *cname = ANONYMOUS_UNION_NAME;
} }
if (cfull_expression) if (cfull_expression)
*cfull_expression = xstrdup (""); *cfull_expression = std::string ();
} }
else else
{ {
if (cname) if (cname)
*cname = xstrdup (TYPE_FIELD_NAME (type, type_index)); *cname = TYPE_FIELD_NAME (type, type_index);
if (cfull_expression) if (cfull_expression)
*cfull_expression *cfull_expression
= xstrprintf ("((%s)%s%s)", parent_expression, join, = string_printf ("((%s)%s%s)", parent_expression, join,
field_name); field_name);
} }
@ -813,7 +807,7 @@ cplus_describe_child (const struct varobj *parent, int index,
{ {
/* This is a baseclass. */ /* This is a baseclass. */
if (cname) if (cname)
*cname = xstrdup (TYPE_FIELD_NAME (type, index)); *cname = TYPE_FIELD_NAME (type, index);
if (cvalue && value) if (cvalue && value)
*cvalue = value_cast (TYPE_FIELD_TYPE (type, index), value); *cvalue = value_cast (TYPE_FIELD_TYPE (type, index), value);
@ -840,7 +834,7 @@ cplus_describe_child (const struct varobj *parent, int index,
as a constructor, if it exists. Therefore, we must as a constructor, if it exists. Therefore, we must
indicate that the name is a class name by using the indicate that the name is a class name by using the
'class' keyword. See PR mi/11912 */ 'class' keyword. See PR mi/11912 */
*cfull_expression = xstrprintf ("(%s(class %s%s) %s)", *cfull_expression = string_printf ("(%s(class %s%s) %s)",
ptr, ptr,
TYPE_FIELD_NAME (type, index), TYPE_FIELD_NAME (type, index),
ptr, ptr,
@ -892,7 +886,7 @@ cplus_describe_child (const struct varobj *parent, int index,
gdb_assert (access); gdb_assert (access);
if (cname) if (cname)
*cname = xstrdup (access); *cname = access;
/* Value and type and full expression are null here. */ /* Value and type and full expression are null here. */
} }
@ -903,19 +897,19 @@ cplus_describe_child (const struct varobj *parent, int index,
} }
} }
static char * static std::string
cplus_name_of_child (const struct varobj *parent, int index) cplus_name_of_child (const struct varobj *parent, int index)
{ {
char *name = NULL; std::string name;
cplus_describe_child (parent, index, &name, NULL, NULL, NULL); cplus_describe_child (parent, index, &name, NULL, NULL, NULL);
return name; return name;
} }
static char * static std::string
cplus_path_expr_of_child (const struct varobj *child) cplus_path_expr_of_child (const struct varobj *child)
{ {
char *path_expr; std::string path_expr;
cplus_describe_child (child->parent, child->index, NULL, NULL, NULL, cplus_describe_child (child->parent, child->index, NULL, NULL, NULL,
&path_expr); &path_expr);
@ -940,7 +934,7 @@ cplus_type_of_child (const struct varobj *parent, int index)
return type; return type;
} }
static char * static std::string
cplus_value_of_variable (const struct varobj *var, cplus_value_of_variable (const struct varobj *var,
enum varobj_display_formats format) enum varobj_display_formats format)
{ {
@ -948,7 +942,7 @@ cplus_value_of_variable (const struct varobj *var,
/* If we have one of our special types, don't print out /* If we have one of our special types, don't print out
any value. */ any value. */
if (CPLUS_FAKE_CHILD (var)) if (CPLUS_FAKE_CHILD (var))
return xstrdup (""); return std::string ();
return c_value_of_variable (var, format); return c_value_of_variable (var, format);
} }

View file

@ -212,7 +212,7 @@ cplus_type_from_type_info (struct value *value)
/* See cp-abi.h. */ /* See cp-abi.h. */
char * std::string
cplus_typename_from_type_info (struct value *value) cplus_typename_from_type_info (struct value *value)
{ {
if (current_cp_abi.get_typename_from_type_info == NULL) if (current_cp_abi.get_typename_from_type_info == NULL)

View file

@ -196,10 +196,9 @@ extern struct type *cplus_type_from_type_info (struct value *value);
/* Given a value which holds a pointer to a std::type_info, return the /* Given a value which holds a pointer to a std::type_info, return the
name of the type which that type_info represents. Throw an name of the type which that type_info represents. Throw an
exception if the type name cannot be found. The result is exception if the type name cannot be found. */
xmalloc'd and must be freed by the caller. */
extern char *cplus_typename_from_type_info (struct value *value); extern std::string cplus_typename_from_type_info (struct value *value);
/* Determine if we are currently in a C++ thunk. If so, get the /* Determine if we are currently in a C++ thunk. If so, get the
address of the routine we are thunking to and continue to there address of the routine we are thunking to and continue to there
@ -245,7 +244,7 @@ struct cp_abi_ops
struct value *(*get_typeid) (struct value *value); struct value *(*get_typeid) (struct value *value);
struct type *(*get_typeid_type) (struct gdbarch *gdbarch); struct type *(*get_typeid_type) (struct gdbarch *gdbarch);
struct type *(*get_type_from_type_info) (struct value *value); struct type *(*get_type_from_type_info) (struct value *value);
char *(*get_typename_from_type_info) (struct value *value); std::string (*get_typename_from_type_info) (struct value *value);
CORE_ADDR (*skip_trampoline) (struct frame_info *, CORE_ADDR); CORE_ADDR (*skip_trampoline) (struct frame_info *, CORE_ADDR);
int (*pass_by_reference) (struct type *type); int (*pass_by_reference) (struct type *type);
}; };

View file

@ -288,14 +288,12 @@ inspect_type (struct demangle_parse_info *info,
Canonicalize the name again, and store it in the Canonicalize the name again, and store it in the
current node (RET_COMP). */ current node (RET_COMP). */
char *canon = cp_canonicalize_string_no_typedefs (name); std::string canon = cp_canonicalize_string_no_typedefs (name);
if (canon != NULL) if (!canon.empty ())
{ {
/* Copy the canonicalization into the obstack and /* Copy the canonicalization into the obstack. */
free CANON. */ name = copy_string_to_obstack (&info->obstack, canon.c_str (), &len);
name = copy_string_to_obstack (&info->obstack, canon, &len);
xfree (canon);
} }
ret_comp->u.s_name.s = name; ret_comp->u.s_name.s = name;
@ -529,22 +527,21 @@ replace_typedefs (struct demangle_parse_info *info,
} }
} }
/* Parse STRING and convert it to canonical form, resolving any typedefs. /* Parse STRING and convert it to canonical form, resolving any
If parsing fails, or if STRING is already canonical, return NULL. typedefs. If parsing fails, or if STRING is already canonical,
Otherwise return the canonical form. The return value is allocated via return the empty string. Otherwise return the canonical form. If
xmalloc. If FINDER is not NULL, then type components are passed to FINDER is not NULL, then type components are passed to FINDER to be
FINDER to be looked up. DATA is passed verbatim to FINDER. */ looked up. DATA is passed verbatim to FINDER. */
char * std::string
cp_canonicalize_string_full (const char *string, cp_canonicalize_string_full (const char *string,
canonicalization_ftype *finder, canonicalization_ftype *finder,
void *data) void *data)
{ {
char *ret; std::string ret;
unsigned int estimated_len; unsigned int estimated_len;
struct demangle_parse_info *info; struct demangle_parse_info *info;
ret = NULL;
estimated_len = strlen (string) * 2; estimated_len = strlen (string) * 2;
info = cp_demangled_name_to_comp (string, NULL); info = cp_demangled_name_to_comp (string, NULL);
if (info != NULL) if (info != NULL)
@ -554,18 +551,15 @@ cp_canonicalize_string_full (const char *string,
/* Convert the tree back into a string. */ /* Convert the tree back into a string. */
ret = cp_comp_to_string (info->tree, estimated_len); ret = cp_comp_to_string (info->tree, estimated_len);
gdb_assert (ret != NULL); gdb_assert (!ret.empty ());
/* Free the parse information. */ /* Free the parse information. */
cp_demangled_name_parse_free (info); cp_demangled_name_parse_free (info);
/* Finally, compare the original string with the computed /* Finally, compare the original string with the computed
name, returning NULL if they are the same. */ name, returning NULL if they are the same. */
if (strcmp (string, ret) == 0) if (ret == string)
{ return std::string ();
xfree (ret);
return NULL;
}
} }
return ret; return ret;
@ -574,46 +568,42 @@ cp_canonicalize_string_full (const char *string,
/* Like cp_canonicalize_string_full, but always passes NULL for /* Like cp_canonicalize_string_full, but always passes NULL for
FINDER. */ FINDER. */
char * std::string
cp_canonicalize_string_no_typedefs (const char *string) cp_canonicalize_string_no_typedefs (const char *string)
{ {
return cp_canonicalize_string_full (string, NULL, NULL); return cp_canonicalize_string_full (string, NULL, NULL);
} }
/* Parse STRING and convert it to canonical form. If parsing fails, /* Parse STRING and convert it to canonical form. If parsing fails,
or if STRING is already canonical, return NULL. Otherwise return or if STRING is already canonical, return the empty string.
the canonical form. The return value is allocated via xmalloc. */ Otherwise return the canonical form. */
char * std::string
cp_canonicalize_string (const char *string) cp_canonicalize_string (const char *string)
{ {
struct demangle_parse_info *info; struct demangle_parse_info *info;
unsigned int estimated_len; unsigned int estimated_len;
char *ret;
if (cp_already_canonical (string)) if (cp_already_canonical (string))
return NULL; return std::string ();
info = cp_demangled_name_to_comp (string, NULL); info = cp_demangled_name_to_comp (string, NULL);
if (info == NULL) if (info == NULL)
return NULL; return std::string ();
estimated_len = strlen (string) * 2; estimated_len = strlen (string) * 2;
ret = cp_comp_to_string (info->tree, estimated_len); std::string ret = cp_comp_to_string (info->tree, estimated_len);
cp_demangled_name_parse_free (info); cp_demangled_name_parse_free (info);
if (ret == NULL) if (ret.empty ())
{ {
warning (_("internal error: string \"%s\" failed to be canonicalized"), warning (_("internal error: string \"%s\" failed to be canonicalized"),
string); string);
return NULL; return std::string ();
} }
if (strcmp (string, ret) == 0) if (ret == string)
{ return std::string ();
xfree (ret);
return NULL;
}
return ret; return ret;
} }

View file

@ -63,13 +63,13 @@ struct demangle_parse_info
/* Functions from cp-support.c. */ /* Functions from cp-support.c. */
extern char *cp_canonicalize_string (const char *string); extern std::string cp_canonicalize_string (const char *string);
extern char *cp_canonicalize_string_no_typedefs (const char *string); extern std::string cp_canonicalize_string_no_typedefs (const char *string);
typedef const char *(canonicalization_ftype) (struct type *, void *); typedef const char *(canonicalization_ftype) (struct type *, void *);
extern char *cp_canonicalize_string_full (const char *string, extern std::string cp_canonicalize_string_full (const char *string,
canonicalization_ftype *finder, canonicalization_ftype *finder,
void *data); void *data);

View file

@ -1664,19 +1664,15 @@ read_dbx_symtab (minimal_symbol_reader &reader, struct objfile *objfile)
sym_name = NULL; /* pacify "gcc -Werror" */ sym_name = NULL; /* pacify "gcc -Werror" */
if (psymtab_language == language_cplus) if (psymtab_language == language_cplus)
{ {
char *new_name, *name = (char *) xmalloc (p - namestring + 1); std::string name (namestring, p - namestring);
memcpy (name, namestring, p - namestring); std::string new_name = cp_canonicalize_string (name.c_str ());
if (!new_name.empty ())
name[p - namestring] = '\0';
new_name = cp_canonicalize_string (name);
if (new_name != NULL)
{ {
sym_len = strlen (new_name); sym_len = new_name.length ();
sym_name = (char *) obstack_copy0 (&objfile->objfile_obstack, sym_name = (char *) obstack_copy0 (&objfile->objfile_obstack,
new_name, sym_len); new_name.c_str (),
xfree (new_name); sym_len);
} }
xfree (name);
} }
if (sym_len == 0) if (sym_len == 0)

View file

@ -19524,14 +19524,14 @@ dwarf2_canonicalize_name (const char *name, struct dwarf2_cu *cu,
{ {
if (name && cu->language == language_cplus) if (name && cu->language == language_cplus)
{ {
char *canon_name = cp_canonicalize_string (name); std::string canon_name = cp_canonicalize_string (name);
if (canon_name != NULL) if (!canon_name.empty ())
{ {
if (strcmp (canon_name, name) != 0) if (canon_name != name)
name = (const char *) obstack_copy0 (obstack, canon_name, name = (const char *) obstack_copy0 (obstack,
strlen (canon_name)); canon_name.c_str (),
xfree (canon_name); canon_name.length ());
} }
} }

View file

@ -1572,7 +1572,6 @@ struct type *
lookup_struct_elt_type (struct type *type, const char *name, int noerr) lookup_struct_elt_type (struct type *type, const char *name, int noerr)
{ {
int i; int i;
char *type_name;
for (;;) for (;;)
{ {
@ -1586,9 +1585,9 @@ lookup_struct_elt_type (struct type *type, const char *name, int noerr)
if (TYPE_CODE (type) != TYPE_CODE_STRUCT if (TYPE_CODE (type) != TYPE_CODE_STRUCT
&& TYPE_CODE (type) != TYPE_CODE_UNION) && TYPE_CODE (type) != TYPE_CODE_UNION)
{ {
type_name = type_to_string (type); std::string type_name = type_to_string (type);
make_cleanup (xfree, type_name); error (_("Type %s is not a structure or union type."),
error (_("Type %s is not a structure or union type."), type_name); type_name.c_str ());
} }
#if 0 #if 0
@ -1640,9 +1639,8 @@ lookup_struct_elt_type (struct type *type, const char *name, int noerr)
return NULL; return NULL;
} }
type_name = type_to_string (type); std::string type_name = type_to_string (type);
make_cleanup (xfree, type_name); error (_("Type %s has no component named %s."), type_name.c_str (), name);
error (_("Type %s has no component named %s."), type_name, name);
} }
/* Store in *MAX the largest number representable by unsigned integer type /* Store in *MAX the largest number representable by unsigned integer type

View file

@ -1081,7 +1081,7 @@ gnuv3_get_typeid (struct value *value)
struct gdbarch *gdbarch; struct gdbarch *gdbarch;
struct cleanup *cleanup; struct cleanup *cleanup;
struct value *result; struct value *result;
char *type_name, *canonical; std::string type_name, canonical;
/* We have to handle values a bit trickily here, to allow this code /* We have to handle values a bit trickily here, to allow this code
to work properly with non_lvalue values that are really just to work properly with non_lvalue values that are really just
@ -1101,20 +1101,16 @@ gnuv3_get_typeid (struct value *value)
gdbarch = get_type_arch (type); gdbarch = get_type_arch (type);
type_name = type_to_string (type); type_name = type_to_string (type);
if (type_name == NULL) if (type_name.empty ())
error (_("cannot find typeinfo for unnamed type")); error (_("cannot find typeinfo for unnamed type"));
cleanup = make_cleanup (xfree, type_name);
/* We need to canonicalize the type name here, because we do lookups /* We need to canonicalize the type name here, because we do lookups
using the demangled name, and so we must match the format it using the demangled name, and so we must match the format it
uses. E.g., GDB tends to use "const char *" as a type name, but uses. E.g., GDB tends to use "const char *" as a type name, but
the demangler uses "char const *". */ the demangler uses "char const *". */
canonical = cp_canonicalize_string (type_name); canonical = cp_canonicalize_string (type_name.c_str ());
if (canonical != NULL) if (!canonical.empty ())
{
make_cleanup (xfree, canonical);
type_name = canonical; type_name = canonical;
}
typeinfo_type = gnuv3_get_typeid_type (gdbarch); typeinfo_type = gnuv3_get_typeid_type (gdbarch);
@ -1129,33 +1125,30 @@ gnuv3_get_typeid (struct value *value)
vtable = gnuv3_get_vtable (gdbarch, type, address); vtable = gnuv3_get_vtable (gdbarch, type, address);
if (vtable == NULL) if (vtable == NULL)
error (_("cannot find typeinfo for object of type '%s'"), type_name); error (_("cannot find typeinfo for object of type '%s'"),
type_name.c_str ());
typeinfo_value = value_field (vtable, vtable_field_type_info); typeinfo_value = value_field (vtable, vtable_field_type_info);
result = value_ind (value_cast (make_pointer_type (typeinfo_type, NULL), result = value_ind (value_cast (make_pointer_type (typeinfo_type, NULL),
typeinfo_value)); typeinfo_value));
} }
else else
{ {
char *sym_name; std::string sym_name = std::string ("typeinfo for ") + type_name;
struct bound_minimal_symbol minsym; bound_minimal_symbol minsym
= lookup_minimal_symbol (sym_name.c_str (), NULL, NULL);
sym_name = concat ("typeinfo for ", type_name, (char *) NULL);
make_cleanup (xfree, sym_name);
minsym = lookup_minimal_symbol (sym_name, NULL, NULL);
if (minsym.minsym == NULL) if (minsym.minsym == NULL)
error (_("could not find typeinfo symbol for '%s'"), type_name); error (_("could not find typeinfo symbol for '%s'"), type_name.c_str ());
result = value_at_lazy (typeinfo_type, BMSYMBOL_VALUE_ADDRESS (minsym)); result = value_at_lazy (typeinfo_type, BMSYMBOL_VALUE_ADDRESS (minsym));
} }
do_cleanups (cleanup);
return result; return result;
} }
/* Implement the 'get_typename_from_type_info' method. */ /* Implement the 'get_typename_from_type_info' method. */
static char * static std::string
gnuv3_get_typename_from_type_info (struct value *type_info_ptr) gnuv3_get_typename_from_type_info (struct value *type_info_ptr)
{ {
struct gdbarch *gdbarch = get_type_arch (value_type (type_info_ptr)); struct gdbarch *gdbarch = get_type_arch (value_type (type_info_ptr));
@ -1183,8 +1176,8 @@ gnuv3_get_typename_from_type_info (struct value *type_info_ptr)
/* Strip off @plt and version suffixes. */ /* Strip off @plt and version suffixes. */
atsign = strchr (class_name, '@'); atsign = strchr (class_name, '@');
if (atsign != NULL) if (atsign != NULL)
return savestring (class_name, atsign - class_name); return std::string (class_name, atsign - class_name);
return xstrdup (class_name); return class_name;
} }
/* Implement the 'get_type_from_type_info' method. */ /* Implement the 'get_type_from_type_info' method. */
@ -1192,26 +1185,14 @@ gnuv3_get_typename_from_type_info (struct value *type_info_ptr)
static struct type * static struct type *
gnuv3_get_type_from_type_info (struct value *type_info_ptr) gnuv3_get_type_from_type_info (struct value *type_info_ptr)
{ {
char *type_name;
struct cleanup *cleanup;
struct value *type_val;
struct type *result;
type_name = gnuv3_get_typename_from_type_info (type_info_ptr);
cleanup = make_cleanup (xfree, type_name);
/* We have to parse the type name, since in general there is not a /* We have to parse the type name, since in general there is not a
symbol for a type. This is somewhat bogus since there may be a symbol for a type. This is somewhat bogus since there may be a
mis-parse. Another approach might be to re-use the demangler's mis-parse. Another approach might be to re-use the demangler's
internal form to reconstruct the type somehow. */ internal form to reconstruct the type somehow. */
std::string type_name = gnuv3_get_typename_from_type_info (type_info_ptr);
expression_up expr = parse_expression (type_name); expression_up expr (parse_expression (type_name.c_str ()));
struct value *type_val = evaluate_type (expr.get ());
type_val = evaluate_type (expr.get ()); return value_type (type_val);
result = value_type (type_val);
do_cleanups (cleanup);
return result;
} }
/* Determine if we are currently in a C++ thunk. If so, get the address /* Determine if we are currently in a C++ thunk. If so, get the address

View file

@ -1688,16 +1688,11 @@ print_return_value_1 (struct ui_out *uiout, struct return_value_info *rv)
} }
else else
{ {
struct cleanup *oldchain; std::string type_name = type_to_string (rv->type);
char *type_name;
type_name = type_to_string (rv->type);
oldchain = make_cleanup (xfree, type_name);
ui_out_text (uiout, "Value returned has type: "); ui_out_text (uiout, "Value returned has type: ");
ui_out_field_string (uiout, "return-type", type_name); ui_out_field_string (uiout, "return-type", type_name.c_str ());
ui_out_text (uiout, "."); ui_out_text (uiout, ".");
ui_out_text (uiout, " Cannot determine contents\n"); ui_out_text (uiout, " Cannot determine contents\n");
do_cleanups (oldchain);
} }
} }

View file

@ -3268,26 +3268,27 @@ find_linespec_symbols (struct linespec_state *state,
VEC (symbolp) **symbols, VEC (symbolp) **symbols,
VEC (bound_minimal_symbol_d) **minsyms) VEC (bound_minimal_symbol_d) **minsyms)
{ {
struct cleanup *cleanup; demangle_result_storage demangle_storage;
char *canon; std::string ada_lookup_storage;
const char *lookup_name; const char *lookup_name;
cleanup = demangle_for_lookup (name, state->language->la_language,
&lookup_name);
if (state->language->la_language == language_ada) if (state->language->la_language == language_ada)
{ {
/* In Ada, the symbol lookups are performed using the encoded /* In Ada, the symbol lookups are performed using the encoded
name rather than the demangled name. */ name rather than the demangled name. */
lookup_name = ada_name_for_lookup (name); ada_lookup_storage = ada_name_for_lookup (name);
make_cleanup (xfree, (void *) lookup_name); lookup_name = ada_lookup_storage.c_str ();
}
else
{
lookup_name = demangle_for_lookup (name,
state->language->la_language,
demangle_storage);
} }
canon = cp_canonicalize_string_no_typedefs (lookup_name); std::string canon = cp_canonicalize_string_no_typedefs (lookup_name);
if (canon != NULL) if (!canon.empty ())
{ lookup_name = canon.c_str ();
lookup_name = canon;
make_cleanup (xfree, canon);
}
/* It's important to not call expand_symtabs_matching unnecessarily /* It's important to not call expand_symtabs_matching unnecessarily
as it can really slow things down (by unnecessarily expanding as it can really slow things down (by unnecessarily expanding
@ -3307,7 +3308,7 @@ find_linespec_symbols (struct linespec_state *state,
if (VEC_empty (symbolp, *symbols) if (VEC_empty (symbolp, *symbols)
&& VEC_empty (bound_minimal_symbol_d, *minsyms)) && VEC_empty (bound_minimal_symbol_d, *minsyms))
{ {
char *klass, *method; std::string klass, method;
const char *last, *p, *scope_op; const char *last, *p, *scope_op;
VEC (symbolp) *classes; VEC (symbolp) *classes;
@ -3327,35 +3328,29 @@ find_linespec_symbols (struct linespec_state *state,
we already attempted to lookup the entire name as a symbol we already attempted to lookup the entire name as a symbol
and failed. */ and failed. */
if (last == NULL) if (last == NULL)
{
do_cleanups (cleanup);
return; return;
}
/* LOOKUP_NAME points to the class name. /* LOOKUP_NAME points to the class name.
LAST points to the method name. */ LAST points to the method name. */
klass = XNEWVEC (char, last - lookup_name + 1); klass = std::string (lookup_name, last - lookup_name);
make_cleanup (xfree, klass);
strncpy (klass, lookup_name, last - lookup_name);
klass[last - lookup_name] = '\0';
/* Skip past the scope operator. */ /* Skip past the scope operator. */
last += strlen (scope_op); last += strlen (scope_op);
method = XNEWVEC (char, strlen (last) + 1); method = last;
make_cleanup (xfree, method);
strcpy (method, last);
/* Find a list of classes named KLASS. */ /* Find a list of classes named KLASS. */
classes = lookup_prefix_sym (state, file_symtabs, klass); classes = lookup_prefix_sym (state, file_symtabs, klass.c_str ());
make_cleanup (VEC_cleanup (symbolp), &classes); struct cleanup *old_chain
= make_cleanup (VEC_cleanup (symbolp), &classes);
if (!VEC_empty (symbolp, classes)) if (!VEC_empty (symbolp, classes))
{ {
/* Now locate a list of suitable methods named METHOD. */ /* Now locate a list of suitable methods named METHOD. */
TRY TRY
{ {
find_method (state, file_symtabs, klass, method, classes, find_method (state, file_symtabs,
symbols, minsyms); klass.c_str (), method.c_str (),
classes, symbols, minsyms);
} }
/* If successful, we're done. If NOT_FOUND_ERROR /* If successful, we're done. If NOT_FOUND_ERROR
@ -3367,9 +3362,9 @@ find_linespec_symbols (struct linespec_state *state,
} }
END_CATCH END_CATCH
} }
}
do_cleanups (cleanup); do_cleanups (old_chain);
}
} }
/* Return all labels named NAME in FUNCTION_SYMBOLS. Return the /* Return all labels named NAME in FUNCTION_SYMBOLS. Return the

View file

@ -49,34 +49,28 @@ print_varobj (struct varobj *var, enum print_values print_values,
int print_expression) int print_expression)
{ {
struct ui_out *uiout = current_uiout; struct ui_out *uiout = current_uiout;
char *type;
int thread_id; int thread_id;
char *display_hint; char *display_hint;
ui_out_field_string (uiout, "name", varobj_get_objname (var)); ui_out_field_string (uiout, "name", varobj_get_objname (var));
if (print_expression) if (print_expression)
{ {
char *exp = varobj_get_expression (var); std::string exp = varobj_get_expression (var);
ui_out_field_string (uiout, "exp", exp); ui_out_field_string (uiout, "exp", exp.c_str ());
xfree (exp);
} }
ui_out_field_int (uiout, "numchild", varobj_get_num_children (var)); ui_out_field_int (uiout, "numchild", varobj_get_num_children (var));
if (mi_print_value_p (var, print_values)) if (mi_print_value_p (var, print_values))
{ {
char *val = varobj_get_value (var); std::string val = varobj_get_value (var);
ui_out_field_string (uiout, "value", val); ui_out_field_string (uiout, "value", val.c_str ());
xfree (val);
} }
type = varobj_get_type (var); std::string type = varobj_get_type (var);
if (type != NULL) if (!type.empty ())
{ ui_out_field_string (uiout, "type", type.c_str ());
ui_out_field_string (uiout, "type", type);
xfree (type);
}
thread_id = varobj_get_thread_id (var); thread_id = varobj_get_thread_id (var);
if (thread_id > 0) if (thread_id > 0)
@ -246,7 +240,6 @@ mi_cmd_var_set_format (char *command, char **argv, int argc)
{ {
enum varobj_display_formats format; enum varobj_display_formats format;
struct varobj *var; struct varobj *var;
char *val;
struct ui_out *uiout = current_uiout; struct ui_out *uiout = current_uiout;
if (argc != 2) if (argc != 2)
@ -264,9 +257,8 @@ mi_cmd_var_set_format (char *command, char **argv, int argc)
ui_out_field_string (uiout, "format", varobj_format_string[(int) format]); ui_out_field_string (uiout, "format", varobj_format_string[(int) format]);
/* Report the value in the new format. */ /* Report the value in the new format. */
val = varobj_get_value (var); std::string val = varobj_get_value (var);
ui_out_field_string (uiout, "value", val); ui_out_field_string (uiout, "value", val.c_str ());
xfree (val);
} }
void void
@ -454,18 +446,15 @@ mi_cmd_var_info_type (char *command, char **argv, int argc)
{ {
struct ui_out *uiout = current_uiout; struct ui_out *uiout = current_uiout;
struct varobj *var; struct varobj *var;
char *type_name;
if (argc != 1) if (argc != 1)
error (_("-var-info-type: Usage: NAME.")); error (_("-var-info-type: Usage: NAME."));
/* Get varobj handle, if a valid var obj name was specified. */ /* Get varobj handle, if a valid var obj name was specified. */
var = varobj_get_handle (argv[0]); var = varobj_get_handle (argv[0]);
type_name = varobj_get_type (var);
ui_out_field_string (uiout, "type", type_name); std::string type_name = varobj_get_type (var);
ui_out_field_string (uiout, "type", type_name.c_str ());
xfree (type_name);
} }
void void
@ -473,7 +462,6 @@ mi_cmd_var_info_path_expression (char *command, char **argv, int argc)
{ {
struct ui_out *uiout = current_uiout; struct ui_out *uiout = current_uiout;
struct varobj *var; struct varobj *var;
char *path_expr;
if (argc != 1) if (argc != 1)
error (_("Usage: NAME.")); error (_("Usage: NAME."));
@ -481,7 +469,7 @@ mi_cmd_var_info_path_expression (char *command, char **argv, int argc)
/* Get varobj handle, if a valid var obj name was specified. */ /* Get varobj handle, if a valid var obj name was specified. */
var = varobj_get_handle (argv[0]); var = varobj_get_handle (argv[0]);
path_expr = varobj_get_path_expr (var); const char *path_expr = varobj_get_path_expr (var);
ui_out_field_string (uiout, "path_expr", path_expr); ui_out_field_string (uiout, "path_expr", path_expr);
} }
@ -492,7 +480,6 @@ mi_cmd_var_info_expression (char *command, char **argv, int argc)
struct ui_out *uiout = current_uiout; struct ui_out *uiout = current_uiout;
const struct language_defn *lang; const struct language_defn *lang;
struct varobj *var; struct varobj *var;
char *exp;
if (argc != 1) if (argc != 1)
error (_("-var-info-expression: Usage: NAME.")); error (_("-var-info-expression: Usage: NAME."));
@ -504,9 +491,8 @@ mi_cmd_var_info_expression (char *command, char **argv, int argc)
ui_out_field_string (uiout, "lang", lang->la_natural_name); ui_out_field_string (uiout, "lang", lang->la_natural_name);
exp = varobj_get_expression (var); std::string exp = varobj_get_expression (var);
ui_out_field_string (uiout, "exp", exp); ui_out_field_string (uiout, "exp", exp.c_str ());
xfree (exp);
} }
void void
@ -588,17 +574,15 @@ mi_cmd_var_evaluate_expression (char *command, char **argv, int argc)
if (formatFound) if (formatFound)
{ {
char *val = varobj_get_formatted_value (var, format); std::string val = varobj_get_formatted_value (var, format);
ui_out_field_string (uiout, "value", val); ui_out_field_string (uiout, "value", val.c_str ());
xfree (val);
} }
else else
{ {
char *val = varobj_get_value (var); std::string val = varobj_get_value (var);
ui_out_field_string (uiout, "value", val); ui_out_field_string (uiout, "value", val.c_str ());
xfree (val);
} }
} }
@ -607,7 +591,6 @@ mi_cmd_var_assign (char *command, char **argv, int argc)
{ {
struct ui_out *uiout = current_uiout; struct ui_out *uiout = current_uiout;
struct varobj *var; struct varobj *var;
char *expression, *val;
if (argc != 2) if (argc != 2)
error (_("-var-assign: Usage: NAME EXPRESSION.")); error (_("-var-assign: Usage: NAME EXPRESSION."));
@ -618,7 +601,7 @@ mi_cmd_var_assign (char *command, char **argv, int argc)
if (!varobj_editable_p (var)) if (!varobj_editable_p (var))
error (_("-var-assign: Variable object is not editable")); error (_("-var-assign: Variable object is not editable"));
expression = xstrdup (argv[1]); const char *expression = argv[1];
/* MI command '-var-assign' may write memory, so suppress memory /* MI command '-var-assign' may write memory, so suppress memory
changed notification if it does. */ changed notification if it does. */
@ -629,9 +612,8 @@ mi_cmd_var_assign (char *command, char **argv, int argc)
error (_("-var-assign: Could not assign " error (_("-var-assign: Could not assign "
"expression to variable object")); "expression to variable object"));
val = varobj_get_value (var); std::string val = varobj_get_value (var);
ui_out_field_string (uiout, "value", val); ui_out_field_string (uiout, "value", val.c_str ());
xfree (val);
} }
/* Type used for parameters passing to mi_cmd_var_update_iter. */ /* Type used for parameters passing to mi_cmd_var_update_iter. */
@ -752,10 +734,9 @@ varobj_update_one (struct varobj *var, enum print_values print_values,
case VAROBJ_IN_SCOPE: case VAROBJ_IN_SCOPE:
if (mi_print_value_p (r->varobj, print_values)) if (mi_print_value_p (r->varobj, print_values))
{ {
char *val = varobj_get_value (r->varobj); std::string val = varobj_get_value (r->varobj);
ui_out_field_string (uiout, "value", val); ui_out_field_string (uiout, "value", val.c_str ());
xfree (val);
} }
ui_out_field_string (uiout, "in_scope", "true"); ui_out_field_string (uiout, "in_scope", "true");
break; break;
@ -777,10 +758,9 @@ varobj_update_one (struct varobj *var, enum print_values print_values,
if (r->type_changed) if (r->type_changed)
{ {
char *type_name = varobj_get_type (r->varobj); std::string type_name = varobj_get_type (r->varobj);
ui_out_field_string (uiout, "new_type", type_name); ui_out_field_string (uiout, "new_type", type_name.c_str ());
xfree (type_name);
} }
if (r->type_changed || r->children_changed) if (r->type_changed || r->children_changed)

View file

@ -158,22 +158,20 @@ lookup_minimal_symbol (const char *name, const char *sfile,
unsigned int hash = msymbol_hash (name) % MINIMAL_SYMBOL_HASH_SIZE; unsigned int hash = msymbol_hash (name) % MINIMAL_SYMBOL_HASH_SIZE;
unsigned int dem_hash = msymbol_hash_iw (name) % MINIMAL_SYMBOL_HASH_SIZE; unsigned int dem_hash = msymbol_hash_iw (name) % MINIMAL_SYMBOL_HASH_SIZE;
int needtofreename = 0; const char *modified_name = name;
const char *modified_name;
if (sfile != NULL) if (sfile != NULL)
sfile = lbasename (sfile); sfile = lbasename (sfile);
/* For C++, canonicalize the input name. */ /* For C++, canonicalize the input name. */
modified_name = name; std::string modified_name_storage;
if (current_language->la_language == language_cplus) if (current_language->la_language == language_cplus)
{ {
char *cname = cp_canonicalize_string (name); std::string cname = cp_canonicalize_string (name);
if (!cname.empty ())
if (cname)
{ {
modified_name = cname; std::swap (modified_name_storage, cname);
needtofreename = 1; modified_name = modified_name_storage.c_str ();
} }
} }
@ -272,9 +270,6 @@ lookup_minimal_symbol (const char *name, const char *sfile,
} }
} }
if (needtofreename)
xfree ((void *) modified_name);
/* External symbols are best. */ /* External symbols are best. */
if (found_symbol.minsym != NULL) if (found_symbol.minsym != NULL)
{ {

View file

@ -113,11 +113,11 @@ py_varobj_iter_next (struct varobj_iter *self)
error (_("Invalid item from the child list")); error (_("Invalid item from the child list"));
} }
vitem = XNEW (struct varobj_item); vitem = new varobj_item ();
vitem->value = convert_value_from_python (py_v); vitem->value = convert_value_from_python (py_v);
if (vitem->value == NULL) if (vitem->value == NULL)
gdbpy_print_stack (); gdbpy_print_stack ();
vitem->name = xstrdup (name); vitem->name = name;
self->next_raw_index++; self->next_raw_index++;
do_cleanups (back_to); do_cleanups (back_to);

View file

@ -2055,13 +2055,11 @@ convert_ast_to_type (struct parser_state *state,
obstack_1grow (&work_obstack, '('); obstack_1grow (&work_obstack, '(');
for (i = 0; VEC_iterate (type_ptr, args, i, type); ++i) for (i = 0; VEC_iterate (type_ptr, args, i, type); ++i)
{ {
char *type_name = type_to_string (type); std::string type_name = type_to_string (type);
if (i > 0) if (i > 0)
obstack_1grow (&work_obstack, ','); obstack_1grow (&work_obstack, ',');
obstack_grow_str (&work_obstack, type_name); obstack_grow_str (&work_obstack, type_name.c_str ());
xfree (type_name);
} }
obstack_grow_str0 (&work_obstack, ")"); obstack_grow_str0 (&work_obstack, ")");
@ -2109,13 +2107,12 @@ convert_name (struct parser_state *state, const struct rust_op *operation)
obstack_1grow (&work_obstack, '<'); obstack_1grow (&work_obstack, '<');
for (i = 0; VEC_iterate (type_ptr, types, i, type); ++i) for (i = 0; VEC_iterate (type_ptr, types, i, type); ++i)
{ {
char *type_name = type_to_string (type); std::string type_name = type_to_string (type);
if (i > 0) if (i > 0)
obstack_1grow (&work_obstack, ','); obstack_1grow (&work_obstack, ',');
obstack_grow_str (&work_obstack, type_name); obstack_grow_str (&work_obstack, type_name.c_str ());
xfree (type_name);
} }
obstack_grow_str0 (&work_obstack, ">"); obstack_grow_str0 (&work_obstack, ">");

View file

@ -649,7 +649,6 @@ define_symbol (CORE_ADDR valu, char *string, int desc, int type,
int deftype; int deftype;
int synonym = 0; int synonym = 0;
int i; int i;
char *new_name = NULL;
/* We would like to eliminate nameless symbols, but keep their types. /* We would like to eliminate nameless symbols, but keep their types.
E.g. stab entry ":t10=*2" should produce a type 10, which is a pointer E.g. stab entry ":t10=*2" should produce a type 10, which is a pointer
@ -733,6 +732,8 @@ define_symbol (CORE_ADDR valu, char *string, int desc, int type,
else else
{ {
normal: normal:
std::string new_name;
if (SYMBOL_LANGUAGE (sym) == language_cplus) if (SYMBOL_LANGUAGE (sym) == language_cplus)
{ {
char *name = (char *) alloca (p - string + 1); char *name = (char *) alloca (p - string + 1);
@ -741,10 +742,11 @@ define_symbol (CORE_ADDR valu, char *string, int desc, int type,
name[p - string] = '\0'; name[p - string] = '\0';
new_name = cp_canonicalize_string (name); new_name = cp_canonicalize_string (name);
} }
if (new_name != NULL) if (!new_name.empty ())
{ {
SYMBOL_SET_NAMES (sym, new_name, strlen (new_name), 1, objfile); SYMBOL_SET_NAMES (sym,
xfree (new_name); new_name.c_str (), new_name.length (),
1, objfile);
} }
else else
SYMBOL_SET_NAMES (sym, string, p - string, 1, objfile); SYMBOL_SET_NAMES (sym, string, p - string, 1, objfile);
@ -1642,17 +1644,18 @@ again:
type_name = NULL; type_name = NULL;
if (current_subfile->language == language_cplus) if (current_subfile->language == language_cplus)
{ {
char *new_name, *name = (char *) alloca (p - *pp + 1); char *name = (char *) alloca (p - *pp + 1);
memcpy (name, *pp, p - *pp); memcpy (name, *pp, p - *pp);
name[p - *pp] = '\0'; name[p - *pp] = '\0';
new_name = cp_canonicalize_string (name);
if (new_name != NULL) std::string new_name = cp_canonicalize_string (name);
if (!new_name.empty ())
{ {
type_name type_name
= (char *) obstack_copy0 (&objfile->objfile_obstack, = (char *) obstack_copy0 (&objfile->objfile_obstack,
new_name, strlen (new_name)); new_name.c_str (),
xfree (new_name); new_name.length ());
} }
} }
if (type_name == NULL) if (type_name == NULL)

View file

@ -1770,10 +1770,10 @@ fixup_symbol_section (struct symbol *sym, struct objfile *objfile)
} }
/* Compute the demangled form of NAME as used by the various symbol /* Compute the demangled form of NAME as used by the various symbol
lookup functions. The result is stored in *RESULT_NAME. Returns a lookup functions. The result can either be the input NAME
cleanup which can be used to clean up the result. directly, or a pointer to a buffer owned by the STORAGE object.
For Ada, this function just sets *RESULT_NAME to NAME, unmodified. For Ada, this function just returns NAME, unmodified.
Normally, Ada symbol lookups are performed using the encoded name Normally, Ada symbol lookups are performed using the encoded name
rather than the demangled name, and so it might seem to make sense rather than the demangled name, and so it might seem to make sense
for this function to return an encoded version of NAME. for this function to return an encoded version of NAME.
@ -1787,59 +1787,38 @@ fixup_symbol_section (struct symbol *sym, struct objfile *objfile)
characters to become lowercase, and thus cause the symbol lookup characters to become lowercase, and thus cause the symbol lookup
to fail. */ to fail. */
struct cleanup * const char *
demangle_for_lookup (const char *name, enum language lang, demangle_for_lookup (const char *name, enum language lang,
const char **result_name) demangle_result_storage &storage)
{ {
char *demangled_name = NULL;
const char *modified_name = NULL;
struct cleanup *cleanup = make_cleanup (null_cleanup, 0);
modified_name = name;
/* If we are using C++, D, or Go, demangle the name before doing a /* If we are using C++, D, or Go, demangle the name before doing a
lookup, so we can always binary search. */ lookup, so we can always binary search. */
if (lang == language_cplus) if (lang == language_cplus)
{ {
demangled_name = gdb_demangle (name, DMGL_ANSI | DMGL_PARAMS); char *demangled_name = gdb_demangle (name, DMGL_ANSI | DMGL_PARAMS);
if (demangled_name) if (demangled_name != NULL)
{ return storage.set_malloc_ptr (demangled_name);
modified_name = demangled_name;
make_cleanup (xfree, demangled_name);
}
else
{
/* If we were given a non-mangled name, canonicalize it /* If we were given a non-mangled name, canonicalize it
according to the language (so far only for C++). */ according to the language (so far only for C++). */
demangled_name = cp_canonicalize_string (name); std::string canon = cp_canonicalize_string (name);
if (demangled_name) if (!canon.empty ())
{ return storage.swap_string (canon);
modified_name = demangled_name;
make_cleanup (xfree, demangled_name);
}
}
} }
else if (lang == language_d) else if (lang == language_d)
{ {
demangled_name = d_demangle (name, 0); char *demangled_name = d_demangle (name, 0);
if (demangled_name) if (demangled_name != NULL)
{ return storage.set_malloc_ptr (demangled_name);
modified_name = demangled_name;
make_cleanup (xfree, demangled_name);
}
} }
else if (lang == language_go) else if (lang == language_go)
{ {
demangled_name = go_demangle (name, 0); char *demangled_name = go_demangle (name, 0);
if (demangled_name) if (demangled_name != NULL)
{ return storage.set_malloc_ptr (demangled_name);
modified_name = demangled_name;
make_cleanup (xfree, demangled_name);
}
} }
*result_name = modified_name; return name;
return cleanup;
} }
/* See symtab.h. /* See symtab.h.
@ -1859,15 +1838,11 @@ lookup_symbol_in_language (const char *name, const struct block *block,
const domain_enum domain, enum language lang, const domain_enum domain, enum language lang,
struct field_of_this_result *is_a_field_of_this) struct field_of_this_result *is_a_field_of_this)
{ {
const char *modified_name; demangle_result_storage storage;
struct block_symbol returnval; const char *modified_name = demangle_for_lookup (name, lang, storage);
struct cleanup *cleanup = demangle_for_lookup (name, lang, &modified_name);
returnval = lookup_symbol_aux (modified_name, block, domain, lang, return lookup_symbol_aux (modified_name, block, domain, lang,
is_a_field_of_this); is_a_field_of_this);
do_cleanups (cleanup);
return returnval;
} }
/* See symtab.h. */ /* See symtab.h. */
@ -2278,11 +2253,11 @@ lookup_symbol_in_objfile_from_linkage_name (struct objfile *objfile,
domain_enum domain) domain_enum domain)
{ {
enum language lang = current_language->la_language; enum language lang = current_language->la_language;
const char *modified_name;
struct cleanup *cleanup = demangle_for_lookup (linkage_name, lang,
&modified_name);
struct objfile *main_objfile, *cur_objfile; struct objfile *main_objfile, *cur_objfile;
demangle_result_storage storage;
const char *modified_name = demangle_for_lookup (linkage_name, lang, storage);
if (objfile->separate_debug_objfile_backlink) if (objfile->separate_debug_objfile_backlink)
main_objfile = objfile->separate_debug_objfile_backlink; main_objfile = objfile->separate_debug_objfile_backlink;
else else
@ -2300,13 +2275,9 @@ lookup_symbol_in_objfile_from_linkage_name (struct objfile *objfile,
result = lookup_symbol_in_objfile_symtabs (cur_objfile, STATIC_BLOCK, result = lookup_symbol_in_objfile_symtabs (cur_objfile, STATIC_BLOCK,
modified_name, domain); modified_name, domain);
if (result.symbol != NULL) if (result.symbol != NULL)
{
do_cleanups (cleanup);
return result; return result;
} }
}
do_cleanups (cleanup);
return (struct block_symbol) {NULL, NULL}; return (struct block_symbol) {NULL, NULL};
} }

View file

@ -1637,8 +1637,43 @@ void iterate_over_symbols (const struct block *block, const char *name,
symbol_found_callback_ftype *callback, symbol_found_callback_ftype *callback,
void *data); void *data);
struct cleanup *demangle_for_lookup (const char *name, enum language lang, /* Storage type used by demangle_for_lookup. demangle_for_lookup
const char **result_name); either returns a const char * pointer that points to either of the
fields of this type, or a pointer to the input NAME. This is done
this way because the underlying functions that demangle_for_lookup
calls either return a std::string (e.g., cp_canonicalize_string) or
a malloc'ed buffer (libiberty's demangled), and we want to avoid
unnecessary reallocation/string copying. */
class demangle_result_storage
{
public:
/* Swap the std::string storage with STR, and return a pointer to
the beginning of the new string. */
const char *swap_string (std::string &str)
{
std::swap (m_string, str);
return m_string.c_str ();
}
/* Set the malloc storage to now point at PTR. Any previous malloc
storage is released. */
const char *set_malloc_ptr (char *ptr)
{
m_malloc.reset (ptr);
return ptr;
}
private:
/* The storage. */
std::string m_string;
gdb::unique_xmalloc_ptr<char> m_malloc;
};
const char *
demangle_for_lookup (const char *name, enum language lang,
demangle_result_storage &storage);
struct symbol *allocate_symbol (struct objfile *); struct symbol *allocate_symbol (struct objfile *);

View file

@ -368,10 +368,10 @@ type_print (struct type *type, const char *varstring, struct ui_file *stream,
/* Print TYPE to a string, returning it. The caller is responsible for /* Print TYPE to a string, returning it. The caller is responsible for
freeing the string. */ freeing the string. */
char * std::string
type_to_string (struct type *type) type_to_string (struct type *type)
{ {
char *s = NULL; std::string s;
struct ui_file *stb; struct ui_file *stb;
struct cleanup *old_chain; struct cleanup *old_chain;
@ -381,11 +381,10 @@ type_to_string (struct type *type)
TRY TRY
{ {
type_print (type, "", stb, -1); type_print (type, "", stb, -1);
s = ui_file_xstrdup (stb, NULL); s = ui_file_as_string (stb);
} }
CATCH (except, RETURN_MASK_ALL) CATCH (except, RETURN_MASK_ALL)
{ {
s = NULL;
} }
END_CATCH END_CATCH

View file

@ -992,7 +992,7 @@ extern void modify_field (struct type *type, gdb_byte *addr,
extern void type_print (struct type *type, const char *varstring, extern void type_print (struct type *type, const char *varstring,
struct ui_file *stream, int show); struct ui_file *stream, int show);
extern char *type_to_string (struct type *type); extern std::string type_to_string (struct type *type);
extern gdb_byte *baseclass_addr (struct type *type, int index, extern gdb_byte *baseclass_addr (struct type *type, int index,
gdb_byte *valaddr, gdb_byte *valaddr,

View file

@ -19,7 +19,7 @@
typedef struct varobj_item typedef struct varobj_item
{ {
/* Name of this item. */ /* Name of this item. */
char *name; std::string name;
/* Value of this item. */ /* Value of this item. */
struct value *value; struct value *value;
@ -67,6 +67,6 @@ struct varobj_iter_ops
if ((ITER) != NULL) \ if ((ITER) != NULL) \
{ \ { \
(ITER)->ops->dtor (ITER); \ (ITER)->ops->dtor (ITER); \
xfree (ITER); \ delete (ITER); \
} \ } \
} while (0) } while (0)

View file

@ -156,7 +156,7 @@ static int install_variable (struct varobj *);
static void uninstall_variable (struct varobj *); static void uninstall_variable (struct varobj *);
static struct varobj *create_child (struct varobj *, int, char *); static struct varobj *create_child (struct varobj *, int, std::string &);
static struct varobj * static struct varobj *
create_child_with_value (struct varobj *parent, int index, create_child_with_value (struct varobj *parent, int index,
@ -184,15 +184,15 @@ static int install_new_value (struct varobj *var, struct value *value,
static int number_of_children (const struct varobj *); static int number_of_children (const struct varobj *);
static char *name_of_variable (const struct varobj *); static std::string name_of_variable (const struct varobj *);
static char *name_of_child (struct varobj *, int); static std::string name_of_child (struct varobj *, int);
static struct value *value_of_root (struct varobj **var_handle, int *); static struct value *value_of_root (struct varobj **var_handle, int *);
static struct value *value_of_child (const struct varobj *parent, int index); static struct value *value_of_child (const struct varobj *parent, int index);
static char *my_value_of_variable (struct varobj *var, static std::string my_value_of_variable (struct varobj *var,
enum varobj_display_formats format); enum varobj_display_formats format);
static int is_root_p (const struct varobj *var); static int is_root_p (const struct varobj *var);
@ -270,8 +270,8 @@ find_frame_addr_in_frame_chain (CORE_ADDR frame_addr)
/* Creates a varobj (not its children). */ /* Creates a varobj (not its children). */
struct varobj * struct varobj *
varobj_create (char *objname, varobj_create (const char *objname,
char *expression, CORE_ADDR frame, enum varobj_type type) const char *expression, CORE_ADDR frame, enum varobj_type type)
{ {
struct varobj *var; struct varobj *var;
struct cleanup *old_chain; struct cleanup *old_chain;
@ -351,9 +351,9 @@ varobj_create (char *objname,
var->format = variable_default_display (var); var->format = variable_default_display (var);
var->root->valid_block = innermost_block; var->root->valid_block = innermost_block;
var->name = xstrdup (expression); var->name = expression;
/* For a root var, the name and the expr are the same. */ /* For a root var, the name and the expr are the same. */
var->path_expr = xstrdup (expression); var->path_expr = expression;
/* When the frame is different from the current frame, /* When the frame is different from the current frame,
we must select the appropriate frame before parsing we must select the appropriate frame before parsing
@ -418,7 +418,7 @@ varobj_create (char *objname,
if ((var != NULL) && (objname != NULL)) if ((var != NULL) && (objname != NULL))
{ {
var->obj_name = xstrdup (objname); var->obj_name = objname;
/* If a varobj name is duplicated, the install will fail so /* If a varobj name is duplicated, the install will fail so
we must cleanup. */ we must cleanup. */
@ -452,7 +452,7 @@ varobj_gen_name (void)
error if OBJNAME cannot be found. */ error if OBJNAME cannot be found. */
struct varobj * struct varobj *
varobj_get_handle (char *objname) varobj_get_handle (const char *objname)
{ {
struct vlist *cv; struct vlist *cv;
const char *chp; const char *chp;
@ -465,7 +465,7 @@ varobj_get_handle (char *objname)
} }
cv = *(varobj_table + index); cv = *(varobj_table + index);
while ((cv != NULL) && (strcmp (cv->var->obj_name, objname) != 0)) while (cv != NULL && cv->var->obj_name != objname)
cv = cv->next; cv = cv->next;
if (cv == NULL) if (cv == NULL)
@ -476,16 +476,16 @@ varobj_get_handle (char *objname)
/* Given the handle, return the name of the object. */ /* Given the handle, return the name of the object. */
char * const char *
varobj_get_objname (const struct varobj *var) varobj_get_objname (const struct varobj *var)
{ {
return var->obj_name; return var->obj_name.c_str ();
} }
/* Given the handle, return the expression represented by the object. The /* Given the handle, return the expression represented by the
result must be freed by the caller. */ object. */
char * std::string
varobj_get_expression (const struct varobj *var) varobj_get_expression (const struct varobj *var)
{ {
return name_of_variable (var); return name_of_variable (var);
@ -544,7 +544,6 @@ varobj_set_display_format (struct varobj *var,
if (varobj_value_is_changeable_p (var) if (varobj_value_is_changeable_p (var)
&& var->value && !value_lazy (var->value)) && var->value && !value_lazy (var->value))
{ {
xfree (var->print_value);
var->print_value = varobj_value_get_print_value (var->value, var->print_value = varobj_value_get_print_value (var->value,
var->format, var); var->format, var);
} }
@ -867,7 +866,6 @@ varobj_get_num_children (struct varobj *var)
VEC (varobj_p)* VEC (varobj_p)*
varobj_list_children (struct varobj *var, int *from, int *to) varobj_list_children (struct varobj *var, int *from, int *to)
{ {
char *name;
int i, children_changed; int i, children_changed;
var->dynamic->children_requested = 1; var->dynamic->children_requested = 1;
@ -904,7 +902,7 @@ varobj_list_children (struct varobj *var, int *from, int *to)
/* Either it's the first call to varobj_list_children for /* Either it's the first call to varobj_list_children for
this variable object, and the child was never created, this variable object, and the child was never created,
or it was explicitly deleted by the client. */ or it was explicitly deleted by the client. */
name = name_of_child (var, i); std::string name = name_of_child (var, i);
existing = create_child (var, i, name); existing = create_child (var, i, name);
VEC_replace (varobj_p, var->children, i, existing); VEC_replace (varobj_p, var->children, i, existing);
} }
@ -929,14 +927,14 @@ varobj_add_child (struct varobj *var, struct varobj_item *item)
prints on the console. The caller is responsible for freeing the string. prints on the console. The caller is responsible for freeing the string.
*/ */
char * std::string
varobj_get_type (struct varobj *var) varobj_get_type (struct varobj *var)
{ {
/* For the "fake" variables, do not return a type. (Its type is /* For the "fake" variables, do not return a type. (Its type is
NULL, too.) NULL, too.)
Do not return a type for invalid variables as well. */ Do not return a type for invalid variables as well. */
if (CPLUS_FAKE_CHILD (var) || !var->root->is_valid) if (CPLUS_FAKE_CHILD (var) || !var->root->is_valid)
return NULL; return std::string ();
return type_to_string (var->type); return type_to_string (var->type);
} }
@ -984,10 +982,11 @@ varobj_get_path_expr_parent (const struct varobj *var)
/* Return a pointer to the full rooted expression of varobj VAR. /* Return a pointer to the full rooted expression of varobj VAR.
If it has not been computed yet, compute it. */ If it has not been computed yet, compute it. */
char *
const char *
varobj_get_path_expr (const struct varobj *var) varobj_get_path_expr (const struct varobj *var)
{ {
if (var->path_expr == NULL) if (var->path_expr.empty ())
{ {
/* For root varobjs, we initialize path_expr /* For root varobjs, we initialize path_expr
when creating varobj, so here it should be when creating varobj, so here it should be
@ -998,7 +997,7 @@ varobj_get_path_expr (const struct varobj *var)
mutable_var->path_expr = (*var->root->lang_ops->path_expr_of_child) (var); mutable_var->path_expr = (*var->root->lang_ops->path_expr_of_child) (var);
} }
return var->path_expr; return var->path_expr.c_str ();
} }
const struct language_defn * const struct language_defn *
@ -1027,14 +1026,14 @@ varobj_is_dynamic_p (const struct varobj *var)
return var->dynamic->pretty_printer != NULL; return var->dynamic->pretty_printer != NULL;
} }
char * std::string
varobj_get_formatted_value (struct varobj *var, varobj_get_formatted_value (struct varobj *var,
enum varobj_display_formats format) enum varobj_display_formats format)
{ {
return my_value_of_variable (var, format); return my_value_of_variable (var, format);
} }
char * std::string
varobj_get_value (struct varobj *var) varobj_get_value (struct varobj *var)
{ {
return my_value_of_variable (var, var->format); return my_value_of_variable (var, var->format);
@ -1045,7 +1044,7 @@ varobj_get_value (struct varobj *var)
/* Note: Invokes functions that can call error(). */ /* Note: Invokes functions that can call error(). */
int int
varobj_set_value (struct varobj *var, char *expression) varobj_set_value (struct varobj *var, const char *expression)
{ {
struct value *val = NULL; /* Initialize to keep gcc happy. */ struct value *val = NULL; /* Initialize to keep gcc happy. */
/* The argument "expression" contains the variable's new value. /* The argument "expression" contains the variable's new value.
@ -1245,18 +1244,12 @@ update_type_if_necessary (struct varobj *var, struct value *new_value)
get_user_print_options (&opts); get_user_print_options (&opts);
if (opts.objectprint) if (opts.objectprint)
{ {
struct type *new_type; struct type *new_type = value_actual_type (new_value, 0, 0);
char *curr_type_str, *new_type_str; std::string new_type_str = type_to_string (new_type);
int type_name_changed; std::string curr_type_str = varobj_get_type (var);
new_type = value_actual_type (new_value, 0, 0); /* Did the type name change? */
new_type_str = type_to_string (new_type); if (curr_type_str != new_type_str)
curr_type_str = varobj_get_type (var);
type_name_changed = strcmp (curr_type_str, new_type_str) != 0;
xfree (curr_type_str);
xfree (new_type_str);
if (type_name_changed)
{ {
var->type = new_type; var->type = new_type;
@ -1292,7 +1285,6 @@ install_new_value (struct varobj *var, struct value *value, int initial)
int need_to_fetch; int need_to_fetch;
int changed = 0; int changed = 0;
int intentionally_not_fetched = 0; int intentionally_not_fetched = 0;
char *print_value = NULL;
/* We need to know the varobj's type to decide if the value should /* We need to know the varobj's type to decide if the value should
be fetched or not. C++ fake children (public/protected/private) be fetched or not. C++ fake children (public/protected/private)
@ -1374,6 +1366,7 @@ install_new_value (struct varobj *var, struct value *value, int initial)
values. Don't get string rendering if the value is values. Don't get string rendering if the value is
lazy -- if it is, the code above has decided that the value lazy -- if it is, the code above has decided that the value
should not be fetched. */ should not be fetched. */
std::string print_value;
if (value != NULL && !value_lazy (value) if (value != NULL && !value_lazy (value)
&& var->dynamic->pretty_printer == NULL) && var->dynamic->pretty_printer == NULL)
print_value = varobj_value_get_print_value (value, var->format, var); print_value = varobj_value_get_print_value (value, var->format, var);
@ -1417,8 +1410,8 @@ install_new_value (struct varobj *var, struct value *value, int initial)
gdb_assert (!value_lazy (var->value)); gdb_assert (!value_lazy (var->value));
gdb_assert (!value_lazy (value)); gdb_assert (!value_lazy (value));
gdb_assert (var->print_value != NULL && print_value != NULL); gdb_assert (!var->print_value.empty () && !print_value.empty ());
if (strcmp (var->print_value, print_value) != 0) if (var->print_value != print_value)
changed = 1; changed = 1;
} }
} }
@ -1449,17 +1442,14 @@ install_new_value (struct varobj *var, struct value *value, int initial)
to see if the variable changed. */ to see if the variable changed. */
if (var->dynamic->pretty_printer != NULL) if (var->dynamic->pretty_printer != NULL)
{ {
xfree (print_value);
print_value = varobj_value_get_print_value (var->value, var->format, print_value = varobj_value_get_print_value (var->value, var->format,
var); var);
if ((var->print_value == NULL && print_value != NULL) if ((var->print_value.empty () && !print_value.empty ())
|| (var->print_value != NULL && print_value == NULL) || (!var->print_value.empty () && print_value.empty ())
|| (var->print_value != NULL && print_value != NULL || (!var->print_value.empty () && !print_value.empty ()
&& strcmp (var->print_value, print_value) != 0)) && var->print_value != print_value))
changed = 1; changed = 1;
} }
if (var->print_value)
xfree (var->print_value);
var->print_value = print_value; var->print_value = print_value;
gdb_assert (!var->value || value_type (var->value)); gdb_assert (!var->value || value_type (var->value));
@ -1854,9 +1844,9 @@ delete_variable_1 (int *delcountp, struct varobj *var, int only_children_p,
return; return;
/* Otherwise, add it to the list of deleted ones and proceed to do so. */ /* Otherwise, add it to the list of deleted ones and proceed to do so. */
/* If the name is null, this is a temporary variable, that has not /* If the name is empty, this is a temporary variable, that has not
yet been installed, don't report it, it belongs to the caller... */ yet been installed, don't report it, it belongs to the caller... */
if (var->obj_name != NULL) if (!var->obj_name.empty ())
{ {
*delcountp = *delcountp + 1; *delcountp = *delcountp + 1;
} }
@ -1871,7 +1861,7 @@ delete_variable_1 (int *delcountp, struct varobj *var, int only_children_p,
VEC_replace (varobj_p, var->parent->children, var->index, NULL); VEC_replace (varobj_p, var->parent->children, var->index, NULL);
} }
if (var->obj_name != NULL) if (!var->obj_name.empty ())
uninstall_variable (var); uninstall_variable (var);
/* Free memory associated with this variable. */ /* Free memory associated with this variable. */
@ -1888,13 +1878,13 @@ install_variable (struct varobj *var)
unsigned int index = 0; unsigned int index = 0;
unsigned int i = 1; unsigned int i = 1;
for (chp = var->obj_name; *chp; chp++) for (chp = var->obj_name.c_str (); *chp; chp++)
{ {
index = (index + (i++ * (unsigned int) *chp)) % VAROBJ_TABLE_SIZE; index = (index + (i++ * (unsigned int) *chp)) % VAROBJ_TABLE_SIZE;
} }
cv = *(varobj_table + index); cv = *(varobj_table + index);
while ((cv != NULL) && (strcmp (cv->var->obj_name, var->obj_name) != 0)) while (cv != NULL && cv->var->obj_name != var->obj_name)
cv = cv->next; cv = cv->next;
if (cv != NULL) if (cv != NULL)
@ -1933,27 +1923,27 @@ uninstall_variable (struct varobj *var)
unsigned int i = 1; unsigned int i = 1;
/* Remove varobj from hash table. */ /* Remove varobj from hash table. */
for (chp = var->obj_name; *chp; chp++) for (chp = var->obj_name.c_str (); *chp; chp++)
{ {
index = (index + (i++ * (unsigned int) *chp)) % VAROBJ_TABLE_SIZE; index = (index + (i++ * (unsigned int) *chp)) % VAROBJ_TABLE_SIZE;
} }
cv = *(varobj_table + index); cv = *(varobj_table + index);
prev = NULL; prev = NULL;
while ((cv != NULL) && (strcmp (cv->var->obj_name, var->obj_name) != 0)) while (cv != NULL && cv->var->obj_name != var->obj_name)
{ {
prev = cv; prev = cv;
cv = cv->next; cv = cv->next;
} }
if (varobjdebug) if (varobjdebug)
fprintf_unfiltered (gdb_stdlog, "Deleting %s\n", var->obj_name); fprintf_unfiltered (gdb_stdlog, "Deleting %s\n", var->obj_name.c_str ());
if (cv == NULL) if (cv == NULL)
{ {
warning warning
("Assertion failed: Could not find variable object \"%s\" to delete", ("Assertion failed: Could not find variable object \"%s\" to delete",
var->obj_name); var->obj_name.c_str ());
return; return;
} }
@ -1983,7 +1973,7 @@ uninstall_variable (struct varobj *var)
{ {
warning (_("Assertion failed: Could not find " warning (_("Assertion failed: Could not find "
"varobj \"%s\" in root list"), "varobj \"%s\" in root list"),
var->obj_name); var->obj_name.c_str ());
return; return;
} }
if (prer == NULL) if (prer == NULL)
@ -2000,11 +1990,11 @@ uninstall_variable (struct varobj *var)
The created VAROBJ takes ownership of the allocated NAME. */ The created VAROBJ takes ownership of the allocated NAME. */
static struct varobj * static struct varobj *
create_child (struct varobj *parent, int index, char *name) create_child (struct varobj *parent, int index, std::string &name)
{ {
struct varobj_item item; struct varobj_item item;
item.name = name; std::swap (item.name, name);
item.value = value_of_child (parent, index); item.value = value_of_child (parent, index);
return create_child_with_value (parent, index, &item); return create_child_with_value (parent, index, &item);
@ -2015,21 +2005,22 @@ create_child_with_value (struct varobj *parent, int index,
struct varobj_item *item) struct varobj_item *item)
{ {
struct varobj *child; struct varobj *child;
char *childs_name;
child = new_variable (); child = new_variable ();
/* NAME is allocated by caller. */ /* NAME is allocated by caller. */
child->name = item->name; std::swap (child->name, item->name);
child->index = index; child->index = index;
child->parent = parent; child->parent = parent;
child->root = parent->root; child->root = parent->root;
if (varobj_is_anonymous_child (child)) if (varobj_is_anonymous_child (child))
childs_name = xstrprintf ("%s.%d_anonymous", parent->obj_name, index); child->obj_name = string_printf ("%s.%d_anonymous",
parent->obj_name.c_str (), index);
else else
childs_name = xstrprintf ("%s.%s", parent->obj_name, item->name); child->obj_name = string_printf ("%s.%s",
child->obj_name = childs_name; parent->obj_name.c_str (),
child->name.c_str ());
install_variable (child); install_variable (child);
@ -2059,10 +2050,7 @@ new_variable (void)
{ {
struct varobj *var; struct varobj *var;
var = XNEW (struct varobj); var = new varobj ();
var->name = NULL;
var->path_expr = NULL;
var->obj_name = NULL;
var->index = -1; var->index = -1;
var->type = NULL; var->type = NULL;
var->value = NULL; var->value = NULL;
@ -2072,7 +2060,6 @@ new_variable (void)
var->format = FORMAT_NATURAL; var->format = FORMAT_NATURAL;
var->root = NULL; var->root = NULL;
var->updated = 0; var->updated = 0;
var->print_value = NULL;
var->frozen = 0; var->frozen = 0;
var->not_fetched = 0; var->not_fetched = 0;
var->dynamic = XNEW (struct varobj_dynamic); var->dynamic = XNEW (struct varobj_dynamic);
@ -2127,12 +2114,8 @@ free_variable (struct varobj *var)
if (is_root_p (var)) if (is_root_p (var))
delete var->root; delete var->root;
xfree (var->name);
xfree (var->obj_name);
xfree (var->print_value);
xfree (var->path_expr);
xfree (var->dynamic); xfree (var->dynamic);
xfree (var); delete var;
} }
static void static void
@ -2203,17 +2186,17 @@ number_of_children (const struct varobj *var)
return (*var->root->lang_ops->number_of_children) (var); return (*var->root->lang_ops->number_of_children) (var);
} }
/* What is the expression for the root varobj VAR? Returns a malloc'd /* What is the expression for the root varobj VAR? */
string. */
static char * static std::string
name_of_variable (const struct varobj *var) name_of_variable (const struct varobj *var)
{ {
return (*var->root->lang_ops->name_of_variable) (var); return (*var->root->lang_ops->name_of_variable) (var);
} }
/* What is the name of the INDEX'th child of VAR? Returns a malloc'd /* What is the name of the INDEX'th child of VAR? */
string. */
static char * static std::string
name_of_child (struct varobj *var, int index) name_of_child (struct varobj *var, int index)
{ {
return (*var->root->lang_ops->name_of_child) (var, index); return (*var->root->lang_ops->name_of_child) (var, index);
@ -2331,17 +2314,16 @@ value_of_root (struct varobj **var_handle, int *type_changed)
if (var->root->floating) if (var->root->floating)
{ {
struct varobj *tmp_var; struct varobj *tmp_var;
char *old_type, *new_type;
tmp_var = varobj_create (NULL, var->name, (CORE_ADDR) 0, tmp_var = varobj_create (NULL, var->name.c_str (), (CORE_ADDR) 0,
USE_SELECTED_FRAME); USE_SELECTED_FRAME);
if (tmp_var == NULL) if (tmp_var == NULL)
{ {
return NULL; return NULL;
} }
old_type = varobj_get_type (var); std::string old_type = varobj_get_type (var);
new_type = varobj_get_type (tmp_var); std::string new_type = varobj_get_type (tmp_var);
if (strcmp (old_type, new_type) == 0) if (old_type == new_type)
{ {
/* The expression presently stored inside var->root->exp /* The expression presently stored inside var->root->exp
remembers the locations of local variables relatively to remembers the locations of local variables relatively to
@ -2356,7 +2338,7 @@ value_of_root (struct varobj **var_handle, int *type_changed)
} }
else else
{ {
tmp_var->obj_name = xstrdup (var->obj_name); tmp_var->obj_name = var->obj_name;
tmp_var->from = var->from; tmp_var->from = var->from;
tmp_var->to = var->to; tmp_var->to = var->to;
varobj_delete (var, 0); varobj_delete (var, 0);
@ -2366,8 +2348,6 @@ value_of_root (struct varobj **var_handle, int *type_changed)
var = *var_handle; var = *var_handle;
*type_changed = 1; *type_changed = 1;
} }
xfree (old_type);
xfree (new_type);
} }
else else
{ {
@ -2410,7 +2390,7 @@ value_of_child (const struct varobj *parent, int index)
} }
/* GDB already has a command called "value_of_variable". Sigh. */ /* GDB already has a command called "value_of_variable". Sigh. */
static char * static std::string
my_value_of_variable (struct varobj *var, enum varobj_display_formats format) my_value_of_variable (struct varobj *var, enum varobj_display_formats format)
{ {
if (var->root->is_valid) if (var->root->is_valid)
@ -2420,7 +2400,7 @@ my_value_of_variable (struct varobj *var, enum varobj_display_formats format)
return (*var->root->lang_ops->value_of_variable) (var, format); return (*var->root->lang_ops->value_of_variable) (var, format);
} }
else else
return NULL; return std::string ();
} }
void void
@ -2432,14 +2412,13 @@ varobj_formatted_print_options (struct value_print_options *opts,
opts->raw = 1; opts->raw = 1;
} }
char * std::string
varobj_value_get_print_value (struct value *value, varobj_value_get_print_value (struct value *value,
enum varobj_display_formats format, enum varobj_display_formats format,
const struct varobj *var) const struct varobj *var)
{ {
struct ui_file *stb; struct ui_file *stb;
struct cleanup *old_chain; struct cleanup *old_chain;
char *thevalue = NULL;
struct value_print_options opts; struct value_print_options opts;
struct type *type = NULL; struct type *type = NULL;
long len = 0; long len = 0;
@ -2449,11 +2428,13 @@ varobj_value_get_print_value (struct value *value,
int string_print = 0; int string_print = 0;
if (value == NULL) if (value == NULL)
return NULL; return std::string ();
stb = mem_fileopen (); stb = mem_fileopen ();
old_chain = make_cleanup_ui_file_delete (stb); old_chain = make_cleanup_ui_file_delete (stb);
std::string thevalue;
#if HAVE_PYTHON #if HAVE_PYTHON
if (gdb_python_initialized) if (gdb_python_initialized)
{ {
@ -2518,8 +2499,8 @@ varobj_value_get_print_value (struct value *value,
xfree (hint); xfree (hint);
} }
len = strlen (s); thevalue = std::string (s);
thevalue = (char *) xmemdup (s, len + 1, len + 1); len = thevalue.size ();
gdbarch = get_type_arch (value_type (value)); gdbarch = get_type_arch (value_type (value));
type = builtin_type (gdbarch)->builtin_char; type = builtin_type (gdbarch)->builtin_char;
xfree (s); xfree (s);
@ -2529,8 +2510,6 @@ varobj_value_get_print_value (struct value *value,
do_cleanups (old_chain); do_cleanups (old_chain);
return thevalue; return thevalue;
} }
make_cleanup (xfree, thevalue);
} }
else else
gdbpy_print_stack (); gdbpy_print_stack ();
@ -2549,8 +2528,9 @@ varobj_value_get_print_value (struct value *value,
varobj_formatted_print_options (&opts, format); varobj_formatted_print_options (&opts, format);
/* If the THEVALUE has contents, it is a regular string. */ /* If the THEVALUE has contents, it is a regular string. */
if (thevalue) if (!thevalue.empty ())
LA_PRINT_STRING (stb, type, (gdb_byte *) thevalue, len, encoding, 0, &opts); LA_PRINT_STRING (stb, type, (gdb_byte *) thevalue.c_str (),
len, encoding, 0, &opts);
else if (string_print) else if (string_print)
/* Otherwise, if string_print is set, and it is not a regular /* Otherwise, if string_print is set, and it is not a regular
string, it is a lazy string. */ string, it is a lazy string. */
@ -2559,7 +2539,7 @@ varobj_value_get_print_value (struct value *value,
/* All other cases. */ /* All other cases. */
common_val_print (value, stb, 0, &opts, current_language); common_val_print (value, stb, 0, &opts, current_language);
thevalue = ui_file_xstrdup (stb, NULL); thevalue = ui_file_as_string (stb);
do_cleanups (old_chain); do_cleanups (old_chain);
return thevalue; return thevalue;
@ -2672,11 +2652,11 @@ varobj_invalidate_iter (struct varobj *var, void *unused)
/* Try to create a varobj with same expression. If we succeed /* Try to create a varobj with same expression. If we succeed
replace the old varobj, otherwise invalidate it. */ replace the old varobj, otherwise invalidate it. */
tmp_var = varobj_create (NULL, var->name, (CORE_ADDR) 0, tmp_var = varobj_create (NULL, var->name.c_str (), (CORE_ADDR) 0,
USE_CURRENT_FRAME); USE_CURRENT_FRAME);
if (tmp_var != NULL) if (tmp_var != NULL)
{ {
tmp_var->obj_name = xstrdup (var->obj_name); tmp_var->obj_name = var->obj_name;
varobj_delete (var, 0); varobj_delete (var, 0);
install_variable (tmp_var); install_variable (tmp_var);
} }

View file

@ -86,22 +86,22 @@ struct varobj_dynamic;
/* Every variable in the system has a structure of this type defined /* Every variable in the system has a structure of this type defined
for it. This structure holds all information necessary to manipulate for it. This structure holds all information necessary to manipulate
a particular object variable. Members which must be freed are noted. */ a particular object variable. */
struct varobj struct varobj
{ {
/* Alloc'd name of the variable for this object. If this variable is a /* Name of the variable for this object. If this variable is a
child, then this name will be the child's source name. child, then this name will be the child's source name.
(bar, not foo.bar). */ (bar, not foo.bar). */
/* NOTE: This is the "expression". */ /* NOTE: This is the "expression". */
char *name; std::string name;
/* Alloc'd expression for this child. Can be used to create a /* Expression for this child. Can be used to create a root variable
root variable corresponding to this child. */ corresponding to this child. */
char *path_expr; std::string path_expr;
/* The alloc'd name for this variable's object. This is here for /* The name for this variable's object. This is here for
convenience when constructing this object's children. */ convenience when constructing this object's children. */
char *obj_name; std::string obj_name;
/* Index of this variable in its parent or -1. */ /* Index of this variable in its parent or -1. */
int index; int index;
@ -137,7 +137,7 @@ struct varobj
int updated; int updated;
/* Last print value. */ /* Last print value. */
char *print_value; std::string print_value;
/* Is this variable frozen. Frozen variables are never implicitly /* Is this variable frozen. Frozen variables are never implicitly
updated by -var-update * updated by -var-update *
@ -170,18 +170,15 @@ struct lang_varobj_ops
/* The number of children of PARENT. */ /* The number of children of PARENT. */
int (*number_of_children) (const struct varobj *parent); int (*number_of_children) (const struct varobj *parent);
/* The name (expression) of a root varobj. The returned value must be freed /* The name (expression) of a root varobj. */
by the caller. */ std::string (*name_of_variable) (const struct varobj *parent);
char *(*name_of_variable) (const struct varobj *parent);
/* The name of the INDEX'th child of PARENT. The returned value must be /* The name of the INDEX'th child of PARENT. */
freed by the caller. */ std::string (*name_of_child) (const struct varobj *parent, int index);
char *(*name_of_child) (const struct varobj *parent, int index);
/* Returns the rooted expression of CHILD, which is a variable /* Returns the rooted expression of CHILD, which is a variable
obtain that has some parent. The returned value must be freed by the obtain that has some parent. */
caller. */ std::string (*path_expr_of_child) (const struct varobj *child);
char *(*path_expr_of_child) (const struct varobj *child);
/* The ``struct value *'' of the INDEX'th child of PARENT. */ /* The ``struct value *'' of the INDEX'th child of PARENT. */
struct value *(*value_of_child) (const struct varobj *parent, int index); struct value *(*value_of_child) (const struct varobj *parent, int index);
@ -189,9 +186,8 @@ struct lang_varobj_ops
/* The type of the INDEX'th child of PARENT. */ /* The type of the INDEX'th child of PARENT. */
struct type *(*type_of_child) (const struct varobj *parent, int index); struct type *(*type_of_child) (const struct varobj *parent, int index);
/* The current value of VAR. The returned value must be freed by the /* The current value of VAR. */
caller. */ std::string (*value_of_variable) (const struct varobj *var,
char *(*value_of_variable) (const struct varobj *var,
enum varobj_display_formats format); enum varobj_display_formats format);
/* Return non-zero if changes in value of VAR must be detected and /* Return non-zero if changes in value of VAR must be detected and
@ -233,17 +229,17 @@ extern const struct lang_varobj_ops ada_varobj_ops;
#define default_varobj_ops c_varobj_ops #define default_varobj_ops c_varobj_ops
/* API functions */ /* API functions */
extern struct varobj *varobj_create (char *objname, extern struct varobj *varobj_create (const char *objname,
char *expression, CORE_ADDR frame, const char *expression, CORE_ADDR frame,
enum varobj_type type); enum varobj_type type);
extern char *varobj_gen_name (void); extern char *varobj_gen_name (void);
extern struct varobj *varobj_get_handle (char *name); extern struct varobj *varobj_get_handle (const char *name);
extern char *varobj_get_objname (const struct varobj *var); extern const char *varobj_get_objname (const struct varobj *var);
extern char *varobj_get_expression (const struct varobj *var); extern std::string varobj_get_expression (const struct varobj *var);
/* Delete a varobj and all its children if only_children == 0, otherwise delete /* Delete a varobj and all its children if only_children == 0, otherwise delete
only the children. Return the number of deleted variables. */ only the children. Return the number of deleted variables. */
@ -283,23 +279,24 @@ extern int varobj_get_num_children (struct varobj *var);
extern VEC (varobj_p)* varobj_list_children (struct varobj *var, extern VEC (varobj_p)* varobj_list_children (struct varobj *var,
int *from, int *to); int *from, int *to);
extern char *varobj_get_type (struct varobj *var); extern std::string varobj_get_type (struct varobj *var);
extern struct type *varobj_get_gdb_type (const struct varobj *var); extern struct type *varobj_get_gdb_type (const struct varobj *var);
extern char *varobj_get_path_expr (const struct varobj *var); extern const char *varobj_get_path_expr (const struct varobj *var);
extern const struct language_defn * extern const struct language_defn *
varobj_get_language (const struct varobj *var); varobj_get_language (const struct varobj *var);
extern int varobj_get_attributes (const struct varobj *var); extern int varobj_get_attributes (const struct varobj *var);
extern char *varobj_get_formatted_value (struct varobj *var, extern std::string
varobj_get_formatted_value (struct varobj *var,
enum varobj_display_formats format); enum varobj_display_formats format);
extern char *varobj_get_value (struct varobj *var); extern std::string varobj_get_value (struct varobj *var);
extern int varobj_set_value (struct varobj *var, char *expression); extern int varobj_set_value (struct varobj *var, const char *expression);
extern void all_root_varobjs (void (*func) (struct varobj *var, void *data), extern void all_root_varobjs (void (*func) (struct varobj *var, void *data),
void *data); void *data);
@ -334,7 +331,8 @@ extern int varobj_is_anonymous_child (const struct varobj *child);
extern const struct varobj * extern const struct varobj *
varobj_get_path_expr_parent (const struct varobj *var); varobj_get_path_expr_parent (const struct varobj *var);
extern char *varobj_value_get_print_value (struct value *value, extern std::string
varobj_value_get_print_value (struct value *value,
enum varobj_display_formats format, enum varobj_display_formats format,
const struct varobj *var); const struct varobj *var);