1 /* Implementation of the GDB variable objects API.
3 Copyright 1999, 2000, 2001, 2005 Free Software Foundation, Inc.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. */
21 #include "exceptions.h"
23 #include "expression.h"
29 #include "gdb_assert.h"
30 #include "gdb_string.h"
34 /* Non-zero if we want to see trace of varobj level stuff. */
38 show_varobjdebug (struct ui_file *file, int from_tty,
39 struct cmd_list_element *c, const char *value)
41 fprintf_filtered (file, _("Varobj debugging is %s.\n"), value);
44 /* String representations of gdb's format codes */
45 char *varobj_format_string[] =
46 { "natural", "binary", "decimal", "hexadecimal", "octal" };
48 /* String representations of gdb's known languages */
49 char *varobj_language_string[] = { "unknown", "C", "C++", "Java" };
53 /* Every root variable has one of these structures saved in its
54 varobj. Members which must be free'd are noted. */
58 /* Alloc'd expression for this parent. */
59 struct expression *exp;
61 /* Block for which this expression is valid */
62 struct block *valid_block;
64 /* The frame for this expression */
65 struct frame_id frame;
67 /* If 1, "update" always recomputes the frame & valid block
68 using the currently selected frame. */
69 int use_selected_frame;
71 /* Language info for this variable and its children */
72 struct language_specific *lang;
74 /* The varobj for this root node. */
75 struct varobj *rootvar;
77 /* Next root variable */
78 struct varobj_root *next;
81 /* Every variable in the system has a structure of this type defined
82 for it. This structure holds all information necessary to manipulate
83 a particular object variable. Members which must be freed are noted. */
87 /* Alloc'd name of the variable for this object.. If this variable is a
88 child, then this name will be the child's source name.
90 /* NOTE: This is the "expression" */
93 /* The alloc'd name for this variable's object. This is here for
94 convenience when constructing this object's children. */
97 /* Index of this variable in its parent or -1 */
100 /* The type of this variable. This may NEVER be NULL. */
103 /* The value of this expression or subexpression. This may be NULL. */
106 /* Did an error occur evaluating the expression or getting its value? */
109 /* The number of (immediate) children this variable has */
112 /* If this object is a child, this points to its immediate parent. */
113 struct varobj *parent;
115 /* A list of this object's children */
116 struct varobj_child *children;
118 /* Description of the root variable. Points to root variable for children. */
119 struct varobj_root *root;
121 /* The format of the output for this object */
122 enum varobj_display_formats format;
124 /* Was this variable updated via a varobj_set_value operation */
128 /* Every variable keeps a linked list of its children, described
129 by the following structure. */
130 /* FIXME: Deprecated. All should use vlist instead */
135 /* Pointer to the child's data */
136 struct varobj *child;
138 /* Pointer to the next child */
139 struct varobj_child *next;
142 /* A stack of varobjs */
143 /* FIXME: Deprecated. All should use vlist instead */
154 struct cpstack *next;
157 /* A list of varobjs */
165 /* Private function prototypes */
167 /* Helper functions for the above subcommands. */
169 static int delete_variable (struct cpstack **, struct varobj *, int);
171 static void delete_variable_1 (struct cpstack **, int *,
172 struct varobj *, int, int);
174 static int install_variable (struct varobj *);
176 static void uninstall_variable (struct varobj *);
178 static struct varobj *child_exists (struct varobj *, char *);
180 static struct varobj *create_child (struct varobj *, int, char *);
182 static void save_child_in_parent (struct varobj *, struct varobj *);
184 static void remove_child_from_parent (struct varobj *, struct varobj *);
186 /* Utility routines */
188 static struct varobj *new_variable (void);
190 static struct varobj *new_root_variable (void);
192 static void free_variable (struct varobj *var);
194 static struct cleanup *make_cleanup_free_variable (struct varobj *var);
196 static struct type *get_type (struct varobj *var);
198 static struct type *get_type_deref (struct varobj *var);
200 static struct type *get_target_type (struct type *);
202 static enum varobj_display_formats variable_default_display (struct varobj *);
204 static int my_value_equal (struct value *, struct value *, int *);
206 static void vpush (struct vstack **pstack, struct varobj *var);
208 static struct varobj *vpop (struct vstack **pstack);
210 static void cppush (struct cpstack **pstack, char *name);
212 static char *cppop (struct cpstack **pstack);
214 /* Language-specific routines. */
216 static enum varobj_languages variable_language (struct varobj *var);
218 static int number_of_children (struct varobj *);
220 static char *name_of_variable (struct varobj *);
222 static char *name_of_child (struct varobj *, int);
224 static struct value *value_of_root (struct varobj **var_handle, int *);
226 static struct value *value_of_child (struct varobj *parent, int index);
228 static struct type *type_of_child (struct varobj *var);
230 static int variable_editable (struct varobj *var);
232 static char *my_value_of_variable (struct varobj *var);
234 static int type_changeable (struct varobj *var);
236 /* C implementation */
238 static int c_number_of_children (struct varobj *var);
240 static char *c_name_of_variable (struct varobj *parent);
242 static char *c_name_of_child (struct varobj *parent, int index);
244 static struct value *c_value_of_root (struct varobj **var_handle);
246 static struct value *c_value_of_child (struct varobj *parent, int index);
248 static struct type *c_type_of_child (struct varobj *parent, int index);
250 static int c_variable_editable (struct varobj *var);
252 static char *c_value_of_variable (struct varobj *var);
254 /* C++ implementation */
256 static int cplus_number_of_children (struct varobj *var);
258 static void cplus_class_num_children (struct type *type, int children[3]);
260 static char *cplus_name_of_variable (struct varobj *parent);
262 static char *cplus_name_of_child (struct varobj *parent, int index);
264 static struct value *cplus_value_of_root (struct varobj **var_handle);
266 static struct value *cplus_value_of_child (struct varobj *parent, int index);
268 static struct type *cplus_type_of_child (struct varobj *parent, int index);
270 static int cplus_variable_editable (struct varobj *var);
272 static char *cplus_value_of_variable (struct varobj *var);
274 /* Java implementation */
276 static int java_number_of_children (struct varobj *var);
278 static char *java_name_of_variable (struct varobj *parent);
280 static char *java_name_of_child (struct varobj *parent, int index);
282 static struct value *java_value_of_root (struct varobj **var_handle);
284 static struct value *java_value_of_child (struct varobj *parent, int index);
286 static struct type *java_type_of_child (struct varobj *parent, int index);
288 static int java_variable_editable (struct varobj *var);
290 static char *java_value_of_variable (struct varobj *var);
292 /* The language specific vector */
294 struct language_specific
297 /* The language of this variable */
298 enum varobj_languages language;
300 /* The number of children of PARENT. */
301 int (*number_of_children) (struct varobj * parent);
303 /* The name (expression) of a root varobj. */
304 char *(*name_of_variable) (struct varobj * parent);
306 /* The name of the INDEX'th child of PARENT. */
307 char *(*name_of_child) (struct varobj * parent, int index);
309 /* The ``struct value *'' of the root variable ROOT. */
310 struct value *(*value_of_root) (struct varobj ** root_handle);
312 /* The ``struct value *'' of the INDEX'th child of PARENT. */
313 struct value *(*value_of_child) (struct varobj * parent, int index);
315 /* The type of the INDEX'th child of PARENT. */
316 struct type *(*type_of_child) (struct varobj * parent, int index);
318 /* Is VAR editable? */
319 int (*variable_editable) (struct varobj * var);
321 /* The current value of VAR. */
322 char *(*value_of_variable) (struct varobj * var);
325 /* Array of known source language routines. */
326 static struct language_specific
327 languages[vlang_end][sizeof (struct language_specific)] = {
328 /* Unknown (try treating as C */
331 c_number_of_children,
343 c_number_of_children,
355 cplus_number_of_children,
356 cplus_name_of_variable,
359 cplus_value_of_child,
361 cplus_variable_editable,
362 cplus_value_of_variable}
367 java_number_of_children,
368 java_name_of_variable,
373 java_variable_editable,
374 java_value_of_variable}
377 /* A little convenience enum for dealing with C++/Java */
380 v_public = 0, v_private, v_protected
385 /* Mappings of varobj_display_formats enums to gdb's format codes */
386 static int format_code[] = { 0, 't', 'd', 'x', 'o' };
388 /* Header of the list of root variable objects */
389 static struct varobj_root *rootlist;
390 static int rootcount = 0; /* number of root varobjs in the list */
392 /* Prime number indicating the number of buckets in the hash table */
393 /* A prime large enough to avoid too many colisions */
394 #define VAROBJ_TABLE_SIZE 227
396 /* Pointer to the varobj hash table (built at run time) */
397 static struct vlist **varobj_table;
399 /* Is the variable X one of our "fake" children? */
400 #define CPLUS_FAKE_CHILD(x) \
401 ((x) != NULL && (x)->type == NULL && (x)->value == NULL)
404 /* API Implementation */
406 /* Creates a varobj (not its children) */
408 /* Return the full FRAME which corresponds to the given CORE_ADDR
409 or NULL if no FRAME on the chain corresponds to CORE_ADDR. */
411 static struct frame_info *
412 find_frame_addr_in_frame_chain (CORE_ADDR frame_addr)
414 struct frame_info *frame = NULL;
416 if (frame_addr == (CORE_ADDR) 0)
421 frame = get_prev_frame (frame);
424 if (get_frame_base_address (frame) == frame_addr)
430 varobj_create (char *objname,
431 char *expression, CORE_ADDR frame, enum varobj_type type)
434 struct frame_info *fi;
435 struct frame_info *old_fi = NULL;
437 struct cleanup *old_chain;
439 /* Fill out a varobj structure for the (root) variable being constructed. */
440 var = new_root_variable ();
441 old_chain = make_cleanup_free_variable (var);
443 if (expression != NULL)
446 enum varobj_languages lang;
448 /* Parse and evaluate the expression, filling in as much
449 of the variable's data as possible */
451 /* Allow creator to specify context of variable */
452 if ((type == USE_CURRENT_FRAME) || (type == USE_SELECTED_FRAME))
453 fi = deprecated_selected_frame;
455 /* FIXME: cagney/2002-11-23: This code should be doing a
456 lookup using the frame ID and not just the frame's
457 ``address''. This, of course, means an interface change.
458 However, with out that interface change ISAs, such as the
459 ia64 with its two stacks, won't work. Similar goes for the
460 case where there is a frameless function. */
461 fi = find_frame_addr_in_frame_chain (frame);
463 /* frame = -2 means always use selected frame */
464 if (type == USE_SELECTED_FRAME)
465 var->root->use_selected_frame = 1;
469 block = get_frame_block (fi, 0);
472 innermost_block = NULL;
473 /* Wrap the call to parse expression, so we can
474 return a sensible error. */
475 if (!gdb_parse_exp_1 (&p, block, 0, &var->root->exp))
480 /* Don't allow variables to be created for types. */
481 if (var->root->exp->elts[0].opcode == OP_TYPE)
483 do_cleanups (old_chain);
484 fprintf_unfiltered (gdb_stderr, "Attempt to use a type name"
485 " as an expression.\n");
489 var->format = variable_default_display (var);
490 var->root->valid_block = innermost_block;
491 var->name = savestring (expression, strlen (expression));
493 /* When the frame is different from the current frame,
494 we must select the appropriate frame before parsing
495 the expression, otherwise the value will not be current.
496 Since select_frame is so benign, just call it for all cases. */
499 var->root->frame = get_frame_id (fi);
500 old_fi = deprecated_selected_frame;
504 /* We definitively need to catch errors here.
505 If evaluate_expression succeeds we got the value we wanted.
506 But if it fails, we still go on with a call to evaluate_type() */
507 if (gdb_evaluate_expression (var->root->exp, &var->value))
510 release_value (var->value);
511 if (value_lazy (var->value))
512 gdb_value_fetch_lazy (var->value);
515 var->value = evaluate_type (var->root->exp);
517 var->type = value_type (var->value);
519 /* Set language info */
520 lang = variable_language (var);
521 var->root->lang = languages[lang];
523 /* Set ourselves as our root */
524 var->root->rootvar = var;
526 /* Reset the selected frame */
528 select_frame (old_fi);
531 /* If the variable object name is null, that means this
532 is a temporary variable, so don't install it. */
534 if ((var != NULL) && (objname != NULL))
536 var->obj_name = savestring (objname, strlen (objname));
538 /* If a varobj name is duplicated, the install will fail so
540 if (!install_variable (var))
542 do_cleanups (old_chain);
547 discard_cleanups (old_chain);
551 /* Generates an unique name that can be used for a varobj */
554 varobj_gen_name (void)
559 /* generate a name for this object */
561 obj_name = xstrprintf ("var%d", id);
566 /* Given an "objname", returns the pointer to the corresponding varobj
567 or NULL if not found */
570 varobj_get_handle (char *objname)
574 unsigned int index = 0;
577 for (chp = objname; *chp; chp++)
579 index = (index + (i++ * (unsigned int) *chp)) % VAROBJ_TABLE_SIZE;
582 cv = *(varobj_table + index);
583 while ((cv != NULL) && (strcmp (cv->var->obj_name, objname) != 0))
587 error (_("Variable object not found"));
592 /* Given the handle, return the name of the object */
595 varobj_get_objname (struct varobj *var)
597 return var->obj_name;
600 /* Given the handle, return the expression represented by the object */
603 varobj_get_expression (struct varobj *var)
605 return name_of_variable (var);
608 /* Deletes a varobj and all its children if only_children == 0,
609 otherwise deletes only the children; returns a malloc'ed list of all the
610 (malloc'ed) names of the variables that have been deleted (NULL terminated) */
613 varobj_delete (struct varobj *var, char ***dellist, int only_children)
617 struct cpstack *result = NULL;
620 /* Initialize a stack for temporary results */
621 cppush (&result, NULL);
624 /* Delete only the variable children */
625 delcount = delete_variable (&result, var, 1 /* only the children */ );
627 /* Delete the variable and all its children */
628 delcount = delete_variable (&result, var, 0 /* parent+children */ );
630 /* We may have been asked to return a list of what has been deleted */
633 *dellist = xmalloc ((delcount + 1) * sizeof (char *));
637 *cp = cppop (&result);
638 while ((*cp != NULL) && (mycount > 0))
642 *cp = cppop (&result);
645 if (mycount || (*cp != NULL))
646 warning (_("varobj_delete: assertion failed - mycount(=%d) <> 0"),
653 /* Set/Get variable object display format */
655 enum varobj_display_formats
656 varobj_set_display_format (struct varobj *var,
657 enum varobj_display_formats format)
664 case FORMAT_HEXADECIMAL:
666 var->format = format;
670 var->format = variable_default_display (var);
676 enum varobj_display_formats
677 varobj_get_display_format (struct varobj *var)
683 varobj_get_num_children (struct varobj *var)
685 if (var->num_children == -1)
686 var->num_children = number_of_children (var);
688 return var->num_children;
691 /* Creates a list of the immediate children of a variable object;
692 the return code is the number of such children or -1 on error */
695 varobj_list_children (struct varobj *var, struct varobj ***childlist)
697 struct varobj *child;
701 /* sanity check: have we been passed a pointer? */
702 if (childlist == NULL)
707 if (var->num_children == -1)
708 var->num_children = number_of_children (var);
710 /* List of children */
711 *childlist = xmalloc ((var->num_children + 1) * sizeof (struct varobj *));
713 for (i = 0; i < var->num_children; i++)
715 /* Mark as the end in case we bail out */
716 *((*childlist) + i) = NULL;
718 /* check if child exists, if not create */
719 name = name_of_child (var, i);
720 child = child_exists (var, name);
722 child = create_child (var, i, name);
724 *((*childlist) + i) = child;
727 /* End of list is marked by a NULL pointer */
728 *((*childlist) + i) = NULL;
730 return var->num_children;
733 /* Obtain the type of an object Variable as a string similar to the one gdb
734 prints on the console */
737 varobj_get_type (struct varobj *var)
740 struct cleanup *old_chain;
745 /* For the "fake" variables, do not return a type. (It's type is
747 if (CPLUS_FAKE_CHILD (var))
750 stb = mem_fileopen ();
751 old_chain = make_cleanup_ui_file_delete (stb);
753 /* To print the type, we simply create a zero ``struct value *'' and
754 cast it to our type. We then typeprint this variable. */
755 val = value_zero (var->type, not_lval);
756 type_print (value_type (val), "", stb, -1);
758 thetype = ui_file_xstrdup (stb, &length);
759 do_cleanups (old_chain);
763 enum varobj_languages
764 varobj_get_language (struct varobj *var)
766 return variable_language (var);
770 varobj_get_attributes (struct varobj *var)
774 if (variable_editable (var))
775 /* FIXME: define masks for attributes */
776 attributes |= 0x00000001; /* Editable */
782 varobj_get_value (struct varobj *var)
784 return my_value_of_variable (var);
787 /* Set the value of an object variable (if it is editable) to the
788 value of the given expression */
789 /* Note: Invokes functions that can call error() */
792 varobj_set_value (struct varobj *var, char *expression)
798 /* The argument "expression" contains the variable's new value.
799 We need to first construct a legal expression for this -- ugh! */
800 /* Does this cover all the bases? */
801 struct expression *exp;
803 int saved_input_radix = input_radix;
805 if (var->value != NULL && variable_editable (var) && !var->error)
807 char *s = expression;
810 input_radix = 10; /* ALWAYS reset to decimal temporarily */
811 if (!gdb_parse_exp_1 (&s, 0, 0, &exp))
812 /* We cannot proceed without a well-formed expression. */
814 if (!gdb_evaluate_expression (exp, &value))
816 /* We cannot proceed without a valid expression. */
821 if (!my_value_equal (var->value, value, &error))
823 if (!gdb_value_assign (var->value, value, &val))
825 value_free (var->value);
828 input_radix = saved_input_radix;
835 /* Returns a malloc'ed list with all root variable objects */
837 varobj_list (struct varobj ***varlist)
840 struct varobj_root *croot;
841 int mycount = rootcount;
843 /* Alloc (rootcount + 1) entries for the result */
844 *varlist = xmalloc ((rootcount + 1) * sizeof (struct varobj *));
848 while ((croot != NULL) && (mycount > 0))
850 *cv = croot->rootvar;
855 /* Mark the end of the list */
858 if (mycount || (croot != NULL))
860 ("varobj_list: assertion failed - wrong tally of root vars (%d:%d)",
866 /* Update the values for a variable and its children. This is a
867 two-pronged attack. First, re-parse the value for the root's
868 expression to see if it's changed. Then go all the way
869 through its children, reconstructing them and noting if they've
872 -1 if there was an error updating the varobj
873 -2 if the type changed
874 Otherwise it is the number of children + parent changed
876 Only root variables can be updated...
878 NOTE: This function may delete the caller's varobj. If it
879 returns -2, then it has done this and VARP will be modified
880 to point to the new varobj. */
883 varobj_update (struct varobj **varp, struct varobj ***changelist)
892 struct varobj **templist = NULL;
894 struct vstack *stack = NULL;
895 struct vstack *result = NULL;
896 struct frame_id old_fid;
897 struct frame_info *fi;
899 /* sanity check: have we been passed a pointer? */
900 if (changelist == NULL)
903 /* Only root variables can be updated... */
904 if ((*varp)->root->rootvar != *varp)
908 /* Save the selected stack frame, since we will need to change it
909 in order to evaluate expressions. */
910 old_fid = get_frame_id (deprecated_selected_frame);
912 /* Update the root variable. value_of_root can return NULL
913 if the variable is no longer around, i.e. we stepped out of
914 the frame in which a local existed. We are letting the
915 value_of_root variable dispose of the varobj if the type
918 new = value_of_root (varp, &type_changed);
925 /* Initialize a stack for temporary results */
926 vpush (&result, NULL);
928 /* If this is a "use_selected_frame" varobj, and its type has changed,
929 them note that it's changed. */
932 vpush (&result, *varp);
935 /* If values are not equal, note that it's changed.
936 There a couple of exceptions here, though.
937 We don't want some types to be reported as "changed". */
938 else if (type_changeable (*varp) &&
939 ((*varp)->updated || !my_value_equal ((*varp)->value, new, &error)))
941 vpush (&result, *varp);
942 (*varp)->updated = 0;
944 /* Its value is going to be updated to NEW. */
945 (*varp)->error = error;
948 /* We must always keep around the new value for this root
949 variable expression, or we lose the updated children! */
950 value_free ((*varp)->value);
951 (*varp)->value = new;
953 /* Initialize a stack */
954 vpush (&stack, NULL);
956 /* Push the root's children */
957 if ((*varp)->children != NULL)
959 struct varobj_child *c;
960 for (c = (*varp)->children; c != NULL; c = c->next)
961 vpush (&stack, c->child);
964 /* Walk through the children, reconstructing them all. */
968 /* Push any children */
969 if (v->children != NULL)
971 struct varobj_child *c;
972 for (c = v->children; c != NULL; c = c->next)
973 vpush (&stack, c->child);
976 /* Update this variable */
977 new = value_of_child (v->parent, v->index);
978 if (type_changeable (v) &&
979 (v->updated || !my_value_equal (v->value, new, &error)))
981 /* Note that it's changed */
986 /* Its value is going to be updated to NEW. */
989 /* We must always keep new values, since children depend on it. */
990 if (v->value != NULL)
991 value_free (v->value);
998 /* Alloc (changed + 1) list entries */
999 /* FIXME: add a cleanup for the allocated list(s)
1000 because one day the select_frame called below can longjump */
1001 *changelist = xmalloc ((changed + 1) * sizeof (struct varobj *));
1004 templist = xmalloc ((changed + 1) * sizeof (struct varobj *));
1010 /* Copy from result stack to list */
1012 *cv = vpop (&result);
1013 while ((*cv != NULL) && (vleft > 0))
1017 *cv = vpop (&result);
1020 warning (_("varobj_update: assertion failed - vleft <> 0"));
1024 /* Now we revert the order. */
1025 for (i = 0; i < changed; i++)
1026 *(*changelist + i) = *(templist + changed - 1 - i);
1027 *(*changelist + changed) = NULL;
1030 /* Restore selected frame */
1031 fi = frame_find_by_id (old_fid);
1042 /* Helper functions */
1045 * Variable object construction/destruction
1049 delete_variable (struct cpstack **resultp, struct varobj *var,
1050 int only_children_p)
1054 delete_variable_1 (resultp, &delcount, var,
1055 only_children_p, 1 /* remove_from_parent_p */ );
1060 /* Delete the variable object VAR and its children */
1061 /* IMPORTANT NOTE: If we delete a variable which is a child
1062 and the parent is not removed we dump core. It must be always
1063 initially called with remove_from_parent_p set */
1065 delete_variable_1 (struct cpstack **resultp, int *delcountp,
1066 struct varobj *var, int only_children_p,
1067 int remove_from_parent_p)
1069 struct varobj_child *vc;
1070 struct varobj_child *next;
1072 /* Delete any children of this variable, too. */
1073 for (vc = var->children; vc != NULL; vc = next)
1075 if (!remove_from_parent_p)
1076 vc->child->parent = NULL;
1077 delete_variable_1 (resultp, delcountp, vc->child, 0, only_children_p);
1082 /* if we were called to delete only the children we are done here */
1083 if (only_children_p)
1086 /* Otherwise, add it to the list of deleted ones and proceed to do so */
1087 /* If the name is null, this is a temporary variable, that has not
1088 yet been installed, don't report it, it belongs to the caller... */
1089 if (var->obj_name != NULL)
1091 cppush (resultp, xstrdup (var->obj_name));
1092 *delcountp = *delcountp + 1;
1095 /* If this variable has a parent, remove it from its parent's list */
1096 /* OPTIMIZATION: if the parent of this variable is also being deleted,
1097 (as indicated by remove_from_parent_p) we don't bother doing an
1098 expensive list search to find the element to remove when we are
1099 discarding the list afterwards */
1100 if ((remove_from_parent_p) && (var->parent != NULL))
1102 remove_child_from_parent (var->parent, var);
1105 if (var->obj_name != NULL)
1106 uninstall_variable (var);
1108 /* Free memory associated with this variable */
1109 free_variable (var);
1112 /* Install the given variable VAR with the object name VAR->OBJ_NAME. */
1114 install_variable (struct varobj *var)
1117 struct vlist *newvl;
1119 unsigned int index = 0;
1122 for (chp = var->obj_name; *chp; chp++)
1124 index = (index + (i++ * (unsigned int) *chp)) % VAROBJ_TABLE_SIZE;
1127 cv = *(varobj_table + index);
1128 while ((cv != NULL) && (strcmp (cv->var->obj_name, var->obj_name) != 0))
1132 error (_("Duplicate variable object name"));
1134 /* Add varobj to hash table */
1135 newvl = xmalloc (sizeof (struct vlist));
1136 newvl->next = *(varobj_table + index);
1138 *(varobj_table + index) = newvl;
1140 /* If root, add varobj to root list */
1141 if (var->root->rootvar == var)
1143 /* Add to list of root variables */
1144 if (rootlist == NULL)
1145 var->root->next = NULL;
1147 var->root->next = rootlist;
1148 rootlist = var->root;
1155 /* Unistall the object VAR. */
1157 uninstall_variable (struct varobj *var)
1161 struct varobj_root *cr;
1162 struct varobj_root *prer;
1164 unsigned int index = 0;
1167 /* Remove varobj from hash table */
1168 for (chp = var->obj_name; *chp; chp++)
1170 index = (index + (i++ * (unsigned int) *chp)) % VAROBJ_TABLE_SIZE;
1173 cv = *(varobj_table + index);
1175 while ((cv != NULL) && (strcmp (cv->var->obj_name, var->obj_name) != 0))
1182 fprintf_unfiltered (gdb_stdlog, "Deleting %s\n", var->obj_name);
1187 ("Assertion failed: Could not find variable object \"%s\" to delete",
1193 *(varobj_table + index) = cv->next;
1195 prev->next = cv->next;
1199 /* If root, remove varobj from root list */
1200 if (var->root->rootvar == var)
1202 /* Remove from list of root variables */
1203 if (rootlist == var->root)
1204 rootlist = var->root->next;
1209 while ((cr != NULL) && (cr->rootvar != var))
1217 ("Assertion failed: Could not find varobj \"%s\" in root list",
1224 prer->next = cr->next;
1231 /* Does a child with the name NAME exist in VAR? If so, return its data.
1232 If not, return NULL. */
1233 static struct varobj *
1234 child_exists (struct varobj *var, char *name)
1236 struct varobj_child *vc;
1238 for (vc = var->children; vc != NULL; vc = vc->next)
1240 if (strcmp (vc->child->name, name) == 0)
1247 /* Create and install a child of the parent of the given name */
1248 static struct varobj *
1249 create_child (struct varobj *parent, int index, char *name)
1251 struct varobj *child;
1254 child = new_variable ();
1256 /* name is allocated by name_of_child */
1258 child->index = index;
1259 child->value = value_of_child (parent, index);
1260 if ((!CPLUS_FAKE_CHILD (child) && child->value == NULL) || parent->error)
1262 child->parent = parent;
1263 child->root = parent->root;
1264 childs_name = xstrprintf ("%s.%s", parent->obj_name, name);
1265 child->obj_name = childs_name;
1266 install_variable (child);
1268 /* Save a pointer to this child in the parent */
1269 save_child_in_parent (parent, child);
1271 /* Note the type of this child */
1272 child->type = type_of_child (child);
1277 /* FIXME: This should be a generic add to list */
1278 /* Save CHILD in the PARENT's data. */
1280 save_child_in_parent (struct varobj *parent, struct varobj *child)
1282 struct varobj_child *vc;
1284 /* Insert the child at the top */
1285 vc = parent->children;
1287 (struct varobj_child *) xmalloc (sizeof (struct varobj_child));
1289 parent->children->next = vc;
1290 parent->children->child = child;
1293 /* FIXME: This should be a generic remove from list */
1294 /* Remove the CHILD from the PARENT's list of children. */
1296 remove_child_from_parent (struct varobj *parent, struct varobj *child)
1298 struct varobj_child *vc, *prev;
1300 /* Find the child in the parent's list */
1302 for (vc = parent->children; vc != NULL;)
1304 if (vc->child == child)
1311 parent->children = vc->next;
1313 prev->next = vc->next;
1319 * Miscellaneous utility functions.
1322 /* Allocate memory and initialize a new variable */
1323 static struct varobj *
1328 var = (struct varobj *) xmalloc (sizeof (struct varobj));
1330 var->obj_name = NULL;
1335 var->num_children = -1;
1337 var->children = NULL;
1345 /* Allocate memory and initialize a new root variable */
1346 static struct varobj *
1347 new_root_variable (void)
1349 struct varobj *var = new_variable ();
1350 var->root = (struct varobj_root *) xmalloc (sizeof (struct varobj_root));;
1351 var->root->lang = NULL;
1352 var->root->exp = NULL;
1353 var->root->valid_block = NULL;
1354 var->root->frame = null_frame_id;
1355 var->root->use_selected_frame = 0;
1356 var->root->rootvar = NULL;
1361 /* Free any allocated memory associated with VAR. */
1363 free_variable (struct varobj *var)
1365 /* Free the expression if this is a root variable. */
1366 if (var->root->rootvar == var)
1368 free_current_contents ((char **) &var->root->exp);
1373 xfree (var->obj_name);
1378 do_free_variable_cleanup (void *var)
1380 free_variable (var);
1383 static struct cleanup *
1384 make_cleanup_free_variable (struct varobj *var)
1386 return make_cleanup (do_free_variable_cleanup, var);
1389 /* This returns the type of the variable. It also skips past typedefs
1390 to return the real type of the variable.
1392 NOTE: TYPE_TARGET_TYPE should NOT be used anywhere in this file
1393 except within get_target_type and get_type. */
1394 static struct type *
1395 get_type (struct varobj *var)
1401 type = check_typedef (type);
1406 /* This returns the type of the variable, dereferencing pointers, too. */
1407 static struct type *
1408 get_type_deref (struct varobj *var)
1412 type = get_type (var);
1414 if (type != NULL && (TYPE_CODE (type) == TYPE_CODE_PTR
1415 || TYPE_CODE (type) == TYPE_CODE_REF))
1416 type = get_target_type (type);
1421 /* This returns the target type (or NULL) of TYPE, also skipping
1422 past typedefs, just like get_type ().
1424 NOTE: TYPE_TARGET_TYPE should NOT be used anywhere in this file
1425 except within get_target_type and get_type. */
1426 static struct type *
1427 get_target_type (struct type *type)
1431 type = TYPE_TARGET_TYPE (type);
1433 type = check_typedef (type);
1439 /* What is the default display for this variable? We assume that
1440 everything is "natural". Any exceptions? */
1441 static enum varobj_display_formats
1442 variable_default_display (struct varobj *var)
1444 return FORMAT_NATURAL;
1447 /* This function is similar to GDB's value_contents_equal, except that
1448 this one is "safe"; it never longjmps. It determines if the VAL1's
1449 value is the same as VAL2. If for some reason the value of VAR2
1450 can't be established, *ERROR2 is set to non-zero. */
1453 my_value_equal (struct value *val1, struct value *volatile val2, int *error2)
1455 volatile struct gdb_exception except;
1457 /* As a special case, if both are null, we say they're equal. */
1458 if (val1 == NULL && val2 == NULL)
1460 else if (val1 == NULL || val2 == NULL)
1463 /* The contents of VAL1 are supposed to be known. */
1464 gdb_assert (!value_lazy (val1));
1466 /* Make sure we also know the contents of VAL2. */
1467 val2 = coerce_array (val2);
1468 TRY_CATCH (except, RETURN_MASK_ERROR)
1470 if (value_lazy (val2))
1471 value_fetch_lazy (val2);
1473 if (except.reason < 0)
1478 gdb_assert (!value_lazy (val2));
1480 return value_contents_equal (val1, val2);
1483 /* FIXME: The following should be generic for any pointer */
1485 vpush (struct vstack **pstack, struct varobj *var)
1489 s = (struct vstack *) xmalloc (sizeof (struct vstack));
1495 /* FIXME: The following should be generic for any pointer */
1496 static struct varobj *
1497 vpop (struct vstack **pstack)
1502 if ((*pstack)->var == NULL && (*pstack)->next == NULL)
1507 *pstack = (*pstack)->next;
1513 /* FIXME: The following should be generic for any pointer */
1515 cppush (struct cpstack **pstack, char *name)
1519 s = (struct cpstack *) xmalloc (sizeof (struct cpstack));
1525 /* FIXME: The following should be generic for any pointer */
1527 cppop (struct cpstack **pstack)
1532 if ((*pstack)->name == NULL && (*pstack)->next == NULL)
1537 *pstack = (*pstack)->next;
1544 * Language-dependencies
1547 /* Common entry points */
1549 /* Get the language of variable VAR. */
1550 static enum varobj_languages
1551 variable_language (struct varobj *var)
1553 enum varobj_languages lang;
1555 switch (var->root->exp->language_defn->la_language)
1561 case language_cplus:
1572 /* Return the number of children for a given variable.
1573 The result of this function is defined by the language
1574 implementation. The number of children returned by this function
1575 is the number of children that the user will see in the variable
1578 number_of_children (struct varobj *var)
1580 return (*var->root->lang->number_of_children) (var);;
1583 /* What is the expression for the root varobj VAR? Returns a malloc'd string. */
1585 name_of_variable (struct varobj *var)
1587 return (*var->root->lang->name_of_variable) (var);
1590 /* What is the name of the INDEX'th child of VAR? Returns a malloc'd string. */
1592 name_of_child (struct varobj *var, int index)
1594 return (*var->root->lang->name_of_child) (var, index);
1597 /* What is the ``struct value *'' of the root variable VAR?
1598 TYPE_CHANGED controls what to do if the type of a
1599 use_selected_frame = 1 variable changes. On input,
1600 TYPE_CHANGED = 1 means discard the old varobj, and replace
1601 it with this one. TYPE_CHANGED = 0 means leave it around.
1602 NB: In both cases, var_handle will point to the new varobj,
1603 so if you use TYPE_CHANGED = 0, you will have to stash the
1604 old varobj pointer away somewhere before calling this.
1605 On return, TYPE_CHANGED will be 1 if the type has changed, and
1607 static struct value *
1608 value_of_root (struct varobj **var_handle, int *type_changed)
1612 if (var_handle == NULL)
1617 /* This should really be an exception, since this should
1618 only get called with a root variable. */
1620 if (var->root->rootvar != var)
1623 if (var->root->use_selected_frame)
1625 struct varobj *tmp_var;
1626 char *old_type, *new_type;
1627 old_type = varobj_get_type (var);
1628 tmp_var = varobj_create (NULL, var->name, (CORE_ADDR) 0,
1629 USE_SELECTED_FRAME);
1630 if (tmp_var == NULL)
1634 new_type = varobj_get_type (tmp_var);
1635 if (strcmp (old_type, new_type) == 0)
1637 varobj_delete (tmp_var, NULL, 0);
1645 savestring (var->obj_name, strlen (var->obj_name));
1646 varobj_delete (var, NULL, 0);
1650 tmp_var->obj_name = varobj_gen_name ();
1652 install_variable (tmp_var);
1653 *var_handle = tmp_var;
1663 return (*var->root->lang->value_of_root) (var_handle);
1666 /* What is the ``struct value *'' for the INDEX'th child of PARENT? */
1667 static struct value *
1668 value_of_child (struct varobj *parent, int index)
1670 struct value *value;
1672 value = (*parent->root->lang->value_of_child) (parent, index);
1674 /* If we're being lazy, fetch the real value of the variable. */
1675 if (value != NULL && value_lazy (value))
1677 /* If we fail to fetch the value of the child, return
1678 NULL so that callers notice that we're leaving an
1680 if (!gdb_value_fetch_lazy (value))
1687 /* What is the type of VAR? */
1688 static struct type *
1689 type_of_child (struct varobj *var)
1692 /* If the child had no evaluation errors, var->value
1693 will be non-NULL and contain a valid type. */
1694 if (var->value != NULL)
1695 return value_type (var->value);
1697 /* Otherwise, we must compute the type. */
1698 return (*var->root->lang->type_of_child) (var->parent, var->index);
1701 /* Is this variable editable? Use the variable's type to make
1702 this determination. */
1704 variable_editable (struct varobj *var)
1706 return (*var->root->lang->variable_editable) (var);
1709 /* GDB already has a command called "value_of_variable". Sigh. */
1711 my_value_of_variable (struct varobj *var)
1713 return (*var->root->lang->value_of_variable) (var);
1716 /* Is VAR something that can change? Depending on language,
1717 some variable's values never change. For example,
1718 struct and unions never change values. */
1720 type_changeable (struct varobj *var)
1725 if (CPLUS_FAKE_CHILD (var))
1728 type = get_type (var);
1730 switch (TYPE_CODE (type))
1732 case TYPE_CODE_STRUCT:
1733 case TYPE_CODE_UNION:
1734 case TYPE_CODE_ARRAY:
1747 c_number_of_children (struct varobj *var)
1750 struct type *target;
1753 type = get_type (var);
1754 target = get_target_type (type);
1757 switch (TYPE_CODE (type))
1759 case TYPE_CODE_ARRAY:
1760 if (TYPE_LENGTH (type) > 0 && TYPE_LENGTH (target) > 0
1761 && TYPE_ARRAY_UPPER_BOUND_TYPE (type) != BOUND_CANNOT_BE_DETERMINED)
1762 children = TYPE_LENGTH (type) / TYPE_LENGTH (target);
1767 case TYPE_CODE_STRUCT:
1768 case TYPE_CODE_UNION:
1769 children = TYPE_NFIELDS (type);
1773 /* This is where things get compilcated. All pointers have one child.
1774 Except, of course, for struct and union ptr, which we automagically
1775 dereference for the user and function ptrs, which have no children.
1776 We also don't dereference void* as we don't know what to show.
1777 We can show char* so we allow it to be dereferenced. If you decide
1778 to test for it, please mind that a little magic is necessary to
1779 properly identify it: char* has TYPE_CODE == TYPE_CODE_INT and
1780 TYPE_NAME == "char" */
1782 switch (TYPE_CODE (target))
1784 case TYPE_CODE_STRUCT:
1785 case TYPE_CODE_UNION:
1786 children = TYPE_NFIELDS (target);
1789 case TYPE_CODE_FUNC:
1790 case TYPE_CODE_VOID:
1800 /* Other types have no children */
1808 c_name_of_variable (struct varobj *parent)
1810 return savestring (parent->name, strlen (parent->name));
1814 c_name_of_child (struct varobj *parent, int index)
1817 struct type *target;
1821 type = get_type (parent);
1822 target = get_target_type (type);
1824 switch (TYPE_CODE (type))
1826 case TYPE_CODE_ARRAY:
1827 name = xstrprintf ("%d", index);
1830 case TYPE_CODE_STRUCT:
1831 case TYPE_CODE_UNION:
1832 string = TYPE_FIELD_NAME (type, index);
1833 name = savestring (string, strlen (string));
1837 switch (TYPE_CODE (target))
1839 case TYPE_CODE_STRUCT:
1840 case TYPE_CODE_UNION:
1841 string = TYPE_FIELD_NAME (target, index);
1842 name = savestring (string, strlen (string));
1846 name = xstrprintf ("*%s", parent->name);
1852 /* This should not happen */
1853 name = xstrdup ("???");
1859 static struct value *
1860 c_value_of_root (struct varobj **var_handle)
1862 struct value *new_val;
1863 struct varobj *var = *var_handle;
1864 struct frame_info *fi;
1867 /* Only root variables can be updated... */
1868 if (var->root->rootvar != var)
1869 /* Not a root var */
1873 /* Determine whether the variable is still around. */
1874 if (var->root->valid_block == NULL)
1878 reinit_frame_cache ();
1879 fi = frame_find_by_id (var->root->frame);
1880 within_scope = fi != NULL;
1881 /* FIXME: select_frame could fail */
1888 /* We need to catch errors here, because if evaluate
1889 expression fails we just want to make val->error = 1 and
1891 if (gdb_evaluate_expression (var->root->exp, &new_val))
1893 if (value_lazy (new_val))
1895 /* We need to catch errors because if
1896 value_fetch_lazy fails we still want to continue
1897 (after making val->error = 1) */
1898 /* FIXME: Shouldn't be using value_contents()? The
1899 comment on value_fetch_lazy() says it is only called
1900 from the macro... */
1901 if (!gdb_value_fetch_lazy (new_val))
1910 release_value (new_val);
1917 static struct value *
1918 c_value_of_child (struct varobj *parent, int index)
1920 struct value *value;
1922 struct value *indval;
1923 struct type *type, *target;
1926 type = get_type (parent);
1927 target = get_target_type (type);
1928 name = name_of_child (parent, index);
1929 temp = parent->value;
1934 switch (TYPE_CODE (type))
1936 case TYPE_CODE_ARRAY:
1938 /* This breaks if the array lives in a (vector) register. */
1939 value = value_slice (temp, index, 1);
1940 temp = value_coerce_array (value);
1941 gdb_value_ind (temp, &value);
1943 indval = value_from_longest (builtin_type_int, (LONGEST) index);
1944 gdb_value_subscript (temp, indval, &value);
1948 case TYPE_CODE_STRUCT:
1949 case TYPE_CODE_UNION:
1950 gdb_value_struct_elt (NULL, &value, &temp, NULL, name, NULL,
1955 switch (TYPE_CODE (target))
1957 case TYPE_CODE_STRUCT:
1958 case TYPE_CODE_UNION:
1959 gdb_value_struct_elt (NULL, &value, &temp, NULL, name, NULL,
1964 gdb_value_ind (temp, &value);
1975 release_value (value);
1981 static struct type *
1982 c_type_of_child (struct varobj *parent, int index)
1985 char *name = name_of_child (parent, index);
1987 switch (TYPE_CODE (parent->type))
1989 case TYPE_CODE_ARRAY:
1990 type = get_target_type (parent->type);
1993 case TYPE_CODE_STRUCT:
1994 case TYPE_CODE_UNION:
1995 type = lookup_struct_elt_type (parent->type, name, 0);
1999 switch (TYPE_CODE (get_target_type (parent->type)))
2001 case TYPE_CODE_STRUCT:
2002 case TYPE_CODE_UNION:
2003 type = lookup_struct_elt_type (parent->type, name, 0);
2007 type = get_target_type (parent->type);
2013 /* This should not happen as only the above types have children */
2014 warning (_("Child of parent whose type does not allow children"));
2015 /* FIXME: Can we still go on? */
2025 c_variable_editable (struct varobj *var)
2027 switch (TYPE_CODE (get_type (var)))
2029 case TYPE_CODE_STRUCT:
2030 case TYPE_CODE_UNION:
2031 case TYPE_CODE_ARRAY:
2032 case TYPE_CODE_FUNC:
2033 case TYPE_CODE_MEMBER:
2034 case TYPE_CODE_METHOD:
2045 c_value_of_variable (struct varobj *var)
2047 /* BOGUS: if val_print sees a struct/class, it will print out its
2048 children instead of "{...}" */
2050 switch (TYPE_CODE (get_type (var)))
2052 case TYPE_CODE_STRUCT:
2053 case TYPE_CODE_UNION:
2054 return xstrdup ("{...}");
2057 case TYPE_CODE_ARRAY:
2060 number = xstrprintf ("[%d]", var->num_children);
2067 if (var->value == NULL)
2069 /* This can happen if we attempt to get the value of a struct
2070 member when the parent is an invalid pointer. This is an
2071 error condition, so we should tell the caller. */
2077 struct ui_file *stb = mem_fileopen ();
2078 struct cleanup *old_chain = make_cleanup_ui_file_delete (stb);
2081 if (value_lazy (var->value))
2082 gdb_value_fetch_lazy (var->value);
2083 common_val_print (var->value, stb,
2084 format_code[(int) var->format], 1, 0, 0);
2085 thevalue = ui_file_xstrdup (stb, &dummy);
2086 do_cleanups (old_chain);
2097 cplus_number_of_children (struct varobj *var)
2100 int children, dont_know;
2105 if (!CPLUS_FAKE_CHILD (var))
2107 type = get_type_deref (var);
2109 if (((TYPE_CODE (type)) == TYPE_CODE_STRUCT) ||
2110 ((TYPE_CODE (type)) == TYPE_CODE_UNION))
2114 cplus_class_num_children (type, kids);
2115 if (kids[v_public] != 0)
2117 if (kids[v_private] != 0)
2119 if (kids[v_protected] != 0)
2122 /* Add any baseclasses */
2123 children += TYPE_N_BASECLASSES (type);
2126 /* FIXME: save children in var */
2133 type = get_type_deref (var->parent);
2135 cplus_class_num_children (type, kids);
2136 if (strcmp (var->name, "public") == 0)
2137 children = kids[v_public];
2138 else if (strcmp (var->name, "private") == 0)
2139 children = kids[v_private];
2141 children = kids[v_protected];
2146 children = c_number_of_children (var);
2151 /* Compute # of public, private, and protected variables in this class.
2152 That means we need to descend into all baseclasses and find out
2153 how many are there, too. */
2155 cplus_class_num_children (struct type *type, int children[3])
2159 children[v_public] = 0;
2160 children[v_private] = 0;
2161 children[v_protected] = 0;
2163 for (i = TYPE_N_BASECLASSES (type); i < TYPE_NFIELDS (type); i++)
2165 /* If we have a virtual table pointer, omit it. */
2166 if (TYPE_VPTR_BASETYPE (type) == type && TYPE_VPTR_FIELDNO (type) == i)
2169 if (TYPE_FIELD_PROTECTED (type, i))
2170 children[v_protected]++;
2171 else if (TYPE_FIELD_PRIVATE (type, i))
2172 children[v_private]++;
2174 children[v_public]++;
2179 cplus_name_of_variable (struct varobj *parent)
2181 return c_name_of_variable (parent);
2185 cplus_name_of_child (struct varobj *parent, int index)
2190 if (CPLUS_FAKE_CHILD (parent))
2192 /* Looking for children of public, private, or protected. */
2193 type = get_type_deref (parent->parent);
2196 type = get_type_deref (parent);
2199 switch (TYPE_CODE (type))
2201 case TYPE_CODE_STRUCT:
2202 case TYPE_CODE_UNION:
2203 if (CPLUS_FAKE_CHILD (parent))
2205 /* The fields of the class type are ordered as they
2206 appear in the class. We are given an index for a
2207 particular access control type ("public","protected",
2208 or "private"). We must skip over fields that don't
2209 have the access control we are looking for to properly
2210 find the indexed field. */
2211 int type_index = TYPE_N_BASECLASSES (type);
2212 if (strcmp (parent->name, "private") == 0)
2216 if (TYPE_VPTR_BASETYPE (type) == type
2217 && type_index == TYPE_VPTR_FIELDNO (type))
2219 else if (TYPE_FIELD_PRIVATE (type, type_index))
2225 else if (strcmp (parent->name, "protected") == 0)
2229 if (TYPE_VPTR_BASETYPE (type) == type
2230 && type_index == TYPE_VPTR_FIELDNO (type))
2232 else if (TYPE_FIELD_PROTECTED (type, type_index))
2242 if (TYPE_VPTR_BASETYPE (type) == type
2243 && type_index == TYPE_VPTR_FIELDNO (type))
2245 else if (!TYPE_FIELD_PRIVATE (type, type_index) &&
2246 !TYPE_FIELD_PROTECTED (type, type_index))
2253 name = TYPE_FIELD_NAME (type, type_index);
2255 else if (index < TYPE_N_BASECLASSES (type))
2256 /* We are looking up the name of a base class */
2257 name = TYPE_FIELD_NAME (type, index);
2261 cplus_class_num_children(type, children);
2263 /* Everything beyond the baseclasses can
2264 only be "public", "private", or "protected"
2266 The special "fake" children are always output by varobj in
2267 this order. So if INDEX == 2, it MUST be "protected". */
2268 index -= TYPE_N_BASECLASSES (type);
2272 if (children[v_public] > 0)
2274 else if (children[v_private] > 0)
2280 if (children[v_public] > 0)
2282 if (children[v_private] > 0)
2287 else if (children[v_private] > 0)
2291 /* Must be protected */
2306 return c_name_of_child (parent, index);
2310 name = savestring (name, strlen (name));
2316 static struct value *
2317 cplus_value_of_root (struct varobj **var_handle)
2319 return c_value_of_root (var_handle);
2322 static struct value *
2323 cplus_value_of_child (struct varobj *parent, int index)
2326 struct value *value;
2328 if (CPLUS_FAKE_CHILD (parent))
2329 type = get_type_deref (parent->parent);
2331 type = get_type_deref (parent);
2335 if (((TYPE_CODE (type)) == TYPE_CODE_STRUCT) ||
2336 ((TYPE_CODE (type)) == TYPE_CODE_UNION))
2338 if (CPLUS_FAKE_CHILD (parent))
2341 struct value *temp = parent->parent->value;
2346 name = name_of_child (parent, index);
2347 gdb_value_struct_elt (NULL, &value, &temp, NULL, name, NULL,
2350 release_value (value);
2354 else if (index >= TYPE_N_BASECLASSES (type))
2356 /* public, private, or protected */
2362 if (parent->value != NULL)
2364 struct value *temp = NULL;
2366 if (TYPE_CODE (value_type (parent->value)) == TYPE_CODE_PTR
2367 || TYPE_CODE (value_type (parent->value)) == TYPE_CODE_REF)
2369 if (!gdb_value_ind (parent->value, &temp))
2373 temp = parent->value;
2377 value = value_cast (TYPE_FIELD_TYPE (type, index), temp);
2378 release_value (value);
2382 /* We failed to evaluate the parent's value, so don't even
2383 bother trying to evaluate this child. */
2391 return c_value_of_child (parent, index);
2396 static struct type *
2397 cplus_type_of_child (struct varobj *parent, int index)
2399 struct type *type, *t;
2401 if (CPLUS_FAKE_CHILD (parent))
2403 /* Looking for the type of a child of public, private, or protected. */
2404 t = get_type_deref (parent->parent);
2407 t = get_type_deref (parent);
2410 switch (TYPE_CODE (t))
2412 case TYPE_CODE_STRUCT:
2413 case TYPE_CODE_UNION:
2414 if (CPLUS_FAKE_CHILD (parent))
2416 char *name = cplus_name_of_child (parent, index);
2417 type = lookup_struct_elt_type (t, name, 0);
2420 else if (index < TYPE_N_BASECLASSES (t))
2421 type = TYPE_FIELD_TYPE (t, index);
2434 return c_type_of_child (parent, index);
2440 cplus_variable_editable (struct varobj *var)
2442 if (CPLUS_FAKE_CHILD (var))
2445 return c_variable_editable (var);
2449 cplus_value_of_variable (struct varobj *var)
2452 /* If we have one of our special types, don't print out
2454 if (CPLUS_FAKE_CHILD (var))
2455 return xstrdup ("");
2457 return c_value_of_variable (var);
2463 java_number_of_children (struct varobj *var)
2465 return cplus_number_of_children (var);
2469 java_name_of_variable (struct varobj *parent)
2473 name = cplus_name_of_variable (parent);
2474 /* If the name has "-" in it, it is because we
2475 needed to escape periods in the name... */
2478 while (*p != '\000')
2489 java_name_of_child (struct varobj *parent, int index)
2493 name = cplus_name_of_child (parent, index);
2494 /* Escape any periods in the name... */
2497 while (*p != '\000')
2507 static struct value *
2508 java_value_of_root (struct varobj **var_handle)
2510 return cplus_value_of_root (var_handle);
2513 static struct value *
2514 java_value_of_child (struct varobj *parent, int index)
2516 return cplus_value_of_child (parent, index);
2519 static struct type *
2520 java_type_of_child (struct varobj *parent, int index)
2522 return cplus_type_of_child (parent, index);
2526 java_variable_editable (struct varobj *var)
2528 return cplus_variable_editable (var);
2532 java_value_of_variable (struct varobj *var)
2534 return cplus_value_of_variable (var);
2537 extern void _initialize_varobj (void);
2539 _initialize_varobj (void)
2541 int sizeof_table = sizeof (struct vlist *) * VAROBJ_TABLE_SIZE;
2543 varobj_table = xmalloc (sizeof_table);
2544 memset (varobj_table, 0, sizeof_table);
2546 add_setshow_zinteger_cmd ("debugvarobj", class_maintenance,
2548 Set varobj debugging."), _("\
2549 Show varobj debugging."), _("\
2550 When non-zero, varobj debugging is enabled."),
2553 &setlist, &showlist);