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
;
116 /* Every variable keeps a linked list of its children, described
117 by the following structure. */
118 /* FIXME: Deprecated. All should use vlist instead */
123 /* Pointer to the child's data */
124 struct varobj
*child
;
126 /* Pointer to the next child */
127 struct varobj_child
*next
;
130 /* A stack of varobjs */
131 /* FIXME: Deprecated. All should use vlist instead */
142 struct cpstack
*next
;
145 /* A list of varobjs */
153 /* Private function prototypes */
155 /* Helper functions for the above subcommands. */
157 static int delete_variable (struct cpstack
**, struct varobj
*, int);
159 static void delete_variable_1 (struct cpstack
**, int *,
160 struct varobj
*, int, int);
162 static int install_variable (struct varobj
*);
164 static void uninstall_variable (struct varobj
*);
166 static struct varobj
*child_exists (struct varobj
*, char *);
168 static struct varobj
*create_child (struct varobj
*, int, char *);
170 static void save_child_in_parent (struct varobj
*, struct varobj
*);
172 static void remove_child_from_parent (struct varobj
*, struct varobj
*);
174 /* Utility routines */
176 static struct varobj
*new_variable (void);
178 static struct varobj
*new_root_variable (void);
180 static void free_variable (struct varobj
*var
);
182 static struct cleanup
*make_cleanup_free_variable (struct varobj
*var
);
184 static struct type
*get_type (struct varobj
*var
);
186 static struct type
*get_type_deref (struct varobj
*var
);
188 static struct type
*get_target_type (struct type
*);
190 static enum varobj_display_formats
variable_default_display (struct varobj
*);
192 static int my_value_equal (struct value
*, struct value
*, int *);
194 static void vpush (struct vstack
**pstack
, struct varobj
*var
);
196 static struct varobj
*vpop (struct vstack
**pstack
);
198 static void cppush (struct cpstack
**pstack
, char *name
);
200 static char *cppop (struct cpstack
**pstack
);
202 /* Language-specific routines. */
204 static enum varobj_languages
variable_language (struct varobj
*var
);
206 static int number_of_children (struct varobj
*);
208 static char *name_of_variable (struct varobj
*);
210 static char *name_of_child (struct varobj
*, int);
212 static struct value
*value_of_root (struct varobj
**var_handle
, int *);
214 static struct value
*value_of_child (struct varobj
*parent
, int index
);
216 static struct type
*type_of_child (struct varobj
*var
);
218 static int variable_editable (struct varobj
*var
);
220 static char *my_value_of_variable (struct varobj
*var
);
222 static int type_changeable (struct varobj
*var
);
224 /* C implementation */
226 static int c_number_of_children (struct varobj
*var
);
228 static char *c_name_of_variable (struct varobj
*parent
);
230 static char *c_name_of_child (struct varobj
*parent
, int index
);
232 static struct value
*c_value_of_root (struct varobj
**var_handle
);
234 static struct value
*c_value_of_child (struct varobj
*parent
, int index
);
236 static struct type
*c_type_of_child (struct varobj
*parent
, int index
);
238 static int c_variable_editable (struct varobj
*var
);
240 static char *c_value_of_variable (struct varobj
*var
);
242 /* C++ implementation */
244 static int cplus_number_of_children (struct varobj
*var
);
246 static void cplus_class_num_children (struct type
*type
, int children
[3]);
248 static char *cplus_name_of_variable (struct varobj
*parent
);
250 static char *cplus_name_of_child (struct varobj
*parent
, int index
);
252 static struct value
*cplus_value_of_root (struct varobj
**var_handle
);
254 static struct value
*cplus_value_of_child (struct varobj
*parent
, int index
);
256 static struct type
*cplus_type_of_child (struct varobj
*parent
, int index
);
258 static int cplus_variable_editable (struct varobj
*var
);
260 static char *cplus_value_of_variable (struct varobj
*var
);
262 /* Java implementation */
264 static int java_number_of_children (struct varobj
*var
);
266 static char *java_name_of_variable (struct varobj
*parent
);
268 static char *java_name_of_child (struct varobj
*parent
, int index
);
270 static struct value
*java_value_of_root (struct varobj
**var_handle
);
272 static struct value
*java_value_of_child (struct varobj
*parent
, int index
);
274 static struct type
*java_type_of_child (struct varobj
*parent
, int index
);
276 static int java_variable_editable (struct varobj
*var
);
278 static char *java_value_of_variable (struct varobj
*var
);
280 /* The language specific vector */
282 struct language_specific
285 /* The language of this variable */
286 enum varobj_languages language
;
288 /* The number of children of PARENT. */
289 int (*number_of_children
) (struct varobj
* parent
);
291 /* The name (expression) of a root varobj. */
292 char *(*name_of_variable
) (struct varobj
* parent
);
294 /* The name of the INDEX'th child of PARENT. */
295 char *(*name_of_child
) (struct varobj
* parent
, int index
);
297 /* The ``struct value *'' of the root variable ROOT. */
298 struct value
*(*value_of_root
) (struct varobj
** root_handle
);
300 /* The ``struct value *'' of the INDEX'th child of PARENT. */
301 struct value
*(*value_of_child
) (struct varobj
* parent
, int index
);
303 /* The type of the INDEX'th child of PARENT. */
304 struct type
*(*type_of_child
) (struct varobj
* parent
, int index
);
306 /* Is VAR editable? */
307 int (*variable_editable
) (struct varobj
* var
);
309 /* The current value of VAR. */
310 char *(*value_of_variable
) (struct varobj
* var
);
313 /* Array of known source language routines. */
314 static struct language_specific
315 languages
[vlang_end
][sizeof (struct language_specific
)] = {
316 /* Unknown (try treating as C */
319 c_number_of_children
,
331 c_number_of_children
,
343 cplus_number_of_children
,
344 cplus_name_of_variable
,
347 cplus_value_of_child
,
349 cplus_variable_editable
,
350 cplus_value_of_variable
}
355 java_number_of_children
,
356 java_name_of_variable
,
361 java_variable_editable
,
362 java_value_of_variable
}
365 /* A little convenience enum for dealing with C++/Java */
368 v_public
= 0, v_private
, v_protected
373 /* Mappings of varobj_display_formats enums to gdb's format codes */
374 static int format_code
[] = { 0, 't', 'd', 'x', 'o' };
376 /* Header of the list of root variable objects */
377 static struct varobj_root
*rootlist
;
378 static int rootcount
= 0; /* number of root varobjs in the list */
380 /* Prime number indicating the number of buckets in the hash table */
381 /* A prime large enough to avoid too many colisions */
382 #define VAROBJ_TABLE_SIZE 227
384 /* Pointer to the varobj hash table (built at run time) */
385 static struct vlist
**varobj_table
;
387 /* Is the variable X one of our "fake" children? */
388 #define CPLUS_FAKE_CHILD(x) \
389 ((x) != NULL && (x)->type == NULL && (x)->value == NULL)
392 /* API Implementation */
394 /* Creates a varobj (not its children) */
397 varobj_create (char *objname
,
398 char *expression
, CORE_ADDR frame
, enum varobj_type type
)
401 struct frame_info
*fi
;
402 struct frame_info
*old_fi
= NULL
;
404 struct cleanup
*old_chain
;
406 /* Fill out a varobj structure for the (root) variable being constructed. */
407 var
= new_root_variable ();
408 old_chain
= make_cleanup_free_variable (var
);
410 if (expression
!= NULL
)
413 enum varobj_languages lang
;
415 /* Parse and evaluate the expression, filling in as much
416 of the variable's data as possible */
418 /* Allow creator to specify context of variable */
419 if ((type
== USE_CURRENT_FRAME
) || (type
== USE_SELECTED_FRAME
))
422 fi
= find_frame_addr_in_frame_chain (frame
);
424 /* frame = -2 means always use selected frame */
425 if (type
== USE_SELECTED_FRAME
)
426 var
->root
->use_selected_frame
= 1;
430 block
= get_frame_block (fi
, 0);
433 innermost_block
= NULL
;
434 /* Wrap the call to parse expression, so we can
435 return a sensible error. */
436 if (!gdb_parse_exp_1 (&p
, block
, 0, &var
->root
->exp
))
441 /* Don't allow variables to be created for types. */
442 if (var
->root
->exp
->elts
[0].opcode
== OP_TYPE
)
444 do_cleanups (old_chain
);
445 fprintf_unfiltered (gdb_stderr
,
446 "Attempt to use a type name as an expression.");
450 var
->format
= variable_default_display (var
);
451 var
->root
->valid_block
= innermost_block
;
452 var
->name
= savestring (expression
, strlen (expression
));
454 /* When the frame is different from the current frame,
455 we must select the appropriate frame before parsing
456 the expression, otherwise the value will not be current.
457 Since select_frame is so benign, just call it for all cases. */
460 get_frame_id (fi
, &var
->root
->frame
);
461 old_fi
= selected_frame
;
465 /* We definitively need to catch errors here.
466 If evaluate_expression succeeds we got the value we wanted.
467 But if it fails, we still go on with a call to evaluate_type() */
468 if (gdb_evaluate_expression (var
->root
->exp
, &var
->value
))
471 release_value (var
->value
);
472 if (VALUE_LAZY (var
->value
))
473 gdb_value_fetch_lazy (var
->value
);
476 var
->value
= evaluate_type (var
->root
->exp
);
478 var
->type
= VALUE_TYPE (var
->value
);
480 /* Set language info */
481 lang
= variable_language (var
);
482 var
->root
->lang
= languages
[lang
];
484 /* Set ourselves as our root */
485 var
->root
->rootvar
= var
;
487 /* Reset the selected frame */
489 select_frame (old_fi
);
492 /* If the variable object name is null, that means this
493 is a temporary variable, so don't install it. */
495 if ((var
!= NULL
) && (objname
!= NULL
))
497 var
->obj_name
= savestring (objname
, strlen (objname
));
499 /* If a varobj name is duplicated, the install will fail so
501 if (!install_variable (var
))
503 do_cleanups (old_chain
);
508 discard_cleanups (old_chain
);
512 /* Generates an unique name that can be used for a varobj */
515 varobj_gen_name (void)
520 /* generate a name for this object */
522 xasprintf (&obj_name
, "var%d", id
);
527 /* Given an "objname", returns the pointer to the corresponding varobj
528 or NULL if not found */
531 varobj_get_handle (char *objname
)
535 unsigned int index
= 0;
538 for (chp
= objname
; *chp
; chp
++)
540 index
= (index
+ (i
++ * (unsigned int) *chp
)) % VAROBJ_TABLE_SIZE
;
543 cv
= *(varobj_table
+ index
);
544 while ((cv
!= NULL
) && (strcmp (cv
->var
->obj_name
, objname
) != 0))
548 error ("Variable object not found");
553 /* Given the handle, return the name of the object */
556 varobj_get_objname (struct varobj
*var
)
558 return var
->obj_name
;
561 /* Given the handle, return the expression represented by the object */
564 varobj_get_expression (struct varobj
*var
)
566 return name_of_variable (var
);
569 /* Deletes a varobj and all its children if only_children == 0,
570 otherwise deletes only the children; returns a malloc'ed list of all the
571 (malloc'ed) names of the variables that have been deleted (NULL terminated) */
574 varobj_delete (struct varobj
*var
, char ***dellist
, int only_children
)
578 struct cpstack
*result
= NULL
;
581 /* Initialize a stack for temporary results */
582 cppush (&result
, NULL
);
585 /* Delete only the variable children */
586 delcount
= delete_variable (&result
, var
, 1 /* only the children */ );
588 /* Delete the variable and all its children */
589 delcount
= delete_variable (&result
, var
, 0 /* parent+children */ );
591 /* We may have been asked to return a list of what has been deleted */
594 *dellist
= xmalloc ((delcount
+ 1) * sizeof (char *));
598 *cp
= cppop (&result
);
599 while ((*cp
!= NULL
) && (mycount
> 0))
603 *cp
= cppop (&result
);
606 if (mycount
|| (*cp
!= NULL
))
607 warning ("varobj_delete: assertion failed - mycount(=%d) <> 0",
614 /* Set/Get variable object display format */
616 enum varobj_display_formats
617 varobj_set_display_format (struct varobj
*var
,
618 enum varobj_display_formats format
)
625 case FORMAT_HEXADECIMAL
:
627 var
->format
= format
;
631 var
->format
= variable_default_display (var
);
637 enum varobj_display_formats
638 varobj_get_display_format (struct varobj
*var
)
644 varobj_get_num_children (struct varobj
*var
)
646 if (var
->num_children
== -1)
647 var
->num_children
= number_of_children (var
);
649 return var
->num_children
;
652 /* Creates a list of the immediate children of a variable object;
653 the return code is the number of such children or -1 on error */
656 varobj_list_children (struct varobj
*var
, struct varobj
***childlist
)
658 struct varobj
*child
;
662 /* sanity check: have we been passed a pointer? */
663 if (childlist
== NULL
)
668 if (var
->num_children
== -1)
669 var
->num_children
= number_of_children (var
);
671 /* List of children */
672 *childlist
= xmalloc ((var
->num_children
+ 1) * sizeof (struct varobj
*));
674 for (i
= 0; i
< var
->num_children
; i
++)
676 /* Mark as the end in case we bail out */
677 *((*childlist
) + i
) = NULL
;
679 /* check if child exists, if not create */
680 name
= name_of_child (var
, i
);
681 child
= child_exists (var
, name
);
683 child
= create_child (var
, i
, name
);
685 *((*childlist
) + i
) = child
;
688 /* End of list is marked by a NULL pointer */
689 *((*childlist
) + i
) = NULL
;
691 return var
->num_children
;
694 /* Obtain the type of an object Variable as a string similar to the one gdb
695 prints on the console */
698 varobj_get_type (struct varobj
*var
)
701 struct cleanup
*old_chain
;
706 /* For the "fake" variables, do not return a type. (It's type is
708 if (CPLUS_FAKE_CHILD (var
))
711 stb
= mem_fileopen ();
712 old_chain
= make_cleanup_ui_file_delete (stb
);
714 /* To print the type, we simply create a zero ``struct value *'' and
715 cast it to our type. We then typeprint this variable. */
716 val
= value_zero (var
->type
, not_lval
);
717 type_print (VALUE_TYPE (val
), "", stb
, -1);
719 thetype
= ui_file_xstrdup (stb
, &length
);
720 do_cleanups (old_chain
);
724 enum varobj_languages
725 varobj_get_language (struct varobj
*var
)
727 return variable_language (var
);
731 varobj_get_attributes (struct varobj
*var
)
735 if (variable_editable (var
))
736 /* FIXME: define masks for attributes */
737 attributes
|= 0x00000001; /* Editable */
743 varobj_get_value (struct varobj
*var
)
745 return my_value_of_variable (var
);
748 /* Set the value of an object variable (if it is editable) to the
749 value of the given expression */
750 /* Note: Invokes functions that can call error() */
753 varobj_set_value (struct varobj
*var
, char *expression
)
758 /* The argument "expression" contains the variable's new value.
759 We need to first construct a legal expression for this -- ugh! */
760 /* Does this cover all the bases? */
761 struct expression
*exp
;
763 int saved_input_radix
= input_radix
;
765 if (var
->value
!= NULL
&& variable_editable (var
) && !var
->error
)
767 char *s
= expression
;
770 input_radix
= 10; /* ALWAYS reset to decimal temporarily */
771 if (!gdb_parse_exp_1 (&s
, 0, 0, &exp
))
772 /* We cannot proceed without a well-formed expression. */
774 if (!gdb_evaluate_expression (exp
, &value
))
776 /* We cannot proceed without a valid expression. */
781 if (!gdb_value_assign (var
->value
, value
, &val
))
783 value_free (var
->value
);
786 input_radix
= saved_input_radix
;
793 /* Returns a malloc'ed list with all root variable objects */
795 varobj_list (struct varobj
***varlist
)
798 struct varobj_root
*croot
;
799 int mycount
= rootcount
;
801 /* Alloc (rootcount + 1) entries for the result */
802 *varlist
= xmalloc ((rootcount
+ 1) * sizeof (struct varobj
*));
806 while ((croot
!= NULL
) && (mycount
> 0))
808 *cv
= croot
->rootvar
;
813 /* Mark the end of the list */
816 if (mycount
|| (croot
!= NULL
))
818 ("varobj_list: assertion failed - wrong tally of root vars (%d:%d)",
824 /* Update the values for a variable and its children. This is a
825 two-pronged attack. First, re-parse the value for the root's
826 expression to see if it's changed. Then go all the way
827 through its children, reconstructing them and noting if they've
830 -1 if there was an error updating the varobj
831 -2 if the type changed
832 Otherwise it is the number of children + parent changed
834 Only root variables can be updated...
836 NOTE: This function may delete the caller's varobj. If it
837 returns -2, then it has done this and VARP will be modified
838 to point to the new varobj. */
841 varobj_update (struct varobj
**varp
, struct varobj
***changelist
)
850 struct varobj
**templist
= NULL
;
852 struct vstack
*stack
= NULL
;
853 struct vstack
*result
= NULL
;
854 struct frame_id old_fid
;
855 struct frame_info
*fi
;
857 /* sanity check: have we been passed a pointer? */
858 if (changelist
== NULL
)
861 /* Only root variables can be updated... */
862 if ((*varp
)->root
->rootvar
!= *varp
)
866 /* Save the selected stack frame, since we will need to change it
867 in order to evaluate expressions. */
868 get_frame_id (selected_frame
, &old_fid
);
870 /* Update the root variable. value_of_root can return NULL
871 if the variable is no longer around, i.e. we stepped out of
872 the frame in which a local existed. We are letting the
873 value_of_root variable dispose of the varobj if the type
876 new = value_of_root (varp
, &type_changed
);
883 /* Initialize a stack for temporary results */
884 vpush (&result
, NULL
);
886 /* If this is a "use_selected_frame" varobj, and its type has changed,
887 them note that it's changed. */
890 vpush (&result
, *varp
);
893 /* If values are not equal, note that it's changed.
894 There a couple of exceptions here, though.
895 We don't want some types to be reported as "changed". */
896 else if (type_changeable (*varp
)
897 && !my_value_equal ((*varp
)->value
, new, &error2
))
899 vpush (&result
, *varp
);
901 /* error2 replaces var->error since this new value
902 WILL replace the old one. */
903 (*varp
)->error
= error2
;
906 /* We must always keep around the new value for this root
907 variable expression, or we lose the updated children! */
908 value_free ((*varp
)->value
);
909 (*varp
)->value
= new;
911 /* Initialize a stack */
912 vpush (&stack
, NULL
);
914 /* Push the root's children */
915 if ((*varp
)->children
!= NULL
)
917 struct varobj_child
*c
;
918 for (c
= (*varp
)->children
; c
!= NULL
; c
= c
->next
)
919 vpush (&stack
, c
->child
);
922 /* Walk through the children, reconstructing them all. */
926 /* Push any children */
927 if (v
->children
!= NULL
)
929 struct varobj_child
*c
;
930 for (c
= v
->children
; c
!= NULL
; c
= c
->next
)
931 vpush (&stack
, c
->child
);
934 /* Update this variable */
935 new = value_of_child (v
->parent
, v
->index
);
936 if (type_changeable (v
) && !my_value_equal (v
->value
, new, &error2
))
938 /* Note that it's changed */
942 /* error2 replaces v->error since this new value
943 WILL replace the old one. */
946 /* We must always keep new values, since children depend on it. */
947 if (v
->value
!= NULL
)
948 value_free (v
->value
);
955 /* Alloc (changed + 1) list entries */
956 /* FIXME: add a cleanup for the allocated list(s)
957 because one day the select_frame called below can longjump */
958 *changelist
= xmalloc ((changed
+ 1) * sizeof (struct varobj
*));
961 templist
= xmalloc ((changed
+ 1) * sizeof (struct varobj
*));
967 /* Copy from result stack to list */
969 *cv
= vpop (&result
);
970 while ((*cv
!= NULL
) && (vleft
> 0))
974 *cv
= vpop (&result
);
977 warning ("varobj_update: assertion failed - vleft <> 0");
981 /* Now we revert the order. */
982 for (i
= 0; i
< changed
; i
++)
983 *(*changelist
+ i
) = *(templist
+ changed
- 1 - i
);
984 *(*changelist
+ changed
) = NULL
;
987 /* Restore selected frame */
988 fi
= frame_find_by_id (old_fid
);
999 /* Helper functions */
1002 * Variable object construction/destruction
1006 delete_variable (struct cpstack
**resultp
, struct varobj
*var
,
1007 int only_children_p
)
1011 delete_variable_1 (resultp
, &delcount
, var
,
1012 only_children_p
, 1 /* remove_from_parent_p */ );
1017 /* Delete the variable object VAR and its children */
1018 /* IMPORTANT NOTE: If we delete a variable which is a child
1019 and the parent is not removed we dump core. It must be always
1020 initially called with remove_from_parent_p set */
1022 delete_variable_1 (struct cpstack
**resultp
, int *delcountp
,
1023 struct varobj
*var
, int only_children_p
,
1024 int remove_from_parent_p
)
1026 struct varobj_child
*vc
;
1027 struct varobj_child
*next
;
1029 /* Delete any children of this variable, too. */
1030 for (vc
= var
->children
; vc
!= NULL
; vc
= next
)
1032 if (!remove_from_parent_p
)
1033 vc
->child
->parent
= NULL
;
1034 delete_variable_1 (resultp
, delcountp
, vc
->child
, 0, only_children_p
);
1039 /* if we were called to delete only the children we are done here */
1040 if (only_children_p
)
1043 /* Otherwise, add it to the list of deleted ones and proceed to do so */
1044 /* If the name is null, this is a temporary variable, that has not
1045 yet been installed, don't report it, it belongs to the caller... */
1046 if (var
->obj_name
!= NULL
)
1048 cppush (resultp
, xstrdup (var
->obj_name
));
1049 *delcountp
= *delcountp
+ 1;
1052 /* If this variable has a parent, remove it from its parent's list */
1053 /* OPTIMIZATION: if the parent of this variable is also being deleted,
1054 (as indicated by remove_from_parent_p) we don't bother doing an
1055 expensive list search to find the element to remove when we are
1056 discarding the list afterwards */
1057 if ((remove_from_parent_p
) && (var
->parent
!= NULL
))
1059 remove_child_from_parent (var
->parent
, var
);
1062 if (var
->obj_name
!= NULL
)
1063 uninstall_variable (var
);
1065 /* Free memory associated with this variable */
1066 free_variable (var
);
1069 /* Install the given variable VAR with the object name VAR->OBJ_NAME. */
1071 install_variable (struct varobj
*var
)
1074 struct vlist
*newvl
;
1076 unsigned int index
= 0;
1079 for (chp
= var
->obj_name
; *chp
; chp
++)
1081 index
= (index
+ (i
++ * (unsigned int) *chp
)) % VAROBJ_TABLE_SIZE
;
1084 cv
= *(varobj_table
+ index
);
1085 while ((cv
!= NULL
) && (strcmp (cv
->var
->obj_name
, var
->obj_name
) != 0))
1089 error ("Duplicate variable object name");
1091 /* Add varobj to hash table */
1092 newvl
= xmalloc (sizeof (struct vlist
));
1093 newvl
->next
= *(varobj_table
+ index
);
1095 *(varobj_table
+ index
) = newvl
;
1097 /* If root, add varobj to root list */
1098 if (var
->root
->rootvar
== var
)
1100 /* Add to list of root variables */
1101 if (rootlist
== NULL
)
1102 var
->root
->next
= NULL
;
1104 var
->root
->next
= rootlist
;
1105 rootlist
= var
->root
;
1112 /* Unistall the object VAR. */
1114 uninstall_variable (struct varobj
*var
)
1118 struct varobj_root
*cr
;
1119 struct varobj_root
*prer
;
1121 unsigned int index
= 0;
1124 /* Remove varobj from hash table */
1125 for (chp
= var
->obj_name
; *chp
; chp
++)
1127 index
= (index
+ (i
++ * (unsigned int) *chp
)) % VAROBJ_TABLE_SIZE
;
1130 cv
= *(varobj_table
+ index
);
1132 while ((cv
!= NULL
) && (strcmp (cv
->var
->obj_name
, var
->obj_name
) != 0))
1139 fprintf_unfiltered (gdb_stdlog
, "Deleting %s\n", var
->obj_name
);
1144 ("Assertion failed: Could not find variable object \"%s\" to delete",
1150 *(varobj_table
+ index
) = cv
->next
;
1152 prev
->next
= cv
->next
;
1156 /* If root, remove varobj from root list */
1157 if (var
->root
->rootvar
== var
)
1159 /* Remove from list of root variables */
1160 if (rootlist
== var
->root
)
1161 rootlist
= var
->root
->next
;
1166 while ((cr
!= NULL
) && (cr
->rootvar
!= var
))
1174 ("Assertion failed: Could not find varobj \"%s\" in root list",
1181 prer
->next
= cr
->next
;
1188 /* Does a child with the name NAME exist in VAR? If so, return its data.
1189 If not, return NULL. */
1190 static struct varobj
*
1191 child_exists (struct varobj
*var
, char *name
)
1193 struct varobj_child
*vc
;
1195 for (vc
= var
->children
; vc
!= NULL
; vc
= vc
->next
)
1197 if (STREQ (vc
->child
->name
, name
))
1204 /* Create and install a child of the parent of the given name */
1205 static struct varobj
*
1206 create_child (struct varobj
*parent
, int index
, char *name
)
1208 struct varobj
*child
;
1211 child
= new_variable ();
1213 /* name is allocated by name_of_child */
1215 child
->index
= index
;
1216 child
->value
= value_of_child (parent
, index
);
1217 if ((!CPLUS_FAKE_CHILD (child
) && child
->value
== NULL
) || parent
->error
)
1219 child
->parent
= parent
;
1220 child
->root
= parent
->root
;
1221 xasprintf (&childs_name
, "%s.%s", parent
->obj_name
, name
);
1222 child
->obj_name
= childs_name
;
1223 install_variable (child
);
1225 /* Save a pointer to this child in the parent */
1226 save_child_in_parent (parent
, child
);
1228 /* Note the type of this child */
1229 child
->type
= type_of_child (child
);
1234 /* FIXME: This should be a generic add to list */
1235 /* Save CHILD in the PARENT's data. */
1237 save_child_in_parent (struct varobj
*parent
, struct varobj
*child
)
1239 struct varobj_child
*vc
;
1241 /* Insert the child at the top */
1242 vc
= parent
->children
;
1244 (struct varobj_child
*) xmalloc (sizeof (struct varobj_child
));
1246 parent
->children
->next
= vc
;
1247 parent
->children
->child
= child
;
1250 /* FIXME: This should be a generic remove from list */
1251 /* Remove the CHILD from the PARENT's list of children. */
1253 remove_child_from_parent (struct varobj
*parent
, struct varobj
*child
)
1255 struct varobj_child
*vc
, *prev
;
1257 /* Find the child in the parent's list */
1259 for (vc
= parent
->children
; vc
!= NULL
;)
1261 if (vc
->child
== child
)
1268 parent
->children
= vc
->next
;
1270 prev
->next
= vc
->next
;
1276 * Miscellaneous utility functions.
1279 /* Allocate memory and initialize a new variable */
1280 static struct varobj
*
1285 var
= (struct varobj
*) xmalloc (sizeof (struct varobj
));
1287 var
->obj_name
= NULL
;
1292 var
->num_children
= -1;
1294 var
->children
= NULL
;
1301 /* Allocate memory and initialize a new root variable */
1302 static struct varobj
*
1303 new_root_variable (void)
1305 struct varobj
*var
= new_variable ();
1306 var
->root
= (struct varobj_root
*) xmalloc (sizeof (struct varobj_root
));;
1307 var
->root
->lang
= NULL
;
1308 var
->root
->exp
= NULL
;
1309 var
->root
->valid_block
= NULL
;
1310 var
->root
->frame
.base
= 0;
1311 var
->root
->frame
.pc
= 0;
1312 var
->root
->use_selected_frame
= 0;
1313 var
->root
->rootvar
= NULL
;
1318 /* Free any allocated memory associated with VAR. */
1320 free_variable (struct varobj
*var
)
1322 /* Free the expression if this is a root variable. */
1323 if (var
->root
->rootvar
== var
)
1325 free_current_contents ((char **) &var
->root
->exp
);
1330 xfree (var
->obj_name
);
1335 do_free_variable_cleanup (void *var
)
1337 free_variable (var
);
1340 static struct cleanup
*
1341 make_cleanup_free_variable (struct varobj
*var
)
1343 return make_cleanup (do_free_variable_cleanup
, var
);
1346 /* This returns the type of the variable. This skips past typedefs
1347 and returns the real type of the variable. It also dereferences
1348 pointers and references.
1350 NOTE: TYPE_TARGET_TYPE should NOT be used anywhere in this file
1351 except within get_target_type and get_type. */
1352 static struct type
*
1353 get_type (struct varobj
*var
)
1358 while (type
!= NULL
&& TYPE_CODE (type
) == TYPE_CODE_TYPEDEF
)
1359 type
= TYPE_TARGET_TYPE (type
);
1364 /* This returns the type of the variable, dereferencing pointers, too. */
1365 static struct type
*
1366 get_type_deref (struct varobj
*var
)
1370 type
= get_type (var
);
1372 if (type
!= NULL
&& (TYPE_CODE (type
) == TYPE_CODE_PTR
1373 || TYPE_CODE (type
) == TYPE_CODE_REF
))
1374 type
= get_target_type (type
);
1379 /* This returns the target type (or NULL) of TYPE, also skipping
1380 past typedefs, just like get_type ().
1382 NOTE: TYPE_TARGET_TYPE should NOT be used anywhere in this file
1383 except within get_target_type and get_type. */
1384 static struct type
*
1385 get_target_type (struct type
*type
)
1389 type
= TYPE_TARGET_TYPE (type
);
1390 while (type
!= NULL
&& TYPE_CODE (type
) == TYPE_CODE_TYPEDEF
)
1391 type
= TYPE_TARGET_TYPE (type
);
1397 /* What is the default display for this variable? We assume that
1398 everything is "natural". Any exceptions? */
1399 static enum varobj_display_formats
1400 variable_default_display (struct varobj
*var
)
1402 return FORMAT_NATURAL
;
1405 /* This function is similar to gdb's value_equal, except that this
1406 one is "safe" -- it NEVER longjmps. It determines if the VAR's
1407 value is the same as VAL2. */
1409 my_value_equal (struct value
*val1
, struct value
*val2
, int *error2
)
1414 /* Special case: NULL values. If both are null, say
1416 if (val1
== NULL
&& val2
== NULL
)
1418 else if (val1
== NULL
|| val2
== NULL
)
1421 /* This is bogus, but unfortunately necessary. We must know
1422 exactly what caused an error -- reading val1 or val2 -- so
1423 that we can really determine if we think that something has changed. */
1426 /* We do need to catch errors here because the whole purpose
1427 is to test if value_equal() has errored */
1428 if (!gdb_value_equal (val1
, val1
, &r
))
1431 if (!gdb_value_equal (val2
, val2
, &r
))
1437 if (!gdb_value_equal (val1
, val2
, &r
))
1439 /* An error occurred, this could have happened if
1440 either val1 or val2 errored. ERR1 and ERR2 tell
1441 us which of these it is. If both errored, then
1442 we assume nothing has changed. If one of them is
1443 valid, though, then something has changed. */
1446 /* both the old and new values caused errors, so
1447 we say the value did not change */
1448 /* This is indeterminate, though. Perhaps we should
1449 be safe and say, yes, it changed anyway?? */
1461 /* FIXME: The following should be generic for any pointer */
1463 vpush (struct vstack
**pstack
, struct varobj
*var
)
1467 s
= (struct vstack
*) xmalloc (sizeof (struct vstack
));
1473 /* FIXME: The following should be generic for any pointer */
1474 static struct varobj
*
1475 vpop (struct vstack
**pstack
)
1480 if ((*pstack
)->var
== NULL
&& (*pstack
)->next
== NULL
)
1485 *pstack
= (*pstack
)->next
;
1491 /* FIXME: The following should be generic for any pointer */
1493 cppush (struct cpstack
**pstack
, char *name
)
1497 s
= (struct cpstack
*) xmalloc (sizeof (struct cpstack
));
1503 /* FIXME: The following should be generic for any pointer */
1505 cppop (struct cpstack
**pstack
)
1510 if ((*pstack
)->name
== NULL
&& (*pstack
)->next
== NULL
)
1515 *pstack
= (*pstack
)->next
;
1522 * Language-dependencies
1525 /* Common entry points */
1527 /* Get the language of variable VAR. */
1528 static enum varobj_languages
1529 variable_language (struct varobj
*var
)
1531 enum varobj_languages lang
;
1533 switch (var
->root
->exp
->language_defn
->la_language
)
1539 case language_cplus
:
1550 /* Return the number of children for a given variable.
1551 The result of this function is defined by the language
1552 implementation. The number of children returned by this function
1553 is the number of children that the user will see in the variable
1556 number_of_children (struct varobj
*var
)
1558 return (*var
->root
->lang
->number_of_children
) (var
);;
1561 /* What is the expression for the root varobj VAR? Returns a malloc'd string. */
1563 name_of_variable (struct varobj
*var
)
1565 return (*var
->root
->lang
->name_of_variable
) (var
);
1568 /* What is the name of the INDEX'th child of VAR? Returns a malloc'd string. */
1570 name_of_child (struct varobj
*var
, int index
)
1572 return (*var
->root
->lang
->name_of_child
) (var
, index
);
1575 /* What is the ``struct value *'' of the root variable VAR?
1576 TYPE_CHANGED controls what to do if the type of a
1577 use_selected_frame = 1 variable changes. On input,
1578 TYPE_CHANGED = 1 means discard the old varobj, and replace
1579 it with this one. TYPE_CHANGED = 0 means leave it around.
1580 NB: In both cases, var_handle will point to the new varobj,
1581 so if you use TYPE_CHANGED = 0, you will have to stash the
1582 old varobj pointer away somewhere before calling this.
1583 On return, TYPE_CHANGED will be 1 if the type has changed, and
1585 static struct value
*
1586 value_of_root (struct varobj
**var_handle
, int *type_changed
)
1590 if (var_handle
== NULL
)
1595 /* This should really be an exception, since this should
1596 only get called with a root variable. */
1598 if (var
->root
->rootvar
!= var
)
1601 if (var
->root
->use_selected_frame
)
1603 struct varobj
*tmp_var
;
1604 char *old_type
, *new_type
;
1605 old_type
= varobj_get_type (var
);
1606 tmp_var
= varobj_create (NULL
, var
->name
, (CORE_ADDR
) 0,
1607 USE_SELECTED_FRAME
);
1608 if (tmp_var
== NULL
)
1612 new_type
= varobj_get_type (tmp_var
);
1613 if (strcmp (old_type
, new_type
) == 0)
1615 varobj_delete (tmp_var
, NULL
, 0);
1623 savestring (var
->obj_name
, strlen (var
->obj_name
));
1624 varobj_delete (var
, NULL
, 0);
1628 tmp_var
->obj_name
= varobj_gen_name ();
1630 install_variable (tmp_var
);
1631 *var_handle
= tmp_var
;
1641 return (*var
->root
->lang
->value_of_root
) (var_handle
);
1644 /* What is the ``struct value *'' for the INDEX'th child of PARENT? */
1645 static struct value
*
1646 value_of_child (struct varobj
*parent
, int index
)
1648 struct value
*value
;
1650 value
= (*parent
->root
->lang
->value_of_child
) (parent
, index
);
1652 /* If we're being lazy, fetch the real value of the variable. */
1653 if (value
!= NULL
&& VALUE_LAZY (value
))
1655 /* If we fail to fetch the value of the child, return
1656 NULL so that callers notice that we're leaving an
1658 if (!gdb_value_fetch_lazy (value
))
1665 /* What is the type of VAR? */
1666 static struct type
*
1667 type_of_child (struct varobj
*var
)
1670 /* If the child had no evaluation errors, var->value
1671 will be non-NULL and contain a valid type. */
1672 if (var
->value
!= NULL
)
1673 return VALUE_TYPE (var
->value
);
1675 /* Otherwise, we must compute the type. */
1676 return (*var
->root
->lang
->type_of_child
) (var
->parent
, var
->index
);
1679 /* Is this variable editable? Use the variable's type to make
1680 this determination. */
1682 variable_editable (struct varobj
*var
)
1684 return (*var
->root
->lang
->variable_editable
) (var
);
1687 /* GDB already has a command called "value_of_variable". Sigh. */
1689 my_value_of_variable (struct varobj
*var
)
1691 return (*var
->root
->lang
->value_of_variable
) (var
);
1694 /* Is VAR something that can change? Depending on language,
1695 some variable's values never change. For example,
1696 struct and unions never change values. */
1698 type_changeable (struct varobj
*var
)
1703 if (CPLUS_FAKE_CHILD (var
))
1706 type
= get_type (var
);
1708 switch (TYPE_CODE (type
))
1710 case TYPE_CODE_STRUCT
:
1711 case TYPE_CODE_UNION
:
1712 case TYPE_CODE_ARRAY
:
1725 c_number_of_children (struct varobj
*var
)
1728 struct type
*target
;
1731 type
= get_type (var
);
1732 target
= get_target_type (type
);
1735 switch (TYPE_CODE (type
))
1737 case TYPE_CODE_ARRAY
:
1738 if (TYPE_LENGTH (type
) > 0 && TYPE_LENGTH (target
) > 0
1739 && TYPE_ARRAY_UPPER_BOUND_TYPE (type
) != BOUND_CANNOT_BE_DETERMINED
)
1740 children
= TYPE_LENGTH (type
) / TYPE_LENGTH (target
);
1745 case TYPE_CODE_STRUCT
:
1746 case TYPE_CODE_UNION
:
1747 children
= TYPE_NFIELDS (type
);
1751 /* This is where things get compilcated. All pointers have one child.
1752 Except, of course, for struct and union ptr, which we automagically
1753 dereference for the user and function ptrs, which have no children.
1754 We also don't dereference void* as we don't know what to show.
1755 We can show char* so we allow it to be dereferenced. If you decide
1756 to test for it, please mind that a little magic is necessary to
1757 properly identify it: char* has TYPE_CODE == TYPE_CODE_INT and
1758 TYPE_NAME == "char" */
1760 switch (TYPE_CODE (target
))
1762 case TYPE_CODE_STRUCT
:
1763 case TYPE_CODE_UNION
:
1764 children
= TYPE_NFIELDS (target
);
1767 case TYPE_CODE_FUNC
:
1768 case TYPE_CODE_VOID
:
1778 /* Other types have no children */
1786 c_name_of_variable (struct varobj
*parent
)
1788 return savestring (parent
->name
, strlen (parent
->name
));
1792 c_name_of_child (struct varobj
*parent
, int index
)
1795 struct type
*target
;
1799 type
= get_type (parent
);
1800 target
= get_target_type (type
);
1802 switch (TYPE_CODE (type
))
1804 case TYPE_CODE_ARRAY
:
1805 xasprintf (&name
, "%d", index
);
1808 case TYPE_CODE_STRUCT
:
1809 case TYPE_CODE_UNION
:
1810 string
= TYPE_FIELD_NAME (type
, index
);
1811 name
= savestring (string
, strlen (string
));
1815 switch (TYPE_CODE (target
))
1817 case TYPE_CODE_STRUCT
:
1818 case TYPE_CODE_UNION
:
1819 string
= TYPE_FIELD_NAME (target
, index
);
1820 name
= savestring (string
, strlen (string
));
1824 xasprintf (&name
, "*%s", parent
->name
);
1830 /* This should not happen */
1831 name
= xstrdup ("???");
1837 static struct value
*
1838 c_value_of_root (struct varobj
**var_handle
)
1840 struct value
*new_val
;
1841 struct varobj
*var
= *var_handle
;
1842 struct frame_info
*fi
;
1845 /* Only root variables can be updated... */
1846 if (var
->root
->rootvar
!= var
)
1847 /* Not a root var */
1851 /* Determine whether the variable is still around. */
1852 if (var
->root
->valid_block
== NULL
)
1856 reinit_frame_cache ();
1857 fi
= frame_find_by_id (var
->root
->frame
);
1858 within_scope
= fi
!= NULL
;
1859 /* FIXME: select_frame could fail */
1866 /* We need to catch errors here, because if evaluate
1867 expression fails we just want to make val->error = 1 and
1869 if (gdb_evaluate_expression (var
->root
->exp
, &new_val
))
1871 if (VALUE_LAZY (new_val
))
1873 /* We need to catch errors because if
1874 value_fetch_lazy fails we still want to continue
1875 (after making val->error = 1) */
1876 /* FIXME: Shouldn't be using VALUE_CONTENTS? The
1877 comment on value_fetch_lazy() says it is only
1878 called from the macro... */
1879 if (!gdb_value_fetch_lazy (new_val
))
1888 release_value (new_val
);
1895 static struct value
*
1896 c_value_of_child (struct varobj
*parent
, int index
)
1898 struct value
*value
;
1900 struct value
*indval
;
1901 struct type
*type
, *target
;
1904 type
= get_type (parent
);
1905 target
= get_target_type (type
);
1906 name
= name_of_child (parent
, index
);
1907 temp
= parent
->value
;
1912 switch (TYPE_CODE (type
))
1914 case TYPE_CODE_ARRAY
:
1916 /* This breaks if the array lives in a (vector) register. */
1917 value
= value_slice (temp
, index
, 1);
1918 temp
= value_coerce_array (value
);
1919 gdb_value_ind (temp
, &value
);
1921 indval
= value_from_longest (builtin_type_int
, (LONGEST
) index
);
1922 gdb_value_subscript (temp
, indval
, &value
);
1926 case TYPE_CODE_STRUCT
:
1927 case TYPE_CODE_UNION
:
1928 gdb_value_struct_elt (NULL
, &value
, &temp
, NULL
, name
, NULL
,
1933 switch (TYPE_CODE (target
))
1935 case TYPE_CODE_STRUCT
:
1936 case TYPE_CODE_UNION
:
1937 gdb_value_struct_elt (NULL
, &value
, &temp
, NULL
, name
, NULL
,
1942 gdb_value_ind (temp
, &value
);
1953 release_value (value
);
1959 static struct type
*
1960 c_type_of_child (struct varobj
*parent
, int index
)
1963 char *name
= name_of_child (parent
, index
);
1965 switch (TYPE_CODE (parent
->type
))
1967 case TYPE_CODE_ARRAY
:
1968 type
= get_target_type (parent
->type
);
1971 case TYPE_CODE_STRUCT
:
1972 case TYPE_CODE_UNION
:
1973 type
= lookup_struct_elt_type (parent
->type
, name
, 0);
1977 switch (TYPE_CODE (get_target_type (parent
->type
)))
1979 case TYPE_CODE_STRUCT
:
1980 case TYPE_CODE_UNION
:
1981 type
= lookup_struct_elt_type (parent
->type
, name
, 0);
1985 type
= get_target_type (parent
->type
);
1991 /* This should not happen as only the above types have children */
1992 warning ("Child of parent whose type does not allow children");
1993 /* FIXME: Can we still go on? */
2003 c_variable_editable (struct varobj
*var
)
2005 switch (TYPE_CODE (get_type (var
)))
2007 case TYPE_CODE_STRUCT
:
2008 case TYPE_CODE_UNION
:
2009 case TYPE_CODE_ARRAY
:
2010 case TYPE_CODE_FUNC
:
2011 case TYPE_CODE_MEMBER
:
2012 case TYPE_CODE_METHOD
:
2023 c_value_of_variable (struct varobj
*var
)
2025 /* BOGUS: if val_print sees a struct/class, it will print out its
2026 children instead of "{...}" */
2028 switch (TYPE_CODE (get_type (var
)))
2030 case TYPE_CODE_STRUCT
:
2031 case TYPE_CODE_UNION
:
2032 return xstrdup ("{...}");
2035 case TYPE_CODE_ARRAY
:
2038 xasprintf (&number
, "[%d]", var
->num_children
);
2045 if (var
->value
== NULL
)
2047 /* This can happen if we attempt to get the value of a struct
2048 member when the parent is an invalid pointer. This is an
2049 error condition, so we should tell the caller. */
2055 struct ui_file
*stb
= mem_fileopen ();
2056 struct cleanup
*old_chain
= make_cleanup_ui_file_delete (stb
);
2059 if (VALUE_LAZY (var
->value
))
2060 gdb_value_fetch_lazy (var
->value
);
2061 val_print (VALUE_TYPE (var
->value
),
2062 VALUE_CONTENTS_RAW (var
->value
), 0,
2063 VALUE_ADDRESS (var
->value
), stb
,
2064 format_code
[(int) var
->format
], 1, 0, 0);
2065 thevalue
= ui_file_xstrdup (stb
, &dummy
);
2066 do_cleanups (old_chain
);
2077 cplus_number_of_children (struct varobj
*var
)
2080 int children
, dont_know
;
2085 if (!CPLUS_FAKE_CHILD (var
))
2087 type
= get_type_deref (var
);
2089 if (((TYPE_CODE (type
)) == TYPE_CODE_STRUCT
) ||
2090 ((TYPE_CODE (type
)) == TYPE_CODE_UNION
))
2094 cplus_class_num_children (type
, kids
);
2095 if (kids
[v_public
] != 0)
2097 if (kids
[v_private
] != 0)
2099 if (kids
[v_protected
] != 0)
2102 /* Add any baseclasses */
2103 children
+= TYPE_N_BASECLASSES (type
);
2106 /* FIXME: save children in var */
2113 type
= get_type_deref (var
->parent
);
2115 cplus_class_num_children (type
, kids
);
2116 if (STREQ (var
->name
, "public"))
2117 children
= kids
[v_public
];
2118 else if (STREQ (var
->name
, "private"))
2119 children
= kids
[v_private
];
2121 children
= kids
[v_protected
];
2126 children
= c_number_of_children (var
);
2131 /* Compute # of public, private, and protected variables in this class.
2132 That means we need to descend into all baseclasses and find out
2133 how many are there, too. */
2135 cplus_class_num_children (struct type
*type
, int children
[3])
2139 children
[v_public
] = 0;
2140 children
[v_private
] = 0;
2141 children
[v_protected
] = 0;
2143 for (i
= TYPE_N_BASECLASSES (type
); i
< TYPE_NFIELDS (type
); i
++)
2145 /* If we have a virtual table pointer, omit it. */
2146 if (TYPE_VPTR_BASETYPE (type
) == type
&& TYPE_VPTR_FIELDNO (type
) == i
)
2149 if (TYPE_FIELD_PROTECTED (type
, i
))
2150 children
[v_protected
]++;
2151 else if (TYPE_FIELD_PRIVATE (type
, i
))
2152 children
[v_private
]++;
2154 children
[v_public
]++;
2159 cplus_name_of_variable (struct varobj
*parent
)
2161 return c_name_of_variable (parent
);
2165 cplus_name_of_child (struct varobj
*parent
, int index
)
2171 if (CPLUS_FAKE_CHILD (parent
))
2173 /* Looking for children of public, private, or protected. */
2174 type
= get_type_deref (parent
->parent
);
2177 type
= get_type_deref (parent
);
2180 switch (TYPE_CODE (type
))
2182 case TYPE_CODE_STRUCT
:
2183 case TYPE_CODE_UNION
:
2184 cplus_class_num_children (type
, children
);
2186 if (CPLUS_FAKE_CHILD (parent
))
2190 /* Skip over vptr, if it exists. */
2191 if (TYPE_VPTR_BASETYPE (type
) == type
2192 && index
>= TYPE_VPTR_FIELDNO (type
))
2195 /* FIXME: This assumes that type orders
2196 inherited, public, private, protected */
2197 i
= index
+ TYPE_N_BASECLASSES (type
);
2198 if (STREQ (parent
->name
, "private")
2199 || STREQ (parent
->name
, "protected"))
2200 i
+= children
[v_public
];
2201 if (STREQ (parent
->name
, "protected"))
2202 i
+= children
[v_private
];
2204 name
= TYPE_FIELD_NAME (type
, i
);
2206 else if (index
< TYPE_N_BASECLASSES (type
))
2207 name
= TYPE_FIELD_NAME (type
, index
);
2210 /* Everything beyond the baseclasses can
2211 only be "public", "private", or "protected" */
2212 index
-= TYPE_N_BASECLASSES (type
);
2216 if (children
[v_public
] != 0)
2222 if (children
[v_private
] != 0)
2228 if (children
[v_protected
] != 0)
2245 return c_name_of_child (parent
, index
);
2249 name
= savestring (name
, strlen (name
));
2255 static struct value
*
2256 cplus_value_of_root (struct varobj
**var_handle
)
2258 return c_value_of_root (var_handle
);
2261 static struct value
*
2262 cplus_value_of_child (struct varobj
*parent
, int index
)
2265 struct value
*value
;
2267 if (CPLUS_FAKE_CHILD (parent
))
2268 type
= get_type_deref (parent
->parent
);
2270 type
= get_type_deref (parent
);
2274 if (((TYPE_CODE (type
)) == TYPE_CODE_STRUCT
) ||
2275 ((TYPE_CODE (type
)) == TYPE_CODE_UNION
))
2277 if (CPLUS_FAKE_CHILD (parent
))
2280 struct value
*temp
= parent
->parent
->value
;
2285 name
= name_of_child (parent
, index
);
2286 gdb_value_struct_elt (NULL
, &value
, &temp
, NULL
, name
, NULL
,
2289 release_value (value
);
2293 else if (index
>= TYPE_N_BASECLASSES (type
))
2295 /* public, private, or protected */
2301 if (parent
->value
!= NULL
)
2303 struct value
*temp
= NULL
;
2305 if (TYPE_CODE (VALUE_TYPE (parent
->value
)) == TYPE_CODE_PTR
2306 || TYPE_CODE (VALUE_TYPE (parent
->value
)) == TYPE_CODE_REF
)
2308 if (!gdb_value_ind (parent
->value
, &temp
))
2312 temp
= parent
->value
;
2316 value
= value_cast (TYPE_FIELD_TYPE (type
, index
), temp
);
2317 release_value (value
);
2321 /* We failed to evaluate the parent's value, so don't even
2322 bother trying to evaluate this child. */
2330 return c_value_of_child (parent
, index
);
2335 static struct type
*
2336 cplus_type_of_child (struct varobj
*parent
, int index
)
2338 struct type
*type
, *t
;
2340 if (CPLUS_FAKE_CHILD (parent
))
2342 /* Looking for the type of a child of public, private, or protected. */
2343 t
= get_type_deref (parent
->parent
);
2346 t
= get_type_deref (parent
);
2349 switch (TYPE_CODE (t
))
2351 case TYPE_CODE_STRUCT
:
2352 case TYPE_CODE_UNION
:
2353 if (CPLUS_FAKE_CHILD (parent
))
2355 char *name
= cplus_name_of_child (parent
, index
);
2356 type
= lookup_struct_elt_type (t
, name
, 0);
2359 else if (index
< TYPE_N_BASECLASSES (t
))
2360 type
= TYPE_FIELD_TYPE (t
, index
);
2373 return c_type_of_child (parent
, index
);
2379 cplus_variable_editable (struct varobj
*var
)
2381 if (CPLUS_FAKE_CHILD (var
))
2384 return c_variable_editable (var
);
2388 cplus_value_of_variable (struct varobj
*var
)
2391 /* If we have one of our special types, don't print out
2393 if (CPLUS_FAKE_CHILD (var
))
2394 return xstrdup ("");
2396 return c_value_of_variable (var
);
2402 java_number_of_children (struct varobj
*var
)
2404 return cplus_number_of_children (var
);
2408 java_name_of_variable (struct varobj
*parent
)
2412 name
= cplus_name_of_variable (parent
);
2413 /* If the name has "-" in it, it is because we
2414 needed to escape periods in the name... */
2417 while (*p
!= '\000')
2428 java_name_of_child (struct varobj
*parent
, int index
)
2432 name
= cplus_name_of_child (parent
, index
);
2433 /* Escape any periods in the name... */
2436 while (*p
!= '\000')
2446 static struct value
*
2447 java_value_of_root (struct varobj
**var_handle
)
2449 return cplus_value_of_root (var_handle
);
2452 static struct value
*
2453 java_value_of_child (struct varobj
*parent
, int index
)
2455 return cplus_value_of_child (parent
, index
);
2458 static struct type
*
2459 java_type_of_child (struct varobj
*parent
, int index
)
2461 return cplus_type_of_child (parent
, index
);
2465 java_variable_editable (struct varobj
*var
)
2467 return cplus_variable_editable (var
);
2471 java_value_of_variable (struct varobj
*var
)
2473 return cplus_value_of_variable (var
);
2476 extern void _initialize_varobj (void);
2478 _initialize_varobj (void)
2480 int sizeof_table
= sizeof (struct vlist
*) * VAROBJ_TABLE_SIZE
;
2482 varobj_table
= xmalloc (sizeof_table
);
2483 memset (varobj_table
, 0, sizeof_table
);
2485 add_show_from_set (add_set_cmd ("debugvarobj", class_maintenance
, var_zinteger
, (char *) &varobjdebug
, "Set varobj debugging.\n\
2486 When non-zero, varobj debugging is enabled.", &setlist
),