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
- the Free Software Foundation; either version 2 of the License, or
+ the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor,
- Boston, MA 02110-1301, USA. */
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include "defs.h"
#include "exceptions.h"
/* NOTE: This is the "expression" */
char *name;
+ /* Alloc'd expression for this child. Can be used to create a
+ root variable corresponding to this child. */
+ char *path_expr;
+
/* The alloc'd name for this variable's object. This is here for
convenience when constructing this object's children. */
char *obj_name;
/* Index of this variable in its parent or -1 */
int index;
- /* The type of this variable. This may NEVER be NULL. */
+ /* The type of this variable. This can be NULL
+ for artifial variable objects -- currently, the "accessibility"
+ variable objects in C++. */
struct type *type;
/* The value of this expression or subexpression. A NULL value
/* Last print value. */
char *print_value;
+
+ /* Is this variable frozen. Frozen variables are never implicitly
+ updated by -var-update *
+ or -var-update <direct-or-indirect-parent>. */
+ int frozen;
+
+ /* Is the value of this variable intentionally not fetched? It is
+ not fetched if either the variable is frozen, or any parents is
+ frozen. */
+ int not_fetched;
};
struct cpstack
static char *c_name_of_child (struct varobj *parent, int index);
+static char *c_path_expr_of_child (struct varobj *child);
+
static struct value *c_value_of_root (struct varobj **var_handle);
static struct value *c_value_of_child (struct varobj *parent, int index);
static char *cplus_name_of_child (struct varobj *parent, int index);
+static char *cplus_path_expr_of_child (struct varobj *child);
+
static struct value *cplus_value_of_root (struct varobj **var_handle);
static struct value *cplus_value_of_child (struct varobj *parent, int index);
static char *java_name_of_child (struct varobj *parent, int index);
+static char *java_path_expr_of_child (struct varobj *child);
+
static struct value *java_value_of_root (struct varobj **var_handle);
static struct value *java_value_of_child (struct varobj *parent, int index);
/* The name of the INDEX'th child of PARENT. */
char *(*name_of_child) (struct varobj * parent, int index);
+ /* Returns the rooted expression of CHILD, which is a variable
+ obtain that has some parent. */
+ char *(*path_expr_of_child) (struct varobj * child);
+
/* The ``struct value *'' of the root variable ROOT. */
struct value *(*value_of_root) (struct varobj ** root_handle);
c_number_of_children,
c_name_of_variable,
c_name_of_child,
+ c_path_expr_of_child,
c_value_of_root,
c_value_of_child,
c_type_of_child,
c_number_of_children,
c_name_of_variable,
c_name_of_child,
+ c_path_expr_of_child,
c_value_of_root,
c_value_of_child,
c_type_of_child,
cplus_number_of_children,
cplus_name_of_variable,
cplus_name_of_child,
+ cplus_path_expr_of_child,
cplus_value_of_root,
cplus_value_of_child,
cplus_type_of_child,
java_number_of_children,
java_name_of_variable,
java_name_of_child,
+ java_path_expr_of_child,
java_value_of_root,
java_value_of_child,
java_type_of_child,
char *p;
enum varobj_languages lang;
struct value *value = NULL;
+ int expr_len;
/* Parse and evaluate the expression, filling in as much
of the variable's data as possible */
var->format = variable_default_display (var);
var->root->valid_block = innermost_block;
- var->name = savestring (expression, strlen (expression));
+ expr_len = strlen (expression);
+ var->name = savestring (expression, expr_len);
+ /* For a root var, the name and the expr are the same. */
+ var->path_expr = savestring (expression, expr_len);
/* When the frame is different from the current frame,
we must select the appropriate frame before parsing
return var->format;
}
+void
+varobj_set_frozen (struct varobj *var, int frozen)
+{
+ /* When a variable is unfrozen, we don't fetch its value.
+ The 'not_fetched' flag remains set, so next -var-update
+ won't complain.
+
+ We don't fetch the value, because for structures the client
+ should do -var-update anyway. It would be bad to have different
+ client-size logic for structure and other types. */
+ var->frozen = frozen;
+}
+
+int
+varobj_get_frozen (struct varobj *var)
+{
+ return var->frozen;
+}
+
+
int
varobj_get_num_children (struct varobj *var)
{
return var->type;
}
+/* 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)
+{
+ if (var->path_expr != NULL)
+ return var->path_expr;
+ else
+ {
+ /* For root varobjs, we initialize path_expr
+ when creating varobj, so here it should be
+ child varobj. */
+ gdb_assert (!is_root_p (var));
+ return (*var->root->lang->path_expr_of_child) (var);
+ }
+}
+
enum varobj_languages
varobj_get_language (struct varobj *var)
{
int changeable;
int need_to_fetch;
int changed = 0;
+ int intentionally_not_fetched = 0;
/* We need to know the varobj's type to decide if the value should
be fetched or not. C++ fake children (public/protected/private) don't have
will be lazy, which means we've lost that old value. */
if (need_to_fetch && value && value_lazy (value))
{
- if (!gdb_value_fetch_lazy (value))
+ struct varobj *parent = var->parent;
+ int frozen = var->frozen;
+ for (; !frozen && parent; parent = parent->parent)
+ frozen |= parent->frozen;
+
+ if (frozen && initial)
+ {
+ /* For variables that are frozen, or are children of frozen
+ variables, we don't do fetch on initial assignment.
+ For non-initial assignemnt we do the fetch, since it means we're
+ explicitly asked to compare the new value with the old one. */
+ intentionally_not_fetched = 1;
+ }
+ else if (!gdb_value_fetch_lazy (value))
{
/* Set the value to NULL, so that for the next -var-update,
we don't try to compare the new value with this value,
{
/* Try to compare the values. That requires that both
values are non-lazy. */
-
- /* Quick comparison of NULL values. */
- if (var->value == NULL && value == NULL)
+ if (var->not_fetched && value_lazy (var->value))
+ {
+ /* This is a frozen varobj and the value was never read.
+ Presumably, UI shows some "never read" indicator.
+ Now that we've fetched the real value, we need to report
+ this varobj as changed so that UI can show the real
+ value. */
+ changed = 1;
+ }
+ else if (var->value == NULL && value == NULL)
/* Equal. */
;
else if (var->value == NULL || value == NULL)
}
/* We must always keep the new value, since children depend on it. */
- if (var->value != NULL)
+ if (var->value != NULL && var->value != value)
value_free (var->value);
var->value = value;
+ if (value && value_lazy (value) && intentionally_not_fetched)
+ var->not_fetched = 1;
+ else
+ var->not_fetched = 0;
var->updated = 0;
gdb_assert (!var->value || value_type (var->value));
< 0 for error values, see varobj.h.
Otherwise it is the number of children + parent changed.
- Only root variables can be updated...
+ The EXPLICIT parameter specifies if this call is result
+ of MI request to update this specific variable, or
+ result of implicit -var-update *. For implicit request, we don't
+ update frozen variables.
NOTE: This function may delete the caller's varobj. If it
returns TYPE_CHANGED, then it has done this and VARP will be modified
to point to the new varobj. */
int
-varobj_update (struct varobj **varp, struct varobj ***changelist)
+varobj_update (struct varobj **varp, struct varobj ***changelist,
+ int explicit)
{
int changed = 0;
- int type_changed;
+ int type_changed = 0;
int i;
int vleft;
struct varobj *v;
/* sanity check: have we been passed a pointer? */
gdb_assert (changelist);
- if (!is_root_p (*varp))
- error (_("Only root variables can be updated"));
+ /* Frozen means frozen -- we don't check for any change in
+ this varobj, including its going out of scope, or
+ changing type. One use case for frozen varobjs is
+ retaining previously evaluated expressions, and we don't
+ want them to be reevaluated at all. */
+ if (!explicit && (*varp)->frozen)
+ return 0;
if (!(*varp)->root->is_valid)
return INVALID;
- /* Save the selected stack frame, since we will need to change it
- in order to evaluate expressions. */
- old_fid = get_frame_id (deprecated_safe_get_selected_frame ());
-
- /* Update the root variable. value_of_root can return NULL
- if the variable is no longer around, i.e. we stepped out of
- the frame in which a local existed. We are letting the
- value_of_root variable dispose of the varobj if the type
- has changed. */
- type_changed = 1;
- new = value_of_root (varp, &type_changed);
-
- /* Restore selected frame. */
- fi = frame_find_by_id (old_fid);
- if (fi)
- select_frame (fi);
-
- /* If this is a "use_selected_frame" varobj, and its type has changed,
- them note that it's changed. */
- if (type_changed)
- VEC_safe_push (varobj_p, result, *varp);
-
- if (install_new_value ((*varp), new, type_changed))
+ if ((*varp)->root->rootvar == *varp)
{
- /* If type_changed is 1, install_new_value will never return
- non-zero, so we'll never report the same variable twice. */
- gdb_assert (!type_changed);
- VEC_safe_push (varobj_p, result, *varp);
- }
+ /* Save the selected stack frame, since we will need to change it
+ in order to evaluate expressions. */
+ old_fid = get_frame_id (deprecated_safe_get_selected_frame ());
+
+ /* Update the root variable. value_of_root can return NULL
+ if the variable is no longer around, i.e. we stepped out of
+ the frame in which a local existed. We are letting the
+ value_of_root variable dispose of the varobj if the type
+ has changed. */
+ type_changed = 1;
+ new = value_of_root (varp, &type_changed);
+
+ /* Restore selected frame. */
+ fi = frame_find_by_id (old_fid);
+ if (fi)
+ select_frame (fi);
+
+ /* If this is a "use_selected_frame" varobj, and its type has changed,
+ them note that it's changed. */
+ if (type_changed)
+ VEC_safe_push (varobj_p, result, *varp);
+
+ if (install_new_value ((*varp), new, type_changed))
+ {
+ /* If type_changed is 1, install_new_value will never return
+ non-zero, so we'll never report the same variable twice. */
+ gdb_assert (!type_changed);
+ VEC_safe_push (varobj_p, result, *varp);
+ }
- if (new == NULL)
- {
- /* This means the varobj itself is out of scope.
- Report it. */
- VEC_free (varobj_p, result);
- return NOT_IN_SCOPE;
+ if (new == NULL)
+ {
+ /* This means the varobj itself is out of scope.
+ Report it. */
+ VEC_free (varobj_p, result);
+ return NOT_IN_SCOPE;
+ }
}
VEC_safe_push (varobj_p, stack, *varp);
{
varobj_p c = VEC_index (varobj_p, v->children, i);
/* Child may be NULL if explicitly deleted by -var-delete. */
- if (c != NULL)
+ if (c != NULL && !c->frozen)
VEC_safe_push (varobj_p, stack, c);
}
/* Update this variable, unless it's a root, which is already
updated. */
- if (v != *varp)
+ if (v->root->rootvar != v)
{
new = value_of_child (v->parent, v->index);
if (install_new_value (v, new, 0 /* type not changed */))
var = (struct varobj *) xmalloc (sizeof (struct varobj));
var->name = NULL;
+ var->path_expr = NULL;
var->obj_name = NULL;
var->index = -1;
var->type = NULL;
var->root = NULL;
var->updated = 0;
var->print_value = NULL;
+ var->frozen = 0;
+ var->not_fetched = 0;
return var;
}
xfree (var->name);
xfree (var->obj_name);
xfree (var->print_value);
+ xfree (var->path_expr);
xfree (var);
}
{
struct varobj *tmp_var;
char *old_type, *new_type;
- old_type = varobj_get_type (var);
+
tmp_var = varobj_create (NULL, var->name, (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)
{
var = *var_handle;
*type_changed = 1;
}
+ xfree (old_type);
+ xfree (new_type);
}
else
{
Both TYPE and *TYPE should be non-null. VALUE
can be null if we want to only translate type.
*VALUE can be null as well -- if the parent
- value is not known. */
+ value is not known.
+
+ If WAS_PTR is not NULL, set *WAS_PTR to 0 or 1
+ depending on whether pointer was deferenced
+ in this function. */
static void
adjust_value_for_child_access (struct value **value,
- struct type **type)
+ struct type **type,
+ int *was_ptr)
{
gdb_assert (type && *type);
+ if (was_ptr)
+ *was_ptr = 0;
+
*type = check_typedef (*type);
/* The type of value stored in varobj, that is passed
if (value && *value)
gdb_value_ind (*value, value);
*type = target_type;
+ if (was_ptr)
+ *was_ptr = 1;
}
}
int children = 0;
struct type *target;
- adjust_value_for_child_access (NULL, &type);
+ adjust_value_for_child_access (NULL, &type, NULL);
target = get_target_type (type);
switch (TYPE_CODE (type))
to NULL. */
static void
c_describe_child (struct varobj *parent, int index,
- char **cname, struct value **cvalue, struct type **ctype)
+ char **cname, struct value **cvalue, struct type **ctype,
+ char **cfull_expression)
{
struct value *value = parent->value;
struct type *type = get_value_type (parent);
+ char *parent_expression = NULL;
+ int was_ptr;
if (cname)
*cname = NULL;
*cvalue = NULL;
if (ctype)
*ctype = NULL;
-
- adjust_value_for_child_access (&value, &type);
+ if (cfull_expression)
+ {
+ *cfull_expression = NULL;
+ parent_expression = varobj_get_path_expr (parent);
+ }
+ adjust_value_for_child_access (&value, &type, &was_ptr);
switch (TYPE_CODE (type))
{
if (ctype)
*ctype = get_target_type (type);
+ if (cfull_expression)
+ *cfull_expression = xstrprintf ("(%s)[%d]", parent_expression,
+ index
+ + TYPE_LOW_BOUND (TYPE_INDEX_TYPE (type)));
+
+
break;
case TYPE_CODE_STRUCT:
if (ctype)
*ctype = TYPE_FIELD_TYPE (type, index);
+ if (cfull_expression)
+ {
+ char *join = was_ptr ? "->" : ".";
+ *cfull_expression = xstrprintf ("(%s)%s%s", parent_expression, join,
+ TYPE_FIELD_NAME (type, index));
+ }
+
break;
case TYPE_CODE_PTR:
declared type of the variable. */
if (ctype)
*ctype = TYPE_TARGET_TYPE (type);
+
+ if (cfull_expression)
+ *cfull_expression = xstrprintf ("*(%s)", parent_expression);
break;
/* This should not happen */
if (cname)
*cname = xstrdup ("???");
+ if (cfull_expression)
+ *cfull_expression = xstrdup ("???");
/* Don't set value and type, we don't know then. */
}
}
c_name_of_child (struct varobj *parent, int index)
{
char *name;
- c_describe_child (parent, index, &name, NULL, NULL);
+ c_describe_child (parent, index, &name, NULL, NULL, NULL);
return name;
}
+static char *
+c_path_expr_of_child (struct varobj *child)
+{
+ c_describe_child (child->parent, child->index, NULL, NULL, NULL,
+ &child->path_expr);
+ return child->path_expr;
+}
+
static struct value *
c_value_of_root (struct varobj **var_handle)
{
c_value_of_child (struct varobj *parent, int index)
{
struct value *value = NULL;
- c_describe_child (parent, index, NULL, &value, NULL);
+ c_describe_child (parent, index, NULL, &value, NULL, NULL);
return value;
}
c_type_of_child (struct varobj *parent, int index)
{
struct type *type = NULL;
- c_describe_child (parent, index, NULL, NULL, &type);
+ c_describe_child (parent, index, NULL, NULL, &type, NULL);
return type;
}
}
else
{
+ if (var->not_fetched && value_lazy (var->value))
+ /* 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;
+
gdb_assert (varobj_value_is_changeable_p (var));
gdb_assert (!value_lazy (var->value));
return value_get_print_value (var->value, var->format);
if (!CPLUS_FAKE_CHILD (var))
{
type = get_value_type (var);
- adjust_value_for_child_access (NULL, &type);
+ adjust_value_for_child_access (NULL, &type, NULL);
if (((TYPE_CODE (type)) == TYPE_CODE_STRUCT) ||
((TYPE_CODE (type)) == TYPE_CODE_UNION))
int kids[3];
type = get_value_type (var->parent);
- adjust_value_for_child_access (NULL, &type);
+ adjust_value_for_child_access (NULL, &type, NULL);
cplus_class_num_children (type, kids);
if (strcmp (var->name, "public") == 0)
static void
cplus_describe_child (struct varobj *parent, int index,
- char **cname, struct value **cvalue, struct type **ctype)
+ char **cname, struct value **cvalue, struct type **ctype,
+ char **cfull_expression)
{
- char *name = 0;
+ char *name = NULL;
struct value *value;
struct type *type;
+ int was_ptr;
+ char *parent_expression = NULL;
if (cname)
*cname = NULL;
*cvalue = NULL;
if (ctype)
*ctype = NULL;
-
+ if (cfull_expression)
+ *cfull_expression = NULL;
if (CPLUS_FAKE_CHILD (parent))
{
value = parent->parent->value;
type = get_value_type (parent->parent);
+ if (cfull_expression)
+ parent_expression = varobj_get_path_expr (parent->parent);
}
else
{
value = parent->value;
type = get_value_type (parent);
+ if (cfull_expression)
+ parent_expression = varobj_get_path_expr (parent);
}
- adjust_value_for_child_access (&value, &type);
+ adjust_value_for_child_access (&value, &type, &was_ptr);
if (TYPE_CODE (type) == TYPE_CODE_STRUCT
|| TYPE_CODE (type) == TYPE_CODE_STRUCT)
{
+ char *join = was_ptr ? "->" : ".";
if (CPLUS_FAKE_CHILD (parent))
{
/* The fields of the class type are ordered as they
if (ctype)
*ctype = TYPE_FIELD_TYPE (type, type_index);
+
+ if (cfull_expression)
+ *cfull_expression = xstrprintf ("((%s)%s%s)", parent_expression,
+ join,
+ TYPE_FIELD_NAME (type, type_index));
}
else if (index < TYPE_N_BASECLASSES (type))
{
if (cvalue && value)
{
*cvalue = value_cast (TYPE_FIELD_TYPE (type, index), value);
+ release_value (*cvalue);
}
if (ctype)
{
*ctype = TYPE_FIELD_TYPE (type, index);
}
+
+ if (cfull_expression)
+ {
+ char *ptr = was_ptr ? "*" : "";
+ /* Cast the parent to the base' type. Note that in gdb,
+ expression like
+ (Base1)d
+ will create an lvalue, for all appearences, so we don't
+ need to use more fancy:
+ *(Base1*)(&d)
+ construct. */
+ *cfull_expression = xstrprintf ("(%s(%s%s) %s)",
+ ptr,
+ TYPE_FIELD_NAME (type, index),
+ ptr,
+ parent_expression);
+ }
}
else
{
- char *access = 0;
+ char *access = NULL;
int children[3];
cplus_class_num_children (type, children);
/* error! */
break;
}
-
+
+ gdb_assert (access);
if (cname)
*cname = xstrdup (access);
- /* Value and type are null here. */
+ /* Value and type and full expression are null here. */
}
}
else
{
- c_describe_child (parent, index, cname, cvalue, ctype);
+ c_describe_child (parent, index, cname, cvalue, ctype, cfull_expression);
}
}
cplus_name_of_child (struct varobj *parent, int index)
{
char *name = NULL;
- cplus_describe_child (parent, index, &name, NULL, NULL);
+ cplus_describe_child (parent, index, &name, NULL, NULL, NULL);
return name;
}
+static char *
+cplus_path_expr_of_child (struct varobj *child)
+{
+ cplus_describe_child (child->parent, child->index, NULL, NULL, NULL,
+ &child->path_expr);
+ return child->path_expr;
+}
+
static struct value *
cplus_value_of_root (struct varobj **var_handle)
{
cplus_value_of_child (struct varobj *parent, int index)
{
struct value *value = NULL;
- cplus_describe_child (parent, index, NULL, &value, NULL);
+ cplus_describe_child (parent, index, NULL, &value, NULL, NULL);
return value;
}
cplus_type_of_child (struct varobj *parent, int index)
{
struct type *type = NULL;
- cplus_describe_child (parent, index, NULL, NULL, &type);
+ cplus_describe_child (parent, index, NULL, NULL, &type, NULL);
return type;
}
return name;
}
+static char *
+java_path_expr_of_child (struct varobj *child)
+{
+ return NULL;
+}
+
static struct value *
java_value_of_root (struct varobj **var_handle)
{