/* Implementation of the GDB variable objects API.
- Copyright 1999, 2000, 2001 Free Software Foundation, Inc.
+
+ Copyright 1999, 2000, 2001, 2005 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
Boston, MA 02111-1307, USA. */
#include "defs.h"
+#include "exceptions.h"
#include "value.h"
#include "expression.h"
#include "frame.h"
#include "language.h"
#include "wrapper.h"
#include "gdbcmd.h"
-#include <math.h>
+
+#include "gdb_assert.h"
+#include "gdb_string.h"
#include "varobj.h"
/* Non-zero if we want to see trace of varobj level stuff. */
int varobjdebug = 0;
+static void
+show_varobjdebug (struct ui_file *file, int from_tty,
+ struct cmd_list_element *c, const char *value)
+{
+ fprintf_filtered (file, _("Varobj debugging is %s.\n"), value);
+}
/* String representations of gdb's format codes */
char *varobj_format_string[] =
struct block *valid_block;
/* The frame for this expression */
- CORE_ADDR frame;
+ struct frame_id frame;
/* If 1, "update" always recomputes the frame & valid block
using the currently selected frame. */
struct type *type;
/* The value of this expression or subexpression. This may be NULL. */
- value_ptr value;
+ struct value *value;
/* Did an error occur evaluating the expression or getting its value? */
int error;
/* The format of the output for this object */
enum varobj_display_formats format;
+
+ /* Was this variable updated via a varobj_set_value operation */
+ int updated;
};
/* Every variable keeps a linked list of its children, described
static enum varobj_display_formats variable_default_display (struct varobj *);
-static int my_value_equal (value_ptr, value_ptr, int *);
+static int my_value_equal (struct value *, struct value *, int *);
static void vpush (struct vstack **pstack, struct varobj *var);
static char *name_of_child (struct varobj *, int);
-static value_ptr value_of_root (struct varobj **var_handle, int *);
+static struct value *value_of_root (struct varobj **var_handle, int *);
-static value_ptr value_of_child (struct varobj *parent, int index);
+static struct value *value_of_child (struct varobj *parent, int index);
static struct type *type_of_child (struct varobj *var);
static char *c_name_of_child (struct varobj *parent, int index);
-static value_ptr c_value_of_root (struct varobj **var_handle);
+static struct value *c_value_of_root (struct varobj **var_handle);
-static value_ptr c_value_of_child (struct varobj *parent, int index);
+static struct value *c_value_of_child (struct varobj *parent, int index);
static struct type *c_type_of_child (struct varobj *parent, int index);
static char *cplus_name_of_child (struct varobj *parent, int index);
-static value_ptr cplus_value_of_root (struct varobj **var_handle);
+static struct value *cplus_value_of_root (struct varobj **var_handle);
-static value_ptr cplus_value_of_child (struct varobj *parent, int index);
+static struct value *cplus_value_of_child (struct varobj *parent, int index);
static struct type *cplus_type_of_child (struct varobj *parent, int index);
static char *java_name_of_child (struct varobj *parent, int index);
-static value_ptr java_value_of_root (struct varobj **var_handle);
+static struct value *java_value_of_root (struct varobj **var_handle);
-static value_ptr java_value_of_child (struct varobj *parent, int index);
+static struct value *java_value_of_child (struct varobj *parent, int index);
static struct type *java_type_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);
- /* The value_ptr of the root variable ROOT. */
- value_ptr (*value_of_root) (struct varobj ** root_handle);
+ /* The ``struct value *'' of the root variable ROOT. */
+ struct value *(*value_of_root) (struct varobj ** root_handle);
- /* The value_ptr of the INDEX'th child of PARENT. */
- value_ptr (*value_of_child) (struct varobj * parent, int index);
+ /* The ``struct value *'' of the INDEX'th child of PARENT. */
+ struct value *(*value_of_child) (struct varobj * parent, int index);
/* The type of the INDEX'th child of PARENT. */
struct type *(*type_of_child) (struct varobj * parent, int index);
/* Creates a varobj (not its children) */
+/* Return the full FRAME which corresponds to the given CORE_ADDR
+ or NULL if no FRAME on the chain corresponds to CORE_ADDR. */
+
+static struct frame_info *
+find_frame_addr_in_frame_chain (CORE_ADDR frame_addr)
+{
+ struct frame_info *frame = NULL;
+
+ if (frame_addr == (CORE_ADDR) 0)
+ return NULL;
+
+ while (1)
+ {
+ frame = get_prev_frame (frame);
+ if (frame == NULL)
+ return NULL;
+ if (get_frame_base_address (frame) == frame_addr)
+ return frame;
+ }
+}
+
struct varobj *
varobj_create (char *objname,
char *expression, CORE_ADDR frame, enum varobj_type type)
/* Allow creator to specify context of variable */
if ((type == USE_CURRENT_FRAME) || (type == USE_SELECTED_FRAME))
- fi = selected_frame;
+ fi = deprecated_selected_frame;
else
+ /* FIXME: cagney/2002-11-23: This code should be doing a
+ lookup using the frame ID and not just the frame's
+ ``address''. This, of course, means an interface change.
+ However, with out that interface change ISAs, such as the
+ ia64 with its two stacks, won't work. Similar goes for the
+ case where there is a frameless function. */
fi = find_frame_addr_in_frame_chain (frame);
/* frame = -2 means always use selected frame */
block = NULL;
if (fi != NULL)
- block = get_frame_block (fi);
+ block = get_frame_block (fi, 0);
p = expression;
innermost_block = NULL;
if (var->root->exp->elts[0].opcode == OP_TYPE)
{
do_cleanups (old_chain);
- fprintf_unfiltered (gdb_stderr,
- "Attempt to use a type name as an expression.");
+ fprintf_unfiltered (gdb_stderr, "Attempt to use a type name"
+ " as an expression.\n");
return NULL;
}
Since select_frame is so benign, just call it for all cases. */
if (fi != NULL)
{
- var->root->frame = FRAME_FP (fi);
- old_fi = selected_frame;
- select_frame (fi, -1);
+ var->root->frame = get_frame_id (fi);
+ old_fi = deprecated_selected_frame;
+ select_frame (fi);
}
/* We definitively need to catch errors here.
{
/* no error */
release_value (var->value);
- if (VALUE_LAZY (var->value))
+ if (value_lazy (var->value))
gdb_value_fetch_lazy (var->value);
}
else
var->value = evaluate_type (var->root->exp);
- var->type = VALUE_TYPE (var->value);
+ var->type = value_type (var->value);
/* Set language info */
lang = variable_language (var);
/* Reset the selected frame */
if (fi != NULL)
- select_frame (old_fi, -1);
+ select_frame (old_fi);
}
/* If the variable object name is null, that means this
varobj_gen_name (void)
{
static int id = 0;
- char obj_name[31];
+ char *obj_name;
/* generate a name for this object */
id++;
- sprintf (obj_name, "var%d", id);
+ obj_name = xstrprintf ("var%d", id);
- return xstrdup (obj_name);
+ return obj_name;
}
/* Given an "objname", returns the pointer to the corresponding varobj
cv = cv->next;
if (cv == NULL)
- error ("Variable object not found");
+ error (_("Variable object not found"));
return cv->var;
}
}
if (mycount || (*cp != NULL))
- warning ("varobj_delete: assertion failed - mycount(=%d) <> 0",
+ warning (_("varobj_delete: assertion failed - mycount(=%d) <> 0"),
mycount);
}
char *
varobj_get_type (struct varobj *var)
{
- value_ptr val;
+ struct value *val;
struct cleanup *old_chain;
struct ui_file *stb;
char *thetype;
stb = mem_fileopen ();
old_chain = make_cleanup_ui_file_delete (stb);
- /* To print the type, we simply create a zero value_ptr and
+ /* To print the type, we simply create a zero ``struct value *'' and
cast it to our type. We then typeprint this variable. */
val = value_zero (var->type, not_lval);
- type_print (VALUE_TYPE (val), "", stb, -1);
+ type_print (value_type (val), "", stb, -1);
thetype = ui_file_xstrdup (stb, &length);
do_cleanups (old_chain);
int
varobj_set_value (struct varobj *var, char *expression)
{
- value_ptr val;
+ struct value *val;
int offset = 0;
+ int error = 0;
/* The argument "expression" contains the variable's new value.
We need to first construct a legal expression for this -- ugh! */
/* Does this cover all the bases? */
struct expression *exp;
- value_ptr value;
+ struct value *value;
int saved_input_radix = input_radix;
- if (variable_editable (var) && !var->error)
+ if (var->value != NULL && variable_editable (var) && !var->error)
{
char *s = expression;
int i;
- value_ptr temp;
input_radix = 10; /* ALWAYS reset to decimal temporarily */
if (!gdb_parse_exp_1 (&s, 0, 0, &exp))
return 0;
}
- /* If our parent is "public", "private", or "protected", we could
- be asking to modify the value of a baseclass. If so, we need to
- adjust our address by the offset of our baseclass in the subclass,
- since VALUE_ADDRESS (var->value) points at the start of the subclass.
- For some reason, value_cast doesn't take care of this properly. */
- temp = var->value;
- if (var->parent != NULL && CPLUS_FAKE_CHILD (var->parent))
- {
- struct varobj *super, *sub;
- struct type *type;
- super = var->parent->parent;
- sub = super->parent;
- if (sub != NULL)
- {
- /* Yes, it is a baseclass */
- type = get_type_deref (sub);
-
- if (super->index < TYPE_N_BASECLASSES (type))
- {
- temp = value_copy (var->value);
- for (i = 0; i < super->index; i++)
- offset += TYPE_LENGTH (TYPE_FIELD_TYPE (type, i));
- }
- }
- }
-
- VALUE_ADDRESS (temp) += offset;
- if (!gdb_value_assign (temp, value, &val))
+ if (!my_value_equal (var->value, value, &error))
+ var->updated = 1;
+ if (!gdb_value_assign (var->value, value, &val))
return 0;
- VALUE_ADDRESS (val) -= offset;
value_free (var->value);
release_value (val);
var->value = val;
varobj_update (struct varobj **varp, struct varobj ***changelist)
{
int changed = 0;
+ int error = 0;
int type_changed;
int i;
int vleft;
- int error2;
struct varobj *v;
struct varobj **cv;
struct varobj **templist = NULL;
- value_ptr new;
+ struct value *new;
struct vstack *stack = NULL;
struct vstack *result = NULL;
- struct frame_info *old_fi;
+ struct frame_id old_fid;
+ struct frame_info *fi;
/* sanity check: have we been passed a pointer? */
if (changelist == NULL)
/* Save the selected stack frame, since we will need to change it
in order to evaluate expressions. */
- old_fi = selected_frame;
+ old_fid = get_frame_id (deprecated_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
/* If values are not equal, note that it's changed.
There a couple of exceptions here, though.
We don't want some types to be reported as "changed". */
- else if (type_changeable (*varp)
- && !my_value_equal ((*varp)->value, new, &error2))
+ else if (type_changeable (*varp) &&
+ ((*varp)->updated || !my_value_equal ((*varp)->value, new, &error)))
{
vpush (&result, *varp);
+ (*varp)->updated = 0;
changed++;
- /* error2 replaces var->error since this new value
- WILL replace the old one. */
- (*varp)->error = error2;
+ /* Its value is going to be updated to NEW. */
+ (*varp)->error = error;
}
/* We must always keep around the new value for this root
/* Update this variable */
new = value_of_child (v->parent, v->index);
- if (type_changeable (v) && !my_value_equal (v->value, new, &error2))
+ if (type_changeable (v) &&
+ (v->updated || !my_value_equal (v->value, new, &error)))
{
/* Note that it's changed */
vpush (&result, v);
+ v->updated = 0;
changed++;
}
- /* error2 replaces v->error since this new value
- WILL replace the old one. */
- v->error = error2;
+ /* Its value is going to be updated to NEW. */
+ v->error = error;
/* We must always keep new values, since children depend on it. */
if (v->value != NULL)
*cv = vpop (&result);
}
if (vleft)
- warning ("varobj_update: assertion failed - vleft <> 0");
+ warning (_("varobj_update: assertion failed - vleft <> 0"));
if (changed > 1)
{
}
/* Restore selected frame */
- select_frame (old_fi, -1);
+ fi = frame_find_by_id (old_fid);
+ if (fi)
+ select_frame (fi);
if (type_changed)
return -2;
cv = cv->next;
if (cv != NULL)
- error ("Duplicate variable object name");
+ error (_("Duplicate variable object name"));
/* Add varobj to hash table */
newvl = xmalloc (sizeof (struct vlist));
for (vc = var->children; vc != NULL; vc = vc->next)
{
- if (STREQ (vc->child->name, name))
+ if (strcmp (vc->child->name, name) == 0)
return vc->child;
}
child->name = name;
child->index = index;
child->value = value_of_child (parent, index);
- if (child->value == NULL || parent->error)
+ if ((!CPLUS_FAKE_CHILD (child) && child->value == NULL) || parent->error)
child->error = 1;
child->parent = parent;
child->root = parent->root;
- childs_name =
- (char *) xmalloc ((strlen (parent->obj_name) + strlen (name) + 2) *
- sizeof (char));
- sprintf (childs_name, "%s.%s", parent->obj_name, name);
+ childs_name = xstrprintf ("%s.%s", parent->obj_name, name);
child->obj_name = childs_name;
install_variable (child);
var->children = NULL;
var->format = 0;
var->root = NULL;
+ var->updated = 0;
return var;
}
var->root->lang = NULL;
var->root->exp = NULL;
var->root->valid_block = NULL;
- var->root->frame = (CORE_ADDR) -1;
+ var->root->frame = null_frame_id;
var->root->use_selected_frame = 0;
var->root->rootvar = NULL;
return make_cleanup (do_free_variable_cleanup, var);
}
-/* This returns the type of the variable. This skips past typedefs
- and returns the real type of the variable. It also dereferences
- pointers and references. */
+/* This returns the type of the variable. It also skips past typedefs
+ to return the real type of the variable.
+
+ NOTE: TYPE_TARGET_TYPE should NOT be used anywhere in this file
+ except within get_target_type and get_type. */
static struct type *
get_type (struct varobj *var)
{
struct type *type;
type = var->type;
- while (type != NULL && TYPE_CODE (type) == TYPE_CODE_TYPEDEF)
- type = TYPE_TARGET_TYPE (type);
+ if (type != NULL)
+ type = check_typedef (type);
return type;
}
}
/* This returns the target type (or NULL) of TYPE, also skipping
- past typedefs, just like get_type (). */
+ past typedefs, just like get_type ().
+
+ NOTE: TYPE_TARGET_TYPE should NOT be used anywhere in this file
+ except within get_target_type and get_type. */
static struct type *
get_target_type (struct type *type)
{
if (type != NULL)
{
type = TYPE_TARGET_TYPE (type);
- while (type != NULL && TYPE_CODE (type) == TYPE_CODE_TYPEDEF)
- type = TYPE_TARGET_TYPE (type);
+ if (type != NULL)
+ type = check_typedef (type);
}
return type;
return FORMAT_NATURAL;
}
-/* This function is similar to gdb's value_equal, except that this
- one is "safe" -- it NEVER longjmps. It determines if the VAR's
- value is the same as VAL2. */
+/* This function is similar to GDB's value_contents_equal, except that
+ this one is "safe"; it never longjmps. It determines if the VAL1's
+ value is the same as VAL2. If for some reason the value of VAR2
+ can't be established, *ERROR2 is set to non-zero. */
+
static int
-my_value_equal (value_ptr val1, value_ptr val2, int *error2)
+my_value_equal (struct value *val1, struct value *val2, int *error2)
{
- int r, err1, err2;
+ volatile struct exception except;
- *error2 = 0;
- /* Special case: NULL values. If both are null, say
- they're equal. */
+ /* As a special case, if both are null, we say they're equal. */
if (val1 == NULL && val2 == NULL)
return 1;
else if (val1 == NULL || val2 == NULL)
return 0;
- /* This is bogus, but unfortunately necessary. We must know
- exactly what caused an error -- reading val1 or val2 -- so
- that we can really determine if we think that something has changed. */
- err1 = 0;
- err2 = 0;
- /* We do need to catch errors here because the whole purpose
- is to test if value_equal() has errored */
- if (!gdb_value_equal (val1, val1, &r))
- err1 = 1;
+ /* The contents of VAL1 are supposed to be known. */
+ gdb_assert (!value_lazy (val1));
- if (!gdb_value_equal (val2, val2, &r))
- *error2 = err2 = 1;
-
- if (err1 != err2)
- return 0;
-
- if (!gdb_value_equal (val1, val2, &r))
+ /* Make sure we also know the contents of VAL2. */
+ val2 = coerce_array (val2);
+ TRY_CATCH (except, RETURN_MASK_ERROR)
{
- /* An error occurred, this could have happened if
- either val1 or val2 errored. ERR1 and ERR2 tell
- us which of these it is. If both errored, then
- we assume nothing has changed. If one of them is
- valid, though, then something has changed. */
- if (err1 == err2)
- {
- /* both the old and new values caused errors, so
- we say the value did not change */
- /* This is indeterminate, though. Perhaps we should
- be safe and say, yes, it changed anyway?? */
- return 1;
- }
- else
- {
- return 0;
- }
+ if (value_lazy (val2))
+ value_fetch_lazy (val2);
+ }
+ if (except.reason < 0)
+ {
+ *error2 = 1;
+ return 0;
}
+ gdb_assert (!value_lazy (val2));
- return r;
+ return value_contents_equal (val1, val2);
}
/* FIXME: The following should be generic for any pointer */
return (*var->root->lang->name_of_child) (var, index);
}
-/* What is the value_ptr of the root variable VAR?
+/* What is the ``struct value *'' of the root variable VAR?
TYPE_CHANGED controls what to do if the type of a
use_selected_frame = 1 variable changes. On input,
TYPE_CHANGED = 1 means discard the old varobj, and replace
old varobj pointer away somewhere before calling this.
On return, TYPE_CHANGED will be 1 if the type has changed, and
0 otherwise. */
-static value_ptr
+static struct value *
value_of_root (struct varobj **var_handle, int *type_changed)
{
struct varobj *var;
return (*var->root->lang->value_of_root) (var_handle);
}
-/* What is the value_ptr for the INDEX'th child of PARENT? */
-static value_ptr
+/* What is the ``struct value *'' for the INDEX'th child of PARENT? */
+static struct value *
value_of_child (struct varobj *parent, int index)
{
- value_ptr value;
+ struct value *value;
value = (*parent->root->lang->value_of_child) (parent, index);
/* If we're being lazy, fetch the real value of the variable. */
- if (value != NULL && VALUE_LAZY (value))
- gdb_value_fetch_lazy (value);
+ if (value != NULL && value_lazy (value))
+ {
+ /* If we fail to fetch the value of the child, return
+ NULL so that callers notice that we're leaving an
+ error message. */
+ if (!gdb_value_fetch_lazy (value))
+ value = NULL;
+ }
return value;
}
/* If the child had no evaluation errors, var->value
will be non-NULL and contain a valid type. */
if (var->value != NULL)
- return VALUE_TYPE (var->value);
+ return value_type (var->value);
/* Otherwise, we must compute the type. */
return (*var->root->lang->type_of_child) (var->parent, var->index);
switch (TYPE_CODE (type))
{
case TYPE_CODE_ARRAY:
- {
- /* We never get here unless parent->num_children is greater than 0... */
- int len = 1;
- while ((int) pow ((double) 10, (double) len) < index)
- len++;
- name = (char *) xmalloc (1 + len * sizeof (char));
- sprintf (name, "%d", index);
- }
+ name = xstrprintf ("%d", index);
break;
case TYPE_CODE_STRUCT:
break;
default:
- name =
- (char *) xmalloc ((strlen (parent->name) + 2) * sizeof (char));
- sprintf (name, "*%s", parent->name);
+ name = xstrprintf ("*%s", parent->name);
break;
}
break;
return name;
}
-static value_ptr
+static struct value *
c_value_of_root (struct varobj **var_handle)
{
- value_ptr new_val;
+ struct value *new_val;
struct varobj *var = *var_handle;
struct frame_info *fi;
int within_scope;
else
{
reinit_frame_cache ();
-
-
- fi = find_frame_addr_in_frame_chain (var->root->frame);
-
+ fi = frame_find_by_id (var->root->frame);
within_scope = fi != NULL;
/* FIXME: select_frame could fail */
if (within_scope)
- select_frame (fi, -1);
+ select_frame (fi);
}
if (within_scope)
go on */
if (gdb_evaluate_expression (var->root->exp, &new_val))
{
- if (VALUE_LAZY (new_val))
+ if (value_lazy (new_val))
{
/* We need to catch errors because if
value_fetch_lazy fails we still want to continue
(after making val->error = 1) */
- /* FIXME: Shouldn't be using VALUE_CONTENTS? The
- comment on value_fetch_lazy() says it is only
- called from the macro... */
+ /* FIXME: Shouldn't be using value_contents()? The
+ comment on value_fetch_lazy() says it is only called
+ from the macro... */
if (!gdb_value_fetch_lazy (new_val))
var->error = 1;
else
return NULL;
}
-static value_ptr
+static struct value *
c_value_of_child (struct varobj *parent, int index)
{
- value_ptr value, temp, indval;
+ struct value *value;
+ struct value *temp;
+ struct value *indval;
struct type *type, *target;
char *name;
case TYPE_CODE_STRUCT:
case TYPE_CODE_UNION:
- value = value_struct_elt (&temp, NULL, name, NULL, "vstructure");
+ gdb_value_struct_elt (NULL, &value, &temp, NULL, name, NULL,
+ "vstructure");
break;
case TYPE_CODE_PTR:
{
case TYPE_CODE_STRUCT:
case TYPE_CODE_UNION:
- value =
- value_struct_elt (&temp, NULL, name, NULL, "vstructure");
+ gdb_value_struct_elt (NULL, &value, &temp, NULL, name, NULL,
+ "vstructure");
break;
default:
if (value != NULL)
release_value (value);
+ xfree (name);
return value;
}
switch (TYPE_CODE (parent->type))
{
case TYPE_CODE_ARRAY:
- type = TYPE_TARGET_TYPE (parent->type);
+ type = get_target_type (parent->type);
break;
case TYPE_CODE_STRUCT:
break;
case TYPE_CODE_PTR:
- switch (TYPE_CODE (TYPE_TARGET_TYPE (parent->type)))
+ switch (TYPE_CODE (get_target_type (parent->type)))
{
case TYPE_CODE_STRUCT:
case TYPE_CODE_UNION:
break;
default:
- type = TYPE_TARGET_TYPE (parent->type);
+ type = get_target_type (parent->type);
break;
}
break;
default:
/* This should not happen as only the above types have children */
- warning ("Child of parent whose type does not allow children");
+ warning (_("Child of parent whose type does not allow children"));
/* FIXME: Can we still go on? */
type = NULL;
break;
}
+ xfree (name);
return type;
}
static char *
c_value_of_variable (struct varobj *var)
{
- struct type *type;
- value_ptr val;
-
- if (var->value != NULL)
- val = var->value;
- else
- {
- /* This can happen if we attempt to get the value of a struct
- member when the parent is an invalid pointer. */
- return xstrdup ("???");
- }
-
/* BOGUS: if val_print sees a struct/class, it will print out its
children instead of "{...}" */
- type = get_type (var);
- switch (TYPE_CODE (type))
+
+ switch (TYPE_CODE (get_type (var)))
{
case TYPE_CODE_STRUCT:
case TYPE_CODE_UNION:
case TYPE_CODE_ARRAY:
{
- char number[18];
- sprintf (number, "[%d]", var->num_children);
- return xstrdup (number);
+ char *number;
+ number = xstrprintf ("[%d]", var->num_children);
+ return (number);
}
/* break; */
default:
{
- long dummy;
- struct ui_file *stb = mem_fileopen ();
- struct cleanup *old_chain = make_cleanup_ui_file_delete (stb);
- char *thevalue;
-
- if (VALUE_LAZY (val))
- gdb_value_fetch_lazy (val);
- val_print (VALUE_TYPE (val), VALUE_CONTENTS_RAW (val), 0,
- VALUE_ADDRESS (val),
- stb, format_code[(int) var->format], 1, 0, 0);
- thevalue = ui_file_xstrdup (stb, &dummy);
- do_cleanups (old_chain);
+ if (var->value == NULL)
+ {
+ /* 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;
+ }
+ else
+ {
+ long dummy;
+ struct ui_file *stb = mem_fileopen ();
+ struct cleanup *old_chain = make_cleanup_ui_file_delete (stb);
+ char *thevalue;
+
+ if (value_lazy (var->value))
+ gdb_value_fetch_lazy (var->value);
+ common_val_print (var->value, stb,
+ format_code[(int) var->format], 1, 0, 0);
+ thevalue = ui_file_xstrdup (stb, &dummy);
+ do_cleanups (old_chain);
return thevalue;
}
- /* break; */
+ }
}
}
\f
type = get_type_deref (var->parent);
cplus_class_num_children (type, kids);
- if (STREQ (var->name, "public"))
+ if (strcmp (var->name, "public") == 0)
children = kids[v_public];
- else if (STREQ (var->name, "private"))
+ else if (strcmp (var->name, "private") == 0)
children = kids[v_private];
else
children = kids[v_protected];
{
char *name;
struct type *type;
- int children[3];
if (CPLUS_FAKE_CHILD (parent))
{
{
case TYPE_CODE_STRUCT:
case TYPE_CODE_UNION:
- cplus_class_num_children (type, children);
-
if (CPLUS_FAKE_CHILD (parent))
{
- /* FIXME: This assumes that type orders
- inherited, public, private, protected */
- int i = index + TYPE_N_BASECLASSES (type);
- if (STREQ (parent->name, "private")
- || STREQ (parent->name, "protected"))
- i += children[v_public];
- if (STREQ (parent->name, "protected"))
- i += children[v_private];
-
- name = TYPE_FIELD_NAME (type, i);
+ /* The fields of the class type are ordered as they
+ appear in the class. We are given an index for a
+ particular access control type ("public","protected",
+ or "private"). We must skip over fields that don't
+ have the access control we are looking for to properly
+ find the indexed field. */
+ int type_index = TYPE_N_BASECLASSES (type);
+ if (strcmp (parent->name, "private") == 0)
+ {
+ while (index >= 0)
+ {
+ if (TYPE_VPTR_BASETYPE (type) == type
+ && type_index == TYPE_VPTR_FIELDNO (type))
+ ; /* ignore vptr */
+ else if (TYPE_FIELD_PRIVATE (type, type_index))
+ --index;
+ ++type_index;
+ }
+ --type_index;
+ }
+ else if (strcmp (parent->name, "protected") == 0)
+ {
+ while (index >= 0)
+ {
+ if (TYPE_VPTR_BASETYPE (type) == type
+ && type_index == TYPE_VPTR_FIELDNO (type))
+ ; /* ignore vptr */
+ else if (TYPE_FIELD_PROTECTED (type, type_index))
+ --index;
+ ++type_index;
+ }
+ --type_index;
+ }
+ else
+ {
+ while (index >= 0)
+ {
+ if (TYPE_VPTR_BASETYPE (type) == type
+ && type_index == TYPE_VPTR_FIELDNO (type))
+ ; /* ignore vptr */
+ else if (!TYPE_FIELD_PRIVATE (type, type_index) &&
+ !TYPE_FIELD_PROTECTED (type, type_index))
+ --index;
+ ++type_index;
+ }
+ --type_index;
+ }
+
+ name = TYPE_FIELD_NAME (type, type_index);
}
else if (index < TYPE_N_BASECLASSES (type))
+ /* We are looking up the name of a base class */
name = TYPE_FIELD_NAME (type, index);
else
{
+ int children[3];
+ cplus_class_num_children(type, children);
+
/* Everything beyond the baseclasses can
- only be "public", "private", or "protected" */
+ only be "public", "private", or "protected"
+
+ The special "fake" children are always output by varobj in
+ this order. So if INDEX == 2, it MUST be "protected". */
index -= TYPE_N_BASECLASSES (type);
switch (index)
{
case 0:
- if (children[v_public] != 0)
- {
- name = "public";
- break;
- }
+ if (children[v_public] > 0)
+ name = "public";
+ else if (children[v_private] > 0)
+ name = "private";
+ else
+ name = "protected";
+ break;
case 1:
- if (children[v_private] != 0)
+ if (children[v_public] > 0)
{
- name = "private";
- break;
+ if (children[v_private] > 0)
+ name = "private";
+ else
+ name = "protected";
}
+ else if (children[v_private] > 0)
+ name = "protected";
+ break;
case 2:
- if (children[v_protected] != 0)
- {
- name = "protected";
- break;
- }
+ /* Must be protected */
+ name = "protected";
+ break;
default:
/* error! */
break;
return name;
}
-static value_ptr
+static struct value *
cplus_value_of_root (struct varobj **var_handle)
{
return c_value_of_root (var_handle);
}
-static value_ptr
+static struct value *
cplus_value_of_child (struct varobj *parent, int index)
{
struct type *type;
- value_ptr value;
- char *name;
+ struct value *value;
if (CPLUS_FAKE_CHILD (parent))
type = get_type_deref (parent->parent);
type = get_type_deref (parent);
value = NULL;
- name = name_of_child (parent, index);
if (((TYPE_CODE (type)) == TYPE_CODE_STRUCT) ||
((TYPE_CODE (type)) == TYPE_CODE_UNION))
{
if (CPLUS_FAKE_CHILD (parent))
{
- value_ptr temp = parent->parent->value;
- value = value_struct_elt (&temp, NULL, name,
- NULL, "cplus_structure");
- release_value (value);
+ char *name;
+ struct value *temp = parent->parent->value;
+
+ if (temp == NULL)
+ return NULL;
+
+ name = name_of_child (parent, index);
+ gdb_value_struct_elt (NULL, &value, &temp, NULL, name, NULL,
+ "cplus_structure");
+ if (value != NULL)
+ release_value (value);
+
+ xfree (name);
}
else if (index >= TYPE_N_BASECLASSES (type))
{
/* Baseclass */
if (parent->value != NULL)
{
- value_ptr temp;
+ struct value *temp = NULL;
- if (TYPE_CODE (VALUE_TYPE (parent->value)) == TYPE_CODE_PTR
- || TYPE_CODE (VALUE_TYPE (parent->value)) == TYPE_CODE_REF)
+ if (TYPE_CODE (value_type (parent->value)) == TYPE_CODE_PTR
+ || TYPE_CODE (value_type (parent->value)) == TYPE_CODE_REF)
{
if (!gdb_value_ind (parent->value, &temp))
return NULL;
else
temp = parent->value;
- value = value_cast (TYPE_FIELD_TYPE (type, index), temp);
- release_value (value);
+ if (temp != NULL)
+ {
+ value = value_cast (TYPE_FIELD_TYPE (type, index), temp);
+ release_value (value);
+ }
+ else
+ {
+ /* We failed to evaluate the parent's value, so don't even
+ bother trying to evaluate this child. */
+ return NULL;
+ }
}
}
}
{
struct type *type, *t;
- t = get_type_deref (parent);
+ if (CPLUS_FAKE_CHILD (parent))
+ {
+ /* Looking for the type of a child of public, private, or protected. */
+ t = get_type_deref (parent->parent);
+ }
+ else
+ t = get_type_deref (parent);
+
type = NULL;
switch (TYPE_CODE (t))
{
case TYPE_CODE_STRUCT:
case TYPE_CODE_UNION:
- if (index >= TYPE_N_BASECLASSES (t))
+ if (CPLUS_FAKE_CHILD (parent))
{
- /* special */
- return NULL;
+ char *name = cplus_name_of_child (parent, index);
+ type = lookup_struct_elt_type (t, name, 0);
+ xfree (name);
}
+ else if (index < TYPE_N_BASECLASSES (t))
+ type = TYPE_FIELD_TYPE (t, index);
else
{
- /* Baseclass */
- type = TYPE_FIELD_TYPE (t, index);
+ /* special */
+ return NULL;
}
break;
return name;
}
-static value_ptr
+static struct value *
java_value_of_root (struct varobj **var_handle)
{
return cplus_value_of_root (var_handle);
}
-static value_ptr
+static struct value *
java_value_of_child (struct varobj *parent, int index)
{
return cplus_value_of_child (parent, index);
varobj_table = xmalloc (sizeof_table);
memset (varobj_table, 0, sizeof_table);
- add_show_from_set (add_set_cmd ("debugvarobj", class_maintenance, var_zinteger, (char *) &varobjdebug, "Set varobj debugging.\n\
-When non-zero, varobj debugging is enabled.", &setlist),
- &showlist);
+ add_setshow_zinteger_cmd ("debugvarobj", class_maintenance,
+ &varobjdebug, _("\
+Set varobj debugging."), _("\
+Show varobj debugging."), _("\
+When non-zero, varobj debugging is enabled."),
+ NULL,
+ show_varobjdebug,
+ &setlist, &showlist);
}