+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>
* language.c (add_language): Use ui_file_as_string and adjust to
}
/* 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 deallocated after use using xfree.
+ be used to look that entity up in Ada units.
NAME can have any form that the "break" or "print" commands might
recognize. In other words, it does not have to be the "natural"
name, or the "encoded" name. */
-char *
+std::string
ada_name_for_lookup (const char *name)
{
- char *canon;
int nlen = strlen (name);
if (name[0] == '<' && name[nlen - 1] == '>')
- {
- canon = (char *) xmalloc (nlen - 1);
- memcpy (canon, name + 1, nlen - 2);
- canon[nlen - 2] = '\0';
- }
+ return std::string (name + 1, nlen - 2);
else
- canon = xstrdup (ada_encode (ada_fold_name (name)));
- return canon;
+ return ada_encode (ada_fold_name (name));
}
/* The result is as for ada_lookup_symbol_list with FULL_SEARCH set
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
(struct gdbarch *gdbarch, enum ada_exception_catchpoint_kind ex_kind,
/* Return a string containing an image of the given scalar value.
VAL is the numeric value, while TYPE is the value's type.
This is useful for plain integers, of course, but even more
- so for enumerated types.
+ so for enumerated types. */
- The result should be deallocated by xfree after use. */
-
-static char *
+static std::string
ada_varobj_scalar_image (struct type *type, LONGEST val)
{
struct ui_file *buf = mem_fileopen ();
struct cleanup *cleanups = make_cleanup_ui_file_delete (buf);
- char *result;
ada_print_scalar (type, val, buf);
- result = ui_file_xstrdup (buf, NULL);
+ std::string result = ui_file_as_string (buf);
do_cleanups (cleanups);
return result;
const char *parent_name,
const char *parent_path_expr,
int child_index,
- char **child_name,
+ std::string *child_name,
struct value **child_value,
struct type **child_type,
- char **child_path_expr);
+ std::string *child_path_expr);
/* Same as ada_varobj_describe_child, but limited to struct/union
objects. */
const char *parent_name,
const char *parent_path_expr,
int child_index,
- char **child_name,
+ std::string *child_name,
struct value **child_value,
struct type **child_type,
- char **child_path_expr)
+ std::string *child_path_expr)
{
int fieldno;
int childno = 0;
const char *field_name = TYPE_FIELD_NAME (parent_type, fieldno);
int child_name_len = ada_name_prefix_len (field_name);
- *child_name = xstrprintf ("%.*s", child_name_len, field_name);
+ *child_name = string_printf ("%.*s", child_name_len, field_name);
}
if (child_value && parent_value)
int child_name_len = ada_name_prefix_len (field_name);
*child_path_expr =
- xstrprintf ("(%s).%.*s", parent_path_expr,
- child_name_len, field_name);
+ string_printf ("(%s).%.*s", parent_path_expr,
+ child_name_len, field_name);
}
return;
const char *parent_name,
const char *parent_path_expr,
int child_index,
- char **child_name,
+ std::string *child_name,
struct value **child_value,
struct type **child_type,
- char **child_path_expr)
+ std::string *child_path_expr)
{
if (child_name)
- *child_name = xstrprintf ("%s.all", parent_name);
+ *child_name = string_printf ("%s.all", parent_name);
if (child_value && parent_value)
ada_varobj_ind (parent_value, parent_type, child_value, NULL);
ada_varobj_ind (parent_value, parent_type, NULL, child_type);
if (child_path_expr)
- *child_path_expr = xstrprintf ("(%s).all", parent_path_expr);
+ *child_path_expr = string_printf ("(%s).all", parent_path_expr);
}
/* Same as ada_varobj_describe_child, limited to simple array objects
const char *parent_name,
const char *parent_path_expr,
int child_index,
- char **child_name,
+ std::string *child_name,
struct value **child_value,
struct type **child_type,
- char **child_path_expr)
+ std::string *child_path_expr)
{
struct type *index_type;
int real_index;
if (child_path_expr)
{
- char *index_img = ada_varobj_scalar_image (index_type, real_index);
- struct cleanup *cleanups = make_cleanup (xfree, index_img);
+ std::string index_img = ada_varobj_scalar_image (index_type, real_index);
/* Enumeration litterals by themselves are potentially ambiguous.
For instance, consider the following package spec:
if (index_type_name != NULL)
*child_path_expr =
- xstrprintf ("(%s)(%.*s'(%s))", parent_path_expr,
- ada_name_prefix_len (index_type_name),
- index_type_name, index_img);
+ string_printf ("(%s)(%.*s'(%s))", parent_path_expr,
+ ada_name_prefix_len (index_type_name),
+ index_type_name, index_img.c_str ());
else
*child_path_expr =
- xstrprintf ("(%s)(%s)", parent_path_expr, index_img);
- do_cleanups (cleanups);
+ string_printf ("(%s)(%s)", parent_path_expr, index_img.c_str ());
}
}
const char *parent_name,
const char *parent_path_expr,
int child_index,
- char **child_name,
+ std::string *child_name,
struct value **child_value,
struct type **child_type,
- char **child_path_expr)
+ std::string *child_path_expr)
{
/* We cannot compute the child's path expression without
the parent's path expression. This is a pre-condition
ada_varobj_adjust_for_child_access (&parent_value, &parent_type);
if (child_name)
- *child_name = NULL;
+ *child_name = std::string ();
if (child_value)
*child_value = NULL;
if (child_type)
*child_type = NULL;
if (child_path_expr)
- *child_path_expr = NULL;
+ *child_path_expr = std::string ();
if (ada_is_array_descriptor_type (parent_type)
&& TYPE_CODE (parent_type) == TYPE_CODE_TYPEDEF)
/* It should never happen. But rather than crash, report dummy names
and return a NULL child_value. */
if (child_name)
- *child_name = xstrdup ("???");
+ *child_name = "???";
}
/* Return the name of the child number CHILD_INDEX of the (PARENT_VALUE,
- PARENT_TYPE) pair. PARENT_NAME is the name of the PARENT.
-
- The result should be deallocated after use with xfree. */
+ PARENT_TYPE) pair. PARENT_NAME is the name of the PARENT. */
-static char *
+static std::string
ada_varobj_get_name_of_child (struct value *parent_value,
struct type *parent_type,
const char *parent_name, int child_index)
{
- char *child_name;
+ std::string child_name;
ada_varobj_describe_child (parent_value, parent_type, parent_name,
NULL, child_index, &child_name, NULL,
/* Return the path expression of the child number CHILD_INDEX of
the (PARENT_VALUE, PARENT_TYPE) pair. PARENT_NAME is the name
of the parent, and PARENT_PATH_EXPR is the parent's path expression.
- Both must be non-NULL.
+ Both must be non-NULL. */
- The result must be deallocated after use with xfree. */
-
-static char *
+static std::string
ada_varobj_get_path_expr_of_child (struct value *parent_value,
struct type *parent_type,
const char *parent_name,
const char *parent_path_expr,
int child_index)
{
- char *child_path_expr;
+ std::string child_path_expr;
ada_varobj_describe_child (parent_value, parent_type, parent_name,
parent_path_expr, child_index, NULL,
The resulting string must be deallocated after use with xfree. */
-static char *
+static std::string
ada_varobj_get_value_image (struct value *value,
struct value_print_options *opts)
{
- char *result;
struct ui_file *buffer;
struct cleanup *old_chain;
old_chain = make_cleanup_ui_file_delete (buffer);
common_val_print (value, buffer, 0, opts, current_language);
- result = ui_file_xstrdup (buffer, NULL);
+ std::string result = ui_file_as_string (buffer);
do_cleanups (old_chain);
return result;
The result should be deallocated after use using xfree. */
-static char *
+static std::string
ada_varobj_get_value_of_array_variable (struct value *value,
struct type *type,
struct value_print_options *opts)
&& ada_is_string_type (type)
&& (opts->format == 0 || opts->format == 's'))
{
- char *str;
- struct cleanup *old_chain;
-
- str = ada_varobj_get_value_image (value, opts);
- old_chain = make_cleanup (xfree, str);
- result = xstrprintf ("[%d] %s", numchild, str);
- do_cleanups (old_chain);
+ std::string str = ada_varobj_get_value_image (value, opts);
+ return string_printf ("[%d] %s", numchild, str.c_str ());
}
else
- result = xstrprintf ("[%d]", numchild);
-
- return result;
+ return string_printf ("[%d]", numchild);
}
/* Return a string representation of the (VALUE, TYPE) pair, using
the given print options OPTS as our formatting options. */
-static char *
+static std::string
ada_varobj_get_value_of_variable (struct value *value,
struct type *type,
struct value_print_options *opts)
{
- char *result = NULL;
-
ada_varobj_decode_var (&value, &type);
switch (TYPE_CODE (type))
{
case TYPE_CODE_STRUCT:
case TYPE_CODE_UNION:
- result = xstrdup ("{...}");
- break;
+ return "{...}";
case TYPE_CODE_ARRAY:
- result = ada_varobj_get_value_of_array_variable (value, type, opts);
- break;
+ return ada_varobj_get_value_of_array_variable (value, type, opts);
default:
if (!value)
- result = xstrdup ("");
+ return "";
else
- result = ada_varobj_get_value_image (value, opts);
- break;
+ return ada_varobj_get_value_image (value, opts);
}
-
- return result;
}
/* Ada specific callbacks for VAROBJs. */
return ada_varobj_get_number_of_children (var->value, var->type);
}
-static char *
+static std::string
ada_name_of_variable (const struct varobj *parent)
{
return c_varobj_ops.name_of_variable (parent);
}
-static char *
+static std::string
ada_name_of_child (const struct varobj *parent, int index)
{
return ada_varobj_get_name_of_child (parent->value, parent->type,
- parent->name, index);
+ parent->name.c_str (), index);
}
-static char*
+static std::string
ada_path_expr_of_child (const struct varobj *child)
{
const struct varobj *parent = child->parent;
return ada_varobj_get_path_expr_of_child (parent->value,
parent->type,
- parent->name,
+ parent->name.c_str (),
parent_path_expr,
child->index);
}
ada_value_of_child (const struct varobj *parent, int index)
{
return ada_varobj_get_value_of_child (parent->value, parent->type,
- parent->name, index);
+ parent->name.c_str (), index);
}
static struct type *
index);
}
-static char *
+static std::string
ada_value_of_variable (const struct varobj *var,
enum varobj_display_formats format)
{
varobj_restrict_range (var->children, &from, &to);
for (i = from; i < to; i++)
- if (strcmp (ada_varobj_get_name_of_child (new_val, new_type,
- var->name, i),
- VEC_index (varobj_p, var->children, i)->name) != 0)
+ if (ada_varobj_get_name_of_child (new_val, new_type,
+ var->name.c_str (), i)
+ != VEC_index (varobj_p, var->children, i)->name)
return 1;
return 0;
{
struct exception_catchpoint *self
= (struct exception_catchpoint *) bs->breakpoint_at;
- char *type_name = NULL;
+ std::string type_name;
bkpt_breakpoint_ops.check_status (bs);
if (bs->stop == 0)
TRY
{
struct value *typeinfo_arg;
- char *canon;
+ std::string canon;
fetch_probe_arguments (NULL, &typeinfo_arg);
type_name = cplus_typename_from_type_info (typeinfo_arg);
- canon = cp_canonicalize_string (type_name);
- if (canon != NULL)
- {
- xfree (type_name);
- type_name = canon;
- }
+ canon = cp_canonicalize_string (type_name.c_str ());
+ if (!canon.empty ())
+ std::swap (type_name, canon);
}
CATCH (e, RETURN_MASK_ERROR)
{
}
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;
-
- xfree (type_name);
}
}
{
struct type *t = value_type (val);
CORE_ADDR addr = value_as_address (val);
- char *name;
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));
- xfree (name);
w->exp_string = xstrprintf ("-location %.*s",
(int) (exp_end - exp_start), exp_start);
error:
{
- char *type_str;
-
- type_str = type_to_string (type);
- if (type_str)
+ std::string type_str = type_to_string (type);
+ if (!type_str.empty ())
{
- make_cleanup (xfree, type_str);
error (_("Trying to read string with inappropriate type `%s'."),
- type_str);
+ type_str.c_str ());
}
else
error (_("Trying to read string with inappropriate type."));
const struct type_print_options *flags,
struct ui_file *stream)
{
- char *s = NULL;
+ std::string s;
if (!flags->raw)
s = cp_canonicalize_string_full (name,
find_typedef_for_canonicalize,
(void *) flags);
- fputs_filtered (s ? s : name, stream);
- xfree (s);
+ fputs_filtered (!s.empty () ? s.c_str () : name, stream);
}
\f
int
varobj_is_anonymous_child (const struct varobj *child)
{
- return (strcmp (child->name, ANONYMOUS_STRUCT_NAME) == 0
- || strcmp (child->name, ANONYMOUS_UNION_NAME) == 0);
+ return (child->name == ANONYMOUS_STRUCT_NAME
+ || child->name == ANONYMOUS_UNION_NAME);
}
/* Given the value and the type of a variable object,
return children;
}
-static char *
+static std::string
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
If any of CNAME, CVALUE, or CTYPE is not null, but the corresponding
information cannot be determined, set *CNAME, *CVALUE, or *CTYPE
- to NULL. */
+ to empty. */
static void
c_describe_child (const struct varobj *parent, int index,
- char **cname, struct value **cvalue, struct type **ctype,
- char **cfull_expression)
+ std::string *cname, struct value **cvalue,
+ struct type **ctype, std::string *cfull_expression)
{
struct value *value = parent->value;
struct type *type = varobj_get_value_type (parent);
- char *parent_expression = NULL;
+ std::string parent_expression;
int was_ptr;
if (cname)
- *cname = NULL;
+ *cname = std::string ();
if (cvalue)
*cvalue = NULL;
if (ctype)
*ctype = NULL;
if (cfull_expression)
{
- *cfull_expression = NULL;
+ *cfull_expression = std::string ();
parent_expression
= varobj_get_path_expr (varobj_get_path_expr_parent (parent));
}
adjust_value_for_child_access (&value, &type, &was_ptr, 0);
-
+
switch (TYPE_CODE (type))
{
case TYPE_CODE_ARRAY:
if (cname)
- *cname
- = xstrdup (int_string (index
- + TYPE_LOW_BOUND (TYPE_INDEX_TYPE (type)),
- 10, 1, 0, 0));
+ *cname = int_string (index
+ + TYPE_LOW_BOUND (TYPE_INDEX_TYPE (type)),
+ 10, 1, 0, 0);
if (cvalue && value)
{
if (cfull_expression)
*cfull_expression =
- xstrprintf ("(%s)[%s]", parent_expression,
- int_string (index
- + TYPE_LOW_BOUND (TYPE_INDEX_TYPE (type)),
- 10, 1, 0, 0));
+ string_printf ("(%s)[%s]", parent_expression.c_str (),
+ int_string (index
+ + TYPE_LOW_BOUND (TYPE_INDEX_TYPE (type)),
+ 10, 1, 0, 0));
break;
{
if (TYPE_CODE (TYPE_FIELD_TYPE (type, index))
== TYPE_CODE_STRUCT)
- *cname = xstrdup (ANONYMOUS_STRUCT_NAME);
+ *cname = ANONYMOUS_STRUCT_NAME;
else
- *cname = xstrdup (ANONYMOUS_UNION_NAME);
+ *cname = ANONYMOUS_UNION_NAME;
}
if (cfull_expression)
- *cfull_expression = xstrdup ("");
+ *cfull_expression = "";
}
else
{
if (cname)
- *cname = xstrdup (field_name);
+ *cname = field_name;
if (cfull_expression)
{
const char *join = was_ptr ? "->" : ".";
- *cfull_expression = xstrprintf ("(%s)%s%s", parent_expression,
- join, field_name);
+ *cfull_expression = string_printf ("(%s)%s%s",
+ parent_expression.c_str (),
+ join, field_name);
}
}
case TYPE_CODE_PTR:
if (cname)
- *cname = xstrprintf ("*%s", parent->name);
+ *cname = string_printf ("*%s", parent->name.c_str ());
if (cvalue && value)
{
*ctype = TYPE_TARGET_TYPE (type);
if (cfull_expression)
- *cfull_expression = xstrprintf ("*(%s)", parent_expression);
-
+ *cfull_expression = string_printf ("*(%s)", parent_expression.c_str ());
break;
default:
/* This should not happen. */
if (cname)
- *cname = xstrdup ("???");
+ *cname = "???";
if (cfull_expression)
- *cfull_expression = xstrdup ("???");
+ *cfull_expression = "???";
/* 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)
{
- char *name;
+ std::string name;
c_describe_child (parent, index, &name, NULL, NULL, NULL);
return name;
}
-static char *
+static std::string
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,
&path_expr);
return type;
}
-static char *
+static std::string
c_value_of_variable (const struct varobj *var,
enum varobj_display_formats format)
{
{
case TYPE_CODE_STRUCT:
case TYPE_CODE_UNION:
- return xstrdup ("{...}");
+ return "{...}";
/* break; */
case TYPE_CODE_ARRAY:
- {
- char *number;
-
- number = xstrprintf ("[%d]", var->num_children);
- return (number);
- }
+ return string_printf ("[%d]", var->num_children);
/* break; */
default:
/* This can happen if we attempt to get the value of a struct
member when the parent is an invalid pointer. This is an
error condition, so we should tell the caller. */
- return NULL;
+ return std::string ();
}
else
{
/* Frozen variable and no value yet. We don't
implicitly fetch the value. MI response will
use empty string for the value, which is OK. */
- return NULL;
+ return std::string ();
gdb_assert (varobj_value_is_changeable_p (var));
gdb_assert (!value_lazy (var->value));
/* If the specified format is the current one,
we can reuse print_value. */
if (format == var->format)
- return xstrdup (var->print_value);
+ return var->print_value;
else
return varobj_value_get_print_value (var->value, format, var);
}
adjust_value_for_child_access (&value, &type, NULL, lookup_actual_type);
cplus_class_num_children (type, kids);
- if (strcmp (var->name, "public") == 0)
+ if (var->name == "public")
children = kids[v_public];
- else if (strcmp (var->name, "private") == 0)
+ else if (var->name == "private")
children = kids[v_private];
else
children = kids[v_protected];
}
}
-static char *
+static std::string
cplus_name_of_variable (const struct varobj *parent)
{
return c_name_of_variable (parent);
static void
cplus_describe_child (const struct varobj *parent, int index,
- char **cname, struct value **cvalue, struct type **ctype,
- char **cfull_expression)
+ std::string *cname, struct value **cvalue, struct type **ctype,
+ std::string *cfull_expression)
{
struct value *value;
struct type *type;
int was_ptr;
int lookup_actual_type = 0;
- char *parent_expression = NULL;
+ const char *parent_expression = NULL;
const struct varobj *var;
struct value_print_options opts;
if (cname)
- *cname = NULL;
+ *cname = std::string ();
if (cvalue)
*cvalue = NULL;
if (ctype)
*ctype = NULL;
if (cfull_expression)
- *cfull_expression = NULL;
+ *cfull_expression = std::string ();
get_user_print_options (&opts);
const char *field_name;
vptr_fieldno = get_vptr_fieldno (type, &basetype);
- if (strcmp (parent->name, "private") == 0)
+ if (parent->name == "private")
acc = private_field;
- else if (strcmp (parent->name, "protected") == 0)
+ else if (parent->name == "protected")
acc = protected_field;
while (index >= 0)
{
if (TYPE_CODE (TYPE_FIELD_TYPE (type, type_index))
== TYPE_CODE_STRUCT)
- *cname = xstrdup (ANONYMOUS_STRUCT_NAME);
+ *cname = ANONYMOUS_STRUCT_NAME;
else if (TYPE_CODE (TYPE_FIELD_TYPE (type, type_index))
== TYPE_CODE_UNION)
- *cname = xstrdup (ANONYMOUS_UNION_NAME);
+ *cname = ANONYMOUS_UNION_NAME;
}
if (cfull_expression)
- *cfull_expression = xstrdup ("");
+ *cfull_expression = std::string ();
}
else
{
if (cname)
- *cname = xstrdup (TYPE_FIELD_NAME (type, type_index));
+ *cname = TYPE_FIELD_NAME (type, type_index);
if (cfull_expression)
*cfull_expression
- = xstrprintf ("((%s)%s%s)", parent_expression, join,
- field_name);
+ = string_printf ("((%s)%s%s)", parent_expression, join,
+ field_name);
}
if (cvalue && value)
{
/* This is a baseclass. */
if (cname)
- *cname = xstrdup (TYPE_FIELD_NAME (type, index));
+ *cname = TYPE_FIELD_NAME (type, index);
if (cvalue && value)
*cvalue = value_cast (TYPE_FIELD_TYPE (type, index), value);
as a constructor, if it exists. Therefore, we must
indicate that the name is a class name by using the
'class' keyword. See PR mi/11912 */
- *cfull_expression = xstrprintf ("(%s(class %s%s) %s)",
- ptr,
- TYPE_FIELD_NAME (type, index),
- ptr,
- parent_expression);
+ *cfull_expression = string_printf ("(%s(class %s%s) %s)",
+ ptr,
+ TYPE_FIELD_NAME (type, index),
+ ptr,
+ parent_expression);
}
}
else
gdb_assert (access);
if (cname)
- *cname = xstrdup (access);
+ *cname = access;
/* Value and type and full expression are null here. */
}
}
}
-static char *
+static std::string
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);
return name;
}
-static char *
+static std::string
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,
&path_expr);
return type;
}
-static char *
+static std::string
cplus_value_of_variable (const struct varobj *var,
enum varobj_display_formats format)
{
/* If we have one of our special types, don't print out
any value. */
if (CPLUS_FAKE_CHILD (var))
- return xstrdup ("");
+ return std::string ();
return c_value_of_variable (var, format);
}
/* See cp-abi.h. */
-char *
+std::string
cplus_typename_from_type_info (struct value *value)
{
if (current_cp_abi.get_typename_from_type_info == NULL)
/* 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
- exception if the type name cannot be found. The result is
- xmalloc'd and must be freed by the caller. */
+ exception if the type name cannot be found. */
-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
address of the routine we are thunking to and continue to there
struct value *(*get_typeid) (struct value *value);
struct type *(*get_typeid_type) (struct gdbarch *gdbarch);
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);
int (*pass_by_reference) (struct type *type);
};
Canonicalize the name again, and store it in the
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
- free CANON. */
- name = copy_string_to_obstack (&info->obstack, canon, &len);
- xfree (canon);
+ /* Copy the canonicalization into the obstack. */
+ name = copy_string_to_obstack (&info->obstack, canon.c_str (), &len);
}
ret_comp->u.s_name.s = name;
}
}
-/* Parse STRING and convert it to canonical form, resolving any typedefs.
- If parsing fails, or if STRING is already canonical, return NULL.
- Otherwise return the canonical form. The return value is allocated via
- xmalloc. If FINDER is not NULL, then type components are passed to
- FINDER to be looked up. DATA is passed verbatim to FINDER. */
+/* Parse STRING and convert it to canonical form, resolving any
+ typedefs. If parsing fails, or if STRING is already canonical,
+ return the empty string. Otherwise return the canonical form. If
+ FINDER is not NULL, then type components are passed to FINDER to be
+ looked up. DATA is passed verbatim to FINDER. */
-char *
+std::string
cp_canonicalize_string_full (const char *string,
canonicalization_ftype *finder,
void *data)
{
- char *ret;
+ std::string ret;
unsigned int estimated_len;
struct demangle_parse_info *info;
- ret = NULL;
estimated_len = strlen (string) * 2;
info = cp_demangled_name_to_comp (string, NULL);
if (info != NULL)
/* Convert the tree back into a string. */
ret = cp_comp_to_string (info->tree, estimated_len);
- gdb_assert (ret != NULL);
+ gdb_assert (!ret.empty ());
/* Free the parse information. */
cp_demangled_name_parse_free (info);
/* Finally, compare the original string with the computed
name, returning NULL if they are the same. */
- if (strcmp (string, ret) == 0)
- {
- xfree (ret);
- return NULL;
- }
+ if (ret == string)
+ return std::string ();
}
return ret;
/* Like cp_canonicalize_string_full, but always passes NULL for
FINDER. */
-char *
+std::string
cp_canonicalize_string_no_typedefs (const char *string)
{
return cp_canonicalize_string_full (string, NULL, NULL);
}
/* Parse STRING and convert it to canonical form. If parsing fails,
- or if STRING is already canonical, return NULL. Otherwise return
- the canonical form. The return value is allocated via xmalloc. */
+ or if STRING is already canonical, return the empty string.
+ Otherwise return the canonical form. */
-char *
+std::string
cp_canonicalize_string (const char *string)
{
struct demangle_parse_info *info;
unsigned int estimated_len;
- char *ret;
if (cp_already_canonical (string))
- return NULL;
+ return std::string ();
info = cp_demangled_name_to_comp (string, NULL);
if (info == NULL)
- return NULL;
+ return std::string ();
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);
- if (ret == NULL)
+ if (ret.empty ())
{
warning (_("internal error: string \"%s\" failed to be canonicalized"),
string);
- return NULL;
+ return std::string ();
}
- if (strcmp (string, ret) == 0)
- {
- xfree (ret);
- return NULL;
- }
+ if (ret == string)
+ return std::string ();
return ret;
}
/* 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 *);
-extern char *cp_canonicalize_string_full (const char *string,
- canonicalization_ftype *finder,
- void *data);
+extern std::string cp_canonicalize_string_full (const char *string,
+ canonicalization_ftype *finder,
+ void *data);
extern char *cp_class_name_from_physname (const char *physname);
sym_name = NULL; /* pacify "gcc -Werror" */
if (psymtab_language == language_cplus)
{
- char *new_name, *name = (char *) xmalloc (p - namestring + 1);
- memcpy (name, namestring, p - namestring);
-
- name[p - namestring] = '\0';
- new_name = cp_canonicalize_string (name);
- if (new_name != NULL)
- {
- sym_len = strlen (new_name);
+ std::string name (namestring, p - namestring);
+ std::string new_name = cp_canonicalize_string (name.c_str ());
+ if (!new_name.empty ())
+ {
+ sym_len = new_name.length ();
sym_name = (char *) obstack_copy0 (&objfile->objfile_obstack,
- new_name, sym_len);
- xfree (new_name);
- }
- xfree (name);
- }
+ new_name.c_str (),
+ sym_len);
+ }
+ }
if (sym_len == 0)
{
{
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)
- name = (const char *) obstack_copy0 (obstack, canon_name,
- strlen (canon_name));
- xfree (canon_name);
+ if (canon_name != name)
+ name = (const char *) obstack_copy0 (obstack,
+ canon_name.c_str (),
+ canon_name.length ());
}
}
lookup_struct_elt_type (struct type *type, const char *name, int noerr)
{
int i;
- char *type_name;
for (;;)
{
if (TYPE_CODE (type) != TYPE_CODE_STRUCT
&& TYPE_CODE (type) != TYPE_CODE_UNION)
{
- type_name = type_to_string (type);
- make_cleanup (xfree, type_name);
- error (_("Type %s is not a structure or union type."), type_name);
+ std::string type_name = type_to_string (type);
+ error (_("Type %s is not a structure or union type."),
+ type_name.c_str ());
}
#if 0
return NULL;
}
- type_name = type_to_string (type);
- make_cleanup (xfree, type_name);
- error (_("Type %s has no component named %s."), type_name, name);
+ std::string type_name = type_to_string (type);
+ error (_("Type %s has no component named %s."), type_name.c_str (), name);
}
/* Store in *MAX the largest number representable by unsigned integer type
struct gdbarch *gdbarch;
struct cleanup *cleanup;
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
to work properly with non_lvalue values that are really just
gdbarch = get_type_arch (type);
type_name = type_to_string (type);
- if (type_name == NULL)
+ if (type_name.empty ())
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
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
the demangler uses "char const *". */
- canonical = cp_canonicalize_string (type_name);
- if (canonical != NULL)
- {
- make_cleanup (xfree, canonical);
- type_name = canonical;
- }
+ canonical = cp_canonicalize_string (type_name.c_str ());
+ if (!canonical.empty ())
+ type_name = canonical;
typeinfo_type = gnuv3_get_typeid_type (gdbarch);
vtable = gnuv3_get_vtable (gdbarch, type, address);
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);
result = value_ind (value_cast (make_pointer_type (typeinfo_type, NULL),
typeinfo_value));
}
else
{
- char *sym_name;
- struct bound_minimal_symbol minsym;
-
- sym_name = concat ("typeinfo for ", type_name, (char *) NULL);
- make_cleanup (xfree, sym_name);
- minsym = lookup_minimal_symbol (sym_name, NULL, NULL);
+ std::string sym_name = std::string ("typeinfo for ") + type_name;
+ bound_minimal_symbol minsym
+ = lookup_minimal_symbol (sym_name.c_str (), NULL, 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));
}
- do_cleanups (cleanup);
return result;
}
/* Implement the 'get_typename_from_type_info' method. */
-static char *
+static std::string
gnuv3_get_typename_from_type_info (struct value *type_info_ptr)
{
struct gdbarch *gdbarch = get_type_arch (value_type (type_info_ptr));
/* Strip off @plt and version suffixes. */
atsign = strchr (class_name, '@');
if (atsign != NULL)
- return savestring (class_name, atsign - class_name);
- return xstrdup (class_name);
+ return std::string (class_name, atsign - class_name);
+ return class_name;
}
/* Implement the 'get_type_from_type_info' method. */
static struct type *
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
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
internal form to reconstruct the type somehow. */
-
- expression_up expr = parse_expression (type_name);
-
- type_val = evaluate_type (expr.get ());
- result = value_type (type_val);
-
- do_cleanups (cleanup);
- return result;
+ std::string type_name = gnuv3_get_typename_from_type_info (type_info_ptr);
+ expression_up expr (parse_expression (type_name.c_str ()));
+ struct value *type_val = evaluate_type (expr.get ());
+ return value_type (type_val);
}
/* Determine if we are currently in a C++ thunk. If so, get the address
}
else
{
- struct cleanup *oldchain;
- char *type_name;
-
- type_name = type_to_string (rv->type);
- oldchain = make_cleanup (xfree, type_name);
+ std::string type_name = type_to_string (rv->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, " Cannot determine contents\n");
- do_cleanups (oldchain);
}
}
VEC (symbolp) **symbols,
VEC (bound_minimal_symbol_d) **minsyms)
{
- struct cleanup *cleanup;
- char *canon;
+ demangle_result_storage demangle_storage;
+ std::string ada_lookup_storage;
const char *lookup_name;
- cleanup = demangle_for_lookup (name, state->language->la_language,
- &lookup_name);
if (state->language->la_language == language_ada)
{
/* In Ada, the symbol lookups are performed using the encoded
name rather than the demangled name. */
- lookup_name = ada_name_for_lookup (name);
- make_cleanup (xfree, (void *) lookup_name);
+ ada_lookup_storage = ada_name_for_lookup (name);
+ lookup_name = ada_lookup_storage.c_str ();
}
-
- canon = cp_canonicalize_string_no_typedefs (lookup_name);
- if (canon != NULL)
+ else
{
- lookup_name = canon;
- make_cleanup (xfree, canon);
+ lookup_name = demangle_for_lookup (name,
+ state->language->la_language,
+ demangle_storage);
}
+ std::string canon = cp_canonicalize_string_no_typedefs (lookup_name);
+ if (!canon.empty ())
+ lookup_name = canon.c_str ();
+
/* It's important to not call expand_symtabs_matching unnecessarily
as it can really slow things down (by unnecessarily expanding
potentially 1000s of symtabs, which when debugging some apps can
if (VEC_empty (symbolp, *symbols)
&& VEC_empty (bound_minimal_symbol_d, *minsyms))
{
- char *klass, *method;
+ std::string klass, method;
const char *last, *p, *scope_op;
VEC (symbolp) *classes;
we already attempted to lookup the entire name as a symbol
and failed. */
if (last == NULL)
- {
- do_cleanups (cleanup);
- return;
- }
+ return;
/* LOOKUP_NAME points to the class name.
LAST points to the method name. */
- klass = XNEWVEC (char, last - lookup_name + 1);
- make_cleanup (xfree, klass);
- strncpy (klass, lookup_name, last - lookup_name);
- klass[last - lookup_name] = '\0';
+ klass = std::string (lookup_name, last - lookup_name);
/* Skip past the scope operator. */
last += strlen (scope_op);
- method = XNEWVEC (char, strlen (last) + 1);
- make_cleanup (xfree, method);
- strcpy (method, last);
+ method = last;
/* Find a list of classes named KLASS. */
- classes = lookup_prefix_sym (state, file_symtabs, klass);
- make_cleanup (VEC_cleanup (symbolp), &classes);
+ classes = lookup_prefix_sym (state, file_symtabs, klass.c_str ());
+ struct cleanup *old_chain
+ = make_cleanup (VEC_cleanup (symbolp), &classes);
if (!VEC_empty (symbolp, classes))
{
/* Now locate a list of suitable methods named METHOD. */
TRY
{
- find_method (state, file_symtabs, klass, method, classes,
- symbols, minsyms);
+ find_method (state, file_symtabs,
+ klass.c_str (), method.c_str (),
+ classes, symbols, minsyms);
}
/* If successful, we're done. If NOT_FOUND_ERROR
}
END_CATCH
}
- }
- do_cleanups (cleanup);
+ do_cleanups (old_chain);
+ }
}
/* Return all labels named NAME in FUNCTION_SYMBOLS. Return the
int print_expression)
{
struct ui_out *uiout = current_uiout;
- char *type;
int thread_id;
char *display_hint;
ui_out_field_string (uiout, "name", varobj_get_objname (var));
if (print_expression)
{
- char *exp = varobj_get_expression (var);
+ std::string exp = varobj_get_expression (var);
- ui_out_field_string (uiout, "exp", exp);
- xfree (exp);
+ ui_out_field_string (uiout, "exp", exp.c_str ());
}
ui_out_field_int (uiout, "numchild", varobj_get_num_children (var));
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);
- xfree (val);
+ ui_out_field_string (uiout, "value", val.c_str ());
}
- type = varobj_get_type (var);
- if (type != NULL)
- {
- ui_out_field_string (uiout, "type", type);
- xfree (type);
- }
+ std::string type = varobj_get_type (var);
+ if (!type.empty ())
+ ui_out_field_string (uiout, "type", type.c_str ());
thread_id = varobj_get_thread_id (var);
if (thread_id > 0)
{
enum varobj_display_formats format;
struct varobj *var;
- char *val;
struct ui_out *uiout = current_uiout;
if (argc != 2)
ui_out_field_string (uiout, "format", varobj_format_string[(int) format]);
/* Report the value in the new format. */
- val = varobj_get_value (var);
- ui_out_field_string (uiout, "value", val);
- xfree (val);
+ std::string val = varobj_get_value (var);
+ ui_out_field_string (uiout, "value", val.c_str ());
}
void
{
struct ui_out *uiout = current_uiout;
struct varobj *var;
- char *type_name;
if (argc != 1)
error (_("-var-info-type: Usage: NAME."));
/* Get varobj handle, if a valid var obj name was specified. */
var = varobj_get_handle (argv[0]);
- type_name = varobj_get_type (var);
-
- ui_out_field_string (uiout, "type", type_name);
- xfree (type_name);
+ std::string type_name = varobj_get_type (var);
+ ui_out_field_string (uiout, "type", type_name.c_str ());
}
void
{
struct ui_out *uiout = current_uiout;
struct varobj *var;
- char *path_expr;
if (argc != 1)
error (_("Usage: NAME."));
/* Get varobj handle, if a valid var obj name was specified. */
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);
}
struct ui_out *uiout = current_uiout;
const struct language_defn *lang;
struct varobj *var;
- char *exp;
if (argc != 1)
error (_("-var-info-expression: Usage: NAME."));
ui_out_field_string (uiout, "lang", lang->la_natural_name);
- exp = varobj_get_expression (var);
- ui_out_field_string (uiout, "exp", exp);
- xfree (exp);
+ std::string exp = varobj_get_expression (var);
+ ui_out_field_string (uiout, "exp", exp.c_str ());
}
void
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);
- xfree (val);
+ ui_out_field_string (uiout, "value", val.c_str ());
}
else
{
- char *val = varobj_get_value (var);
+ std::string val = varobj_get_value (var);
- ui_out_field_string (uiout, "value", val);
- xfree (val);
+ ui_out_field_string (uiout, "value", val.c_str ());
}
}
{
struct ui_out *uiout = current_uiout;
struct varobj *var;
- char *expression, *val;
if (argc != 2)
error (_("-var-assign: Usage: NAME EXPRESSION."));
if (!varobj_editable_p (var))
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
changed notification if it does. */
error (_("-var-assign: Could not assign "
"expression to variable object"));
- val = varobj_get_value (var);
- ui_out_field_string (uiout, "value", val);
- xfree (val);
+ std::string val = varobj_get_value (var);
+ ui_out_field_string (uiout, "value", val.c_str ());
}
/* Type used for parameters passing to mi_cmd_var_update_iter. */
case VAROBJ_IN_SCOPE:
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);
- xfree (val);
+ ui_out_field_string (uiout, "value", val.c_str ());
}
ui_out_field_string (uiout, "in_scope", "true");
break;
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);
- xfree (type_name);
+ ui_out_field_string (uiout, "new_type", type_name.c_str ());
}
if (r->type_changed || r->children_changed)
unsigned int hash = msymbol_hash (name) % MINIMAL_SYMBOL_HASH_SIZE;
unsigned int dem_hash = msymbol_hash_iw (name) % MINIMAL_SYMBOL_HASH_SIZE;
- int needtofreename = 0;
- const char *modified_name;
+ const char *modified_name = name;
if (sfile != NULL)
sfile = lbasename (sfile);
/* For C++, canonicalize the input name. */
- modified_name = name;
+ std::string modified_name_storage;
if (current_language->la_language == language_cplus)
{
- char *cname = cp_canonicalize_string (name);
-
- if (cname)
+ std::string cname = cp_canonicalize_string (name);
+ if (!cname.empty ())
{
- modified_name = cname;
- needtofreename = 1;
+ std::swap (modified_name_storage, cname);
+ modified_name = modified_name_storage.c_str ();
}
}
}
}
- if (needtofreename)
- xfree ((void *) modified_name);
-
/* External symbols are best. */
if (found_symbol.minsym != NULL)
{
error (_("Invalid item from the child list"));
}
- vitem = XNEW (struct varobj_item);
+ vitem = new varobj_item ();
vitem->value = convert_value_from_python (py_v);
if (vitem->value == NULL)
gdbpy_print_stack ();
- vitem->name = xstrdup (name);
+ vitem->name = name;
self->next_raw_index++;
do_cleanups (back_to);
obstack_1grow (&work_obstack, '(');
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)
obstack_1grow (&work_obstack, ',');
- obstack_grow_str (&work_obstack, type_name);
-
- xfree (type_name);
+ obstack_grow_str (&work_obstack, type_name.c_str ());
}
obstack_grow_str0 (&work_obstack, ")");
obstack_1grow (&work_obstack, '<');
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)
obstack_1grow (&work_obstack, ',');
- obstack_grow_str (&work_obstack, type_name);
- xfree (type_name);
+ obstack_grow_str (&work_obstack, type_name.c_str ());
}
obstack_grow_str0 (&work_obstack, ">");
int deftype;
int synonym = 0;
int i;
- char *new_name = NULL;
/* 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
else
{
normal:
+ std::string new_name;
+
if (SYMBOL_LANGUAGE (sym) == language_cplus)
{
char *name = (char *) alloca (p - string + 1);
name[p - string] = '\0';
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);
- xfree (new_name);
+ SYMBOL_SET_NAMES (sym,
+ new_name.c_str (), new_name.length (),
+ 1, objfile);
}
else
SYMBOL_SET_NAMES (sym, string, p - string, 1, objfile);
type_name = NULL;
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);
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
= (char *) obstack_copy0 (&objfile->objfile_obstack,
- new_name, strlen (new_name));
- xfree (new_name);
+ new_name.c_str (),
+ new_name.length ());
}
}
if (type_name == NULL)
}
/* Compute the demangled form of NAME as used by the various symbol
- lookup functions. The result is stored in *RESULT_NAME. Returns a
- cleanup which can be used to clean up the result.
+ lookup functions. The result can either be the input NAME
+ 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
rather than the demangled name, and so it might seem to make sense
for this function to return an encoded version of NAME.
characters to become lowercase, and thus cause the symbol lookup
to fail. */
-struct cleanup *
+const char *
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
lookup, so we can always binary search. */
if (lang == language_cplus)
{
- demangled_name = gdb_demangle (name, DMGL_ANSI | DMGL_PARAMS);
- if (demangled_name)
- {
- modified_name = demangled_name;
- make_cleanup (xfree, demangled_name);
- }
- else
- {
- /* If we were given a non-mangled name, canonicalize it
- according to the language (so far only for C++). */
- demangled_name = cp_canonicalize_string (name);
- if (demangled_name)
- {
- modified_name = demangled_name;
- make_cleanup (xfree, demangled_name);
- }
- }
+ char *demangled_name = gdb_demangle (name, DMGL_ANSI | DMGL_PARAMS);
+ if (demangled_name != NULL)
+ return storage.set_malloc_ptr (demangled_name);
+
+ /* If we were given a non-mangled name, canonicalize it
+ according to the language (so far only for C++). */
+ std::string canon = cp_canonicalize_string (name);
+ if (!canon.empty ())
+ return storage.swap_string (canon);
}
else if (lang == language_d)
{
- demangled_name = d_demangle (name, 0);
- if (demangled_name)
- {
- modified_name = demangled_name;
- make_cleanup (xfree, demangled_name);
- }
+ char *demangled_name = d_demangle (name, 0);
+ if (demangled_name != NULL)
+ return storage.set_malloc_ptr (demangled_name);
}
else if (lang == language_go)
{
- demangled_name = go_demangle (name, 0);
- if (demangled_name)
- {
- modified_name = demangled_name;
- make_cleanup (xfree, demangled_name);
- }
+ char *demangled_name = go_demangle (name, 0);
+ if (demangled_name != NULL)
+ return storage.set_malloc_ptr (demangled_name);
}
- *result_name = modified_name;
- return cleanup;
+ return name;
}
/* See symtab.h.
const domain_enum domain, enum language lang,
struct field_of_this_result *is_a_field_of_this)
{
- const char *modified_name;
- struct block_symbol returnval;
- struct cleanup *cleanup = demangle_for_lookup (name, lang, &modified_name);
+ demangle_result_storage storage;
+ const char *modified_name = demangle_for_lookup (name, lang, storage);
- returnval = lookup_symbol_aux (modified_name, block, domain, lang,
- is_a_field_of_this);
- do_cleanups (cleanup);
-
- return returnval;
+ return lookup_symbol_aux (modified_name, block, domain, lang,
+ is_a_field_of_this);
}
/* See symtab.h. */
domain_enum domain)
{
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;
+ demangle_result_storage storage;
+ const char *modified_name = demangle_for_lookup (linkage_name, lang, storage);
+
if (objfile->separate_debug_objfile_backlink)
main_objfile = objfile->separate_debug_objfile_backlink;
else
result = lookup_symbol_in_objfile_symtabs (cur_objfile, STATIC_BLOCK,
modified_name, domain);
if (result.symbol != NULL)
- {
- do_cleanups (cleanup);
- return result;
- }
+ return result;
}
- do_cleanups (cleanup);
return (struct block_symbol) {NULL, NULL};
}
symbol_found_callback_ftype *callback,
void *data);
-struct cleanup *demangle_for_lookup (const char *name, enum language lang,
- const char **result_name);
+/* Storage type used by demangle_for_lookup. demangle_for_lookup
+ 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 *);
/* Print TYPE to a string, returning it. The caller is responsible for
freeing the string. */
-char *
+std::string
type_to_string (struct type *type)
{
- char *s = NULL;
+ std::string s;
struct ui_file *stb;
struct cleanup *old_chain;
TRY
{
type_print (type, "", stb, -1);
- s = ui_file_xstrdup (stb, NULL);
+ s = ui_file_as_string (stb);
}
CATCH (except, RETURN_MASK_ALL)
{
- s = NULL;
}
END_CATCH
extern void type_print (struct type *type, const char *varstring,
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,
gdb_byte *valaddr,
typedef struct varobj_item
{
/* Name of this item. */
- char *name;
+ std::string name;
/* Value of this item. */
struct value *value;
if ((ITER) != NULL) \
{ \
(ITER)->ops->dtor (ITER); \
- xfree (ITER); \
+ delete (ITER); \
} \
} while (0)
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 *
create_child_with_value (struct varobj *parent, int index,
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_child (const struct varobj *parent, int index);
-static char *my_value_of_variable (struct varobj *var,
- enum varobj_display_formats format);
+static std::string my_value_of_variable (struct varobj *var,
+ enum varobj_display_formats format);
static int is_root_p (const struct varobj *var);
/* Creates a varobj (not its children). */
struct varobj *
-varobj_create (char *objname,
- char *expression, CORE_ADDR frame, enum varobj_type type)
+varobj_create (const char *objname,
+ const char *expression, CORE_ADDR frame, enum varobj_type type)
{
struct varobj *var;
struct cleanup *old_chain;
var->format = variable_default_display (var);
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. */
- var->path_expr = xstrdup (expression);
+ var->path_expr = expression;
/* When the frame is different from the current frame,
we must select the appropriate frame before parsing
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
we must cleanup. */
error if OBJNAME cannot be found. */
struct varobj *
-varobj_get_handle (char *objname)
+varobj_get_handle (const char *objname)
{
struct vlist *cv;
const char *chp;
}
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;
if (cv == NULL)
/* Given the handle, return the name of the object. */
-char *
+const char *
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
- result must be freed by the caller. */
+/* Given the handle, return the expression represented by the
+ object. */
-char *
+std::string
varobj_get_expression (const struct varobj *var)
{
return name_of_variable (var);
if (varobj_value_is_changeable_p (var)
&& var->value && !value_lazy (var->value))
{
- xfree (var->print_value);
var->print_value = varobj_value_get_print_value (var->value,
var->format, var);
}
VEC (varobj_p)*
varobj_list_children (struct varobj *var, int *from, int *to)
{
- char *name;
int i, children_changed;
var->dynamic->children_requested = 1;
/* Either it's the first call to varobj_list_children for
this variable object, and the child was never created,
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);
VEC_replace (varobj_p, var->children, i, existing);
}
prints on the console. The caller is responsible for freeing the string.
*/
-char *
+std::string
varobj_get_type (struct varobj *var)
{
/* For the "fake" variables, do not return a type. (Its type is
NULL, too.)
Do not return a type for invalid variables as well. */
if (CPLUS_FAKE_CHILD (var) || !var->root->is_valid)
- return NULL;
+ return std::string ();
return type_to_string (var->type);
}
/* Return a pointer to the full rooted expression of varobj VAR.
If it has not been computed yet, compute it. */
-char *
+
+const char *
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
when creating varobj, so here it should be
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 *
return var->dynamic->pretty_printer != NULL;
}
-char *
+std::string
varobj_get_formatted_value (struct varobj *var,
enum varobj_display_formats format)
{
return my_value_of_variable (var, format);
}
-char *
+std::string
varobj_get_value (struct varobj *var)
{
return my_value_of_variable (var, var->format);
/* Note: Invokes functions that can call error(). */
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. */
/* The argument "expression" contains the variable's new value.
get_user_print_options (&opts);
if (opts.objectprint)
{
- struct type *new_type;
- char *curr_type_str, *new_type_str;
- int type_name_changed;
+ struct type *new_type = value_actual_type (new_value, 0, 0);
+ std::string new_type_str = type_to_string (new_type);
+ std::string curr_type_str = varobj_get_type (var);
- new_type = value_actual_type (new_value, 0, 0);
- new_type_str = type_to_string (new_type);
- 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)
+ /* Did the type name change? */
+ if (curr_type_str != new_type_str)
{
var->type = new_type;
int need_to_fetch;
int changed = 0;
int intentionally_not_fetched = 0;
- char *print_value = NULL;
/* We need to know the varobj's type to decide if the value should
be fetched or not. C++ fake children (public/protected/private)
values. Don't get string rendering if the value is
lazy -- if it is, the code above has decided that the value
should not be fetched. */
+ std::string print_value;
if (value != NULL && !value_lazy (value)
&& var->dynamic->pretty_printer == NULL)
print_value = varobj_value_get_print_value (value, var->format, var);
gdb_assert (!value_lazy (var->value));
gdb_assert (!value_lazy (value));
- gdb_assert (var->print_value != NULL && print_value != NULL);
- if (strcmp (var->print_value, print_value) != 0)
+ gdb_assert (!var->print_value.empty () && !print_value.empty ());
+ if (var->print_value != print_value)
changed = 1;
}
}
to see if the variable changed. */
if (var->dynamic->pretty_printer != NULL)
{
- xfree (print_value);
print_value = varobj_value_get_print_value (var->value, var->format,
var);
- if ((var->print_value == NULL && print_value != NULL)
- || (var->print_value != NULL && print_value == NULL)
- || (var->print_value != NULL && print_value != NULL
- && strcmp (var->print_value, print_value) != 0))
- changed = 1;
+ if ((var->print_value.empty () && !print_value.empty ())
+ || (!var->print_value.empty () && print_value.empty ())
+ || (!var->print_value.empty () && !print_value.empty ()
+ && var->print_value != print_value))
+ changed = 1;
}
- if (var->print_value)
- xfree (var->print_value);
var->print_value = print_value;
gdb_assert (!var->value || value_type (var->value));
return;
/* 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... */
- if (var->obj_name != NULL)
+ if (!var->obj_name.empty ())
{
*delcountp = *delcountp + 1;
}
VEC_replace (varobj_p, var->parent->children, var->index, NULL);
}
- if (var->obj_name != NULL)
+ if (!var->obj_name.empty ())
uninstall_variable (var);
/* Free memory associated with this variable. */
unsigned int index = 0;
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;
}
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;
if (cv != NULL)
unsigned int i = 1;
/* 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;
}
cv = *(varobj_table + index);
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;
cv = cv->next;
}
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)
{
warning
("Assertion failed: Could not find variable object \"%s\" to delete",
- var->obj_name);
+ var->obj_name.c_str ());
return;
}
{
warning (_("Assertion failed: Could not find "
"varobj \"%s\" in root list"),
- var->obj_name);
+ var->obj_name.c_str ());
return;
}
if (prer == NULL)
The created VAROBJ takes ownership of the allocated NAME. */
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;
- item.name = name;
+ std::swap (item.name, name);
item.value = value_of_child (parent, index);
return create_child_with_value (parent, index, &item);
struct varobj_item *item)
{
struct varobj *child;
- char *childs_name;
child = new_variable ();
/* NAME is allocated by caller. */
- child->name = item->name;
+ std::swap (child->name, item->name);
child->index = index;
child->parent = parent;
child->root = parent->root;
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
- childs_name = xstrprintf ("%s.%s", parent->obj_name, item->name);
- child->obj_name = childs_name;
+ child->obj_name = string_printf ("%s.%s",
+ parent->obj_name.c_str (),
+ child->name.c_str ());
install_variable (child);
{
struct varobj *var;
- var = XNEW (struct varobj);
- var->name = NULL;
- var->path_expr = NULL;
- var->obj_name = NULL;
+ var = new varobj ();
var->index = -1;
var->type = NULL;
var->value = NULL;
var->format = FORMAT_NATURAL;
var->root = NULL;
var->updated = 0;
- var->print_value = NULL;
var->frozen = 0;
var->not_fetched = 0;
var->dynamic = XNEW (struct varobj_dynamic);
if (is_root_p (var))
delete var->root;
- xfree (var->name);
- xfree (var->obj_name);
- xfree (var->print_value);
- xfree (var->path_expr);
xfree (var->dynamic);
- xfree (var);
+ delete var;
}
static void
return (*var->root->lang_ops->number_of_children) (var);
}
-/* What is the expression for the root varobj VAR? Returns a malloc'd
- string. */
-static char *
+/* What is the expression for the root varobj VAR? */
+
+static std::string
name_of_variable (const struct varobj *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
- string. */
-static char *
+/* What is the name of the INDEX'th child of VAR? */
+
+static std::string
name_of_child (struct varobj *var, int index)
{
return (*var->root->lang_ops->name_of_child) (var, index);
if (var->root->floating)
{
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);
if (tmp_var == NULL)
{
return NULL;
}
- old_type = varobj_get_type (var);
- new_type = varobj_get_type (tmp_var);
- if (strcmp (old_type, new_type) == 0)
+ std::string old_type = varobj_get_type (var);
+ std::string new_type = varobj_get_type (tmp_var);
+ if (old_type == new_type)
{
/* The expression presently stored inside var->root->exp
remembers the locations of local variables relatively to
}
else
{
- tmp_var->obj_name = xstrdup (var->obj_name);
+ tmp_var->obj_name = var->obj_name;
tmp_var->from = var->from;
tmp_var->to = var->to;
varobj_delete (var, 0);
var = *var_handle;
*type_changed = 1;
}
- xfree (old_type);
- xfree (new_type);
}
else
{
}
/* 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)
{
if (var->root->is_valid)
return (*var->root->lang_ops->value_of_variable) (var, format);
}
else
- return NULL;
+ return std::string ();
}
void
opts->raw = 1;
}
-char *
+std::string
varobj_value_get_print_value (struct value *value,
enum varobj_display_formats format,
const struct varobj *var)
{
struct ui_file *stb;
struct cleanup *old_chain;
- char *thevalue = NULL;
struct value_print_options opts;
struct type *type = NULL;
long len = 0;
int string_print = 0;
if (value == NULL)
- return NULL;
+ return std::string ();
stb = mem_fileopen ();
old_chain = make_cleanup_ui_file_delete (stb);
+ std::string thevalue;
+
#if HAVE_PYTHON
if (gdb_python_initialized)
{
xfree (hint);
}
- len = strlen (s);
- thevalue = (char *) xmemdup (s, len + 1, len + 1);
+ thevalue = std::string (s);
+ len = thevalue.size ();
gdbarch = get_type_arch (value_type (value));
type = builtin_type (gdbarch)->builtin_char;
xfree (s);
do_cleanups (old_chain);
return thevalue;
}
-
- make_cleanup (xfree, thevalue);
}
else
gdbpy_print_stack ();
varobj_formatted_print_options (&opts, format);
/* If the THEVALUE has contents, it is a regular string. */
- if (thevalue)
- LA_PRINT_STRING (stb, type, (gdb_byte *) thevalue, len, encoding, 0, &opts);
+ if (!thevalue.empty ())
+ LA_PRINT_STRING (stb, type, (gdb_byte *) thevalue.c_str (),
+ len, encoding, 0, &opts);
else if (string_print)
/* Otherwise, if string_print is set, and it is not a regular
string, it is a lazy string. */
/* All other cases. */
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);
return thevalue;
/* Try to create a varobj with same expression. If we succeed
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);
if (tmp_var != NULL)
{
- tmp_var->obj_name = xstrdup (var->obj_name);
+ tmp_var->obj_name = var->obj_name;
varobj_delete (var, 0);
install_variable (tmp_var);
}
/* Every variable in the system has a structure of this type defined
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
{
- /* 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.
(bar, not foo.bar). */
/* NOTE: This is the "expression". */
- char *name;
+ std::string name;
- /* Alloc'd expression for this child. Can be used to create a
- root variable corresponding to this child. */
- char *path_expr;
+ /* Expression for this child. Can be used to create a root variable
+ corresponding to this child. */
+ 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. */
- char *obj_name;
+ std::string obj_name;
/* Index of this variable in its parent or -1. */
int index;
int updated;
/* Last print value. */
- char *print_value;
+ std::string print_value;
/* Is this variable frozen. Frozen variables are never implicitly
updated by -var-update *
/* The number of children of PARENT. */
int (*number_of_children) (const struct varobj *parent);
- /* The name (expression) of a root varobj. The returned value must be freed
- by the caller. */
- char *(*name_of_variable) (const struct varobj *parent);
+ /* The name (expression) of a root varobj. */
+ std::string (*name_of_variable) (const struct varobj *parent);
- /* The name of the INDEX'th child of PARENT. The returned value must be
- freed by the caller. */
- char *(*name_of_child) (const struct varobj *parent, int index);
+ /* The name of the INDEX'th child of PARENT. */
+ std::string (*name_of_child) (const struct varobj *parent, int index);
/* Returns the rooted expression of CHILD, which is a variable
- obtain that has some parent. The returned value must be freed by the
- caller. */
- char *(*path_expr_of_child) (const struct varobj *child);
+ obtain that has some parent. */
+ std::string (*path_expr_of_child) (const struct varobj *child);
/* The ``struct value *'' of the INDEX'th child of PARENT. */
struct value *(*value_of_child) (const struct varobj *parent, int index);
/* The type of the INDEX'th child of PARENT. */
struct type *(*type_of_child) (const struct varobj *parent, int index);
- /* The current value of VAR. The returned value must be freed by the
- caller. */
- char *(*value_of_variable) (const struct varobj *var,
- enum varobj_display_formats format);
+ /* The current value of VAR. */
+ std::string (*value_of_variable) (const struct varobj *var,
+ enum varobj_display_formats format);
/* Return non-zero if changes in value of VAR must be detected and
reported by -var-update. Return zero if -var-update should never
#define default_varobj_ops c_varobj_ops
/* API functions */
-extern struct varobj *varobj_create (char *objname,
- char *expression, CORE_ADDR frame,
+extern struct varobj *varobj_create (const char *objname,
+ const char *expression, CORE_ADDR frame,
enum varobj_type type);
extern char *varobj_gen_name (void);
-extern 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
only the children. Return the number of deleted variables. */
extern VEC (varobj_p)* varobj_list_children (struct varobj *var,
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 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 *
varobj_get_language (const struct varobj *var);
extern int varobj_get_attributes (const struct varobj *var);
-extern char *varobj_get_formatted_value (struct varobj *var,
- enum varobj_display_formats format);
+extern std::string
+ varobj_get_formatted_value (struct varobj *var,
+ 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),
void *data);
extern const struct varobj *
varobj_get_path_expr_parent (const struct varobj *var);
-extern char *varobj_value_get_print_value (struct value *value,
- enum varobj_display_formats format,
- const struct varobj *var);
+extern std::string
+ varobj_value_get_print_value (struct value *value,
+ enum varobj_display_formats format,
+ const struct varobj *var);
extern void varobj_formatted_print_options (struct value_print_options *opts,
enum varobj_display_formats format);