1 /* Implementation of the GDB variable objects API.
3 Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006
4 Free Software Foundation, Inc.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 Boston, MA 02110-1301, USA. */
22 #include "exceptions.h"
24 #include "expression.h"
31 #include "gdb_assert.h"
32 #include "gdb_string.h"
37 /* Non-zero if we want to see trace of varobj level stuff. */
41 show_varobjdebug (struct ui_file *file, int from_tty,
42 struct cmd_list_element *c, const char *value)
44 fprintf_filtered (file, _("Varobj debugging is %s.\n"), value);
47 /* String representations of gdb's format codes */
48 char *varobj_format_string[] =
49 { "natural", "binary", "decimal", "hexadecimal", "octal" };
51 /* String representations of gdb's known languages */
52 char *varobj_language_string[] = { "unknown", "C", "C++", "Java" };
56 /* Every root variable has one of these structures saved in its
57 varobj. Members which must be free'd are noted. */
61 /* Alloc'd expression for this parent. */
62 struct expression *exp;
64 /* Block for which this expression is valid */
65 struct block *valid_block;
67 /* The frame for this expression */
68 struct frame_id frame;
70 /* If 1, "update" always recomputes the frame & valid block
71 using the currently selected frame. */
72 int use_selected_frame;
74 /* Language info for this variable and its children */
75 struct language_specific *lang;
77 /* The varobj for this root node. */
78 struct varobj *rootvar;
80 /* Next root variable */
81 struct varobj_root *next;
84 typedef struct varobj *varobj_p;
88 /* Every variable in the system has a structure of this type defined
89 for it. This structure holds all information necessary to manipulate
90 a particular object variable. Members which must be freed are noted. */
94 /* Alloc'd name of the variable for this object.. If this variable is a
95 child, then this name will be the child's source name.
97 /* NOTE: This is the "expression" */
100 /* The alloc'd name for this variable's object. This is here for
101 convenience when constructing this object's children. */
104 /* Index of this variable in its parent or -1 */
107 /* The type of this variable. This may NEVER be NULL. */
110 /* The value of this expression or subexpression. This may be NULL.
111 Invariant: if varobj_value_is_changeable_p (this) is non-zero,
112 the value is either NULL, or not lazy. */
115 /* Did an error occur evaluating the expression or getting its value? */
118 /* The number of (immediate) children this variable has */
121 /* If this object is a child, this points to its immediate parent. */
122 struct varobj *parent;
124 /* Children of this object. */
125 VEC (varobj_p) *children;
127 /* Description of the root variable. Points to root variable for children. */
128 struct varobj_root *root;
130 /* The format of the output for this object */
131 enum varobj_display_formats format;
133 /* Was this variable updated via a varobj_set_value operation */
140 struct cpstack *next;
143 /* A list of varobjs */
151 /* Private function prototypes */
153 /* Helper functions for the above subcommands. */
155 static int delete_variable (struct cpstack **, struct varobj *, int);
157 static void delete_variable_1 (struct cpstack **, int *,
158 struct varobj *, int, int);
160 static int install_variable (struct varobj *);
162 static void uninstall_variable (struct varobj *);
164 static struct varobj *create_child (struct varobj *, int, char *);
166 /* Utility routines */
168 static struct varobj *new_variable (void);
170 static struct varobj *new_root_variable (void);
172 static void free_variable (struct varobj *var);
174 static struct cleanup *make_cleanup_free_variable (struct varobj *var);
176 static struct type *get_type (struct varobj *var);
178 static struct type *get_type_deref (struct varobj *var);
180 static struct type *get_target_type (struct type *);
182 static enum varobj_display_formats variable_default_display (struct varobj *);
184 static void cppush (struct cpstack **pstack, char *name);
186 static char *cppop (struct cpstack **pstack);
188 static int install_new_value (struct varobj *var, struct value *value,
191 /* Language-specific routines. */
193 static enum varobj_languages variable_language (struct varobj *var);
195 static int number_of_children (struct varobj *);
197 static char *name_of_variable (struct varobj *);
199 static char *name_of_child (struct varobj *, int);
201 static struct value *value_of_root (struct varobj **var_handle, int *);
203 static struct value *value_of_child (struct varobj *parent, int index);
205 static int variable_editable (struct varobj *var);
207 static char *my_value_of_variable (struct varobj *var);
209 static int varobj_value_is_changeable_p (struct varobj *var);
211 static int is_root_p (struct varobj *var);
213 /* C implementation */
215 static int c_number_of_children (struct varobj *var);
217 static char *c_name_of_variable (struct varobj *parent);
219 static char *c_name_of_child (struct varobj *parent, int index);
221 static struct value *c_value_of_root (struct varobj **var_handle);
223 static struct value *c_value_of_child (struct varobj *parent, int index);
225 static struct type *c_type_of_child (struct varobj *parent, int index);
227 static int c_variable_editable (struct varobj *var);
229 static char *c_value_of_variable (struct varobj *var);
231 /* C++ implementation */
233 static int cplus_number_of_children (struct varobj *var);
235 static void cplus_class_num_children (struct type *type, int children[3]);
237 static char *cplus_name_of_variable (struct varobj *parent);
239 static char *cplus_name_of_child (struct varobj *parent, int index);
241 static struct value *cplus_value_of_root (struct varobj **var_handle);
243 static struct value *cplus_value_of_child (struct varobj *parent, int index);
245 static struct type *cplus_type_of_child (struct varobj *parent, int index);
247 static int cplus_variable_editable (struct varobj *var);
249 static char *cplus_value_of_variable (struct varobj *var);
251 /* Java implementation */
253 static int java_number_of_children (struct varobj *var);
255 static char *java_name_of_variable (struct varobj *parent);
257 static char *java_name_of_child (struct varobj *parent, int index);
259 static struct value *java_value_of_root (struct varobj **var_handle);
261 static struct value *java_value_of_child (struct varobj *parent, int index);
263 static struct type *java_type_of_child (struct varobj *parent, int index);
265 static int java_variable_editable (struct varobj *var);
267 static char *java_value_of_variable (struct varobj *var);
269 /* The language specific vector */
271 struct language_specific
274 /* The language of this variable */
275 enum varobj_languages language;
277 /* The number of children of PARENT. */
278 int (*number_of_children) (struct varobj * parent);
280 /* The name (expression) of a root varobj. */
281 char *(*name_of_variable) (struct varobj * parent);
283 /* The name of the INDEX'th child of PARENT. */
284 char *(*name_of_child) (struct varobj * parent, int index);
286 /* The ``struct value *'' of the root variable ROOT. */
287 struct value *(*value_of_root) (struct varobj ** root_handle);
289 /* The ``struct value *'' of the INDEX'th child of PARENT. */
290 struct value *(*value_of_child) (struct varobj * parent, int index);
292 /* The type of the INDEX'th child of PARENT. */
293 struct type *(*type_of_child) (struct varobj * parent, int index);
295 /* Is VAR editable? */
296 int (*variable_editable) (struct varobj * var);
298 /* The current value of VAR. */
299 char *(*value_of_variable) (struct varobj * var);
302 /* Array of known source language routines. */
303 static struct language_specific languages[vlang_end] = {
304 /* Unknown (try treating as C */
307 c_number_of_children,
319 c_number_of_children,
331 cplus_number_of_children,
332 cplus_name_of_variable,
335 cplus_value_of_child,
337 cplus_variable_editable,
338 cplus_value_of_variable}
343 java_number_of_children,
344 java_name_of_variable,
349 java_variable_editable,
350 java_value_of_variable}
353 /* A little convenience enum for dealing with C++/Java */
356 v_public = 0, v_private, v_protected
361 /* Mappings of varobj_display_formats enums to gdb's format codes */
362 static int format_code[] = { 0, 't', 'd', 'x', 'o' };
364 /* Header of the list of root variable objects */
365 static struct varobj_root *rootlist;
366 static int rootcount = 0; /* number of root varobjs in the list */
368 /* Prime number indicating the number of buckets in the hash table */
369 /* A prime large enough to avoid too many colisions */
370 #define VAROBJ_TABLE_SIZE 227
372 /* Pointer to the varobj hash table (built at run time) */
373 static struct vlist **varobj_table;
375 /* Is the variable X one of our "fake" children? */
376 #define CPLUS_FAKE_CHILD(x) \
377 ((x) != NULL && (x)->type == NULL && (x)->value == NULL)
380 /* API Implementation */
382 is_root_p (struct varobj *var)
384 return (var->root->rootvar == var);
387 /* Creates a varobj (not its children) */
389 /* Return the full FRAME which corresponds to the given CORE_ADDR
390 or NULL if no FRAME on the chain corresponds to CORE_ADDR. */
392 static struct frame_info *
393 find_frame_addr_in_frame_chain (CORE_ADDR frame_addr)
395 struct frame_info *frame = NULL;
397 if (frame_addr == (CORE_ADDR) 0)
402 frame = get_prev_frame (frame);
405 if (get_frame_base_address (frame) == frame_addr)
411 varobj_create (char *objname,
412 char *expression, CORE_ADDR frame, enum varobj_type type)
415 struct frame_info *fi;
416 struct frame_info *old_fi = NULL;
418 struct cleanup *old_chain;
420 /* Fill out a varobj structure for the (root) variable being constructed. */
421 var = new_root_variable ();
422 old_chain = make_cleanup_free_variable (var);
424 if (expression != NULL)
427 enum varobj_languages lang;
430 /* Parse and evaluate the expression, filling in as much
431 of the variable's data as possible */
433 /* Allow creator to specify context of variable */
434 if ((type == USE_CURRENT_FRAME) || (type == USE_SELECTED_FRAME))
435 fi = deprecated_selected_frame;
437 /* FIXME: cagney/2002-11-23: This code should be doing a
438 lookup using the frame ID and not just the frame's
439 ``address''. This, of course, means an interface change.
440 However, with out that interface change ISAs, such as the
441 ia64 with its two stacks, won't work. Similar goes for the
442 case where there is a frameless function. */
443 fi = find_frame_addr_in_frame_chain (frame);
445 /* frame = -2 means always use selected frame */
446 if (type == USE_SELECTED_FRAME)
447 var->root->use_selected_frame = 1;
451 block = get_frame_block (fi, 0);
454 innermost_block = NULL;
455 /* Wrap the call to parse expression, so we can
456 return a sensible error. */
457 if (!gdb_parse_exp_1 (&p, block, 0, &var->root->exp))
462 /* Don't allow variables to be created for types. */
463 if (var->root->exp->elts[0].opcode == OP_TYPE)
465 do_cleanups (old_chain);
466 fprintf_unfiltered (gdb_stderr, "Attempt to use a type name"
467 " as an expression.\n");
471 var->format = variable_default_display (var);
472 var->root->valid_block = innermost_block;
473 var->name = savestring (expression, strlen (expression));
475 /* When the frame is different from the current frame,
476 we must select the appropriate frame before parsing
477 the expression, otherwise the value will not be current.
478 Since select_frame is so benign, just call it for all cases. */
481 var->root->frame = get_frame_id (fi);
482 old_fi = deprecated_selected_frame;
486 /* We definitively need to catch errors here.
487 If evaluate_expression succeeds we got the value we wanted.
488 But if it fails, we still go on with a call to evaluate_type() */
489 if (!gdb_evaluate_expression (var->root->exp, &value))
490 /* Error getting the value. Try to at least get the
492 value = evaluate_type (var->root->exp);
494 var->type = value_type (value);
495 install_new_value (var, value, 1 /* Initial assignment */);
497 /* Set language info */
498 lang = variable_language (var);
499 var->root->lang = &languages[lang];
501 /* Set ourselves as our root */
502 var->root->rootvar = var;
504 /* Reset the selected frame */
506 select_frame (old_fi);
509 /* If the variable object name is null, that means this
510 is a temporary variable, so don't install it. */
512 if ((var != NULL) && (objname != NULL))
514 var->obj_name = savestring (objname, strlen (objname));
516 /* If a varobj name is duplicated, the install will fail so
518 if (!install_variable (var))
520 do_cleanups (old_chain);
525 discard_cleanups (old_chain);
529 /* Generates an unique name that can be used for a varobj */
532 varobj_gen_name (void)
537 /* generate a name for this object */
539 obj_name = xstrprintf ("var%d", id);
544 /* Given an "objname", returns the pointer to the corresponding varobj
545 or NULL if not found */
548 varobj_get_handle (char *objname)
552 unsigned int index = 0;
555 for (chp = objname; *chp; chp++)
557 index = (index + (i++ * (unsigned int) *chp)) % VAROBJ_TABLE_SIZE;
560 cv = *(varobj_table + index);
561 while ((cv != NULL) && (strcmp (cv->var->obj_name, objname) != 0))
565 error (_("Variable object not found"));
570 /* Given the handle, return the name of the object */
573 varobj_get_objname (struct varobj *var)
575 return var->obj_name;
578 /* Given the handle, return the expression represented by the object */
581 varobj_get_expression (struct varobj *var)
583 return name_of_variable (var);
586 /* Deletes a varobj and all its children if only_children == 0,
587 otherwise deletes only the children; returns a malloc'ed list of all the
588 (malloc'ed) names of the variables that have been deleted (NULL terminated) */
591 varobj_delete (struct varobj *var, char ***dellist, int only_children)
595 struct cpstack *result = NULL;
598 /* Initialize a stack for temporary results */
599 cppush (&result, NULL);
602 /* Delete only the variable children */
603 delcount = delete_variable (&result, var, 1 /* only the children */ );
605 /* Delete the variable and all its children */
606 delcount = delete_variable (&result, var, 0 /* parent+children */ );
608 /* We may have been asked to return a list of what has been deleted */
611 *dellist = xmalloc ((delcount + 1) * sizeof (char *));
615 *cp = cppop (&result);
616 while ((*cp != NULL) && (mycount > 0))
620 *cp = cppop (&result);
623 if (mycount || (*cp != NULL))
624 warning (_("varobj_delete: assertion failed - mycount(=%d) <> 0"),
631 /* Set/Get variable object display format */
633 enum varobj_display_formats
634 varobj_set_display_format (struct varobj *var,
635 enum varobj_display_formats format)
642 case FORMAT_HEXADECIMAL:
644 var->format = format;
648 var->format = variable_default_display (var);
654 enum varobj_display_formats
655 varobj_get_display_format (struct varobj *var)
661 varobj_get_num_children (struct varobj *var)
663 if (var->num_children == -1)
664 var->num_children = number_of_children (var);
666 return var->num_children;
669 /* Creates a list of the immediate children of a variable object;
670 the return code is the number of such children or -1 on error */
673 varobj_list_children (struct varobj *var, struct varobj ***childlist)
675 struct varobj *child;
679 /* sanity check: have we been passed a pointer? */
680 if (childlist == NULL)
685 if (var->num_children == -1)
686 var->num_children = number_of_children (var);
688 /* If we're called when the list of children is not yet initialized,
689 allocate enough elements in it. */
690 while (VEC_length (varobj_p, var->children) < var->num_children)
691 VEC_safe_push (varobj_p, var->children, NULL);
693 /* List of children */
694 *childlist = xmalloc ((var->num_children + 1) * sizeof (struct varobj *));
696 for (i = 0; i < var->num_children; i++)
700 /* Mark as the end in case we bail out */
701 *((*childlist) + i) = NULL;
703 existing = VEC_index (varobj_p, var->children, i);
705 if (existing == NULL)
707 /* Either it's the first call to varobj_list_children for
708 this variable object, and the child was never created,
709 or it was explicitly deleted by the client. */
710 name = name_of_child (var, i);
711 existing = create_child (var, i, name);
712 VEC_replace (varobj_p, var->children, i, existing);
715 *((*childlist) + i) = existing;
718 /* End of list is marked by a NULL pointer */
719 *((*childlist) + i) = NULL;
721 return var->num_children;
724 /* Obtain the type of an object Variable as a string similar to the one gdb
725 prints on the console */
728 varobj_get_type (struct varobj *var)
731 struct cleanup *old_chain;
736 /* For the "fake" variables, do not return a type. (It's type is
738 if (CPLUS_FAKE_CHILD (var))
741 stb = mem_fileopen ();
742 old_chain = make_cleanup_ui_file_delete (stb);
744 /* To print the type, we simply create a zero ``struct value *'' and
745 cast it to our type. We then typeprint this variable. */
746 val = value_zero (var->type, not_lval);
747 type_print (value_type (val), "", stb, -1);
749 thetype = ui_file_xstrdup (stb, &length);
750 do_cleanups (old_chain);
754 /* Obtain the type of an object variable. */
757 varobj_get_gdb_type (struct varobj *var)
762 enum varobj_languages
763 varobj_get_language (struct varobj *var)
765 return variable_language (var);
769 varobj_get_attributes (struct varobj *var)
773 if (variable_editable (var))
774 /* FIXME: define masks for attributes */
775 attributes |= 0x00000001; /* Editable */
781 varobj_get_value (struct varobj *var)
783 return my_value_of_variable (var);
786 /* Set the value of an object variable (if it is editable) to the
787 value of the given expression */
788 /* Note: Invokes functions that can call error() */
791 varobj_set_value (struct varobj *var, char *expression)
797 /* The argument "expression" contains the variable's new value.
798 We need to first construct a legal expression for this -- ugh! */
799 /* Does this cover all the bases? */
800 struct expression *exp;
802 int saved_input_radix = input_radix;
804 if (var->value != NULL && variable_editable (var) && !var->error)
806 char *s = expression;
809 input_radix = 10; /* ALWAYS reset to decimal temporarily */
810 exp = parse_exp_1 (&s, 0, 0);
811 if (!gdb_evaluate_expression (exp, &value))
813 /* We cannot proceed without a valid expression. */
818 /* All types that are editable must also be changeable. */
819 gdb_assert (varobj_value_is_changeable_p (var));
821 /* The value of a changeable variable object must not be lazy. */
822 gdb_assert (!value_lazy (var->value));
824 /* Need to coerce the input. We want to check if the
825 value of the variable object will be different
826 after assignment, and the first thing value_assign
827 does is coerce the input.
828 For example, if we are assigning an array to a pointer variable we
829 should compare the pointer with the the array's address, not with the
831 value = coerce_array (value);
833 /* The new value may be lazy. gdb_value_assign, or
834 rather value_contents, will take care of this.
835 If fetching of the new value will fail, gdb_value_assign
836 with catch the exception. */
837 if (!gdb_value_assign (var->value, value, &val))
840 /* If the value has changed, record it, so that next -var-update can
841 report this change. If a variable had a value of '1', we've set it
842 to '333' and then set again to '1', when -var-update will report this
843 variable as changed -- because the first assignment has set the
844 'updated' flag. There's no need to optimize that, because return value
845 of -var-update should be considered an approximation. */
846 var->updated = install_new_value (var, val, 0 /* Compare values. */);
847 input_radix = saved_input_radix;
854 /* Returns a malloc'ed list with all root variable objects */
856 varobj_list (struct varobj ***varlist)
859 struct varobj_root *croot;
860 int mycount = rootcount;
862 /* Alloc (rootcount + 1) entries for the result */
863 *varlist = xmalloc ((rootcount + 1) * sizeof (struct varobj *));
867 while ((croot != NULL) && (mycount > 0))
869 *cv = croot->rootvar;
874 /* Mark the end of the list */
877 if (mycount || (croot != NULL))
879 ("varobj_list: assertion failed - wrong tally of root vars (%d:%d)",
885 /* Assign a new value to a variable object. If INITIAL is non-zero,
886 this is the first assignement after the variable object was just
887 created, or changed type. In that case, just assign the value
889 Otherwise, assign the value and if type_changeable returns non-zero,
890 find if the new value is different from the current value.
891 Return 1 if so, and 0 if the values are equal.
893 The VALUE parameter should not be released -- the function will
894 take care of releasing it when needed. */
896 install_new_value (struct varobj *var, struct value *value, int initial)
903 /* We need to know the varobj's type to decide if the value should
904 be fetched or not. C++ fake children (public/protected/private) don't have
906 gdb_assert (var->type || CPLUS_FAKE_CHILD (var));
907 changeable = varobj_value_is_changeable_p (var);
908 need_to_fetch = changeable;
910 /* We are not interested in the address of references, and given
911 that in C++ a reference is not rebindable, it cannot
912 meaningfully change. So, get hold of the real value. */
915 value = coerce_ref (value);
916 release_value (value);
919 if (var->type && TYPE_CODE (var->type) == TYPE_CODE_UNION)
920 /* For unions, we need to fetch the value implicitly because
921 of implementation of union member fetch. When gdb
922 creates a value for a field and the value of the enclosing
923 structure is not lazy, it immediately copies the necessary
924 bytes from the enclosing values. If the enclosing value is
925 lazy, the call to value_fetch_lazy on the field will read
926 the data from memory. For unions, that means we'll read the
927 same memory more than once, which is not desirable. So
931 /* The new value might be lazy. If the type is changeable,
932 that is we'll be comparing values of this type, fetch the
933 value now. Otherwise, on the next update the old value
934 will be lazy, which means we've lost that old value. */
935 if (need_to_fetch && value && value_lazy (value))
937 if (!gdb_value_fetch_lazy (value))
940 /* Set the value to NULL, so that for the next -var-update,
941 we don't try to compare the new value with this value,
942 that we couldn't even read. */
949 /* If the type is changeable, compare the old and the new values.
950 If this is the initial assignment, we don't have any old value
952 if (!initial && changeable)
954 /* If the value of the varobj was changed by -var-set-value, then the
955 value in the varobj and in the target is the same. However, that value
956 is different from the value that the varobj had after the previous
957 -var-update. So need to the varobj as changed. */
962 /* Try to compare the values. That requires that both
963 values are non-lazy. */
965 /* Quick comparison of NULL values. */
966 if (var->value == NULL && value == NULL)
969 else if (var->value == NULL || value == NULL)
973 gdb_assert (!value_lazy (var->value));
974 gdb_assert (!value_lazy (value));
976 if (!value_contents_equal (var->value, value))
982 /* We must always keep the new value, since children depend on it. */
983 if (var->value != NULL)
984 value_free (var->value);
988 gdb_assert (!var->value || value_type (var->value));
994 /* Update the values for a variable and its children. This is a
995 two-pronged attack. First, re-parse the value for the root's
996 expression to see if it's changed. Then go all the way
997 through its children, reconstructing them and noting if they've
1000 -1 if there was an error updating the varobj
1001 -2 if the type changed
1002 Otherwise it is the number of children + parent changed
1004 Only root variables can be updated...
1006 NOTE: This function may delete the caller's varobj. If it
1007 returns -2, then it has done this and VARP will be modified
1008 to point to the new varobj. */
1011 varobj_update (struct varobj **varp, struct varobj ***changelist)
1020 struct varobj **templist = NULL;
1022 VEC (varobj_p) *stack = NULL;
1023 VEC (varobj_p) *result = NULL;
1024 struct frame_id old_fid;
1025 struct frame_info *fi;
1027 /* sanity check: have we been passed a pointer? */
1028 if (changelist == NULL)
1031 /* Only root variables can be updated... */
1032 if (!is_root_p (*varp))
1033 /* Not a root var */
1036 /* Save the selected stack frame, since we will need to change it
1037 in order to evaluate expressions. */
1038 old_fid = get_frame_id (deprecated_selected_frame);
1040 /* Update the root variable. value_of_root can return NULL
1041 if the variable is no longer around, i.e. we stepped out of
1042 the frame in which a local existed. We are letting the
1043 value_of_root variable dispose of the varobj if the type
1046 new = value_of_root (varp, &type_changed);
1048 /* Restore selected frame */
1049 fi = frame_find_by_id (old_fid);
1059 /* If this is a "use_selected_frame" varobj, and its type has changed,
1060 them note that it's changed. */
1062 VEC_safe_push (varobj_p, result, *varp);
1064 if (install_new_value ((*varp), new, type_changed))
1066 /* If type_changed is 1, install_new_value will never return
1067 non-zero, so we'll never report the same variable twice. */
1068 gdb_assert (!type_changed);
1069 VEC_safe_push (varobj_p, result, *varp);
1072 VEC_safe_push (varobj_p, stack, *varp);
1074 /* Walk through the children, reconstructing them all. */
1075 while (!VEC_empty (varobj_p, stack))
1077 v = VEC_pop (varobj_p, stack);
1079 /* Push any children. Use reverse order so that the first
1080 child is popped from the work stack first, and so
1081 will be added to result first. This does not
1082 affect correctness, just "nicer". */
1083 for (i = VEC_length (varobj_p, v->children)-1; i >= 0; --i)
1085 varobj_p c = VEC_index (varobj_p, v->children, i);
1086 /* Child may be NULL if explicitly deleted by -var-delete. */
1088 VEC_safe_push (varobj_p, stack, c);
1091 /* Update this variable, unless it's a root, which is already
1095 new = value_of_child (v->parent, v->index);
1096 if (install_new_value (v, new, 0 /* type not changed */))
1098 /* Note that it's changed */
1099 VEC_safe_push (varobj_p, result, v);
1105 /* Alloc (changed + 1) list entries */
1106 changed = VEC_length (varobj_p, result);
1107 *changelist = xmalloc ((changed + 1) * sizeof (struct varobj *));
1110 for (i = 0; i < changed; ++i)
1112 *cv = VEC_index (varobj_p, result, i);
1113 gdb_assert (*cv != NULL);
1125 /* Helper functions */
1128 * Variable object construction/destruction
1132 delete_variable (struct cpstack **resultp, struct varobj *var,
1133 int only_children_p)
1137 delete_variable_1 (resultp, &delcount, var,
1138 only_children_p, 1 /* remove_from_parent_p */ );
1143 /* Delete the variable object VAR and its children */
1144 /* IMPORTANT NOTE: If we delete a variable which is a child
1145 and the parent is not removed we dump core. It must be always
1146 initially called with remove_from_parent_p set */
1148 delete_variable_1 (struct cpstack **resultp, int *delcountp,
1149 struct varobj *var, int only_children_p,
1150 int remove_from_parent_p)
1154 /* Delete any children of this variable, too. */
1155 for (i = 0; i < VEC_length (varobj_p, var->children); ++i)
1157 varobj_p child = VEC_index (varobj_p, var->children, i);
1158 if (!remove_from_parent_p)
1159 child->parent = NULL;
1160 delete_variable_1 (resultp, delcountp, child, 0, only_children_p);
1162 VEC_free (varobj_p, var->children);
1164 /* if we were called to delete only the children we are done here */
1165 if (only_children_p)
1168 /* Otherwise, add it to the list of deleted ones and proceed to do so */
1169 /* If the name is null, this is a temporary variable, that has not
1170 yet been installed, don't report it, it belongs to the caller... */
1171 if (var->obj_name != NULL)
1173 cppush (resultp, xstrdup (var->obj_name));
1174 *delcountp = *delcountp + 1;
1177 /* If this variable has a parent, remove it from its parent's list */
1178 /* OPTIMIZATION: if the parent of this variable is also being deleted,
1179 (as indicated by remove_from_parent_p) we don't bother doing an
1180 expensive list search to find the element to remove when we are
1181 discarding the list afterwards */
1182 if ((remove_from_parent_p) && (var->parent != NULL))
1184 VEC_replace (varobj_p, var->parent->children, var->index, NULL);
1187 if (var->obj_name != NULL)
1188 uninstall_variable (var);
1190 /* Free memory associated with this variable */
1191 free_variable (var);
1194 /* Install the given variable VAR with the object name VAR->OBJ_NAME. */
1196 install_variable (struct varobj *var)
1199 struct vlist *newvl;
1201 unsigned int index = 0;
1204 for (chp = var->obj_name; *chp; chp++)
1206 index = (index + (i++ * (unsigned int) *chp)) % VAROBJ_TABLE_SIZE;
1209 cv = *(varobj_table + index);
1210 while ((cv != NULL) && (strcmp (cv->var->obj_name, var->obj_name) != 0))
1214 error (_("Duplicate variable object name"));
1216 /* Add varobj to hash table */
1217 newvl = xmalloc (sizeof (struct vlist));
1218 newvl->next = *(varobj_table + index);
1220 *(varobj_table + index) = newvl;
1222 /* If root, add varobj to root list */
1223 if (is_root_p (var))
1225 /* Add to list of root variables */
1226 if (rootlist == NULL)
1227 var->root->next = NULL;
1229 var->root->next = rootlist;
1230 rootlist = var->root;
1237 /* Unistall the object VAR. */
1239 uninstall_variable (struct varobj *var)
1243 struct varobj_root *cr;
1244 struct varobj_root *prer;
1246 unsigned int index = 0;
1249 /* Remove varobj from hash table */
1250 for (chp = var->obj_name; *chp; chp++)
1252 index = (index + (i++ * (unsigned int) *chp)) % VAROBJ_TABLE_SIZE;
1255 cv = *(varobj_table + index);
1257 while ((cv != NULL) && (strcmp (cv->var->obj_name, var->obj_name) != 0))
1264 fprintf_unfiltered (gdb_stdlog, "Deleting %s\n", var->obj_name);
1269 ("Assertion failed: Could not find variable object \"%s\" to delete",
1275 *(varobj_table + index) = cv->next;
1277 prev->next = cv->next;
1281 /* If root, remove varobj from root list */
1282 if (is_root_p (var))
1284 /* Remove from list of root variables */
1285 if (rootlist == var->root)
1286 rootlist = var->root->next;
1291 while ((cr != NULL) && (cr->rootvar != var))
1299 ("Assertion failed: Could not find varobj \"%s\" in root list",
1306 prer->next = cr->next;
1313 /* Create and install a child of the parent of the given name */
1314 static struct varobj *
1315 create_child (struct varobj *parent, int index, char *name)
1317 struct varobj *child;
1319 struct value *value;
1321 child = new_variable ();
1323 /* name is allocated by name_of_child */
1325 child->index = index;
1326 value = value_of_child (parent, index);
1327 child->parent = parent;
1328 child->root = parent->root;
1329 childs_name = xstrprintf ("%s.%s", parent->obj_name, name);
1330 child->obj_name = childs_name;
1331 install_variable (child);
1333 /* Compute the type of the child. Must do this before
1334 calling install_new_value. */
1336 /* If the child had no evaluation errors, var->value
1337 will be non-NULL and contain a valid type. */
1338 child->type = value_type (value);
1340 /* Otherwise, we must compute the type. */
1341 child->type = (*child->root->lang->type_of_child) (child->parent,
1343 install_new_value (child, value, 1);
1345 if ((!CPLUS_FAKE_CHILD (child) && child->value == NULL) || parent->error)
1353 * Miscellaneous utility functions.
1356 /* Allocate memory and initialize a new variable */
1357 static struct varobj *
1362 var = (struct varobj *) xmalloc (sizeof (struct varobj));
1364 var->obj_name = NULL;
1369 var->num_children = -1;
1371 var->children = NULL;
1379 /* Allocate memory and initialize a new root variable */
1380 static struct varobj *
1381 new_root_variable (void)
1383 struct varobj *var = new_variable ();
1384 var->root = (struct varobj_root *) xmalloc (sizeof (struct varobj_root));;
1385 var->root->lang = NULL;
1386 var->root->exp = NULL;
1387 var->root->valid_block = NULL;
1388 var->root->frame = null_frame_id;
1389 var->root->use_selected_frame = 0;
1390 var->root->rootvar = NULL;
1395 /* Free any allocated memory associated with VAR. */
1397 free_variable (struct varobj *var)
1399 /* Free the expression if this is a root variable. */
1400 if (is_root_p (var))
1402 free_current_contents (&var->root->exp);
1407 xfree (var->obj_name);
1412 do_free_variable_cleanup (void *var)
1414 free_variable (var);
1417 static struct cleanup *
1418 make_cleanup_free_variable (struct varobj *var)
1420 return make_cleanup (do_free_variable_cleanup, var);
1423 /* This returns the type of the variable. It also skips past typedefs
1424 to return the real type of the variable.
1426 NOTE: TYPE_TARGET_TYPE should NOT be used anywhere in this file
1427 except within get_target_type and get_type. */
1428 static struct type *
1429 get_type (struct varobj *var)
1435 type = check_typedef (type);
1440 /* This returns the type of the variable, dereferencing pointers, too. */
1441 static struct type *
1442 get_type_deref (struct varobj *var)
1446 type = get_type (var);
1448 if (type != NULL && (TYPE_CODE (type) == TYPE_CODE_PTR
1449 || TYPE_CODE (type) == TYPE_CODE_REF))
1450 type = get_target_type (type);
1455 /* This returns the target type (or NULL) of TYPE, also skipping
1456 past typedefs, just like get_type ().
1458 NOTE: TYPE_TARGET_TYPE should NOT be used anywhere in this file
1459 except within get_target_type and get_type. */
1460 static struct type *
1461 get_target_type (struct type *type)
1465 type = TYPE_TARGET_TYPE (type);
1467 type = check_typedef (type);
1473 /* What is the default display for this variable? We assume that
1474 everything is "natural". Any exceptions? */
1475 static enum varobj_display_formats
1476 variable_default_display (struct varobj *var)
1478 return FORMAT_NATURAL;
1481 /* FIXME: The following should be generic for any pointer */
1483 cppush (struct cpstack **pstack, char *name)
1487 s = (struct cpstack *) xmalloc (sizeof (struct cpstack));
1493 /* FIXME: The following should be generic for any pointer */
1495 cppop (struct cpstack **pstack)
1500 if ((*pstack)->name == NULL && (*pstack)->next == NULL)
1505 *pstack = (*pstack)->next;
1512 * Language-dependencies
1515 /* Common entry points */
1517 /* Get the language of variable VAR. */
1518 static enum varobj_languages
1519 variable_language (struct varobj *var)
1521 enum varobj_languages lang;
1523 switch (var->root->exp->language_defn->la_language)
1529 case language_cplus:
1540 /* Return the number of children for a given variable.
1541 The result of this function is defined by the language
1542 implementation. The number of children returned by this function
1543 is the number of children that the user will see in the variable
1546 number_of_children (struct varobj *var)
1548 return (*var->root->lang->number_of_children) (var);;
1551 /* What is the expression for the root varobj VAR? Returns a malloc'd string. */
1553 name_of_variable (struct varobj *var)
1555 return (*var->root->lang->name_of_variable) (var);
1558 /* What is the name of the INDEX'th child of VAR? Returns a malloc'd string. */
1560 name_of_child (struct varobj *var, int index)
1562 return (*var->root->lang->name_of_child) (var, index);
1565 /* What is the ``struct value *'' of the root variable VAR?
1566 TYPE_CHANGED controls what to do if the type of a
1567 use_selected_frame = 1 variable changes. On input,
1568 TYPE_CHANGED = 1 means discard the old varobj, and replace
1569 it with this one. TYPE_CHANGED = 0 means leave it around.
1570 NB: In both cases, var_handle will point to the new varobj,
1571 so if you use TYPE_CHANGED = 0, you will have to stash the
1572 old varobj pointer away somewhere before calling this.
1573 On return, TYPE_CHANGED will be 1 if the type has changed, and
1575 static struct value *
1576 value_of_root (struct varobj **var_handle, int *type_changed)
1580 if (var_handle == NULL)
1585 /* This should really be an exception, since this should
1586 only get called with a root variable. */
1588 if (!is_root_p (var))
1591 if (var->root->use_selected_frame)
1593 struct varobj *tmp_var;
1594 char *old_type, *new_type;
1595 old_type = varobj_get_type (var);
1596 tmp_var = varobj_create (NULL, var->name, (CORE_ADDR) 0,
1597 USE_SELECTED_FRAME);
1598 if (tmp_var == NULL)
1602 new_type = varobj_get_type (tmp_var);
1603 if (strcmp (old_type, new_type) == 0)
1605 varobj_delete (tmp_var, NULL, 0);
1613 savestring (var->obj_name, strlen (var->obj_name));
1614 varobj_delete (var, NULL, 0);
1618 tmp_var->obj_name = varobj_gen_name ();
1620 install_variable (tmp_var);
1621 *var_handle = tmp_var;
1631 return (*var->root->lang->value_of_root) (var_handle);
1634 /* What is the ``struct value *'' for the INDEX'th child of PARENT? */
1635 static struct value *
1636 value_of_child (struct varobj *parent, int index)
1638 struct value *value;
1640 value = (*parent->root->lang->value_of_child) (parent, index);
1645 /* Is this variable editable? Use the variable's type to make
1646 this determination. */
1648 variable_editable (struct varobj *var)
1650 return (*var->root->lang->variable_editable) (var);
1653 /* GDB already has a command called "value_of_variable". Sigh. */
1655 my_value_of_variable (struct varobj *var)
1657 return (*var->root->lang->value_of_variable) (var);
1660 /* Return non-zero if changes in value of VAR
1661 must be detected and reported by -var-update.
1662 Return zero is -var-update should never report
1663 changes of such values. This makes sense for structures
1664 (since the changes in children values will be reported separately),
1665 or for artifical objects (like 'public' pseudo-field in C++).
1667 Return value of 0 means that gdb need not call value_fetch_lazy
1668 for the value of this variable object. */
1670 varobj_value_is_changeable_p (struct varobj *var)
1675 if (CPLUS_FAKE_CHILD (var))
1678 type = get_type (var);
1680 switch (TYPE_CODE (type))
1682 case TYPE_CODE_STRUCT:
1683 case TYPE_CODE_UNION:
1684 case TYPE_CODE_ARRAY:
1697 c_number_of_children (struct varobj *var)
1700 struct type *target;
1703 type = get_type (var);
1704 target = get_target_type (type);
1707 switch (TYPE_CODE (type))
1709 case TYPE_CODE_ARRAY:
1710 if (TYPE_LENGTH (type) > 0 && TYPE_LENGTH (target) > 0
1711 && TYPE_ARRAY_UPPER_BOUND_TYPE (type) != BOUND_CANNOT_BE_DETERMINED)
1712 children = TYPE_LENGTH (type) / TYPE_LENGTH (target);
1717 case TYPE_CODE_STRUCT:
1718 case TYPE_CODE_UNION:
1719 children = TYPE_NFIELDS (type);
1723 /* This is where things get compilcated. All pointers have one child.
1724 Except, of course, for struct and union ptr, which we automagically
1725 dereference for the user and function ptrs, which have no children.
1726 We also don't dereference void* as we don't know what to show.
1727 We can show char* so we allow it to be dereferenced. If you decide
1728 to test for it, please mind that a little magic is necessary to
1729 properly identify it: char* has TYPE_CODE == TYPE_CODE_INT and
1730 TYPE_NAME == "char" */
1732 switch (TYPE_CODE (target))
1734 case TYPE_CODE_STRUCT:
1735 case TYPE_CODE_UNION:
1736 children = TYPE_NFIELDS (target);
1739 case TYPE_CODE_FUNC:
1740 case TYPE_CODE_VOID:
1750 /* Other types have no children */
1758 c_name_of_variable (struct varobj *parent)
1760 return savestring (parent->name, strlen (parent->name));
1763 /* Return the value of element TYPE_INDEX of a structure
1764 value VALUE. VALUE's type should be a structure,
1765 or union, or a typedef to struct/union.
1767 Returns NULL if getting the value fails. Never throws. */
1768 static struct value *
1769 value_struct_element_index (struct value *value, int type_index)
1771 struct value *result = NULL;
1772 volatile struct gdb_exception e;
1774 struct type *type = value_type (value);
1775 type = check_typedef (type);
1777 gdb_assert (TYPE_CODE (type) == TYPE_CODE_STRUCT
1778 || TYPE_CODE (type) == TYPE_CODE_UNION);
1780 TRY_CATCH (e, RETURN_MASK_ERROR)
1782 if (TYPE_FIELD_STATIC (type, type_index))
1783 result = value_static_field (type, type_index);
1785 result = value_primitive_field (value, 0, type_index, type);
1797 /* Obtain the information about child INDEX of the variable
1799 If CNAME is not null, sets *CNAME to the name of the child relative
1801 If CVALUE is not null, sets *CVALUE to the value of the child.
1802 If CTYPE is not null, sets *CTYPE to the type of the child.
1804 If any of CNAME, CVALUE, or CTYPE is not null, but the corresponding
1805 information cannot be determined, set *CNAME, *CVALUE, or *CTYPE
1808 c_describe_child (struct varobj *parent, int index,
1809 char **cname, struct value **cvalue, struct type **ctype)
1811 struct value *value = parent->value;
1812 struct type *type = get_type (parent);
1821 /* Pointers to structures are treated just like
1822 structures when accessing children. */
1823 if (TYPE_CODE (type) == TYPE_CODE_PTR)
1825 struct type *target_type = get_target_type (type);
1826 if (TYPE_CODE (target_type) == TYPE_CODE_STRUCT
1827 || TYPE_CODE (target_type) == TYPE_CODE_UNION)
1830 gdb_value_ind (value, &value);
1835 switch (TYPE_CODE (type))
1837 case TYPE_CODE_ARRAY:
1839 *cname = xstrprintf ("%d", index
1840 + TYPE_LOW_BOUND (TYPE_INDEX_TYPE (type)));
1842 if (cvalue && value)
1844 int real_index = index + TYPE_LOW_BOUND (TYPE_INDEX_TYPE (type));
1845 struct value *indval =
1846 value_from_longest (builtin_type_int, (LONGEST) real_index);
1847 gdb_value_subscript (value, indval, cvalue);
1851 *ctype = get_target_type (type);
1855 case TYPE_CODE_STRUCT:
1856 case TYPE_CODE_UNION:
1859 char *string = TYPE_FIELD_NAME (type, index);
1860 *cname = savestring (string, strlen (string));
1863 if (cvalue && value)
1865 /* For C, varobj index is the same as type index. */
1866 *cvalue = value_struct_element_index (value, index);
1870 *ctype = TYPE_FIELD_TYPE (type, index);
1876 *cname = xstrprintf ("*%s", parent->name);
1878 if (cvalue && value)
1879 gdb_value_ind (value, cvalue);
1882 *ctype = get_target_type (type);
1887 /* This should not happen */
1889 *cname = xstrdup ("???");
1890 /* Don't set value and type, we don't know then. */
1895 c_name_of_child (struct varobj *parent, int index)
1898 c_describe_child (parent, index, &name, NULL, NULL);
1902 static struct value *
1903 c_value_of_root (struct varobj **var_handle)
1905 struct value *new_val;
1906 struct varobj *var = *var_handle;
1907 struct frame_info *fi;
1910 /* Only root variables can be updated... */
1911 if (!is_root_p (var))
1912 /* Not a root var */
1916 /* Determine whether the variable is still around. */
1917 if (var->root->valid_block == NULL)
1921 reinit_frame_cache ();
1922 fi = frame_find_by_id (var->root->frame);
1923 within_scope = fi != NULL;
1924 /* FIXME: select_frame could fail */
1927 CORE_ADDR pc = get_frame_pc (fi);
1928 if (pc < BLOCK_START (var->root->valid_block) ||
1929 pc >= BLOCK_END (var->root->valid_block))
1937 /* We need to catch errors here, because if evaluate
1938 expression fails we just want to make val->error = 1 and
1940 if (gdb_evaluate_expression (var->root->exp, &new_val))
1943 release_value (new_val);
1954 static struct value *
1955 c_value_of_child (struct varobj *parent, int index)
1957 struct value *value = NULL;
1958 c_describe_child (parent, index, NULL, &value, NULL);
1960 release_value (value);
1965 static struct type *
1966 c_type_of_child (struct varobj *parent, int index)
1968 struct type *type = NULL;
1969 c_describe_child (parent, index, NULL, NULL, &type);
1974 c_variable_editable (struct varobj *var)
1976 switch (TYPE_CODE (get_type (var)))
1978 case TYPE_CODE_STRUCT:
1979 case TYPE_CODE_UNION:
1980 case TYPE_CODE_ARRAY:
1981 case TYPE_CODE_FUNC:
1982 case TYPE_CODE_METHOD:
1993 c_value_of_variable (struct varobj *var)
1995 /* BOGUS: if val_print sees a struct/class, or a reference to one,
1996 it will print out its children instead of "{...}". So we need to
1997 catch that case explicitly. */
1998 struct type *type = get_type (var);
2000 /* Strip top-level references. */
2001 while (TYPE_CODE (type) == TYPE_CODE_REF)
2002 type = check_typedef (TYPE_TARGET_TYPE (type));
2004 switch (TYPE_CODE (type))
2006 case TYPE_CODE_STRUCT:
2007 case TYPE_CODE_UNION:
2008 return xstrdup ("{...}");
2011 case TYPE_CODE_ARRAY:
2014 number = xstrprintf ("[%d]", var->num_children);
2021 if (var->value == NULL)
2023 /* This can happen if we attempt to get the value of a struct
2024 member when the parent is an invalid pointer. This is an
2025 error condition, so we should tell the caller. */
2031 struct ui_file *stb = mem_fileopen ();
2032 struct cleanup *old_chain = make_cleanup_ui_file_delete (stb);
2035 gdb_assert (varobj_value_is_changeable_p (var));
2036 gdb_assert (!value_lazy (var->value));
2037 common_val_print (var->value, stb,
2038 format_code[(int) var->format], 1, 0, 0);
2039 thevalue = ui_file_xstrdup (stb, &dummy);
2040 do_cleanups (old_chain);
2051 cplus_number_of_children (struct varobj *var)
2054 int children, dont_know;
2059 if (!CPLUS_FAKE_CHILD (var))
2061 type = get_type_deref (var);
2063 if (((TYPE_CODE (type)) == TYPE_CODE_STRUCT) ||
2064 ((TYPE_CODE (type)) == TYPE_CODE_UNION))
2068 cplus_class_num_children (type, kids);
2069 if (kids[v_public] != 0)
2071 if (kids[v_private] != 0)
2073 if (kids[v_protected] != 0)
2076 /* Add any baseclasses */
2077 children += TYPE_N_BASECLASSES (type);
2080 /* FIXME: save children in var */
2087 type = get_type_deref (var->parent);
2089 cplus_class_num_children (type, kids);
2090 if (strcmp (var->name, "public") == 0)
2091 children = kids[v_public];
2092 else if (strcmp (var->name, "private") == 0)
2093 children = kids[v_private];
2095 children = kids[v_protected];
2100 children = c_number_of_children (var);
2105 /* Compute # of public, private, and protected variables in this class.
2106 That means we need to descend into all baseclasses and find out
2107 how many are there, too. */
2109 cplus_class_num_children (struct type *type, int children[3])
2113 children[v_public] = 0;
2114 children[v_private] = 0;
2115 children[v_protected] = 0;
2117 for (i = TYPE_N_BASECLASSES (type); i < TYPE_NFIELDS (type); i++)
2119 /* If we have a virtual table pointer, omit it. */
2120 if (TYPE_VPTR_BASETYPE (type) == type && TYPE_VPTR_FIELDNO (type) == i)
2123 if (TYPE_FIELD_PROTECTED (type, i))
2124 children[v_protected]++;
2125 else if (TYPE_FIELD_PRIVATE (type, i))
2126 children[v_private]++;
2128 children[v_public]++;
2133 cplus_name_of_variable (struct varobj *parent)
2135 return c_name_of_variable (parent);
2139 cplus_name_of_child (struct varobj *parent, int index)
2144 if (CPLUS_FAKE_CHILD (parent))
2146 /* Looking for children of public, private, or protected. */
2147 type = get_type_deref (parent->parent);
2150 type = get_type_deref (parent);
2153 switch (TYPE_CODE (type))
2155 case TYPE_CODE_STRUCT:
2156 case TYPE_CODE_UNION:
2157 if (CPLUS_FAKE_CHILD (parent))
2159 /* The fields of the class type are ordered as they
2160 appear in the class. We are given an index for a
2161 particular access control type ("public","protected",
2162 or "private"). We must skip over fields that don't
2163 have the access control we are looking for to properly
2164 find the indexed field. */
2165 int type_index = TYPE_N_BASECLASSES (type);
2166 if (strcmp (parent->name, "private") == 0)
2170 if (TYPE_VPTR_BASETYPE (type) == type
2171 && type_index == TYPE_VPTR_FIELDNO (type))
2173 else if (TYPE_FIELD_PRIVATE (type, type_index))
2179 else if (strcmp (parent->name, "protected") == 0)
2183 if (TYPE_VPTR_BASETYPE (type) == type
2184 && type_index == TYPE_VPTR_FIELDNO (type))
2186 else if (TYPE_FIELD_PROTECTED (type, type_index))
2196 if (TYPE_VPTR_BASETYPE (type) == type
2197 && type_index == TYPE_VPTR_FIELDNO (type))
2199 else if (!TYPE_FIELD_PRIVATE (type, type_index) &&
2200 !TYPE_FIELD_PROTECTED (type, type_index))
2207 name = TYPE_FIELD_NAME (type, type_index);
2209 else if (index < TYPE_N_BASECLASSES (type))
2210 /* We are looking up the name of a base class */
2211 name = TYPE_FIELD_NAME (type, index);
2215 cplus_class_num_children(type, children);
2217 /* Everything beyond the baseclasses can
2218 only be "public", "private", or "protected"
2220 The special "fake" children are always output by varobj in
2221 this order. So if INDEX == 2, it MUST be "protected". */
2222 index -= TYPE_N_BASECLASSES (type);
2226 if (children[v_public] > 0)
2228 else if (children[v_private] > 0)
2234 if (children[v_public] > 0)
2236 if (children[v_private] > 0)
2241 else if (children[v_private] > 0)
2245 /* Must be protected */
2260 return c_name_of_child (parent, index);
2264 name = savestring (name, strlen (name));
2270 static struct value *
2271 cplus_value_of_root (struct varobj **var_handle)
2273 return c_value_of_root (var_handle);
2276 static struct value *
2277 cplus_value_of_child (struct varobj *parent, int index)
2280 struct value *value;
2282 if (CPLUS_FAKE_CHILD (parent))
2283 type = get_type_deref (parent->parent);
2285 type = get_type_deref (parent);
2289 if (((TYPE_CODE (type)) == TYPE_CODE_STRUCT) ||
2290 ((TYPE_CODE (type)) == TYPE_CODE_UNION))
2292 if (CPLUS_FAKE_CHILD (parent))
2295 struct value *temp = parent->parent->value;
2300 name = name_of_child (parent, index);
2301 gdb_value_struct_elt (NULL, &value, &temp, NULL, name, NULL,
2304 release_value (value);
2308 else if (index >= TYPE_N_BASECLASSES (type))
2310 /* public, private, or protected */
2316 if (parent->value != NULL)
2318 struct value *temp = NULL;
2320 /* No special processing for references is needed --
2321 value_cast below handles references. */
2322 if (TYPE_CODE (value_type (parent->value)) == TYPE_CODE_PTR)
2324 if (!gdb_value_ind (parent->value, &temp))
2328 temp = parent->value;
2332 value = value_cast (TYPE_FIELD_TYPE (type, index), temp);
2333 release_value (value);
2337 /* We failed to evaluate the parent's value, so don't even
2338 bother trying to evaluate this child. */
2346 return c_value_of_child (parent, index);
2351 static struct type *
2352 cplus_type_of_child (struct varobj *parent, int index)
2354 struct type *type, *t;
2356 if (CPLUS_FAKE_CHILD (parent))
2358 /* Looking for the type of a child of public, private, or protected. */
2359 t = get_type_deref (parent->parent);
2362 t = get_type_deref (parent);
2365 switch (TYPE_CODE (t))
2367 case TYPE_CODE_STRUCT:
2368 case TYPE_CODE_UNION:
2369 if (CPLUS_FAKE_CHILD (parent))
2371 char *name = cplus_name_of_child (parent, index);
2372 type = lookup_struct_elt_type (t, name, 0);
2375 else if (index < TYPE_N_BASECLASSES (t))
2376 type = TYPE_FIELD_TYPE (t, index);
2389 return c_type_of_child (parent, index);
2395 cplus_variable_editable (struct varobj *var)
2397 if (CPLUS_FAKE_CHILD (var))
2400 return c_variable_editable (var);
2404 cplus_value_of_variable (struct varobj *var)
2407 /* If we have one of our special types, don't print out
2409 if (CPLUS_FAKE_CHILD (var))
2410 return xstrdup ("");
2412 return c_value_of_variable (var);
2418 java_number_of_children (struct varobj *var)
2420 return cplus_number_of_children (var);
2424 java_name_of_variable (struct varobj *parent)
2428 name = cplus_name_of_variable (parent);
2429 /* If the name has "-" in it, it is because we
2430 needed to escape periods in the name... */
2433 while (*p != '\000')
2444 java_name_of_child (struct varobj *parent, int index)
2448 name = cplus_name_of_child (parent, index);
2449 /* Escape any periods in the name... */
2452 while (*p != '\000')
2462 static struct value *
2463 java_value_of_root (struct varobj **var_handle)
2465 return cplus_value_of_root (var_handle);
2468 static struct value *
2469 java_value_of_child (struct varobj *parent, int index)
2471 return cplus_value_of_child (parent, index);
2474 static struct type *
2475 java_type_of_child (struct varobj *parent, int index)
2477 return cplus_type_of_child (parent, index);
2481 java_variable_editable (struct varobj *var)
2483 return cplus_variable_editable (var);
2487 java_value_of_variable (struct varobj *var)
2489 return cplus_value_of_variable (var);
2492 extern void _initialize_varobj (void);
2494 _initialize_varobj (void)
2496 int sizeof_table = sizeof (struct vlist *) * VAROBJ_TABLE_SIZE;
2498 varobj_table = xmalloc (sizeof_table);
2499 memset (varobj_table, 0, sizeof_table);
2501 add_setshow_zinteger_cmd ("debugvarobj", class_maintenance,
2503 Set varobj debugging."), _("\
2504 Show varobj debugging."), _("\
2505 When non-zero, varobj debugging is enabled."),
2508 &setlist, &showlist);