/* Implementation of the GDB variable objects API.
- Copyright (C) 1999-2014 Free Software Foundation, Inc.
+ Copyright (C) 1999-2015 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include "defs.h"
-#include "exceptions.h"
#include "value.h"
#include "expression.h"
#include "frame.h"
#include "gdbcmd.h"
#include "block.h"
#include "valprint.h"
-
-#include "gdb_assert.h"
-#include <string.h>
#include "gdb_regex.h"
#include "varobj.h"
/* Language-specific routines. */
-static int number_of_children (struct varobj *);
+static int number_of_children (const struct varobj *);
-static char *name_of_variable (struct varobj *);
+static char *name_of_variable (const struct varobj *);
static char *name_of_child (struct varobj *, int);
static struct value *value_of_root (struct varobj **var_handle, int *);
-static struct value *value_of_child (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,
enum varobj_display_formats format);
-static int is_root_p (struct varobj *var);
+static int is_root_p (const struct varobj *var);
static struct varobj *varobj_add_child (struct varobj *var,
struct varobj_item *item);
/* API Implementation */
static int
-is_root_p (struct varobj *var)
+is_root_p (const struct varobj *var)
{
return (var->root->rootvar == var);
}
/* Helper function to install a Python environment suitable for
use during operations on VAR. */
struct cleanup *
-varobj_ensure_python_env (struct varobj *var)
+varobj_ensure_python_env (const struct varobj *var)
{
return ensure_python_env (var->root->exp->gdbarch,
var->root->exp->language_defn);
{
struct frame_info *fi;
struct frame_id old_id = null_frame_id;
- struct block *block;
+ const struct block *block;
const char *p;
struct value *value = NULL;
volatile struct gdb_exception except;
/* Given the handle, return the name of the object. */
char *
-varobj_get_objname (struct varobj *var)
+varobj_get_objname (const struct varobj *var)
{
return var->obj_name;
}
-/* Given the handle, return the expression represented by the object. */
+/* Given the handle, return the expression represented by the object. The
+ result must be freed by the caller. */
char *
-varobj_get_expression (struct varobj *var)
+varobj_get_expression (const struct varobj *var)
{
return name_of_variable (var);
}
/* Deletes a varobj and all its children if only_children == 0,
- otherwise deletes only the children; returns a malloc'ed list of
- all the (malloc'ed) names of the variables that have been deleted
- (NULL terminated). */
+ otherwise deletes only the children. If DELLIST is non-NULL, it is
+ assigned a malloc'ed list of all the (malloc'ed) names of the variables
+ that have been deleted (NULL terminated). Returns the number of deleted
+ variables. */
int
varobj_delete (struct varobj *var, char ***dellist, int only_children)
}
enum varobj_display_formats
-varobj_get_display_format (struct varobj *var)
+varobj_get_display_format (const struct varobj *var)
{
return var->format;
}
char *
-varobj_get_display_hint (struct varobj *var)
+varobj_get_display_hint (const struct varobj *var)
{
char *result = NULL;
/* Return true if the varobj has items after TO, false otherwise. */
int
-varobj_has_more (struct varobj *var, int to)
+varobj_has_more (const struct varobj *var, int to)
{
if (VEC_length (varobj_p, var->children) > to)
return 1;
inside that thread, returns GDB id of the thread -- which
is always positive. Otherwise, returns -1. */
int
-varobj_get_thread_id (struct varobj *var)
+varobj_get_thread_id (const struct varobj *var)
{
if (var->root->valid_block && var->root->thread_id > 0)
return var->root->thread_id;
}
int
-varobj_get_frozen (struct varobj *var)
+varobj_get_frozen (const struct varobj *var)
{
return var->frozen;
}
#if HAVE_PYTHON
static int
-dynamic_varobj_has_child_method (struct varobj *var)
+dynamic_varobj_has_child_method (const struct varobj *var)
{
struct cleanup *back_to;
PyObject *printer = var->dynamic->pretty_printer;
{
if (var->num_children == -1)
{
- if (var->dynamic->pretty_printer != NULL)
+ if (varobj_is_dynamic_p (var))
{
int dummy;
var->dynamic->children_requested = 1;
- if (var->dynamic->pretty_printer != NULL)
+ if (varobj_is_dynamic_p (var))
{
/* This, in theory, can result in the number of children changing without
frontend noticing. But well, calling -var-list-children on the same
}
/* Obtain the type of an object Variable as a string similar to the one gdb
- prints on the console. */
+ prints on the console. The caller is responsible for freeing the string.
+ */
char *
varobj_get_type (struct varobj *var)
/* Obtain the type of an object variable. */
struct type *
-varobj_get_gdb_type (struct varobj *var)
+varobj_get_gdb_type (const struct varobj *var)
{
return var->type;
}
a valid path expression? */
static int
-is_path_expr_parent (struct varobj *var)
+is_path_expr_parent (const struct varobj *var)
{
- struct type *type;
-
- /* "Fake" children are not path_expr parents. */
- if (CPLUS_FAKE_CHILD (var))
- return 0;
+ gdb_assert (var->root->lang_ops->is_path_expr_parent != NULL);
+ return var->root->lang_ops->is_path_expr_parent (var);
+}
- type = varobj_get_value_type (var);
+/* Is VAR a path expression parent, i.e., can it be used to construct
+ a valid path expression? By default we assume any VAR can be a path
+ parent. */
- /* Anonymous unions and structs are also not path_expr parents. */
- return !((TYPE_CODE (type) == TYPE_CODE_STRUCT
- || TYPE_CODE (type) == TYPE_CODE_UNION)
- && TYPE_NAME (type) == NULL);
+int
+varobj_default_is_path_expr_parent (const struct varobj *var)
+{
+ return 1;
}
/* Return the path expression parent for VAR. */
-struct varobj *
-varobj_get_path_expr_parent (struct varobj *var)
+const struct varobj *
+varobj_get_path_expr_parent (const struct varobj *var)
{
- struct varobj *parent = var;
+ const struct varobj *parent = var;
while (!is_root_p (parent) && !is_path_expr_parent (parent))
parent = parent->parent;
/* Return a pointer to the full rooted expression of varobj VAR.
If it has not been computed yet, compute it. */
char *
-varobj_get_path_expr (struct varobj *var)
+varobj_get_path_expr (const struct varobj *var)
{
- if (var->path_expr != NULL)
- return var->path_expr;
- else
+ if (var->path_expr == NULL)
{
/* For root varobjs, we initialize path_expr
when creating varobj, so here it should be
child varobj. */
+ struct varobj *mutable_var = (struct varobj *) var;
gdb_assert (!is_root_p (var));
- return (*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;
}
const struct language_defn *
-varobj_get_language (struct varobj *var)
+varobj_get_language (const struct varobj *var)
{
return var->root->exp->language_defn;
}
int
-varobj_get_attributes (struct varobj *var)
+varobj_get_attributes (const struct varobj *var)
{
int attributes = 0;
return attributes;
}
+/* Return true if VAR is a dynamic varobj. */
+
int
-varobj_pretty_printed_p (struct varobj *var)
+varobj_is_dynamic_p (const struct varobj *var)
{
return var->dynamic->pretty_printer != NULL;
}
{
struct type *new_type;
char *curr_type_str, *new_type_str;
+ int type_name_changed;
new_type = value_actual_type (new_value, 0, 0);
new_type_str = type_to_string (new_type);
curr_type_str = varobj_get_type (var);
- if (strcmp (curr_type_str, new_type_str) != 0)
+ 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;
will be lazy, which means we've lost that old value. */
if (need_to_fetch && value && value_lazy (value))
{
- struct varobj *parent = var->parent;
+ const struct varobj *parent = var->parent;
int frozen = var->frozen;
for (; !frozen && parent; parent = parent->parent)
selected sub-range of VAR. If no range was selected using
-var-set-update-range, then both will be -1. */
void
-varobj_get_child_range (struct varobj *var, int *from, int *to)
+varobj_get_child_range (const struct varobj *var, int *from, int *to)
{
*from = var->from;
*to = var->to;
NEW_VALUE may be NULL, if the varobj is now out of scope. */
static int
-varobj_value_has_mutated (struct varobj *var, struct value *new_value,
+varobj_value_has_mutated (const struct varobj *var, struct value *new_value,
struct type *new_type)
{
/* If we haven't previously computed the number of children in var,
}
}
- /* We probably should not get children of a varobj that has a
- pretty-printer, but for which -var-list-children was never
- invoked. */
- if (v->dynamic->pretty_printer != NULL)
+ /* We probably should not get children of a dynamic varobj, but
+ for which -var-list-children was never invoked. */
+ if (varobj_is_dynamic_p (v))
{
VEC (varobj_p) *changed = 0, *type_changed = 0, *unchanged = 0;
VEC (varobj_p) *new = 0;
}
-/* Create and install a child of the parent of the given name. */
+/* Create and install a child of the parent of the given name.
+
+ The created VAROBJ takes ownership of the allocated NAME. */
+
static struct varobj *
create_child (struct varobj *parent, int index, char *name)
{
For example, top-level references are always stripped. */
struct type *
-varobj_get_value_type (struct varobj *var)
+varobj_get_value_type (const struct varobj *var)
{
struct type *type;
is the number of children that the user will see in the variable
display. */
static int
-number_of_children (struct varobj *var)
+number_of_children (const struct varobj *var)
{
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 *
-name_of_variable (struct varobj *var)
+name_of_variable (const struct varobj *var)
{
return (*var->root->lang_ops->name_of_variable) (var);
}
to it and return 1. Otherwise, return 0. */
static int
-check_scope (struct varobj *var)
+check_scope (const struct varobj *var)
{
struct frame_info *fi;
int scope;
/* What is the ``struct value *'' for the INDEX'th child of PARENT? */
static struct value *
-value_of_child (struct varobj *parent, int index)
+value_of_child (const struct varobj *parent, int index)
{
struct value *value;
char *
varobj_value_get_print_value (struct value *value,
enum varobj_display_formats format,
- struct varobj *var)
+ const struct varobj *var)
{
struct ui_file *stb;
struct cleanup *old_chain;
}
int
-varobj_editable_p (struct varobj *var)
+varobj_editable_p (const struct varobj *var)
{
struct type *type;
/* Call VAR's value_is_changeable_p language-specific callback. */
int
-varobj_value_is_changeable_p (struct varobj *var)
+varobj_value_is_changeable_p (const struct varobj *var)
{
return var->root->lang_ops->value_is_changeable_p (var);
}
selected frame, and not bound to thread/frame. Such variable objects
are created using '@' as frame specifier to -var-create. */
int
-varobj_floating_p (struct varobj *var)
+varobj_floating_p (const struct varobj *var)
{
return var->root->floating;
}
languages. */
int
-varobj_default_value_is_changeable_p (struct varobj *var)
+varobj_default_value_is_changeable_p (const struct varobj *var)
{
int r;
struct type *type;
(*func) (var_root->rootvar, data);
}
}
-\f
-extern void _initialize_varobj (void);
-void
-_initialize_varobj (void)
-{
- int sizeof_table = sizeof (struct vlist *) * VAROBJ_TABLE_SIZE;
-
- varobj_table = xmalloc (sizeof_table);
- memset (varobj_table, 0, sizeof_table);
-
- add_setshow_zuinteger_cmd ("varobj", class_maintenance,
- &varobjdebug,
- _("Set varobj debugging."),
- _("Show varobj debugging."),
- _("When non-zero, varobj debugging is enabled."),
- NULL, show_varobjdebug,
- &setdebuglist, &showdebuglist);
-}
/* Invalidate varobj VAR if it is tied to locals and re-create it if it is
defined on globals. It is a helper for varobj_invalidate.
{
all_root_varobjs (varobj_invalidate_iter, NULL);
}
+\f
+extern void _initialize_varobj (void);
+void
+_initialize_varobj (void)
+{
+ int sizeof_table = sizeof (struct vlist *) * VAROBJ_TABLE_SIZE;
+
+ varobj_table = xmalloc (sizeof_table);
+ memset (varobj_table, 0, sizeof_table);
+
+ add_setshow_zuinteger_cmd ("varobj", class_maintenance,
+ &varobjdebug,
+ _("Set varobj debugging."),
+ _("Show varobj debugging."),
+ _("When non-zero, varobj debugging is enabled."),
+ NULL, show_varobjdebug,
+ &setdebuglist, &showdebuglist);
+}