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"
30 /* Non-zero if we want to see trace of varobj level stuff. */
34 /* String representations of gdb's format codes */
35 char *varobj_format_string
[] =
36 { "natural", "binary", "decimal", "hexadecimal", "octal" };
38 /* String representations of gdb's known languages */
39 char *varobj_language_string
[] = { "unknown", "C", "C++", "Java" };
43 /* Every root variable has one of these structures saved in its
44 varobj. Members which must be free'd are noted. */
48 /* Alloc'd expression for this parent. */
49 struct expression
*exp
;
51 /* Block for which this expression is valid */
52 struct block
*valid_block
;
54 /* The frame for this expression */
57 /* If 1, "update" always recomputes the frame & valid block
58 using the currently selected frame. */
59 int use_selected_frame
;
61 /* Language info for this variable and its children */
62 struct language_specific
*lang
;
64 /* The varobj for this root node. */
65 struct varobj
*rootvar
;
67 /* Next root variable */
68 struct varobj_root
*next
;
71 /* Every variable in the system has a structure of this type defined
72 for it. This structure holds all information necessary to manipulate
73 a particular object variable. Members which must be freed are noted. */
77 /* Alloc'd name of the variable for this object.. If this variable is a
78 child, then this name will be the child's source name.
80 /* NOTE: This is the "expression" */
83 /* The alloc'd name for this variable's object. This is here for
84 convenience when constructing this object's children. */
87 /* Index of this variable in its parent or -1 */
90 /* The type of this variable. This may NEVER be NULL. */
93 /* The value of this expression or subexpression. This may be NULL. */
96 /* Did an error occur evaluating the expression or getting its value? */
99 /* The number of (immediate) children this variable has */
102 /* If this object is a child, this points to its immediate parent. */
103 struct varobj
*parent
;
105 /* A list of this object's children */
106 struct varobj_child
*children
;
108 /* Description of the root variable. Points to root variable for children. */
109 struct varobj_root
*root
;
111 /* The format of the output for this object */
112 enum varobj_display_formats format
;
115 /* Every variable keeps a linked list of its children, described
116 by the following structure. */
117 /* FIXME: Deprecated. All should use vlist instead */
122 /* Pointer to the child's data */
123 struct varobj
*child
;
125 /* Pointer to the next child */
126 struct varobj_child
*next
;
129 /* A stack of varobjs */
130 /* FIXME: Deprecated. All should use vlist instead */
141 struct cpstack
*next
;
144 /* A list of varobjs */
152 /* Private function prototypes */
154 /* Helper functions for the above subcommands. */
156 static int delete_variable (struct cpstack
**, struct varobj
*, int);
158 static void delete_variable_1 (struct cpstack
**, int *,
159 struct varobj
*, int, int);
161 static int install_variable (struct varobj
*);
163 static void uninstall_variable (struct varobj
*);
165 static struct varobj
*child_exists (struct varobj
*, char *);
167 static struct varobj
*create_child (struct varobj
*, int, char *);
169 static void save_child_in_parent (struct varobj
*, struct varobj
*);
171 static void remove_child_from_parent (struct varobj
*, struct varobj
*);
173 /* Utility routines */
175 static struct varobj
*new_variable (void);
177 static struct varobj
*new_root_variable (void);
179 static void free_variable (struct varobj
*var
);
181 static struct cleanup
*make_cleanup_free_variable (struct varobj
*var
);
183 static struct type
*get_type (struct varobj
*var
);
185 static struct type
*get_type_deref (struct varobj
*var
);
187 static struct type
*get_target_type (struct type
*);
189 static enum varobj_display_formats
variable_default_display (struct varobj
*);
191 static int my_value_equal (struct value
*, struct value
*, int *);
193 static void vpush (struct vstack
**pstack
, struct varobj
*var
);
195 static struct varobj
*vpop (struct vstack
**pstack
);
197 static void cppush (struct cpstack
**pstack
, char *name
);
199 static char *cppop (struct cpstack
**pstack
);
201 /* Language-specific routines. */
203 static enum varobj_languages
variable_language (struct varobj
*var
);
205 static int number_of_children (struct varobj
*);
207 static char *name_of_variable (struct varobj
*);
209 static char *name_of_child (struct varobj
*, int);
211 static struct value
*value_of_root (struct varobj
**var_handle
, int *);
213 static struct value
*value_of_child (struct varobj
*parent
, int index
);
215 static struct type
*type_of_child (struct varobj
*var
);
217 static int variable_editable (struct varobj
*var
);
219 static char *my_value_of_variable (struct varobj
*var
);
221 static int type_changeable (struct varobj
*var
);
223 /* C implementation */
225 static int c_number_of_children (struct varobj
*var
);
227 static char *c_name_of_variable (struct varobj
*parent
);
229 static char *c_name_of_child (struct varobj
*parent
, int index
);
231 static struct value
*c_value_of_root (struct varobj
**var_handle
);
233 static struct value
*c_value_of_child (struct varobj
*parent
, int index
);
235 static struct type
*c_type_of_child (struct varobj
*parent
, int index
);
237 static int c_variable_editable (struct varobj
*var
);
239 static char *c_value_of_variable (struct varobj
*var
);
241 /* C++ implementation */
243 static int cplus_number_of_children (struct varobj
*var
);
245 static void cplus_class_num_children (struct type
*type
, int children
[3]);
247 static char *cplus_name_of_variable (struct varobj
*parent
);
249 static char *cplus_name_of_child (struct varobj
*parent
, int index
);
251 static struct value
*cplus_value_of_root (struct varobj
**var_handle
);
253 static struct value
*cplus_value_of_child (struct varobj
*parent
, int index
);
255 static struct type
*cplus_type_of_child (struct varobj
*parent
, int index
);
257 static int cplus_variable_editable (struct varobj
*var
);
259 static char *cplus_value_of_variable (struct varobj
*var
);
261 /* Java implementation */
263 static int java_number_of_children (struct varobj
*var
);
265 static char *java_name_of_variable (struct varobj
*parent
);
267 static char *java_name_of_child (struct varobj
*parent
, int index
);
269 static struct value
*java_value_of_root (struct varobj
**var_handle
);
271 static struct value
*java_value_of_child (struct varobj
*parent
, int index
);
273 static struct type
*java_type_of_child (struct varobj
*parent
, int index
);
275 static int java_variable_editable (struct varobj
*var
);
277 static char *java_value_of_variable (struct varobj
*var
);
279 /* The language specific vector */
281 struct language_specific
284 /* The language of this variable */
285 enum varobj_languages language
;
287 /* The number of children of PARENT. */
288 int (*number_of_children
) (struct varobj
* parent
);
290 /* The name (expression) of a root varobj. */
291 char *(*name_of_variable
) (struct varobj
* parent
);
293 /* The name of the INDEX'th child of PARENT. */
294 char *(*name_of_child
) (struct varobj
* parent
, int index
);
296 /* The ``struct value *'' of the root variable ROOT. */
297 struct value
*(*value_of_root
) (struct varobj
** root_handle
);
299 /* The ``struct value *'' of the INDEX'th child of PARENT. */
300 struct value
*(*value_of_child
) (struct varobj
* parent
, int index
);
302 /* The type of the INDEX'th child of PARENT. */
303 struct type
*(*type_of_child
) (struct varobj
* parent
, int index
);
305 /* Is VAR editable? */
306 int (*variable_editable
) (struct varobj
* var
);
308 /* The current value of VAR. */
309 char *(*value_of_variable
) (struct varobj
* var
);
312 /* Array of known source language routines. */
313 static struct language_specific
314 languages
[vlang_end
][sizeof (struct language_specific
)] = {
315 /* Unknown (try treating as C */
318 c_number_of_children
,
330 c_number_of_children
,
342 cplus_number_of_children
,
343 cplus_name_of_variable
,
346 cplus_value_of_child
,
348 cplus_variable_editable
,
349 cplus_value_of_variable
}
354 java_number_of_children
,
355 java_name_of_variable
,
360 java_variable_editable
,
361 java_value_of_variable
}
364 /* A little convenience enum for dealing with C++/Java */
367 v_public
= 0, v_private
, v_protected
372 /* Mappings of varobj_display_formats enums to gdb's format codes */
373 static int format_code
[] = { 0, 't', 'd', 'x', 'o' };
375 /* Header of the list of root variable objects */
376 static struct varobj_root
*rootlist
;
377 static int rootcount
= 0; /* number of root varobjs in the list */
379 /* Prime number indicating the number of buckets in the hash table */
380 /* A prime large enough to avoid too many colisions */
381 #define VAROBJ_TABLE_SIZE 227
383 /* Pointer to the varobj hash table (built at run time) */
384 static struct vlist
**varobj_table
;
386 /* Is the variable X one of our "fake" children? */
387 #define CPLUS_FAKE_CHILD(x) \
388 ((x) != NULL && (x)->type == NULL && (x)->value == NULL)
391 /* API Implementation */
393 /* Creates a varobj (not its children) */
396 varobj_create (char *objname
,
397 char *expression
, CORE_ADDR frame
, enum varobj_type type
)
400 struct frame_info
*fi
;
401 struct frame_info
*old_fi
= NULL
;
403 struct cleanup
*old_chain
;
405 /* Fill out a varobj structure for the (root) variable being constructed. */
406 var
= new_root_variable ();
407 old_chain
= make_cleanup_free_variable (var
);
409 if (expression
!= NULL
)
412 enum varobj_languages lang
;
414 /* Parse and evaluate the expression, filling in as much
415 of the variable's data as possible */
417 /* Allow creator to specify context of variable */
418 if ((type
== USE_CURRENT_FRAME
) || (type
== USE_SELECTED_FRAME
))
421 fi
= find_frame_addr_in_frame_chain (frame
);
423 /* frame = -2 means always use selected frame */
424 if (type
== USE_SELECTED_FRAME
)
425 var
->root
->use_selected_frame
= 1;
429 block
= get_frame_block (fi
);
432 innermost_block
= NULL
;
433 /* Wrap the call to parse expression, so we can
434 return a sensible error. */
435 if (!gdb_parse_exp_1 (&p
, block
, 0, &var
->root
->exp
))
440 /* Don't allow variables to be created for types. */
441 if (var
->root
->exp
->elts
[0].opcode
== OP_TYPE
)
443 do_cleanups (old_chain
);
444 fprintf_unfiltered (gdb_stderr
,
445 "Attempt to use a type name as an expression.");
449 var
->format
= variable_default_display (var
);
450 var
->root
->valid_block
= innermost_block
;
451 var
->name
= savestring (expression
, strlen (expression
));
453 /* When the frame is different from the current frame,
454 we must select the appropriate frame before parsing
455 the expression, otherwise the value will not be current.
456 Since select_frame is so benign, just call it for all cases. */
459 var
->root
->frame
= FRAME_FP (fi
);
460 old_fi
= selected_frame
;
461 select_frame (fi
, -1);
464 /* We definitively need to catch errors here.
465 If evaluate_expression succeeds we got the value we wanted.
466 But if it fails, we still go on with a call to evaluate_type() */
467 if (gdb_evaluate_expression (var
->root
->exp
, &var
->value
))
470 release_value (var
->value
);
471 if (VALUE_LAZY (var
->value
))
472 gdb_value_fetch_lazy (var
->value
);
475 var
->value
= evaluate_type (var
->root
->exp
);
477 var
->type
= VALUE_TYPE (var
->value
);
479 /* Set language info */
480 lang
= variable_language (var
);
481 var
->root
->lang
= languages
[lang
];
483 /* Set ourselves as our root */
484 var
->root
->rootvar
= var
;
486 /* Reset the selected frame */
488 select_frame (old_fi
, -1);
491 /* If the variable object name is null, that means this
492 is a temporary variable, so don't install it. */
494 if ((var
!= NULL
) && (objname
!= NULL
))
496 var
->obj_name
= savestring (objname
, strlen (objname
));
498 /* If a varobj name is duplicated, the install will fail so
500 if (!install_variable (var
))
502 do_cleanups (old_chain
);
507 discard_cleanups (old_chain
);
511 /* Generates an unique name that can be used for a varobj */
514 varobj_gen_name (void)
519 /* generate a name for this object */
521 sprintf (obj_name
, "var%d", id
);
523 return xstrdup (obj_name
);
526 /* Given an "objname", returns the pointer to the corresponding varobj
527 or NULL if not found */
530 varobj_get_handle (char *objname
)
534 unsigned int index
= 0;
537 for (chp
= objname
; *chp
; chp
++)
539 index
= (index
+ (i
++ * (unsigned int) *chp
)) % VAROBJ_TABLE_SIZE
;
542 cv
= *(varobj_table
+ index
);
543 while ((cv
!= NULL
) && (strcmp (cv
->var
->obj_name
, objname
) != 0))
547 error ("Variable object not found");
552 /* Given the handle, return the name of the object */
555 varobj_get_objname (struct varobj
*var
)
557 return var
->obj_name
;
560 /* Given the handle, return the expression represented by the object */
563 varobj_get_expression (struct varobj
*var
)
565 return name_of_variable (var
);
568 /* Deletes a varobj and all its children if only_children == 0,
569 otherwise deletes only the children; returns a malloc'ed list of all the
570 (malloc'ed) names of the variables that have been deleted (NULL terminated) */
573 varobj_delete (struct varobj
*var
, char ***dellist
, int only_children
)
577 struct cpstack
*result
= NULL
;
580 /* Initialize a stack for temporary results */
581 cppush (&result
, NULL
);
584 /* Delete only the variable children */
585 delcount
= delete_variable (&result
, var
, 1 /* only the children */ );
587 /* Delete the variable and all its children */
588 delcount
= delete_variable (&result
, var
, 0 /* parent+children */ );
590 /* We may have been asked to return a list of what has been deleted */
593 *dellist
= xmalloc ((delcount
+ 1) * sizeof (char *));
597 *cp
= cppop (&result
);
598 while ((*cp
!= NULL
) && (mycount
> 0))
602 *cp
= cppop (&result
);
605 if (mycount
|| (*cp
!= NULL
))
606 warning ("varobj_delete: assertion failed - mycount(=%d) <> 0",
613 /* Set/Get variable object display format */
615 enum varobj_display_formats
616 varobj_set_display_format (struct varobj
*var
,
617 enum varobj_display_formats format
)
624 case FORMAT_HEXADECIMAL
:
626 var
->format
= format
;
630 var
->format
= variable_default_display (var
);
636 enum varobj_display_formats
637 varobj_get_display_format (struct varobj
*var
)
643 varobj_get_num_children (struct varobj
*var
)
645 if (var
->num_children
== -1)
646 var
->num_children
= number_of_children (var
);
648 return var
->num_children
;
651 /* Creates a list of the immediate children of a variable object;
652 the return code is the number of such children or -1 on error */
655 varobj_list_children (struct varobj
*var
, struct varobj
***childlist
)
657 struct varobj
*child
;
661 /* sanity check: have we been passed a pointer? */
662 if (childlist
== NULL
)
667 if (var
->num_children
== -1)
668 var
->num_children
= number_of_children (var
);
670 /* List of children */
671 *childlist
= xmalloc ((var
->num_children
+ 1) * sizeof (struct varobj
*));
673 for (i
= 0; i
< var
->num_children
; i
++)
675 /* Mark as the end in case we bail out */
676 *((*childlist
) + i
) = NULL
;
678 /* check if child exists, if not create */
679 name
= name_of_child (var
, i
);
680 child
= child_exists (var
, name
);
682 child
= create_child (var
, i
, name
);
684 *((*childlist
) + i
) = child
;
687 /* End of list is marked by a NULL pointer */
688 *((*childlist
) + i
) = NULL
;
690 return var
->num_children
;
693 /* Obtain the type of an object Variable as a string similar to the one gdb
694 prints on the console */
697 varobj_get_type (struct varobj
*var
)
700 struct cleanup
*old_chain
;
705 /* For the "fake" variables, do not return a type. (It's type is
707 if (CPLUS_FAKE_CHILD (var
))
710 stb
= mem_fileopen ();
711 old_chain
= make_cleanup_ui_file_delete (stb
);
713 /* To print the type, we simply create a zero ``struct value *'' and
714 cast it to our type. We then typeprint this variable. */
715 val
= value_zero (var
->type
, not_lval
);
716 type_print (VALUE_TYPE (val
), "", stb
, -1);
718 thetype
= ui_file_xstrdup (stb
, &length
);
719 do_cleanups (old_chain
);
723 enum varobj_languages
724 varobj_get_language (struct varobj
*var
)
726 return variable_language (var
);
730 varobj_get_attributes (struct varobj
*var
)
734 if (variable_editable (var
))
735 /* FIXME: define masks for attributes */
736 attributes
|= 0x00000001; /* Editable */
742 varobj_get_value (struct varobj
*var
)
744 return my_value_of_variable (var
);
747 /* Set the value of an object variable (if it is editable) to the
748 value of the given expression */
749 /* Note: Invokes functions that can call error() */
752 varobj_set_value (struct varobj
*var
, char *expression
)
757 /* The argument "expression" contains the variable's new value.
758 We need to first construct a legal expression for this -- ugh! */
759 /* Does this cover all the bases? */
760 struct expression
*exp
;
762 int saved_input_radix
= input_radix
;
764 if (var
->value
!= NULL
&& variable_editable (var
) && !var
->error
)
766 char *s
= expression
;
769 input_radix
= 10; /* ALWAYS reset to decimal temporarily */
770 if (!gdb_parse_exp_1 (&s
, 0, 0, &exp
))
771 /* We cannot proceed without a well-formed expression. */
773 if (!gdb_evaluate_expression (exp
, &value
))
775 /* We cannot proceed without a valid expression. */
780 if (!gdb_value_assign (var
->value
, value
, &val
))
782 value_free (var
->value
);
785 input_radix
= saved_input_radix
;
792 /* Returns a malloc'ed list with all root variable objects */
794 varobj_list (struct varobj
***varlist
)
797 struct varobj_root
*croot
;
798 int mycount
= rootcount
;
800 /* Alloc (rootcount + 1) entries for the result */
801 *varlist
= xmalloc ((rootcount
+ 1) * sizeof (struct varobj
*));
805 while ((croot
!= NULL
) && (mycount
> 0))
807 *cv
= croot
->rootvar
;
812 /* Mark the end of the list */
815 if (mycount
|| (croot
!= NULL
))
817 ("varobj_list: assertion failed - wrong tally of root vars (%d:%d)",
823 /* Update the values for a variable and its children. This is a
824 two-pronged attack. First, re-parse the value for the root's
825 expression to see if it's changed. Then go all the way
826 through its children, reconstructing them and noting if they've
829 -1 if there was an error updating the varobj
830 -2 if the type changed
831 Otherwise it is the number of children + parent changed
833 Only root variables can be updated...
835 NOTE: This function may delete the caller's varobj. If it
836 returns -2, then it has done this and VARP will be modified
837 to point to the new varobj. */
840 varobj_update (struct varobj
**varp
, struct varobj
***changelist
)
849 struct varobj
**templist
= NULL
;
851 struct vstack
*stack
= NULL
;
852 struct vstack
*result
= NULL
;
853 struct frame_info
*old_fi
;
855 /* sanity check: have we been passed a pointer? */
856 if (changelist
== NULL
)
859 /* Only root variables can be updated... */
860 if ((*varp
)->root
->rootvar
!= *varp
)
864 /* Save the selected stack frame, since we will need to change it
865 in order to evaluate expressions. */
866 old_fi
= selected_frame
;
868 /* Update the root variable. value_of_root can return NULL
869 if the variable is no longer around, i.e. we stepped out of
870 the frame in which a local existed. We are letting the
871 value_of_root variable dispose of the varobj if the type
874 new = value_of_root (varp
, &type_changed
);
881 /* Initialize a stack for temporary results */
882 vpush (&result
, NULL
);
884 /* If this is a "use_selected_frame" varobj, and its type has changed,
885 them note that it's changed. */
888 vpush (&result
, *varp
);
891 /* If values are not equal, note that it's changed.
892 There a couple of exceptions here, though.
893 We don't want some types to be reported as "changed". */
894 else if (type_changeable (*varp
)
895 && !my_value_equal ((*varp
)->value
, new, &error2
))
897 vpush (&result
, *varp
);
899 /* error2 replaces var->error since this new value
900 WILL replace the old one. */
901 (*varp
)->error
= error2
;
904 /* We must always keep around the new value for this root
905 variable expression, or we lose the updated children! */
906 value_free ((*varp
)->value
);
907 (*varp
)->value
= new;
909 /* Initialize a stack */
910 vpush (&stack
, NULL
);
912 /* Push the root's children */
913 if ((*varp
)->children
!= NULL
)
915 struct varobj_child
*c
;
916 for (c
= (*varp
)->children
; c
!= NULL
; c
= c
->next
)
917 vpush (&stack
, c
->child
);
920 /* Walk through the children, reconstructing them all. */
924 /* Push any children */
925 if (v
->children
!= NULL
)
927 struct varobj_child
*c
;
928 for (c
= v
->children
; c
!= NULL
; c
= c
->next
)
929 vpush (&stack
, c
->child
);
932 /* Update this variable */
933 new = value_of_child (v
->parent
, v
->index
);
934 if (type_changeable (v
) && !my_value_equal (v
->value
, new, &error2
))
936 /* Note that it's changed */
940 /* error2 replaces v->error since this new value
941 WILL replace the old one. */
944 /* We must always keep new values, since children depend on it. */
945 if (v
->value
!= NULL
)
946 value_free (v
->value
);
953 /* Alloc (changed + 1) list entries */
954 /* FIXME: add a cleanup for the allocated list(s)
955 because one day the select_frame called below can longjump */
956 *changelist
= xmalloc ((changed
+ 1) * sizeof (struct varobj
*));
959 templist
= xmalloc ((changed
+ 1) * sizeof (struct varobj
*));
965 /* Copy from result stack to list */
967 *cv
= vpop (&result
);
968 while ((*cv
!= NULL
) && (vleft
> 0))
972 *cv
= vpop (&result
);
975 warning ("varobj_update: assertion failed - vleft <> 0");
979 /* Now we revert the order. */
980 for (i
= 0; i
< changed
; i
++)
981 *(*changelist
+ i
) = *(templist
+ changed
- 1 - i
);
982 *(*changelist
+ changed
) = NULL
;
985 /* Restore selected frame */
986 select_frame (old_fi
, -1);
995 /* Helper functions */
998 * Variable object construction/destruction
1002 delete_variable (struct cpstack
**resultp
, struct varobj
*var
,
1003 int only_children_p
)
1007 delete_variable_1 (resultp
, &delcount
, var
,
1008 only_children_p
, 1 /* remove_from_parent_p */ );
1013 /* Delete the variable object VAR and its children */
1014 /* IMPORTANT NOTE: If we delete a variable which is a child
1015 and the parent is not removed we dump core. It must be always
1016 initially called with remove_from_parent_p set */
1018 delete_variable_1 (struct cpstack
**resultp
, int *delcountp
,
1019 struct varobj
*var
, int only_children_p
,
1020 int remove_from_parent_p
)
1022 struct varobj_child
*vc
;
1023 struct varobj_child
*next
;
1025 /* Delete any children of this variable, too. */
1026 for (vc
= var
->children
; vc
!= NULL
; vc
= next
)
1028 if (!remove_from_parent_p
)
1029 vc
->child
->parent
= NULL
;
1030 delete_variable_1 (resultp
, delcountp
, vc
->child
, 0, only_children_p
);
1035 /* if we were called to delete only the children we are done here */
1036 if (only_children_p
)
1039 /* Otherwise, add it to the list of deleted ones and proceed to do so */
1040 /* If the name is null, this is a temporary variable, that has not
1041 yet been installed, don't report it, it belongs to the caller... */
1042 if (var
->obj_name
!= NULL
)
1044 cppush (resultp
, xstrdup (var
->obj_name
));
1045 *delcountp
= *delcountp
+ 1;
1048 /* If this variable has a parent, remove it from its parent's list */
1049 /* OPTIMIZATION: if the parent of this variable is also being deleted,
1050 (as indicated by remove_from_parent_p) we don't bother doing an
1051 expensive list search to find the element to remove when we are
1052 discarding the list afterwards */
1053 if ((remove_from_parent_p
) && (var
->parent
!= NULL
))
1055 remove_child_from_parent (var
->parent
, var
);
1058 if (var
->obj_name
!= NULL
)
1059 uninstall_variable (var
);
1061 /* Free memory associated with this variable */
1062 free_variable (var
);
1065 /* Install the given variable VAR with the object name VAR->OBJ_NAME. */
1067 install_variable (struct varobj
*var
)
1070 struct vlist
*newvl
;
1072 unsigned int index
= 0;
1075 for (chp
= var
->obj_name
; *chp
; chp
++)
1077 index
= (index
+ (i
++ * (unsigned int) *chp
)) % VAROBJ_TABLE_SIZE
;
1080 cv
= *(varobj_table
+ index
);
1081 while ((cv
!= NULL
) && (strcmp (cv
->var
->obj_name
, var
->obj_name
) != 0))
1085 error ("Duplicate variable object name");
1087 /* Add varobj to hash table */
1088 newvl
= xmalloc (sizeof (struct vlist
));
1089 newvl
->next
= *(varobj_table
+ index
);
1091 *(varobj_table
+ index
) = newvl
;
1093 /* If root, add varobj to root list */
1094 if (var
->root
->rootvar
== var
)
1096 /* Add to list of root variables */
1097 if (rootlist
== NULL
)
1098 var
->root
->next
= NULL
;
1100 var
->root
->next
= rootlist
;
1101 rootlist
= var
->root
;
1108 /* Unistall the object VAR. */
1110 uninstall_variable (struct varobj
*var
)
1114 struct varobj_root
*cr
;
1115 struct varobj_root
*prer
;
1117 unsigned int index
= 0;
1120 /* Remove varobj from hash table */
1121 for (chp
= var
->obj_name
; *chp
; chp
++)
1123 index
= (index
+ (i
++ * (unsigned int) *chp
)) % VAROBJ_TABLE_SIZE
;
1126 cv
= *(varobj_table
+ index
);
1128 while ((cv
!= NULL
) && (strcmp (cv
->var
->obj_name
, var
->obj_name
) != 0))
1135 fprintf_unfiltered (gdb_stdlog
, "Deleting %s\n", var
->obj_name
);
1140 ("Assertion failed: Could not find variable object \"%s\" to delete",
1146 *(varobj_table
+ index
) = cv
->next
;
1148 prev
->next
= cv
->next
;
1152 /* If root, remove varobj from root list */
1153 if (var
->root
->rootvar
== var
)
1155 /* Remove from list of root variables */
1156 if (rootlist
== var
->root
)
1157 rootlist
= var
->root
->next
;
1162 while ((cr
!= NULL
) && (cr
->rootvar
!= var
))
1170 ("Assertion failed: Could not find varobj \"%s\" in root list",
1177 prer
->next
= cr
->next
;
1184 /* Does a child with the name NAME exist in VAR? If so, return its data.
1185 If not, return NULL. */
1186 static struct varobj
*
1187 child_exists (struct varobj
*var
, char *name
)
1189 struct varobj_child
*vc
;
1191 for (vc
= var
->children
; vc
!= NULL
; vc
= vc
->next
)
1193 if (STREQ (vc
->child
->name
, name
))
1200 /* Create and install a child of the parent of the given name */
1201 static struct varobj
*
1202 create_child (struct varobj
*parent
, int index
, char *name
)
1204 struct varobj
*child
;
1207 child
= new_variable ();
1209 /* name is allocated by name_of_child */
1211 child
->index
= index
;
1212 child
->value
= value_of_child (parent
, index
);
1213 if ((!CPLUS_FAKE_CHILD(child
) && child
->value
== NULL
) || parent
->error
)
1215 child
->parent
= parent
;
1216 child
->root
= parent
->root
;
1218 (char *) xmalloc ((strlen (parent
->obj_name
) + strlen (name
) + 2) *
1220 sprintf (childs_name
, "%s.%s", parent
->obj_name
, name
);
1221 child
->obj_name
= childs_name
;
1222 install_variable (child
);
1224 /* Save a pointer to this child in the parent */
1225 save_child_in_parent (parent
, child
);
1227 /* Note the type of this child */
1228 child
->type
= type_of_child (child
);
1233 /* FIXME: This should be a generic add to list */
1234 /* Save CHILD in the PARENT's data. */
1236 save_child_in_parent (struct varobj
*parent
, struct varobj
*child
)
1238 struct varobj_child
*vc
;
1240 /* Insert the child at the top */
1241 vc
= parent
->children
;
1243 (struct varobj_child
*) xmalloc (sizeof (struct varobj_child
));
1245 parent
->children
->next
= vc
;
1246 parent
->children
->child
= child
;
1249 /* FIXME: This should be a generic remove from list */
1250 /* Remove the CHILD from the PARENT's list of children. */
1252 remove_child_from_parent (struct varobj
*parent
, struct varobj
*child
)
1254 struct varobj_child
*vc
, *prev
;
1256 /* Find the child in the parent's list */
1258 for (vc
= parent
->children
; vc
!= NULL
;)
1260 if (vc
->child
== child
)
1267 parent
->children
= vc
->next
;
1269 prev
->next
= vc
->next
;
1275 * Miscellaneous utility functions.
1278 /* Allocate memory and initialize a new variable */
1279 static struct varobj
*
1284 var
= (struct varobj
*) xmalloc (sizeof (struct varobj
));
1286 var
->obj_name
= NULL
;
1291 var
->num_children
= -1;
1293 var
->children
= NULL
;
1300 /* Allocate memory and initialize a new root variable */
1301 static struct varobj
*
1302 new_root_variable (void)
1304 struct varobj
*var
= new_variable ();
1305 var
->root
= (struct varobj_root
*) xmalloc (sizeof (struct varobj_root
));;
1306 var
->root
->lang
= NULL
;
1307 var
->root
->exp
= NULL
;
1308 var
->root
->valid_block
= NULL
;
1309 var
->root
->frame
= (CORE_ADDR
) -1;
1310 var
->root
->use_selected_frame
= 0;
1311 var
->root
->rootvar
= NULL
;
1316 /* Free any allocated memory associated with VAR. */
1318 free_variable (struct varobj
*var
)
1320 /* Free the expression if this is a root variable. */
1321 if (var
->root
->rootvar
== var
)
1323 free_current_contents ((char **) &var
->root
->exp
);
1328 xfree (var
->obj_name
);
1333 do_free_variable_cleanup (void *var
)
1335 free_variable (var
);
1338 static struct cleanup
*
1339 make_cleanup_free_variable (struct varobj
*var
)
1341 return make_cleanup (do_free_variable_cleanup
, var
);
1344 /* This returns the type of the variable. This skips past typedefs
1345 and returns the real type of the variable. It also dereferences
1346 pointers and references. */
1347 static struct type
*
1348 get_type (struct varobj
*var
)
1353 while (type
!= NULL
&& TYPE_CODE (type
) == TYPE_CODE_TYPEDEF
)
1354 type
= TYPE_TARGET_TYPE (type
);
1359 /* This returns the type of the variable, dereferencing pointers, too. */
1360 static struct type
*
1361 get_type_deref (struct varobj
*var
)
1365 type
= get_type (var
);
1367 if (type
!= NULL
&& (TYPE_CODE (type
) == TYPE_CODE_PTR
1368 || TYPE_CODE (type
) == TYPE_CODE_REF
))
1369 type
= get_target_type (type
);
1374 /* This returns the target type (or NULL) of TYPE, also skipping
1375 past typedefs, just like get_type (). */
1376 static struct type
*
1377 get_target_type (struct type
*type
)
1381 type
= TYPE_TARGET_TYPE (type
);
1382 while (type
!= NULL
&& TYPE_CODE (type
) == TYPE_CODE_TYPEDEF
)
1383 type
= TYPE_TARGET_TYPE (type
);
1389 /* What is the default display for this variable? We assume that
1390 everything is "natural". Any exceptions? */
1391 static enum varobj_display_formats
1392 variable_default_display (struct varobj
*var
)
1394 return FORMAT_NATURAL
;
1397 /* This function is similar to gdb's value_equal, except that this
1398 one is "safe" -- it NEVER longjmps. It determines if the VAR's
1399 value is the same as VAL2. */
1401 my_value_equal (struct value
*val1
, struct value
*val2
, int *error2
)
1406 /* Special case: NULL values. If both are null, say
1408 if (val1
== NULL
&& val2
== NULL
)
1410 else if (val1
== NULL
|| val2
== NULL
)
1413 /* This is bogus, but unfortunately necessary. We must know
1414 exactly what caused an error -- reading val1 or val2 -- so
1415 that we can really determine if we think that something has changed. */
1418 /* We do need to catch errors here because the whole purpose
1419 is to test if value_equal() has errored */
1420 if (!gdb_value_equal (val1
, val1
, &r
))
1423 if (!gdb_value_equal (val2
, val2
, &r
))
1429 if (!gdb_value_equal (val1
, val2
, &r
))
1431 /* An error occurred, this could have happened if
1432 either val1 or val2 errored. ERR1 and ERR2 tell
1433 us which of these it is. If both errored, then
1434 we assume nothing has changed. If one of them is
1435 valid, though, then something has changed. */
1438 /* both the old and new values caused errors, so
1439 we say the value did not change */
1440 /* This is indeterminate, though. Perhaps we should
1441 be safe and say, yes, it changed anyway?? */
1453 /* FIXME: The following should be generic for any pointer */
1455 vpush (struct vstack
**pstack
, struct varobj
*var
)
1459 s
= (struct vstack
*) xmalloc (sizeof (struct vstack
));
1465 /* FIXME: The following should be generic for any pointer */
1466 static struct varobj
*
1467 vpop (struct vstack
**pstack
)
1472 if ((*pstack
)->var
== NULL
&& (*pstack
)->next
== NULL
)
1477 *pstack
= (*pstack
)->next
;
1483 /* FIXME: The following should be generic for any pointer */
1485 cppush (struct cpstack
**pstack
, char *name
)
1489 s
= (struct cpstack
*) xmalloc (sizeof (struct cpstack
));
1495 /* FIXME: The following should be generic for any pointer */
1497 cppop (struct cpstack
**pstack
)
1502 if ((*pstack
)->name
== NULL
&& (*pstack
)->next
== NULL
)
1507 *pstack
= (*pstack
)->next
;
1514 * Language-dependencies
1517 /* Common entry points */
1519 /* Get the language of variable VAR. */
1520 static enum varobj_languages
1521 variable_language (struct varobj
*var
)
1523 enum varobj_languages lang
;
1525 switch (var
->root
->exp
->language_defn
->la_language
)
1531 case language_cplus
:
1542 /* Return the number of children for a given variable.
1543 The result of this function is defined by the language
1544 implementation. The number of children returned by this function
1545 is the number of children that the user will see in the variable
1548 number_of_children (struct varobj
*var
)
1550 return (*var
->root
->lang
->number_of_children
) (var
);;
1553 /* What is the expression for the root varobj VAR? Returns a malloc'd string. */
1555 name_of_variable (struct varobj
*var
)
1557 return (*var
->root
->lang
->name_of_variable
) (var
);
1560 /* What is the name of the INDEX'th child of VAR? Returns a malloc'd string. */
1562 name_of_child (struct varobj
*var
, int index
)
1564 return (*var
->root
->lang
->name_of_child
) (var
, index
);
1567 /* What is the ``struct value *'' of the root variable VAR?
1568 TYPE_CHANGED controls what to do if the type of a
1569 use_selected_frame = 1 variable changes. On input,
1570 TYPE_CHANGED = 1 means discard the old varobj, and replace
1571 it with this one. TYPE_CHANGED = 0 means leave it around.
1572 NB: In both cases, var_handle will point to the new varobj,
1573 so if you use TYPE_CHANGED = 0, you will have to stash the
1574 old varobj pointer away somewhere before calling this.
1575 On return, TYPE_CHANGED will be 1 if the type has changed, and
1577 static struct value
*
1578 value_of_root (struct varobj
**var_handle
, int *type_changed
)
1582 if (var_handle
== NULL
)
1587 /* This should really be an exception, since this should
1588 only get called with a root variable. */
1590 if (var
->root
->rootvar
!= var
)
1593 if (var
->root
->use_selected_frame
)
1595 struct varobj
*tmp_var
;
1596 char *old_type
, *new_type
;
1597 old_type
= varobj_get_type (var
);
1598 tmp_var
= varobj_create (NULL
, var
->name
, (CORE_ADDR
) 0,
1599 USE_SELECTED_FRAME
);
1600 if (tmp_var
== NULL
)
1604 new_type
= varobj_get_type (tmp_var
);
1605 if (strcmp (old_type
, new_type
) == 0)
1607 varobj_delete (tmp_var
, NULL
, 0);
1615 savestring (var
->obj_name
, strlen (var
->obj_name
));
1616 varobj_delete (var
, NULL
, 0);
1620 tmp_var
->obj_name
= varobj_gen_name ();
1622 install_variable (tmp_var
);
1623 *var_handle
= tmp_var
;
1633 return (*var
->root
->lang
->value_of_root
) (var_handle
);
1636 /* What is the ``struct value *'' for the INDEX'th child of PARENT? */
1637 static struct value
*
1638 value_of_child (struct varobj
*parent
, int index
)
1640 struct value
*value
;
1642 value
= (*parent
->root
->lang
->value_of_child
) (parent
, index
);
1644 /* If we're being lazy, fetch the real value of the variable. */
1645 if (value
!= NULL
&& VALUE_LAZY (value
))
1647 /* If we fail to fetch the value of the child, return
1648 NULL so that callers notice that we're leaving an
1650 if (!gdb_value_fetch_lazy (value
))
1657 /* What is the type of VAR? */
1658 static struct type
*
1659 type_of_child (struct varobj
*var
)
1662 /* If the child had no evaluation errors, var->value
1663 will be non-NULL and contain a valid type. */
1664 if (var
->value
!= NULL
)
1665 return VALUE_TYPE (var
->value
);
1667 /* Otherwise, we must compute the type. */
1668 return (*var
->root
->lang
->type_of_child
) (var
->parent
, var
->index
);
1671 /* Is this variable editable? Use the variable's type to make
1672 this determination. */
1674 variable_editable (struct varobj
*var
)
1676 return (*var
->root
->lang
->variable_editable
) (var
);
1679 /* GDB already has a command called "value_of_variable". Sigh. */
1681 my_value_of_variable (struct varobj
*var
)
1683 return (*var
->root
->lang
->value_of_variable
) (var
);
1686 /* Is VAR something that can change? Depending on language,
1687 some variable's values never change. For example,
1688 struct and unions never change values. */
1690 type_changeable (struct varobj
*var
)
1695 if (CPLUS_FAKE_CHILD (var
))
1698 type
= get_type (var
);
1700 switch (TYPE_CODE (type
))
1702 case TYPE_CODE_STRUCT
:
1703 case TYPE_CODE_UNION
:
1704 case TYPE_CODE_ARRAY
:
1717 c_number_of_children (struct varobj
*var
)
1720 struct type
*target
;
1723 type
= get_type (var
);
1724 target
= get_target_type (type
);
1727 switch (TYPE_CODE (type
))
1729 case TYPE_CODE_ARRAY
:
1730 if (TYPE_LENGTH (type
) > 0 && TYPE_LENGTH (target
) > 0
1731 && TYPE_ARRAY_UPPER_BOUND_TYPE (type
) != BOUND_CANNOT_BE_DETERMINED
)
1732 children
= TYPE_LENGTH (type
) / TYPE_LENGTH (target
);
1737 case TYPE_CODE_STRUCT
:
1738 case TYPE_CODE_UNION
:
1739 children
= TYPE_NFIELDS (type
);
1743 /* This is where things get compilcated. All pointers have one child.
1744 Except, of course, for struct and union ptr, which we automagically
1745 dereference for the user and function ptrs, which have no children.
1746 We also don't dereference void* as we don't know what to show.
1747 We can show char* so we allow it to be dereferenced. If you decide
1748 to test for it, please mind that a little magic is necessary to
1749 properly identify it: char* has TYPE_CODE == TYPE_CODE_INT and
1750 TYPE_NAME == "char" */
1752 switch (TYPE_CODE (target
))
1754 case TYPE_CODE_STRUCT
:
1755 case TYPE_CODE_UNION
:
1756 children
= TYPE_NFIELDS (target
);
1759 case TYPE_CODE_FUNC
:
1760 case TYPE_CODE_VOID
:
1770 /* Other types have no children */
1778 c_name_of_variable (struct varobj
*parent
)
1780 return savestring (parent
->name
, strlen (parent
->name
));
1784 c_name_of_child (struct varobj
*parent
, int index
)
1787 struct type
*target
;
1791 type
= get_type (parent
);
1792 target
= get_target_type (type
);
1794 switch (TYPE_CODE (type
))
1796 case TYPE_CODE_ARRAY
:
1798 /* We never get here unless parent->num_children is greater than 0... */
1800 while ((int) pow ((double) 10, (double) len
) < index
)
1802 name
= (char *) xmalloc (1 + len
* sizeof (char));
1803 sprintf (name
, "%d", index
);
1807 case TYPE_CODE_STRUCT
:
1808 case TYPE_CODE_UNION
:
1809 string
= TYPE_FIELD_NAME (type
, index
);
1810 name
= savestring (string
, strlen (string
));
1814 switch (TYPE_CODE (target
))
1816 case TYPE_CODE_STRUCT
:
1817 case TYPE_CODE_UNION
:
1818 string
= TYPE_FIELD_NAME (target
, index
);
1819 name
= savestring (string
, strlen (string
));
1824 (char *) xmalloc ((strlen (parent
->name
) + 2) * sizeof (char));
1825 sprintf (name
, "*%s", parent
->name
);
1831 /* This should not happen */
1832 name
= xstrdup ("???");
1838 static struct value
*
1839 c_value_of_root (struct varobj
**var_handle
)
1841 struct value
*new_val
;
1842 struct varobj
*var
= *var_handle
;
1843 struct frame_info
*fi
;
1846 /* Only root variables can be updated... */
1847 if (var
->root
->rootvar
!= var
)
1848 /* Not a root var */
1852 /* Determine whether the variable is still around. */
1853 if (var
->root
->valid_block
== NULL
)
1857 reinit_frame_cache ();
1860 fi
= find_frame_addr_in_frame_chain (var
->root
->frame
);
1862 within_scope
= fi
!= NULL
;
1863 /* FIXME: select_frame could fail */
1865 select_frame (fi
, -1);
1870 /* We need to catch errors here, because if evaluate
1871 expression fails we just want to make val->error = 1 and
1873 if (gdb_evaluate_expression (var
->root
->exp
, &new_val
))
1875 if (VALUE_LAZY (new_val
))
1877 /* We need to catch errors because if
1878 value_fetch_lazy fails we still want to continue
1879 (after making val->error = 1) */
1880 /* FIXME: Shouldn't be using VALUE_CONTENTS? The
1881 comment on value_fetch_lazy() says it is only
1882 called from the macro... */
1883 if (!gdb_value_fetch_lazy (new_val
))
1892 release_value (new_val
);
1899 static struct value
*
1900 c_value_of_child (struct varobj
*parent
, int index
)
1902 struct value
*value
;
1904 struct value
*indval
;
1905 struct type
*type
, *target
;
1908 type
= get_type (parent
);
1909 target
= get_target_type (type
);
1910 name
= name_of_child (parent
, index
);
1911 temp
= parent
->value
;
1916 switch (TYPE_CODE (type
))
1918 case TYPE_CODE_ARRAY
:
1920 /* This breaks if the array lives in a (vector) register. */
1921 value
= value_slice (temp
, index
, 1);
1922 temp
= value_coerce_array (value
);
1923 gdb_value_ind (temp
, &value
);
1925 indval
= value_from_longest (builtin_type_int
, (LONGEST
) index
);
1926 gdb_value_subscript (temp
, indval
, &value
);
1930 case TYPE_CODE_STRUCT
:
1931 case TYPE_CODE_UNION
:
1932 gdb_value_struct_elt (NULL
, &value
, &temp
, NULL
, name
, NULL
, "vstructure");
1936 switch (TYPE_CODE (target
))
1938 case TYPE_CODE_STRUCT
:
1939 case TYPE_CODE_UNION
:
1940 gdb_value_struct_elt (NULL
, &value
, &temp
, NULL
, name
, NULL
, "vstructure");
1944 gdb_value_ind (temp
, &value
);
1955 release_value (value
);
1961 static struct type
*
1962 c_type_of_child (struct varobj
*parent
, int index
)
1965 char *name
= name_of_child (parent
, index
);
1967 switch (TYPE_CODE (parent
->type
))
1969 case TYPE_CODE_ARRAY
:
1970 type
= TYPE_TARGET_TYPE (parent
->type
);
1973 case TYPE_CODE_STRUCT
:
1974 case TYPE_CODE_UNION
:
1975 type
= lookup_struct_elt_type (parent
->type
, name
, 0);
1979 switch (TYPE_CODE (TYPE_TARGET_TYPE (parent
->type
)))
1981 case TYPE_CODE_STRUCT
:
1982 case TYPE_CODE_UNION
:
1983 type
= lookup_struct_elt_type (parent
->type
, name
, 0);
1987 type
= TYPE_TARGET_TYPE (parent
->type
);
1993 /* This should not happen as only the above types have children */
1994 warning ("Child of parent whose type does not allow children");
1995 /* FIXME: Can we still go on? */
2005 c_variable_editable (struct varobj
*var
)
2007 switch (TYPE_CODE (get_type (var
)))
2009 case TYPE_CODE_STRUCT
:
2010 case TYPE_CODE_UNION
:
2011 case TYPE_CODE_ARRAY
:
2012 case TYPE_CODE_FUNC
:
2013 case TYPE_CODE_MEMBER
:
2014 case TYPE_CODE_METHOD
:
2025 c_value_of_variable (struct varobj
*var
)
2029 /* BOGUS: if val_print sees a struct/class, it will print out its
2030 children instead of "{...}" */
2031 type
= get_type (var
);
2032 switch (TYPE_CODE (type
))
2034 case TYPE_CODE_STRUCT
:
2035 case TYPE_CODE_UNION
:
2036 return xstrdup ("{...}");
2039 case TYPE_CODE_ARRAY
:
2042 sprintf (number
, "[%d]", var
->num_children
);
2043 return xstrdup (number
);
2050 struct ui_file
*stb
= mem_fileopen ();
2051 struct cleanup
*old_chain
= make_cleanup_ui_file_delete (stb
);
2054 if (var
->value
== NULL
)
2056 /* This can happen if we attempt to get the value of a struct
2057 member when the parent is an invalid pointer. This is an
2058 error condition, so we should tell the caller. */
2063 if (VALUE_LAZY (var
->value
))
2064 gdb_value_fetch_lazy (var
->value
);
2065 val_print (VALUE_TYPE (var
->value
), VALUE_CONTENTS_RAW (var
->value
), 0,
2066 VALUE_ADDRESS (var
->value
),
2067 stb
, format_code
[(int) var
->format
], 1, 0, 0);
2068 thevalue
= ui_file_xstrdup (stb
, &dummy
);
2069 do_cleanups (old_chain
);
2082 cplus_number_of_children (struct varobj
*var
)
2085 int children
, dont_know
;
2090 if (!CPLUS_FAKE_CHILD (var
))
2092 type
= get_type_deref (var
);
2094 if (((TYPE_CODE (type
)) == TYPE_CODE_STRUCT
) ||
2095 ((TYPE_CODE (type
)) == TYPE_CODE_UNION
))
2099 cplus_class_num_children (type
, kids
);
2100 if (kids
[v_public
] != 0)
2102 if (kids
[v_private
] != 0)
2104 if (kids
[v_protected
] != 0)
2107 /* Add any baseclasses */
2108 children
+= TYPE_N_BASECLASSES (type
);
2111 /* FIXME: save children in var */
2118 type
= get_type_deref (var
->parent
);
2120 cplus_class_num_children (type
, kids
);
2121 if (STREQ (var
->name
, "public"))
2122 children
= kids
[v_public
];
2123 else if (STREQ (var
->name
, "private"))
2124 children
= kids
[v_private
];
2126 children
= kids
[v_protected
];
2131 children
= c_number_of_children (var
);
2136 /* Compute # of public, private, and protected variables in this class.
2137 That means we need to descend into all baseclasses and find out
2138 how many are there, too. */
2140 cplus_class_num_children (struct type
*type
, int children
[3])
2144 children
[v_public
] = 0;
2145 children
[v_private
] = 0;
2146 children
[v_protected
] = 0;
2148 for (i
= TYPE_N_BASECLASSES (type
); i
< TYPE_NFIELDS (type
); i
++)
2150 /* If we have a virtual table pointer, omit it. */
2151 if (TYPE_VPTR_BASETYPE (type
) == type
&& TYPE_VPTR_FIELDNO (type
) == i
)
2154 if (TYPE_FIELD_PROTECTED (type
, i
))
2155 children
[v_protected
]++;
2156 else if (TYPE_FIELD_PRIVATE (type
, i
))
2157 children
[v_private
]++;
2159 children
[v_public
]++;
2164 cplus_name_of_variable (struct varobj
*parent
)
2166 return c_name_of_variable (parent
);
2170 cplus_name_of_child (struct varobj
*parent
, int index
)
2176 if (CPLUS_FAKE_CHILD (parent
))
2178 /* Looking for children of public, private, or protected. */
2179 type
= get_type_deref (parent
->parent
);
2182 type
= get_type_deref (parent
);
2185 switch (TYPE_CODE (type
))
2187 case TYPE_CODE_STRUCT
:
2188 case TYPE_CODE_UNION
:
2189 cplus_class_num_children (type
, children
);
2191 if (CPLUS_FAKE_CHILD (parent
))
2195 /* Skip over vptr, if it exists. */
2196 if (TYPE_VPTR_BASETYPE (type
) == type
2197 && index
>= TYPE_VPTR_FIELDNO (type
))
2200 /* FIXME: This assumes that type orders
2201 inherited, public, private, protected */
2202 i
= index
+ TYPE_N_BASECLASSES (type
);
2203 if (STREQ (parent
->name
, "private") || STREQ (parent
->name
, "protected"))
2204 i
+= children
[v_public
];
2205 if (STREQ (parent
->name
, "protected"))
2206 i
+= children
[v_private
];
2208 name
= TYPE_FIELD_NAME (type
, i
);
2210 else if (index
< TYPE_N_BASECLASSES (type
))
2211 name
= TYPE_FIELD_NAME (type
, index
);
2214 /* Everything beyond the baseclasses can
2215 only be "public", "private", or "protected" */
2216 index
-= TYPE_N_BASECLASSES (type
);
2220 if (children
[v_public
] != 0)
2226 if (children
[v_private
] != 0)
2232 if (children
[v_protected
] != 0)
2249 return c_name_of_child (parent
, index
);
2253 name
= savestring (name
, strlen (name
));
2259 static struct value
*
2260 cplus_value_of_root (struct varobj
**var_handle
)
2262 return c_value_of_root (var_handle
);
2265 static struct value
*
2266 cplus_value_of_child (struct varobj
*parent
, int index
)
2269 struct value
*value
;
2271 if (CPLUS_FAKE_CHILD (parent
))
2272 type
= get_type_deref (parent
->parent
);
2274 type
= get_type_deref (parent
);
2278 if (((TYPE_CODE (type
)) == TYPE_CODE_STRUCT
) ||
2279 ((TYPE_CODE (type
)) == TYPE_CODE_UNION
))
2281 if (CPLUS_FAKE_CHILD (parent
))
2284 struct value
*temp
= parent
->parent
->value
;
2289 name
= name_of_child (parent
, index
);
2290 gdb_value_struct_elt (NULL
, &value
, &temp
, NULL
, name
, NULL
,
2293 release_value (value
);
2297 else if (index
>= TYPE_N_BASECLASSES (type
))
2299 /* public, private, or protected */
2305 if (parent
->value
!= NULL
)
2307 struct value
*temp
= NULL
;
2309 if (TYPE_CODE (VALUE_TYPE (parent
->value
)) == TYPE_CODE_PTR
2310 || TYPE_CODE (VALUE_TYPE (parent
->value
)) == TYPE_CODE_REF
)
2312 if (!gdb_value_ind (parent
->value
, &temp
))
2316 temp
= parent
->value
;
2320 value
= value_cast (TYPE_FIELD_TYPE (type
, index
), temp
);
2321 release_value (value
);
2325 /* We failed to evaluate the parent's value, so don't even
2326 bother trying to evaluate this child. */
2334 return c_value_of_child (parent
, index
);
2339 static struct type
*
2340 cplus_type_of_child (struct varobj
*parent
, int index
)
2342 struct type
*type
, *t
;
2344 if (CPLUS_FAKE_CHILD (parent
))
2346 /* Looking for the type of a child of public, private, or protected. */
2347 t
= get_type_deref (parent
->parent
);
2350 t
= get_type_deref (parent
);
2353 switch (TYPE_CODE (t
))
2355 case TYPE_CODE_STRUCT
:
2356 case TYPE_CODE_UNION
:
2357 if (CPLUS_FAKE_CHILD (parent
))
2359 char *name
= cplus_name_of_child (parent
, index
);
2360 type
= lookup_struct_elt_type (t
, name
, 0);
2363 else if (index
< TYPE_N_BASECLASSES (t
))
2364 type
= TYPE_FIELD_TYPE (t
, index
);
2377 return c_type_of_child (parent
, index
);
2383 cplus_variable_editable (struct varobj
*var
)
2385 if (CPLUS_FAKE_CHILD (var
))
2388 return c_variable_editable (var
);
2392 cplus_value_of_variable (struct varobj
*var
)
2395 /* If we have one of our special types, don't print out
2397 if (CPLUS_FAKE_CHILD (var
))
2398 return xstrdup ("");
2400 return c_value_of_variable (var
);
2406 java_number_of_children (struct varobj
*var
)
2408 return cplus_number_of_children (var
);
2412 java_name_of_variable (struct varobj
*parent
)
2416 name
= cplus_name_of_variable (parent
);
2417 /* If the name has "-" in it, it is because we
2418 needed to escape periods in the name... */
2421 while (*p
!= '\000')
2432 java_name_of_child (struct varobj
*parent
, int index
)
2436 name
= cplus_name_of_child (parent
, index
);
2437 /* Escape any periods in the name... */
2440 while (*p
!= '\000')
2450 static struct value
*
2451 java_value_of_root (struct varobj
**var_handle
)
2453 return cplus_value_of_root (var_handle
);
2456 static struct value
*
2457 java_value_of_child (struct varobj
*parent
, int index
)
2459 return cplus_value_of_child (parent
, index
);
2462 static struct type
*
2463 java_type_of_child (struct varobj
*parent
, int index
)
2465 return cplus_type_of_child (parent
, index
);
2469 java_variable_editable (struct varobj
*var
)
2471 return cplus_variable_editable (var
);
2475 java_value_of_variable (struct varobj
*var
)
2477 return cplus_value_of_variable (var
);
2480 extern void _initialize_varobj (void);
2482 _initialize_varobj (void)
2484 int sizeof_table
= sizeof (struct vlist
*) * VAROBJ_TABLE_SIZE
;
2486 varobj_table
= xmalloc (sizeof_table
);
2487 memset (varobj_table
, 0, sizeof_table
);
2489 add_show_from_set (add_set_cmd ("debugvarobj", class_maintenance
, var_zinteger
, (char *) &varobjdebug
, "Set varobj debugging.\n\
2490 When non-zero, varobj debugging is enabled.", &setlist
),