1 /* Implementation of the GDB variable objects API.
2 Copyright 1999, 2000, 2001 Free Software Foundation, Inc.
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA. */
21 #include "expression.h"
26 #include "gdb_string.h"
31 /* Non-zero if we want to see trace of varobj level stuff. */
35 /* String representations of gdb's format codes */
36 char *varobj_format_string[] =
37 { "natural", "binary", "decimal", "hexadecimal", "octal" };
39 /* String representations of gdb's known languages */
40 char *varobj_language_string[] = { "unknown", "C", "C++", "Java" };
44 /* Every root variable has one of these structures saved in its
45 varobj. Members which must be free'd are noted. */
49 /* Alloc'd expression for this parent. */
50 struct expression *exp;
52 /* Block for which this expression is valid */
53 struct block *valid_block;
55 /* The frame for this expression */
56 struct frame_id frame;
58 /* If 1, "update" always recomputes the frame & valid block
59 using the currently selected frame. */
60 int use_selected_frame;
62 /* Language info for this variable and its children */
63 struct language_specific *lang;
65 /* The varobj for this root node. */
66 struct varobj *rootvar;
68 /* Next root variable */
69 struct varobj_root *next;
72 /* Every variable in the system has a structure of this type defined
73 for it. This structure holds all information necessary to manipulate
74 a particular object variable. Members which must be freed are noted. */
78 /* Alloc'd name of the variable for this object.. If this variable is a
79 child, then this name will be the child's source name.
81 /* NOTE: This is the "expression" */
84 /* The alloc'd name for this variable's object. This is here for
85 convenience when constructing this object's children. */
88 /* Index of this variable in its parent or -1 */
91 /* The type of this variable. This may NEVER be NULL. */
94 /* The value of this expression or subexpression. This may be NULL. */
97 /* Did an error occur evaluating the expression or getting its value? */
100 /* The number of (immediate) children this variable has */
103 /* If this object is a child, this points to its immediate parent. */
104 struct varobj *parent;
106 /* A list of this object's children */
107 struct varobj_child *children;
109 /* Description of the root variable. Points to root variable for children. */
110 struct varobj_root *root;
112 /* The format of the output for this object */
113 enum varobj_display_formats format;
115 /* Was this variable updated via a varobj_set_value operation */
119 /* Every variable keeps a linked list of its children, described
120 by the following structure. */
121 /* FIXME: Deprecated. All should use vlist instead */
126 /* Pointer to the child's data */
127 struct varobj *child;
129 /* Pointer to the next child */
130 struct varobj_child *next;
133 /* A stack of varobjs */
134 /* FIXME: Deprecated. All should use vlist instead */
145 struct cpstack *next;
148 /* A list of varobjs */
156 /* Private function prototypes */
158 /* Helper functions for the above subcommands. */
160 static int delete_variable (struct cpstack **, struct varobj *, int);
162 static void delete_variable_1 (struct cpstack **, int *,
163 struct varobj *, int, int);
165 static int install_variable (struct varobj *);
167 static void uninstall_variable (struct varobj *);
169 static struct varobj *child_exists (struct varobj *, char *);
171 static struct varobj *create_child (struct varobj *, int, char *);
173 static void save_child_in_parent (struct varobj *, struct varobj *);
175 static void remove_child_from_parent (struct varobj *, struct varobj *);
177 /* Utility routines */
179 static struct varobj *new_variable (void);
181 static struct varobj *new_root_variable (void);
183 static void free_variable (struct varobj *var);
185 static struct cleanup *make_cleanup_free_variable (struct varobj *var);
187 static struct type *get_type (struct varobj *var);
189 static struct type *get_type_deref (struct varobj *var);
191 static struct type *get_target_type (struct type *);
193 static enum varobj_display_formats variable_default_display (struct varobj *);
195 static int my_value_equal (struct value *, struct value *, int *);
197 static void vpush (struct vstack **pstack, struct varobj *var);
199 static struct varobj *vpop (struct vstack **pstack);
201 static void cppush (struct cpstack **pstack, char *name);
203 static char *cppop (struct cpstack **pstack);
205 /* Language-specific routines. */
207 static enum varobj_languages variable_language (struct varobj *var);
209 static int number_of_children (struct varobj *);
211 static char *name_of_variable (struct varobj *);
213 static char *name_of_child (struct varobj *, int);
215 static struct value *value_of_root (struct varobj **var_handle, int *);
217 static struct value *value_of_child (struct varobj *parent, int index);
219 static struct type *type_of_child (struct varobj *var);
221 static int variable_editable (struct varobj *var);
223 static char *my_value_of_variable (struct varobj *var);
225 static int type_changeable (struct varobj *var);
227 /* C implementation */
229 static int c_number_of_children (struct varobj *var);
231 static char *c_name_of_variable (struct varobj *parent);
233 static char *c_name_of_child (struct varobj *parent, int index);
235 static struct value *c_value_of_root (struct varobj **var_handle);
237 static struct value *c_value_of_child (struct varobj *parent, int index);
239 static struct type *c_type_of_child (struct varobj *parent, int index);
241 static int c_variable_editable (struct varobj *var);
243 static char *c_value_of_variable (struct varobj *var);
245 /* C++ implementation */
247 static int cplus_number_of_children (struct varobj *var);
249 static void cplus_class_num_children (struct type *type, int children[3]);
251 static char *cplus_name_of_variable (struct varobj *parent);
253 static char *cplus_name_of_child (struct varobj *parent, int index);
255 static struct value *cplus_value_of_root (struct varobj **var_handle);
257 static struct value *cplus_value_of_child (struct varobj *parent, int index);
259 static struct type *cplus_type_of_child (struct varobj *parent, int index);
261 static int cplus_variable_editable (struct varobj *var);
263 static char *cplus_value_of_variable (struct varobj *var);
265 /* Java implementation */
267 static int java_number_of_children (struct varobj *var);
269 static char *java_name_of_variable (struct varobj *parent);
271 static char *java_name_of_child (struct varobj *parent, int index);
273 static struct value *java_value_of_root (struct varobj **var_handle);
275 static struct value *java_value_of_child (struct varobj *parent, int index);
277 static struct type *java_type_of_child (struct varobj *parent, int index);
279 static int java_variable_editable (struct varobj *var);
281 static char *java_value_of_variable (struct varobj *var);
283 /* The language specific vector */
285 struct language_specific
288 /* The language of this variable */
289 enum varobj_languages language;
291 /* The number of children of PARENT. */
292 int (*number_of_children) (struct varobj * parent);
294 /* The name (expression) of a root varobj. */
295 char *(*name_of_variable) (struct varobj * parent);
297 /* The name of the INDEX'th child of PARENT. */
298 char *(*name_of_child) (struct varobj * parent, int index);
300 /* The ``struct value *'' of the root variable ROOT. */
301 struct value *(*value_of_root) (struct varobj ** root_handle);
303 /* The ``struct value *'' of the INDEX'th child of PARENT. */
304 struct value *(*value_of_child) (struct varobj * parent, int index);
306 /* The type of the INDEX'th child of PARENT. */
307 struct type *(*type_of_child) (struct varobj * parent, int index);
309 /* Is VAR editable? */
310 int (*variable_editable) (struct varobj * var);
312 /* The current value of VAR. */
313 char *(*value_of_variable) (struct varobj * var);
316 /* Array of known source language routines. */
317 static struct language_specific
318 languages[vlang_end][sizeof (struct language_specific)] = {
319 /* Unknown (try treating as C */
322 c_number_of_children,
334 c_number_of_children,
346 cplus_number_of_children,
347 cplus_name_of_variable,
350 cplus_value_of_child,
352 cplus_variable_editable,
353 cplus_value_of_variable}
358 java_number_of_children,
359 java_name_of_variable,
364 java_variable_editable,
365 java_value_of_variable}
368 /* A little convenience enum for dealing with C++/Java */
371 v_public = 0, v_private, v_protected
376 /* Mappings of varobj_display_formats enums to gdb's format codes */
377 static int format_code[] = { 0, 't', 'd', 'x', 'o' };
379 /* Header of the list of root variable objects */
380 static struct varobj_root *rootlist;
381 static int rootcount = 0; /* number of root varobjs in the list */
383 /* Prime number indicating the number of buckets in the hash table */
384 /* A prime large enough to avoid too many colisions */
385 #define VAROBJ_TABLE_SIZE 227
387 /* Pointer to the varobj hash table (built at run time) */
388 static struct vlist **varobj_table;
390 /* Is the variable X one of our "fake" children? */
391 #define CPLUS_FAKE_CHILD(x) \
392 ((x) != NULL && (x)->type == NULL && (x)->value == NULL)
395 /* API Implementation */
397 /* Creates a varobj (not its children) */
399 /* Return the full FRAME which corresponds to the given CORE_ADDR
400 or NULL if no FRAME on the chain corresponds to CORE_ADDR. */
402 static struct frame_info *
403 find_frame_addr_in_frame_chain (CORE_ADDR frame_addr)
405 struct frame_info *frame = NULL;
407 if (frame_addr == (CORE_ADDR) 0)
412 frame = get_prev_frame (frame);
415 if (get_frame_base (frame) == frame_addr)
421 varobj_create (char *objname,
422 char *expression, CORE_ADDR frame, enum varobj_type type)
425 struct frame_info *fi;
426 struct frame_info *old_fi = NULL;
428 struct cleanup *old_chain;
430 /* Fill out a varobj structure for the (root) variable being constructed. */
431 var = new_root_variable ();
432 old_chain = make_cleanup_free_variable (var);
434 if (expression != NULL)
437 enum varobj_languages lang;
439 /* Parse and evaluate the expression, filling in as much
440 of the variable's data as possible */
442 /* Allow creator to specify context of variable */
443 if ((type == USE_CURRENT_FRAME) || (type == USE_SELECTED_FRAME))
444 fi = deprecated_selected_frame;
446 /* FIXME: cagney/2002-11-23: This code should be doing a
447 lookup using the frame ID and not just the frame's
448 ``address''. This, of course, means an interface change.
449 However, with out that interface change ISAs, such as the
450 ia64 with its two stacks, won't work. Similar goes for the
451 case where there is a frameless function. */
452 fi = find_frame_addr_in_frame_chain (frame);
454 /* frame = -2 means always use selected frame */
455 if (type == USE_SELECTED_FRAME)
456 var->root->use_selected_frame = 1;
460 block = get_frame_block (fi, 0);
463 innermost_block = NULL;
464 /* Wrap the call to parse expression, so we can
465 return a sensible error. */
466 if (!gdb_parse_exp_1 (&p, block, 0, &var->root->exp))
471 /* Don't allow variables to be created for types. */
472 if (var->root->exp->elts[0].opcode == OP_TYPE)
474 do_cleanups (old_chain);
475 fprintf_unfiltered (gdb_stderr,
476 "Attempt to use a type name as an expression.");
480 var->format = variable_default_display (var);
481 var->root->valid_block = innermost_block;
482 var->name = savestring (expression, strlen (expression));
484 /* When the frame is different from the current frame,
485 we must select the appropriate frame before parsing
486 the expression, otherwise the value will not be current.
487 Since select_frame is so benign, just call it for all cases. */
490 var->root->frame = get_frame_id (fi);
491 old_fi = deprecated_selected_frame;
495 /* We definitively need to catch errors here.
496 If evaluate_expression succeeds we got the value we wanted.
497 But if it fails, we still go on with a call to evaluate_type() */
498 if (gdb_evaluate_expression (var->root->exp, &var->value))
501 release_value (var->value);
502 if (VALUE_LAZY (var->value))
503 gdb_value_fetch_lazy (var->value);
506 var->value = evaluate_type (var->root->exp);
508 var->type = VALUE_TYPE (var->value);
510 /* Set language info */
511 lang = variable_language (var);
512 var->root->lang = languages[lang];
514 /* Set ourselves as our root */
515 var->root->rootvar = var;
517 /* Reset the selected frame */
519 select_frame (old_fi);
522 /* If the variable object name is null, that means this
523 is a temporary variable, so don't install it. */
525 if ((var != NULL) && (objname != NULL))
527 var->obj_name = savestring (objname, strlen (objname));
529 /* If a varobj name is duplicated, the install will fail so
531 if (!install_variable (var))
533 do_cleanups (old_chain);
538 discard_cleanups (old_chain);
542 /* Generates an unique name that can be used for a varobj */
545 varobj_gen_name (void)
550 /* generate a name for this object */
552 xasprintf (&obj_name, "var%d", id);
557 /* Given an "objname", returns the pointer to the corresponding varobj
558 or NULL if not found */
561 varobj_get_handle (char *objname)
565 unsigned int index = 0;
568 for (chp = objname; *chp; chp++)
570 index = (index + (i++ * (unsigned int) *chp)) % VAROBJ_TABLE_SIZE;
573 cv = *(varobj_table + index);
574 while ((cv != NULL) && (strcmp (cv->var->obj_name, objname) != 0))
578 error ("Variable object not found");
583 /* Given the handle, return the name of the object */
586 varobj_get_objname (struct varobj *var)
588 return var->obj_name;
591 /* Given the handle, return the expression represented by the object */
594 varobj_get_expression (struct varobj *var)
596 return name_of_variable (var);
599 /* Deletes a varobj and all its children if only_children == 0,
600 otherwise deletes only the children; returns a malloc'ed list of all the
601 (malloc'ed) names of the variables that have been deleted (NULL terminated) */
604 varobj_delete (struct varobj *var, char ***dellist, int only_children)
608 struct cpstack *result = NULL;
611 /* Initialize a stack for temporary results */
612 cppush (&result, NULL);
615 /* Delete only the variable children */
616 delcount = delete_variable (&result, var, 1 /* only the children */ );
618 /* Delete the variable and all its children */
619 delcount = delete_variable (&result, var, 0 /* parent+children */ );
621 /* We may have been asked to return a list of what has been deleted */
624 *dellist = xmalloc ((delcount + 1) * sizeof (char *));
628 *cp = cppop (&result);
629 while ((*cp != NULL) && (mycount > 0))
633 *cp = cppop (&result);
636 if (mycount || (*cp != NULL))
637 warning ("varobj_delete: assertion failed - mycount(=%d) <> 0",
644 /* Set/Get variable object display format */
646 enum varobj_display_formats
647 varobj_set_display_format (struct varobj *var,
648 enum varobj_display_formats format)
655 case FORMAT_HEXADECIMAL:
657 var->format = format;
661 var->format = variable_default_display (var);
667 enum varobj_display_formats
668 varobj_get_display_format (struct varobj *var)
674 varobj_get_num_children (struct varobj *var)
676 if (var->num_children == -1)
677 var->num_children = number_of_children (var);
679 return var->num_children;
682 /* Creates a list of the immediate children of a variable object;
683 the return code is the number of such children or -1 on error */
686 varobj_list_children (struct varobj *var, struct varobj ***childlist)
688 struct varobj *child;
692 /* sanity check: have we been passed a pointer? */
693 if (childlist == NULL)
698 if (var->num_children == -1)
699 var->num_children = number_of_children (var);
701 /* List of children */
702 *childlist = xmalloc ((var->num_children + 1) * sizeof (struct varobj *));
704 for (i = 0; i < var->num_children; i++)
706 /* Mark as the end in case we bail out */
707 *((*childlist) + i) = NULL;
709 /* check if child exists, if not create */
710 name = name_of_child (var, i);
711 child = child_exists (var, name);
713 child = create_child (var, i, name);
715 *((*childlist) + i) = child;
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 enum varobj_languages
755 varobj_get_language (struct varobj *var)
757 return variable_language (var);
761 varobj_get_attributes (struct varobj *var)
765 if (variable_editable (var))
766 /* FIXME: define masks for attributes */
767 attributes |= 0x00000001; /* Editable */
773 varobj_get_value (struct varobj *var)
775 return my_value_of_variable (var);
778 /* Set the value of an object variable (if it is editable) to the
779 value of the given expression */
780 /* Note: Invokes functions that can call error() */
783 varobj_set_value (struct varobj *var, char *expression)
789 /* The argument "expression" contains the variable's new value.
790 We need to first construct a legal expression for this -- ugh! */
791 /* Does this cover all the bases? */
792 struct expression *exp;
794 int saved_input_radix = input_radix;
796 if (var->value != NULL && variable_editable (var) && !var->error)
798 char *s = expression;
801 input_radix = 10; /* ALWAYS reset to decimal temporarily */
802 if (!gdb_parse_exp_1 (&s, 0, 0, &exp))
803 /* We cannot proceed without a well-formed expression. */
805 if (!gdb_evaluate_expression (exp, &value))
807 /* We cannot proceed without a valid expression. */
812 if (!my_value_equal (var->value, value, &error))
814 if (!gdb_value_assign (var->value, value, &val))
816 value_free (var->value);
819 input_radix = saved_input_radix;
826 /* Returns a malloc'ed list with all root variable objects */
828 varobj_list (struct varobj ***varlist)
831 struct varobj_root *croot;
832 int mycount = rootcount;
834 /* Alloc (rootcount + 1) entries for the result */
835 *varlist = xmalloc ((rootcount + 1) * sizeof (struct varobj *));
839 while ((croot != NULL) && (mycount > 0))
841 *cv = croot->rootvar;
846 /* Mark the end of the list */
849 if (mycount || (croot != NULL))
851 ("varobj_list: assertion failed - wrong tally of root vars (%d:%d)",
857 /* Update the values for a variable and its children. This is a
858 two-pronged attack. First, re-parse the value for the root's
859 expression to see if it's changed. Then go all the way
860 through its children, reconstructing them and noting if they've
863 -1 if there was an error updating the varobj
864 -2 if the type changed
865 Otherwise it is the number of children + parent changed
867 Only root variables can be updated...
869 NOTE: This function may delete the caller's varobj. If it
870 returns -2, then it has done this and VARP will be modified
871 to point to the new varobj. */
874 varobj_update (struct varobj **varp, struct varobj ***changelist)
883 struct varobj **templist = NULL;
885 struct vstack *stack = NULL;
886 struct vstack *result = NULL;
887 struct frame_id old_fid;
888 struct frame_info *fi;
890 /* sanity check: have we been passed a pointer? */
891 if (changelist == NULL)
894 /* Only root variables can be updated... */
895 if ((*varp)->root->rootvar != *varp)
899 /* Save the selected stack frame, since we will need to change it
900 in order to evaluate expressions. */
901 old_fid = get_frame_id (deprecated_selected_frame);
903 /* Update the root variable. value_of_root can return NULL
904 if the variable is no longer around, i.e. we stepped out of
905 the frame in which a local existed. We are letting the
906 value_of_root variable dispose of the varobj if the type
909 new = value_of_root (varp, &type_changed);
916 /* Initialize a stack for temporary results */
917 vpush (&result, NULL);
919 /* If this is a "use_selected_frame" varobj, and its type has changed,
920 them note that it's changed. */
923 vpush (&result, *varp);
926 /* If values are not equal, note that it's changed.
927 There a couple of exceptions here, though.
928 We don't want some types to be reported as "changed". */
929 else if (type_changeable (*varp) &&
930 ((*varp)->updated || !my_value_equal ((*varp)->value, new, &error2)))
932 vpush (&result, *varp);
933 (*varp)->updated = 0;
935 /* error2 replaces var->error since this new value
936 WILL replace the old one. */
937 (*varp)->error = error2;
940 /* We must always keep around the new value for this root
941 variable expression, or we lose the updated children! */
942 value_free ((*varp)->value);
943 (*varp)->value = new;
945 /* Initialize a stack */
946 vpush (&stack, NULL);
948 /* Push the root's children */
949 if ((*varp)->children != NULL)
951 struct varobj_child *c;
952 for (c = (*varp)->children; c != NULL; c = c->next)
953 vpush (&stack, c->child);
956 /* Walk through the children, reconstructing them all. */
960 /* Push any children */
961 if (v->children != NULL)
963 struct varobj_child *c;
964 for (c = v->children; c != NULL; c = c->next)
965 vpush (&stack, c->child);
968 /* Update this variable */
969 new = value_of_child (v->parent, v->index);
970 if (type_changeable (v) &&
971 (v->updated || !my_value_equal (v->value, new, &error2)))
973 /* Note that it's changed */
978 /* error2 replaces v->error since this new value
979 WILL replace the old one. */
982 /* We must always keep new values, since children depend on it. */
983 if (v->value != NULL)
984 value_free (v->value);
991 /* Alloc (changed + 1) list entries */
992 /* FIXME: add a cleanup for the allocated list(s)
993 because one day the select_frame called below can longjump */
994 *changelist = xmalloc ((changed + 1) * sizeof (struct varobj *));
997 templist = xmalloc ((changed + 1) * sizeof (struct varobj *));
1003 /* Copy from result stack to list */
1005 *cv = vpop (&result);
1006 while ((*cv != NULL) && (vleft > 0))
1010 *cv = vpop (&result);
1013 warning ("varobj_update: assertion failed - vleft <> 0");
1017 /* Now we revert the order. */
1018 for (i = 0; i < changed; i++)
1019 *(*changelist + i) = *(templist + changed - 1 - i);
1020 *(*changelist + changed) = NULL;
1023 /* Restore selected frame */
1024 fi = frame_find_by_id (old_fid);
1035 /* Helper functions */
1038 * Variable object construction/destruction
1042 delete_variable (struct cpstack **resultp, struct varobj *var,
1043 int only_children_p)
1047 delete_variable_1 (resultp, &delcount, var,
1048 only_children_p, 1 /* remove_from_parent_p */ );
1053 /* Delete the variable object VAR and its children */
1054 /* IMPORTANT NOTE: If we delete a variable which is a child
1055 and the parent is not removed we dump core. It must be always
1056 initially called with remove_from_parent_p set */
1058 delete_variable_1 (struct cpstack **resultp, int *delcountp,
1059 struct varobj *var, int only_children_p,
1060 int remove_from_parent_p)
1062 struct varobj_child *vc;
1063 struct varobj_child *next;
1065 /* Delete any children of this variable, too. */
1066 for (vc = var->children; vc != NULL; vc = next)
1068 if (!remove_from_parent_p)
1069 vc->child->parent = NULL;
1070 delete_variable_1 (resultp, delcountp, vc->child, 0, only_children_p);
1075 /* if we were called to delete only the children we are done here */
1076 if (only_children_p)
1079 /* Otherwise, add it to the list of deleted ones and proceed to do so */
1080 /* If the name is null, this is a temporary variable, that has not
1081 yet been installed, don't report it, it belongs to the caller... */
1082 if (var->obj_name != NULL)
1084 cppush (resultp, xstrdup (var->obj_name));
1085 *delcountp = *delcountp + 1;
1088 /* If this variable has a parent, remove it from its parent's list */
1089 /* OPTIMIZATION: if the parent of this variable is also being deleted,
1090 (as indicated by remove_from_parent_p) we don't bother doing an
1091 expensive list search to find the element to remove when we are
1092 discarding the list afterwards */
1093 if ((remove_from_parent_p) && (var->parent != NULL))
1095 remove_child_from_parent (var->parent, var);
1098 if (var->obj_name != NULL)
1099 uninstall_variable (var);
1101 /* Free memory associated with this variable */
1102 free_variable (var);
1105 /* Install the given variable VAR with the object name VAR->OBJ_NAME. */
1107 install_variable (struct varobj *var)
1110 struct vlist *newvl;
1112 unsigned int index = 0;
1115 for (chp = var->obj_name; *chp; chp++)
1117 index = (index + (i++ * (unsigned int) *chp)) % VAROBJ_TABLE_SIZE;
1120 cv = *(varobj_table + index);
1121 while ((cv != NULL) && (strcmp (cv->var->obj_name, var->obj_name) != 0))
1125 error ("Duplicate variable object name");
1127 /* Add varobj to hash table */
1128 newvl = xmalloc (sizeof (struct vlist));
1129 newvl->next = *(varobj_table + index);
1131 *(varobj_table + index) = newvl;
1133 /* If root, add varobj to root list */
1134 if (var->root->rootvar == var)
1136 /* Add to list of root variables */
1137 if (rootlist == NULL)
1138 var->root->next = NULL;
1140 var->root->next = rootlist;
1141 rootlist = var->root;
1148 /* Unistall the object VAR. */
1150 uninstall_variable (struct varobj *var)
1154 struct varobj_root *cr;
1155 struct varobj_root *prer;
1157 unsigned int index = 0;
1160 /* Remove varobj from hash table */
1161 for (chp = var->obj_name; *chp; chp++)
1163 index = (index + (i++ * (unsigned int) *chp)) % VAROBJ_TABLE_SIZE;
1166 cv = *(varobj_table + index);
1168 while ((cv != NULL) && (strcmp (cv->var->obj_name, var->obj_name) != 0))
1175 fprintf_unfiltered (gdb_stdlog, "Deleting %s\n", var->obj_name);
1180 ("Assertion failed: Could not find variable object \"%s\" to delete",
1186 *(varobj_table + index) = cv->next;
1188 prev->next = cv->next;
1192 /* If root, remove varobj from root list */
1193 if (var->root->rootvar == var)
1195 /* Remove from list of root variables */
1196 if (rootlist == var->root)
1197 rootlist = var->root->next;
1202 while ((cr != NULL) && (cr->rootvar != var))
1210 ("Assertion failed: Could not find varobj \"%s\" in root list",
1217 prer->next = cr->next;
1224 /* Does a child with the name NAME exist in VAR? If so, return its data.
1225 If not, return NULL. */
1226 static struct varobj *
1227 child_exists (struct varobj *var, char *name)
1229 struct varobj_child *vc;
1231 for (vc = var->children; vc != NULL; vc = vc->next)
1233 if (strcmp (vc->child->name, name) == 0)
1240 /* Create and install a child of the parent of the given name */
1241 static struct varobj *
1242 create_child (struct varobj *parent, int index, char *name)
1244 struct varobj *child;
1247 child = new_variable ();
1249 /* name is allocated by name_of_child */
1251 child->index = index;
1252 child->value = value_of_child (parent, index);
1253 if ((!CPLUS_FAKE_CHILD (child) && child->value == NULL) || parent->error)
1255 child->parent = parent;
1256 child->root = parent->root;
1257 xasprintf (&childs_name, "%s.%s", parent->obj_name, name);
1258 child->obj_name = childs_name;
1259 install_variable (child);
1261 /* Save a pointer to this child in the parent */
1262 save_child_in_parent (parent, child);
1264 /* Note the type of this child */
1265 child->type = type_of_child (child);
1270 /* FIXME: This should be a generic add to list */
1271 /* Save CHILD in the PARENT's data. */
1273 save_child_in_parent (struct varobj *parent, struct varobj *child)
1275 struct varobj_child *vc;
1277 /* Insert the child at the top */
1278 vc = parent->children;
1280 (struct varobj_child *) xmalloc (sizeof (struct varobj_child));
1282 parent->children->next = vc;
1283 parent->children->child = child;
1286 /* FIXME: This should be a generic remove from list */
1287 /* Remove the CHILD from the PARENT's list of children. */
1289 remove_child_from_parent (struct varobj *parent, struct varobj *child)
1291 struct varobj_child *vc, *prev;
1293 /* Find the child in the parent's list */
1295 for (vc = parent->children; vc != NULL;)
1297 if (vc->child == child)
1304 parent->children = vc->next;
1306 prev->next = vc->next;
1312 * Miscellaneous utility functions.
1315 /* Allocate memory and initialize a new variable */
1316 static struct varobj *
1321 var = (struct varobj *) xmalloc (sizeof (struct varobj));
1323 var->obj_name = NULL;
1328 var->num_children = -1;
1330 var->children = NULL;
1338 /* Allocate memory and initialize a new root variable */
1339 static struct varobj *
1340 new_root_variable (void)
1342 struct varobj *var = new_variable ();
1343 var->root = (struct varobj_root *) xmalloc (sizeof (struct varobj_root));;
1344 var->root->lang = NULL;
1345 var->root->exp = NULL;
1346 var->root->valid_block = NULL;
1347 var->root->frame = null_frame_id;
1348 var->root->use_selected_frame = 0;
1349 var->root->rootvar = NULL;
1354 /* Free any allocated memory associated with VAR. */
1356 free_variable (struct varobj *var)
1358 /* Free the expression if this is a root variable. */
1359 if (var->root->rootvar == var)
1361 free_current_contents ((char **) &var->root->exp);
1366 xfree (var->obj_name);
1371 do_free_variable_cleanup (void *var)
1373 free_variable (var);
1376 static struct cleanup *
1377 make_cleanup_free_variable (struct varobj *var)
1379 return make_cleanup (do_free_variable_cleanup, var);
1382 /* This returns the type of the variable. This skips past typedefs
1383 and returns the real type of the variable. It also dereferences
1384 pointers and references.
1386 NOTE: TYPE_TARGET_TYPE should NOT be used anywhere in this file
1387 except within get_target_type and get_type. */
1388 static struct type *
1389 get_type (struct varobj *var)
1394 while (type != NULL && TYPE_CODE (type) == TYPE_CODE_TYPEDEF)
1395 type = TYPE_TARGET_TYPE (type);
1400 /* This returns the type of the variable, dereferencing pointers, too. */
1401 static struct type *
1402 get_type_deref (struct varobj *var)
1406 type = get_type (var);
1408 if (type != NULL && (TYPE_CODE (type) == TYPE_CODE_PTR
1409 || TYPE_CODE (type) == TYPE_CODE_REF))
1410 type = get_target_type (type);
1415 /* This returns the target type (or NULL) of TYPE, also skipping
1416 past typedefs, just like get_type ().
1418 NOTE: TYPE_TARGET_TYPE should NOT be used anywhere in this file
1419 except within get_target_type and get_type. */
1420 static struct type *
1421 get_target_type (struct type *type)
1425 type = TYPE_TARGET_TYPE (type);
1426 while (type != NULL && TYPE_CODE (type) == TYPE_CODE_TYPEDEF)
1427 type = TYPE_TARGET_TYPE (type);
1433 /* What is the default display for this variable? We assume that
1434 everything is "natural". Any exceptions? */
1435 static enum varobj_display_formats
1436 variable_default_display (struct varobj *var)
1438 return FORMAT_NATURAL;
1441 /* This function is similar to gdb's value_equal, except that this
1442 one is "safe" -- it NEVER longjmps. It determines if the VAR's
1443 value is the same as VAL2. */
1445 my_value_equal (struct value *val1, struct value *val2, int *error2)
1450 /* Special case: NULL values. If both are null, say
1452 if (val1 == NULL && val2 == NULL)
1454 else if (val1 == NULL || val2 == NULL)
1457 /* This is bogus, but unfortunately necessary. We must know
1458 exactly what caused an error -- reading val1 or val2 -- so
1459 that we can really determine if we think that something has changed. */
1462 /* We do need to catch errors here because the whole purpose
1463 is to test if value_equal() has errored */
1464 if (!gdb_value_equal (val1, val1, &r))
1467 if (!gdb_value_equal (val2, val2, &r))
1473 if (!gdb_value_equal (val1, val2, &r))
1475 /* An error occurred, this could have happened if
1476 either val1 or val2 errored. ERR1 and ERR2 tell
1477 us which of these it is. If both errored, then
1478 we assume nothing has changed. If one of them is
1479 valid, though, then something has changed. */
1482 /* both the old and new values caused errors, so
1483 we say the value did not change */
1484 /* This is indeterminate, though. Perhaps we should
1485 be safe and say, yes, it changed anyway?? */
1497 /* FIXME: The following should be generic for any pointer */
1499 vpush (struct vstack **pstack, struct varobj *var)
1503 s = (struct vstack *) xmalloc (sizeof (struct vstack));
1509 /* FIXME: The following should be generic for any pointer */
1510 static struct varobj *
1511 vpop (struct vstack **pstack)
1516 if ((*pstack)->var == NULL && (*pstack)->next == NULL)
1521 *pstack = (*pstack)->next;
1527 /* FIXME: The following should be generic for any pointer */
1529 cppush (struct cpstack **pstack, char *name)
1533 s = (struct cpstack *) xmalloc (sizeof (struct cpstack));
1539 /* FIXME: The following should be generic for any pointer */
1541 cppop (struct cpstack **pstack)
1546 if ((*pstack)->name == NULL && (*pstack)->next == NULL)
1551 *pstack = (*pstack)->next;
1558 * Language-dependencies
1561 /* Common entry points */
1563 /* Get the language of variable VAR. */
1564 static enum varobj_languages
1565 variable_language (struct varobj *var)
1567 enum varobj_languages lang;
1569 switch (var->root->exp->language_defn->la_language)
1575 case language_cplus:
1586 /* Return the number of children for a given variable.
1587 The result of this function is defined by the language
1588 implementation. The number of children returned by this function
1589 is the number of children that the user will see in the variable
1592 number_of_children (struct varobj *var)
1594 return (*var->root->lang->number_of_children) (var);;
1597 /* What is the expression for the root varobj VAR? Returns a malloc'd string. */
1599 name_of_variable (struct varobj *var)
1601 return (*var->root->lang->name_of_variable) (var);
1604 /* What is the name of the INDEX'th child of VAR? Returns a malloc'd string. */
1606 name_of_child (struct varobj *var, int index)
1608 return (*var->root->lang->name_of_child) (var, index);
1611 /* What is the ``struct value *'' of the root variable VAR?
1612 TYPE_CHANGED controls what to do if the type of a
1613 use_selected_frame = 1 variable changes. On input,
1614 TYPE_CHANGED = 1 means discard the old varobj, and replace
1615 it with this one. TYPE_CHANGED = 0 means leave it around.
1616 NB: In both cases, var_handle will point to the new varobj,
1617 so if you use TYPE_CHANGED = 0, you will have to stash the
1618 old varobj pointer away somewhere before calling this.
1619 On return, TYPE_CHANGED will be 1 if the type has changed, and
1621 static struct value *
1622 value_of_root (struct varobj **var_handle, int *type_changed)
1626 if (var_handle == NULL)
1631 /* This should really be an exception, since this should
1632 only get called with a root variable. */
1634 if (var->root->rootvar != var)
1637 if (var->root->use_selected_frame)
1639 struct varobj *tmp_var;
1640 char *old_type, *new_type;
1641 old_type = varobj_get_type (var);
1642 tmp_var = varobj_create (NULL, var->name, (CORE_ADDR) 0,
1643 USE_SELECTED_FRAME);
1644 if (tmp_var == NULL)
1648 new_type = varobj_get_type (tmp_var);
1649 if (strcmp (old_type, new_type) == 0)
1651 varobj_delete (tmp_var, NULL, 0);
1659 savestring (var->obj_name, strlen (var->obj_name));
1660 varobj_delete (var, NULL, 0);
1664 tmp_var->obj_name = varobj_gen_name ();
1666 install_variable (tmp_var);
1667 *var_handle = tmp_var;
1677 return (*var->root->lang->value_of_root) (var_handle);
1680 /* What is the ``struct value *'' for the INDEX'th child of PARENT? */
1681 static struct value *
1682 value_of_child (struct varobj *parent, int index)
1684 struct value *value;
1686 value = (*parent->root->lang->value_of_child) (parent, index);
1688 /* If we're being lazy, fetch the real value of the variable. */
1689 if (value != NULL && VALUE_LAZY (value))
1691 /* If we fail to fetch the value of the child, return
1692 NULL so that callers notice that we're leaving an
1694 if (!gdb_value_fetch_lazy (value))
1701 /* What is the type of VAR? */
1702 static struct type *
1703 type_of_child (struct varobj *var)
1706 /* If the child had no evaluation errors, var->value
1707 will be non-NULL and contain a valid type. */
1708 if (var->value != NULL)
1709 return VALUE_TYPE (var->value);
1711 /* Otherwise, we must compute the type. */
1712 return (*var->root->lang->type_of_child) (var->parent, var->index);
1715 /* Is this variable editable? Use the variable's type to make
1716 this determination. */
1718 variable_editable (struct varobj *var)
1720 return (*var->root->lang->variable_editable) (var);
1723 /* GDB already has a command called "value_of_variable". Sigh. */
1725 my_value_of_variable (struct varobj *var)
1727 return (*var->root->lang->value_of_variable) (var);
1730 /* Is VAR something that can change? Depending on language,
1731 some variable's values never change. For example,
1732 struct and unions never change values. */
1734 type_changeable (struct varobj *var)
1739 if (CPLUS_FAKE_CHILD (var))
1742 type = get_type (var);
1744 switch (TYPE_CODE (type))
1746 case TYPE_CODE_STRUCT:
1747 case TYPE_CODE_UNION:
1748 case TYPE_CODE_ARRAY:
1761 c_number_of_children (struct varobj *var)
1764 struct type *target;
1767 type = get_type (var);
1768 target = get_target_type (type);
1771 switch (TYPE_CODE (type))
1773 case TYPE_CODE_ARRAY:
1774 if (TYPE_LENGTH (type) > 0 && TYPE_LENGTH (target) > 0
1775 && TYPE_ARRAY_UPPER_BOUND_TYPE (type) != BOUND_CANNOT_BE_DETERMINED)
1776 children = TYPE_LENGTH (type) / TYPE_LENGTH (target);
1781 case TYPE_CODE_STRUCT:
1782 case TYPE_CODE_UNION:
1783 children = TYPE_NFIELDS (type);
1787 /* This is where things get compilcated. All pointers have one child.
1788 Except, of course, for struct and union ptr, which we automagically
1789 dereference for the user and function ptrs, which have no children.
1790 We also don't dereference void* as we don't know what to show.
1791 We can show char* so we allow it to be dereferenced. If you decide
1792 to test for it, please mind that a little magic is necessary to
1793 properly identify it: char* has TYPE_CODE == TYPE_CODE_INT and
1794 TYPE_NAME == "char" */
1796 switch (TYPE_CODE (target))
1798 case TYPE_CODE_STRUCT:
1799 case TYPE_CODE_UNION:
1800 children = TYPE_NFIELDS (target);
1803 case TYPE_CODE_FUNC:
1804 case TYPE_CODE_VOID:
1814 /* Other types have no children */
1822 c_name_of_variable (struct varobj *parent)
1824 return savestring (parent->name, strlen (parent->name));
1828 c_name_of_child (struct varobj *parent, int index)
1831 struct type *target;
1835 type = get_type (parent);
1836 target = get_target_type (type);
1838 switch (TYPE_CODE (type))
1840 case TYPE_CODE_ARRAY:
1841 xasprintf (&name, "%d", index);
1844 case TYPE_CODE_STRUCT:
1845 case TYPE_CODE_UNION:
1846 string = TYPE_FIELD_NAME (type, index);
1847 name = savestring (string, strlen (string));
1851 switch (TYPE_CODE (target))
1853 case TYPE_CODE_STRUCT:
1854 case TYPE_CODE_UNION:
1855 string = TYPE_FIELD_NAME (target, index);
1856 name = savestring (string, strlen (string));
1860 xasprintf (&name, "*%s", parent->name);
1866 /* This should not happen */
1867 name = xstrdup ("???");
1873 static struct value *
1874 c_value_of_root (struct varobj **var_handle)
1876 struct value *new_val;
1877 struct varobj *var = *var_handle;
1878 struct frame_info *fi;
1881 /* Only root variables can be updated... */
1882 if (var->root->rootvar != var)
1883 /* Not a root var */
1887 /* Determine whether the variable is still around. */
1888 if (var->root->valid_block == NULL)
1892 reinit_frame_cache ();
1893 fi = frame_find_by_id (var->root->frame);
1894 within_scope = fi != NULL;
1895 /* FIXME: select_frame could fail */
1902 /* We need to catch errors here, because if evaluate
1903 expression fails we just want to make val->error = 1 and
1905 if (gdb_evaluate_expression (var->root->exp, &new_val))
1907 if (VALUE_LAZY (new_val))
1909 /* We need to catch errors because if
1910 value_fetch_lazy fails we still want to continue
1911 (after making val->error = 1) */
1912 /* FIXME: Shouldn't be using VALUE_CONTENTS? The
1913 comment on value_fetch_lazy() says it is only
1914 called from the macro... */
1915 if (!gdb_value_fetch_lazy (new_val))
1924 release_value (new_val);
1931 static struct value *
1932 c_value_of_child (struct varobj *parent, int index)
1934 struct value *value;
1936 struct value *indval;
1937 struct type *type, *target;
1940 type = get_type (parent);
1941 target = get_target_type (type);
1942 name = name_of_child (parent, index);
1943 temp = parent->value;
1948 switch (TYPE_CODE (type))
1950 case TYPE_CODE_ARRAY:
1952 /* This breaks if the array lives in a (vector) register. */
1953 value = value_slice (temp, index, 1);
1954 temp = value_coerce_array (value);
1955 gdb_value_ind (temp, &value);
1957 indval = value_from_longest (builtin_type_int, (LONGEST) index);
1958 gdb_value_subscript (temp, indval, &value);
1962 case TYPE_CODE_STRUCT:
1963 case TYPE_CODE_UNION:
1964 gdb_value_struct_elt (NULL, &value, &temp, NULL, name, NULL,
1969 switch (TYPE_CODE (target))
1971 case TYPE_CODE_STRUCT:
1972 case TYPE_CODE_UNION:
1973 gdb_value_struct_elt (NULL, &value, &temp, NULL, name, NULL,
1978 gdb_value_ind (temp, &value);
1989 release_value (value);
1995 static struct type *
1996 c_type_of_child (struct varobj *parent, int index)
1999 char *name = name_of_child (parent, index);
2001 switch (TYPE_CODE (parent->type))
2003 case TYPE_CODE_ARRAY:
2004 type = get_target_type (parent->type);
2007 case TYPE_CODE_STRUCT:
2008 case TYPE_CODE_UNION:
2009 type = lookup_struct_elt_type (parent->type, name, 0);
2013 switch (TYPE_CODE (get_target_type (parent->type)))
2015 case TYPE_CODE_STRUCT:
2016 case TYPE_CODE_UNION:
2017 type = lookup_struct_elt_type (parent->type, name, 0);
2021 type = get_target_type (parent->type);
2027 /* This should not happen as only the above types have children */
2028 warning ("Child of parent whose type does not allow children");
2029 /* FIXME: Can we still go on? */
2039 c_variable_editable (struct varobj *var)
2041 switch (TYPE_CODE (get_type (var)))
2043 case TYPE_CODE_STRUCT:
2044 case TYPE_CODE_UNION:
2045 case TYPE_CODE_ARRAY:
2046 case TYPE_CODE_FUNC:
2047 case TYPE_CODE_MEMBER:
2048 case TYPE_CODE_METHOD:
2059 c_value_of_variable (struct varobj *var)
2061 /* BOGUS: if val_print sees a struct/class, it will print out its
2062 children instead of "{...}" */
2064 switch (TYPE_CODE (get_type (var)))
2066 case TYPE_CODE_STRUCT:
2067 case TYPE_CODE_UNION:
2068 return xstrdup ("{...}");
2071 case TYPE_CODE_ARRAY:
2074 xasprintf (&number, "[%d]", var->num_children);
2081 if (var->value == NULL)
2083 /* This can happen if we attempt to get the value of a struct
2084 member when the parent is an invalid pointer. This is an
2085 error condition, so we should tell the caller. */
2091 struct ui_file *stb = mem_fileopen ();
2092 struct cleanup *old_chain = make_cleanup_ui_file_delete (stb);
2095 if (VALUE_LAZY (var->value))
2096 gdb_value_fetch_lazy (var->value);
2097 val_print (VALUE_TYPE (var->value),
2098 VALUE_CONTENTS_RAW (var->value), 0,
2099 VALUE_ADDRESS (var->value), stb,
2100 format_code[(int) var->format], 1, 0, 0);
2101 thevalue = ui_file_xstrdup (stb, &dummy);
2102 do_cleanups (old_chain);
2113 cplus_number_of_children (struct varobj *var)
2116 int children, dont_know;
2121 if (!CPLUS_FAKE_CHILD (var))
2123 type = get_type_deref (var);
2125 if (((TYPE_CODE (type)) == TYPE_CODE_STRUCT) ||
2126 ((TYPE_CODE (type)) == TYPE_CODE_UNION))
2130 cplus_class_num_children (type, kids);
2131 if (kids[v_public] != 0)
2133 if (kids[v_private] != 0)
2135 if (kids[v_protected] != 0)
2138 /* Add any baseclasses */
2139 children += TYPE_N_BASECLASSES (type);
2142 /* FIXME: save children in var */
2149 type = get_type_deref (var->parent);
2151 cplus_class_num_children (type, kids);
2152 if (strcmp (var->name, "public") == 0)
2153 children = kids[v_public];
2154 else if (strcmp (var->name, "private") == 0)
2155 children = kids[v_private];
2157 children = kids[v_protected];
2162 children = c_number_of_children (var);
2167 /* Compute # of public, private, and protected variables in this class.
2168 That means we need to descend into all baseclasses and find out
2169 how many are there, too. */
2171 cplus_class_num_children (struct type *type, int children[3])
2175 children[v_public] = 0;
2176 children[v_private] = 0;
2177 children[v_protected] = 0;
2179 for (i = TYPE_N_BASECLASSES (type); i < TYPE_NFIELDS (type); i++)
2181 /* If we have a virtual table pointer, omit it. */
2182 if (TYPE_VPTR_BASETYPE (type) == type && TYPE_VPTR_FIELDNO (type) == i)
2185 if (TYPE_FIELD_PROTECTED (type, i))
2186 children[v_protected]++;
2187 else if (TYPE_FIELD_PRIVATE (type, i))
2188 children[v_private]++;
2190 children[v_public]++;
2195 cplus_name_of_variable (struct varobj *parent)
2197 return c_name_of_variable (parent);
2201 cplus_name_of_child (struct varobj *parent, int index)
2206 if (CPLUS_FAKE_CHILD (parent))
2208 /* Looking for children of public, private, or protected. */
2209 type = get_type_deref (parent->parent);
2212 type = get_type_deref (parent);
2215 switch (TYPE_CODE (type))
2217 case TYPE_CODE_STRUCT:
2218 case TYPE_CODE_UNION:
2219 if (CPLUS_FAKE_CHILD (parent))
2221 /* The fields of the class type are ordered as they
2222 appear in the class. We are given an index for a
2223 particular access control type ("public","protected",
2224 or "private"). We must skip over fields that don't
2225 have the access control we are looking for to properly
2226 find the indexed field. */
2227 int type_index = TYPE_N_BASECLASSES (type);
2228 if (strcmp (parent->name, "private") == 0)
2232 if (TYPE_VPTR_BASETYPE (type) == type
2233 && type_index == TYPE_VPTR_FIELDNO (type))
2235 else if (TYPE_FIELD_PRIVATE (type, type_index))
2241 else if (strcmp (parent->name, "protected") == 0)
2245 if (TYPE_VPTR_BASETYPE (type) == type
2246 && type_index == TYPE_VPTR_FIELDNO (type))
2248 else if (TYPE_FIELD_PROTECTED (type, type_index))
2258 if (TYPE_VPTR_BASETYPE (type) == type
2259 && type_index == TYPE_VPTR_FIELDNO (type))
2261 else if (!TYPE_FIELD_PRIVATE (type, type_index) &&
2262 !TYPE_FIELD_PROTECTED (type, type_index))
2269 name = TYPE_FIELD_NAME (type, type_index);
2271 else if (index < TYPE_N_BASECLASSES (type))
2272 /* We are looking up the name of a base class */
2273 name = TYPE_FIELD_NAME (type, index);
2277 cplus_class_num_children(type, children);
2279 /* Everything beyond the baseclasses can
2280 only be "public", "private", or "protected"
2282 The special "fake" children are always output by varobj in
2283 this order. So if INDEX == 2, it MUST be "protected". */
2284 index -= TYPE_N_BASECLASSES (type);
2288 if (children[v_public] > 0)
2290 else if (children[v_private] > 0)
2296 if (children[v_public] > 0)
2298 if (children[v_private] > 0)
2303 else if (children[v_private] > 0)
2307 /* Must be protected */
2322 return c_name_of_child (parent, index);
2326 name = savestring (name, strlen (name));
2332 static struct value *
2333 cplus_value_of_root (struct varobj **var_handle)
2335 return c_value_of_root (var_handle);
2338 static struct value *
2339 cplus_value_of_child (struct varobj *parent, int index)
2342 struct value *value;
2344 if (CPLUS_FAKE_CHILD (parent))
2345 type = get_type_deref (parent->parent);
2347 type = get_type_deref (parent);
2351 if (((TYPE_CODE (type)) == TYPE_CODE_STRUCT) ||
2352 ((TYPE_CODE (type)) == TYPE_CODE_UNION))
2354 if (CPLUS_FAKE_CHILD (parent))
2357 struct value *temp = parent->parent->value;
2362 name = name_of_child (parent, index);
2363 gdb_value_struct_elt (NULL, &value, &temp, NULL, name, NULL,
2366 release_value (value);
2370 else if (index >= TYPE_N_BASECLASSES (type))
2372 /* public, private, or protected */
2378 if (parent->value != NULL)
2380 struct value *temp = NULL;
2382 if (TYPE_CODE (VALUE_TYPE (parent->value)) == TYPE_CODE_PTR
2383 || TYPE_CODE (VALUE_TYPE (parent->value)) == TYPE_CODE_REF)
2385 if (!gdb_value_ind (parent->value, &temp))
2389 temp = parent->value;
2393 value = value_cast (TYPE_FIELD_TYPE (type, index), temp);
2394 release_value (value);
2398 /* We failed to evaluate the parent's value, so don't even
2399 bother trying to evaluate this child. */
2407 return c_value_of_child (parent, index);
2412 static struct type *
2413 cplus_type_of_child (struct varobj *parent, int index)
2415 struct type *type, *t;
2417 if (CPLUS_FAKE_CHILD (parent))
2419 /* Looking for the type of a child of public, private, or protected. */
2420 t = get_type_deref (parent->parent);
2423 t = get_type_deref (parent);
2426 switch (TYPE_CODE (t))
2428 case TYPE_CODE_STRUCT:
2429 case TYPE_CODE_UNION:
2430 if (CPLUS_FAKE_CHILD (parent))
2432 char *name = cplus_name_of_child (parent, index);
2433 type = lookup_struct_elt_type (t, name, 0);
2436 else if (index < TYPE_N_BASECLASSES (t))
2437 type = TYPE_FIELD_TYPE (t, index);
2450 return c_type_of_child (parent, index);
2456 cplus_variable_editable (struct varobj *var)
2458 if (CPLUS_FAKE_CHILD (var))
2461 return c_variable_editable (var);
2465 cplus_value_of_variable (struct varobj *var)
2468 /* If we have one of our special types, don't print out
2470 if (CPLUS_FAKE_CHILD (var))
2471 return xstrdup ("");
2473 return c_value_of_variable (var);
2479 java_number_of_children (struct varobj *var)
2481 return cplus_number_of_children (var);
2485 java_name_of_variable (struct varobj *parent)
2489 name = cplus_name_of_variable (parent);
2490 /* If the name has "-" in it, it is because we
2491 needed to escape periods in the name... */
2494 while (*p != '\000')
2505 java_name_of_child (struct varobj *parent, int index)
2509 name = cplus_name_of_child (parent, index);
2510 /* Escape any periods in the name... */
2513 while (*p != '\000')
2523 static struct value *
2524 java_value_of_root (struct varobj **var_handle)
2526 return cplus_value_of_root (var_handle);
2529 static struct value *
2530 java_value_of_child (struct varobj *parent, int index)
2532 return cplus_value_of_child (parent, index);
2535 static struct type *
2536 java_type_of_child (struct varobj *parent, int index)
2538 return cplus_type_of_child (parent, index);
2542 java_variable_editable (struct varobj *var)
2544 return cplus_variable_editable (var);
2548 java_value_of_variable (struct varobj *var)
2550 return cplus_value_of_variable (var);
2553 extern void _initialize_varobj (void);
2555 _initialize_varobj (void)
2557 int sizeof_table = sizeof (struct vlist *) * VAROBJ_TABLE_SIZE;
2559 varobj_table = xmalloc (sizeof_table);
2560 memset (varobj_table, 0, sizeof_table);
2562 add_show_from_set (add_set_cmd ("debugvarobj", class_maintenance, var_zinteger, (char *) &varobjdebug, "Set varobj debugging.\n\
2563 When non-zero, varobj debugging is enabled.", &setlist),