1 /* Implementation of the GDB variable objects API.
2 Copyright 1999, 2000 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"
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
[] =
41 {"unknown", "C", "C++", "Java"};
45 /* Every root variable has one of these structures saved in its
46 varobj. Members which must be free'd are noted. */
50 /* Alloc'd expression for this parent. */
51 struct expression
*exp
;
53 /* Block for which this expression is valid */
54 struct block
*valid_block
;
56 /* The frame for this expression */
59 /* If 1, "update" always recomputes the frame & valid block
60 using the currently selected frame. */
61 int use_selected_frame
;
63 /* Language info for this variable and its children */
64 struct language_specific
*lang
;
66 /* The varobj for this root node. */
67 struct varobj
*rootvar
;
69 /* Next root variable */
70 struct varobj_root
*next
;
73 /* Every variable in the system has a structure of this type defined
74 for it. This structure holds all information necessary to manipulate
75 a particular object variable. Members which must be freed are noted. */
79 /* Alloc'd name of the variable for this object.. If this variable is a
80 child, then this name will be the child's source name.
82 /* NOTE: This is the "expression" */
85 /* The alloc'd name for this variable's object. This is here for
86 convenience when constructing this object's children. */
89 /* Index of this variable in its parent or -1 */
92 /* The type of this variable. This may NEVER be NULL. */
95 /* The value of this expression or subexpression. This may be NULL. */
98 /* Did an error occur evaluating the expression or getting its value? */
101 /* The number of (immediate) children this variable has */
104 /* If this object is a child, this points to its immediate parent. */
105 struct varobj
*parent
;
107 /* A list of this object's children */
108 struct varobj_child
*children
;
110 /* Description of the root variable. Points to root variable for children. */
111 struct varobj_root
*root
;
113 /* The format of the output for this object */
114 enum varobj_display_formats format
;
117 /* Every variable keeps a linked list of its children, described
118 by the following structure. */
119 /* FIXME: Deprecated. All should use vlist instead */
124 /* Pointer to the child's data */
125 struct varobj
*child
;
127 /* Pointer to the next child */
128 struct varobj_child
*next
;
131 /* A stack of varobjs */
132 /* FIXME: Deprecated. All should use vlist instead */
143 struct cpstack
*next
;
146 /* A list of varobjs */
154 /* Private function prototypes */
156 /* Helper functions for the above subcommands. */
158 static int delete_variable
PARAMS ((struct cpstack
**, struct varobj
*, int));
160 static void delete_variable_1
PARAMS ((struct cpstack
**, int *,
161 struct varobj
*, int, int));
163 static int install_variable
PARAMS ((struct varobj
*));
165 static void uninstall_variable
PARAMS ((struct varobj
*));
167 static struct varobj
*child_exists
PARAMS ((struct varobj
*, char *));
169 static struct varobj
*create_child
PARAMS ((struct varobj
*, int, char *));
171 static void save_child_in_parent
PARAMS ((struct varobj
*, struct varobj
*));
173 static void remove_child_from_parent
PARAMS ((struct varobj
*, struct varobj
*));
175 /* Utility routines */
177 static struct varobj
*new_variable
PARAMS ((void));
179 static struct varobj
*new_root_variable
PARAMS ((void));
181 static void free_variable
PARAMS ((struct varobj
* var
));
183 static struct type
*get_type
PARAMS ((struct varobj
* var
));
185 static struct type
*get_type_deref
PARAMS ((struct varobj
* var
));
187 static struct type
*get_target_type
PARAMS ((struct type
*));
189 static enum varobj_display_formats variable_default_display
PARAMS ((struct varobj
*));
191 static int my_value_equal
PARAMS ((value_ptr
, value_ptr
, int *));
193 static void vpush
PARAMS ((struct vstack
** pstack
, struct varobj
* var
));
195 static struct varobj
*vpop
PARAMS ((struct vstack
** pstack
));
197 static void cppush
PARAMS ((struct cpstack
** pstack
, char *name
));
199 static char *cppop
PARAMS ((struct cpstack
** pstack
));
201 /* Language-specific routines. */
203 static enum varobj_languages variable_language
PARAMS ((struct varobj
* var
));
205 static int number_of_children
PARAMS ((struct varobj
*));
207 static char *name_of_variable
PARAMS ((struct varobj
*));
209 static char *name_of_child
PARAMS ((struct varobj
*, int));
211 static value_ptr value_of_root
PARAMS ((struct varobj
** var_handle
,
214 static value_ptr value_of_child
PARAMS ((struct varobj
* parent
, int index
));
216 static struct type
*type_of_child
PARAMS ((struct varobj
* var
));
218 static int variable_editable
PARAMS ((struct varobj
* var
));
220 static char *my_value_of_variable
PARAMS ((struct varobj
* var
));
222 static int type_changeable
PARAMS ((struct varobj
* var
));
224 /* C implementation */
226 static int c_number_of_children
PARAMS ((struct varobj
* var
));
228 static char *c_name_of_variable
PARAMS ((struct varobj
* parent
));
230 static char *c_name_of_child
PARAMS ((struct varobj
* parent
, int index
));
232 static value_ptr c_value_of_root
PARAMS ((struct varobj
** var_handle
));
234 static value_ptr c_value_of_child
PARAMS ((struct varobj
* parent
, int index
));
236 static struct type
*c_type_of_child
PARAMS ((struct varobj
* parent
, int index
));
238 static int c_variable_editable
PARAMS ((struct varobj
* var
));
240 static char *c_value_of_variable
PARAMS ((struct varobj
* var
));
242 /* C++ implementation */
244 static int cplus_number_of_children
PARAMS ((struct varobj
* var
));
246 static void cplus_class_num_children
PARAMS ((struct type
* type
, int children
[3]));
248 static char *cplus_name_of_variable
PARAMS ((struct varobj
* parent
));
250 static char *cplus_name_of_child
PARAMS ((struct varobj
* parent
, int index
));
252 static value_ptr cplus_value_of_root
PARAMS ((struct varobj
** var_handle
));
254 static value_ptr cplus_value_of_child
PARAMS ((struct varobj
* parent
, int index
));
256 static struct type
*cplus_type_of_child
PARAMS ((struct varobj
* parent
, int index
));
258 static int cplus_variable_editable
PARAMS ((struct varobj
* var
));
260 static char *cplus_value_of_variable
PARAMS ((struct varobj
* var
));
262 /* Java implementation */
264 static int java_number_of_children
PARAMS ((struct varobj
* var
));
266 static char *java_name_of_variable
PARAMS ((struct varobj
* parent
));
268 static char *java_name_of_child
PARAMS ((struct varobj
* parent
, int index
));
270 static value_ptr java_value_of_root
PARAMS ((struct varobj
** var_handle
));
272 static value_ptr java_value_of_child
PARAMS ((struct varobj
* parent
, int index
));
274 static struct type
*java_type_of_child
PARAMS ((struct varobj
* parent
, int index
));
276 static int java_variable_editable
PARAMS ((struct varobj
* var
));
278 static char *java_value_of_variable
PARAMS ((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
) PARAMS ((struct varobj
* parent
));
291 /* The name (expression) of a root varobj. */
292 char *(*name_of_variable
) PARAMS ((struct varobj
* parent
));
294 /* The name of the INDEX'th child of PARENT. */
295 char *(*name_of_child
) PARAMS ((struct varobj
* parent
, int index
));
297 /* The value_ptr of the root variable ROOT. */
298 value_ptr (*value_of_root
) PARAMS ((struct varobj
** root_handle
));
300 /* The value_ptr of the INDEX'th child of PARENT. */
301 value_ptr (*value_of_child
) PARAMS ((struct varobj
* parent
, int index
));
303 /* The type of the INDEX'th child of PARENT. */
304 struct type
*(*type_of_child
) PARAMS ((struct varobj
* parent
, int index
));
306 /* Is VAR editable? */
307 int (*variable_editable
) PARAMS ((struct varobj
* var
));
309 /* The current value of VAR. */
310 char *(*value_of_variable
) PARAMS ((struct varobj
* var
));
313 /* Array of known source language routines. */
314 static struct language_specific
315 languages
[vlang_end
][sizeof (struct language_specific
)] =
317 /* Unknown (try treating as C */
320 c_number_of_children
,
333 c_number_of_children
,
346 cplus_number_of_children
,
347 cplus_name_of_variable
,
350 cplus_value_of_child
,
352 cplus_variable_editable
,
353 cplus_value_of_variable
359 java_number_of_children
,
360 java_name_of_variable
,
365 java_variable_editable
,
366 java_value_of_variable
370 /* A little convenience enum for dealing with C++/Java */
373 v_public
= 0, v_private
, v_protected
378 /* Mappings of varobj_display_formats enums to gdb's format codes */
379 static int format_code
[] =
380 {0, 't', 'd', 'x', 'o'};
382 /* Header of the list of root variable objects */
383 static struct varobj_root
*rootlist
;
384 static int rootcount
= 0; /* number of root varobjs in the list */
386 /* Prime number indicating the number of buckets in the hash table */
387 /* A prime large enough to avoid too many colisions */
388 #define VAROBJ_TABLE_SIZE 227
390 /* Pointer to the varobj hash table (built at run time) */
391 static struct vlist
**varobj_table
;
396 #define FREEIF(x) if (x != NULL) free((char *) (x))
398 /* Is the variable X one of our "fake" children? */
399 #define CPLUS_FAKE_CHILD(x) \
400 ((x) != NULL && (x)->type == NULL && (x)->value == NULL)
403 /* API Implementation */
405 /* Creates a varobj (not its children) */
408 varobj_create (char *objname
,
409 char *expression
, CORE_ADDR frame
,
410 enum varobj_type type
)
413 struct frame_info
*fi
, *old_fi
;
415 struct cleanup
*old_chain
;
417 /* Fill out a varobj structure for the (root) variable being constructed. */
418 var
= new_root_variable ();
419 old_chain
= make_cleanup ((make_cleanup_func
) free_variable
, var
);
421 if (expression
!= NULL
)
424 enum varobj_languages lang
;
426 /* Parse and evaluate the expression, filling in as much
427 of the variable's data as possible */
429 /* Allow creator to specify context of variable */
430 if ((type
== USE_CURRENT_FRAME
)
431 || (type
== USE_SELECTED_FRAME
))
434 fi
= find_frame_addr_in_frame_chain (frame
);
436 /* frame = -2 means always use selected frame */
437 if (type
== USE_SELECTED_FRAME
)
438 var
->root
->use_selected_frame
= 1;
442 block
= get_frame_block (fi
);
445 innermost_block
= NULL
;
446 /* Wrap the call to parse expression, so we can
447 return a sensible error. */
448 if (!gdb_parse_exp_1 (&p
, block
, 0, &var
->root
->exp
))
453 /* Don't allow variables to be created for types. */
454 if (var
->root
->exp
->elts
[0].opcode
== OP_TYPE
)
456 do_cleanups (old_chain
);
457 fprintf_unfiltered (gdb_stderr
,
458 "Attempt to use a type name as an expression.");
462 var
->format
= variable_default_display (var
);
463 var
->root
->valid_block
= innermost_block
;
464 var
->name
= savestring (expression
, strlen (expression
));
466 /* When the frame is different from the current frame,
467 we must select the appropriate frame before parsing
468 the expression, otherwise the value will not be current.
469 Since select_frame is so benign, just call it for all cases. */
472 var
->root
->frame
= FRAME_FP (fi
);
473 old_fi
= selected_frame
;
474 select_frame (fi
, -1);
477 /* We definitively need to catch errors here.
478 If evaluate_expression succeeds we got the value we wanted.
479 But if it fails, we still go on with a call to evaluate_type() */
480 if (gdb_evaluate_expression (var
->root
->exp
, &var
->value
))
483 release_value (var
->value
);
484 if (VALUE_LAZY (var
->value
))
485 gdb_value_fetch_lazy (var
->value
);
488 var
->value
= evaluate_type (var
->root
->exp
);
490 var
->type
= VALUE_TYPE (var
->value
);
492 /* Set language info */
493 lang
= variable_language (var
);
494 var
->root
->lang
= languages
[lang
];
496 /* Set ourselves as our root */
497 var
->root
->rootvar
= var
;
499 /* Reset the selected frame */
501 select_frame (old_fi
, -1);
504 /* If the variable object name is null, that means this
505 is a temporary variable, so don't install it. */
507 if ((var
!= NULL
) && (objname
!= NULL
))
509 var
->obj_name
= savestring (objname
, strlen (objname
));
511 /* If a varobj name is duplicated, the install will fail so
513 if (!install_variable (var
))
515 do_cleanups (old_chain
);
520 discard_cleanups (old_chain
);
524 /* Generates an unique name that can be used for a varobj */
527 varobj_gen_name (void)
532 /* generate a name for this object */
534 sprintf (obj_name
, "var%d", id
);
536 return xstrdup (obj_name
);
539 /* Given an "objname", returns the pointer to the corresponding varobj
540 or NULL if not found */
543 varobj_get_handle (char *objname
)
547 unsigned int index
= 0;
550 for (chp
= objname
; *chp
; chp
++)
552 index
= (index
+ (i
++ * (unsigned int) *chp
)) % VAROBJ_TABLE_SIZE
;
555 cv
= *(varobj_table
+ index
);
556 while ((cv
!= NULL
) && (strcmp (cv
->var
->obj_name
, objname
) != 0))
560 error ("Variable object not found");
565 /* Given the handle, return the name of the object */
568 varobj_get_objname (struct varobj
*var
)
570 return var
->obj_name
;
573 /* Given the handle, return the expression represented by the object */
576 varobj_get_expression (struct varobj
*var
)
578 return name_of_variable (var
);
581 /* Deletes a varobj and all its children if only_children == 0,
582 otherwise deletes only the children; returns a malloc'ed list of all the
583 (malloc'ed) names of the variables that have been deleted (NULL terminated) */
586 varobj_delete (struct varobj
*var
, char ***dellist
, int only_children
)
590 struct cpstack
*result
= NULL
;
593 /* Initialize a stack for temporary results */
594 cppush (&result
, NULL
);
597 /* Delete only the variable children */
598 delcount
= delete_variable (&result
, var
, 1 /* only the children */ );
600 /* Delete the variable and all its children */
601 delcount
= delete_variable (&result
, var
, 0 /* parent+children */ );
603 /* We may have been asked to return a list of what has been deleted */
606 *dellist
= xmalloc ((delcount
+ 1) * sizeof (char *));
610 *cp
= cppop (&result
);
611 while ((*cp
!= NULL
) && (mycount
> 0))
615 *cp
= cppop (&result
);
618 if (mycount
|| (*cp
!= NULL
))
619 warning ("varobj_delete: assertion failed - mycount(=%d) <> 0", mycount
);
625 /* Set/Get variable object display format */
627 enum varobj_display_formats
628 varobj_set_display_format (struct varobj
*var
,
629 enum varobj_display_formats format
)
636 case FORMAT_HEXADECIMAL
:
638 var
->format
= format
;
642 var
->format
= variable_default_display (var
);
648 enum varobj_display_formats
649 varobj_get_display_format (struct varobj
*var
)
655 varobj_get_num_children (struct varobj
*var
)
657 if (var
->num_children
== -1)
658 var
->num_children
= number_of_children (var
);
660 return var
->num_children
;
663 /* Creates a list of the immediate children of a variable object;
664 the return code is the number of such children or -1 on error */
667 varobj_list_children (struct varobj
*var
, struct varobj
***childlist
)
669 struct varobj
*child
;
673 /* sanity check: have we been passed a pointer? */
674 if (childlist
== NULL
)
679 if (var
->num_children
== -1)
680 var
->num_children
= number_of_children (var
);
682 /* List of children */
683 *childlist
= xmalloc ((var
->num_children
+ 1) * sizeof (struct varobj
*));
685 for (i
= 0; i
< var
->num_children
; i
++)
687 /* Mark as the end in case we bail out */
688 *((*childlist
) + i
) = NULL
;
690 /* check if child exists, if not create */
691 name
= name_of_child (var
, i
);
692 child
= child_exists (var
, name
);
694 child
= create_child (var
, i
, name
);
696 *((*childlist
) + i
) = child
;
699 /* End of list is marked by a NULL pointer */
700 *((*childlist
) + i
) = NULL
;
702 return var
->num_children
;
705 /* Obtain the type of an object Variable as a string similar to the one gdb
706 prints on the console */
709 varobj_get_type (struct varobj
*var
)
712 struct cleanup
*old_chain
;
717 /* For the "fake" variables, do not return a type. (It's type is
719 if (CPLUS_FAKE_CHILD (var
))
722 stb
= mem_fileopen ();
723 old_chain
= make_cleanup_ui_file_delete (stb
);
725 /* To print the type, we simply create a zero value_ptr and
726 cast it to our type. We then typeprint this variable. */
727 val
= value_zero (var
->type
, not_lval
);
728 type_print (VALUE_TYPE (val
), "", stb
, -1);
730 thetype
= ui_file_xstrdup (stb
, &length
);
731 do_cleanups (old_chain
);
735 enum varobj_languages
736 varobj_get_language (struct varobj
*var
)
738 return variable_language (var
);
742 varobj_get_attributes (struct varobj
*var
)
746 if (variable_editable (var
))
747 /* FIXME: define masks for attributes */
748 attributes
|= 0x00000001; /* Editable */
754 varobj_get_value (struct varobj
*var
)
756 return my_value_of_variable (var
);
759 /* Set the value of an object variable (if it is editable) to the
760 value of the given expression */
761 /* Note: Invokes functions that can call error() */
764 varobj_set_value (struct varobj
*var
, char *expression
)
769 /* The argument "expression" contains the variable's new value.
770 We need to first construct a legal expression for this -- ugh! */
771 /* Does this cover all the bases? */
772 struct expression
*exp
;
774 int saved_input_radix
= input_radix
;
776 if (variable_editable (var
) && !var
->error
)
778 char *s
= expression
;
782 input_radix
= 10; /* ALWAYS reset to decimal temporarily */
783 /* FIXME: Callee may longjump */
784 exp
= parse_exp_1 (&s
, 0, 0);
785 if (!gdb_evaluate_expression (exp
, &value
))
787 /* We cannot proceed without a valid expression. */
792 /* If our parent is "public", "private", or "protected", we could
793 be asking to modify the value of a baseclass. If so, we need to
794 adjust our address by the offset of our baseclass in the subclass,
795 since VALUE_ADDRESS (var->value) points at the start of the subclass.
796 For some reason, value_cast doesn't take care of this properly. */
798 if (var
->parent
!= NULL
&& CPLUS_FAKE_CHILD (var
->parent
))
800 struct varobj
*super
, *sub
;
802 super
= var
->parent
->parent
;
806 /* Yes, it is a baseclass */
807 type
= get_type_deref (sub
);
809 if (super
->index
< TYPE_N_BASECLASSES (type
))
811 temp
= value_copy (var
->value
);
812 for (i
= 0; i
< super
->index
; i
++)
813 offset
+= TYPE_LENGTH (TYPE_FIELD_TYPE (type
, i
));
818 VALUE_ADDRESS (temp
) += offset
;
819 val
= value_assign (temp
, value
);
820 VALUE_ADDRESS (val
) -= offset
;
821 value_free (var
->value
);
824 input_radix
= saved_input_radix
;
831 /* Returns a malloc'ed list with all root variable objects */
833 varobj_list (struct varobj
***varlist
)
836 struct varobj_root
*croot
;
837 int mycount
= rootcount
;
839 /* Alloc (rootcount + 1) entries for the result */
840 *varlist
= xmalloc ((rootcount
+ 1) * sizeof (struct varobj
*));
844 while ((croot
!= NULL
) && (mycount
> 0))
846 *cv
= croot
->rootvar
;
851 /* Mark the end of the list */
854 if (mycount
|| (croot
!= NULL
))
855 warning ("varobj_list: assertion failed - wrong tally of root vars (%d:%d)",
861 /* Update the values for a variable and its children. This is a
862 two-pronged attack. First, re-parse the value for the root's
863 expression to see if it's changed. Then go all the way
864 through its children, reconstructing them and noting if they've
867 -1 if there was an error updating the varobj
868 -2 if the type changed
869 Otherwise it is the number of children + parent changed
871 Only root variables can be updated... */
874 varobj_update (struct varobj
*var
, struct varobj
***changelist
)
883 struct varobj
**templist
;
885 struct vstack
*stack
= NULL
;
886 struct vstack
*result
= NULL
;
887 struct frame_info
*old_fi
;
889 /* sanity check: have we been passed a pointer? */
890 if (changelist
== NULL
)
893 /* Only root variables can be updated... */
894 if (var
->root
->rootvar
!= var
)
898 /* Save the selected stack frame, since we will need to change it
899 in order to evaluate expressions. */
900 old_fi
= selected_frame
;
902 /* Update the root variable. value_of_root can return NULL
903 if the variable is no longer around, i.e. we stepped out of
904 the frame in which a local existed. We are letting the
905 value_of_root variable dispose of the varobj if the type
908 new = value_of_root (&var
, &type_changed
);
915 /* Initialize a stack for temporary results */
916 vpush (&result
, NULL
);
918 if (type_changed
|| !my_value_equal (var
->value
, new, &error2
))
920 /* Note that it's changed There a couple of exceptions here,
921 though. We don't want some types to be reported as
922 "changed". The exception to this is if this is a
923 "use_selected_frame" varobj, and its type has changed. */
924 if (type_changed
|| type_changeable (var
))
926 vpush (&result
, var
);
930 /* error2 replaces var->error since this new value
931 WILL replace the old one. */
934 /* We must always keep around the new value for this root
935 variable expression, or we lose the updated children! */
936 value_free (var
->value
);
939 /* Initialize a stack */
940 vpush (&stack
, NULL
);
942 /* Push the root's children */
943 if (var
->children
!= NULL
)
945 struct varobj_child
*c
;
946 for (c
= var
->children
; c
!= NULL
; c
= c
->next
)
947 vpush (&stack
, c
->child
);
950 /* Walk through the children, reconstructing them all. */
954 /* Push any children */
955 if (v
->children
!= NULL
)
957 struct varobj_child
*c
;
958 for (c
= v
->children
; c
!= NULL
; c
= c
->next
)
959 vpush (&stack
, c
->child
);
962 /* Update this variable */
963 new = value_of_child (v
->parent
, v
->index
);
964 if (type_changeable (v
) && !my_value_equal (v
->value
, new, &error2
))
966 /* Note that it's changed */
970 /* error2 replaces v->error since this new value
971 WILL replace the old one. */
974 /* We must always keep new values, since children depend on it. */
975 if (v
->value
!= NULL
)
976 value_free (v
->value
);
983 /* Alloc (changed + 1) list entries */
984 /* FIXME: add a cleanup for the allocated list(s)
985 because one day the select_frame called below can longjump */
986 *changelist
= xmalloc ((changed
+ 1) * sizeof (struct varobj
*));
989 templist
= xmalloc ((changed
+ 1) * sizeof (struct varobj
*));
995 /* Copy from result stack to list */
997 *cv
= vpop (&result
);
998 while ((*cv
!= NULL
) && (vleft
> 0))
1002 *cv
= vpop (&result
);
1005 warning ("varobj_update: assertion failed - vleft <> 0");
1009 /* Now we revert the order. */
1010 for (i
=0; i
< changed
; i
++)
1011 *(*changelist
+ i
) = *(templist
+ changed
-1 - i
);
1012 *(*changelist
+ changed
) = NULL
;
1015 /* Restore selected frame */
1016 select_frame (old_fi
, -1);
1025 /* Helper functions */
1028 * Variable object construction/destruction
1032 delete_variable (resultp
, var
, only_children_p
)
1033 struct cpstack
**resultp
;
1035 int only_children_p
;
1039 delete_variable_1 (resultp
, &delcount
, var
,
1040 only_children_p
, 1 /* remove_from_parent_p */ );
1045 /* Delete the variable object VAR and its children */
1046 /* IMPORTANT NOTE: If we delete a variable which is a child
1047 and the parent is not removed we dump core. It must be always
1048 initially called with remove_from_parent_p set */
1050 delete_variable_1 (resultp
, delcountp
, var
,
1051 only_children_p
, remove_from_parent_p
)
1052 struct cpstack
**resultp
;
1055 int only_children_p
;
1056 int remove_from_parent_p
;
1058 struct varobj_child
*vc
;
1059 struct varobj_child
*next
;
1061 /* Delete any children of this variable, too. */
1062 for (vc
= var
->children
; vc
!= NULL
; vc
= next
)
1064 if (!remove_from_parent_p
)
1065 vc
->child
->parent
= NULL
;
1066 delete_variable_1 (resultp
, delcountp
, vc
->child
, 0, only_children_p
);
1071 /* if we were called to delete only the children we are done here */
1072 if (only_children_p
)
1075 /* Otherwise, add it to the list of deleted ones and proceed to do so */
1076 /* If the name is null, this is a temporary variable, that has not
1077 yet been installed, don't report it, it belongs to the caller... */
1078 if (var
->obj_name
!= NULL
)
1080 cppush (resultp
, strdup (var
->obj_name
));
1081 *delcountp
= *delcountp
+ 1;
1084 /* If this variable has a parent, remove it from its parent's list */
1085 /* OPTIMIZATION: if the parent of this variable is also being deleted,
1086 (as indicated by remove_from_parent_p) we don't bother doing an
1087 expensive list search to find the element to remove when we are
1088 discarding the list afterwards */
1089 if ((remove_from_parent_p
) &&
1090 (var
->parent
!= NULL
))
1092 remove_child_from_parent (var
->parent
, var
);
1095 if (var
->obj_name
!= NULL
)
1096 uninstall_variable (var
);
1098 /* Free memory associated with this variable */
1099 free_variable (var
);
1102 /* Install the given variable VAR with the object name VAR->OBJ_NAME. */
1104 install_variable (var
)
1108 struct vlist
*newvl
;
1110 unsigned int index
= 0;
1113 for (chp
= var
->obj_name
; *chp
; chp
++)
1115 index
= (index
+ (i
++ * (unsigned int) *chp
)) % VAROBJ_TABLE_SIZE
;
1118 cv
= *(varobj_table
+ index
);
1119 while ((cv
!= NULL
) && (strcmp (cv
->var
->obj_name
, var
->obj_name
) != 0))
1123 error ("Duplicate variable object name");
1125 /* Add varobj to hash table */
1126 newvl
= xmalloc (sizeof (struct vlist
));
1127 newvl
->next
= *(varobj_table
+ index
);
1129 *(varobj_table
+ index
) = newvl
;
1131 /* If root, add varobj to root list */
1132 if (var
->root
->rootvar
== var
)
1134 /* Add to list of root variables */
1135 if (rootlist
== NULL
)
1136 var
->root
->next
= NULL
;
1138 var
->root
->next
= rootlist
;
1139 rootlist
= var
->root
;
1146 /* Unistall the object VAR. */
1148 uninstall_variable (var
)
1153 struct varobj_root
*cr
;
1154 struct varobj_root
*prer
;
1156 unsigned int index
= 0;
1159 /* Remove varobj from hash table */
1160 for (chp
= var
->obj_name
; *chp
; chp
++)
1162 index
= (index
+ (i
++ * (unsigned int) *chp
)) % VAROBJ_TABLE_SIZE
;
1165 cv
= *(varobj_table
+ index
);
1167 while ((cv
!= NULL
) && (strcmp (cv
->var
->obj_name
, var
->obj_name
) != 0))
1174 fprintf_unfiltered (gdb_stdlog
, "Deleting %s\n", var
->obj_name
);
1178 warning ("Assertion failed: Could not find variable object \"%s\" to delete", var
->obj_name
);
1183 *(varobj_table
+ index
) = cv
->next
;
1185 prev
->next
= cv
->next
;
1189 /* If root, remove varobj from root list */
1190 if (var
->root
->rootvar
== var
)
1192 /* Remove from list of root variables */
1193 if (rootlist
== var
->root
)
1194 rootlist
= var
->root
->next
;
1199 while ((cr
!= NULL
) && (cr
->rootvar
!= var
))
1206 warning ("Assertion failed: Could not find varobj \"%s\" in root list", var
->obj_name
);
1212 prer
->next
= cr
->next
;
1219 /* Does a child with the name NAME exist in VAR? If so, return its data.
1220 If not, return NULL. */
1221 static struct varobj
*
1222 child_exists (var
, name
)
1223 struct varobj
*var
; /* Parent */
1224 char *name
; /* name of child */
1226 struct varobj_child
*vc
;
1228 for (vc
= var
->children
; vc
!= NULL
; vc
= vc
->next
)
1230 if (STREQ (vc
->child
->name
, name
))
1237 /* Create and install a child of the parent of the given name */
1238 static struct varobj
*
1239 create_child (parent
, index
, name
)
1240 struct varobj
*parent
;
1244 struct varobj
*child
;
1247 child
= new_variable ();
1249 /* name is allocated by name_of_child */
1251 child
->index
= index
;
1252 child
->value
= value_of_child (parent
, index
);
1253 if (child
->value
== NULL
|| parent
->error
)
1255 child
->parent
= parent
;
1256 child
->root
= parent
->root
;
1257 childs_name
= (char *) xmalloc ((strlen (parent
->obj_name
) + strlen (name
) + 2)
1259 sprintf (childs_name
, "%s.%s", parent
->obj_name
, name
);
1260 child
->obj_name
= childs_name
;
1261 install_variable (child
);
1263 /* Save a pointer to this child in the parent */
1264 save_child_in_parent (parent
, child
);
1266 /* Note the type of this child */
1267 child
->type
= type_of_child (child
);
1272 /* FIXME: This should be a generic add to list */
1273 /* Save CHILD in the PARENT's data. */
1275 save_child_in_parent (parent
, child
)
1276 struct varobj
*parent
;
1277 struct varobj
*child
;
1279 struct varobj_child
*vc
;
1281 /* Insert the child at the top */
1282 vc
= parent
->children
;
1284 (struct varobj_child
*) xmalloc (sizeof (struct varobj_child
));
1286 parent
->children
->next
= vc
;
1287 parent
->children
->child
= child
;
1290 /* FIXME: This should be a generic remove from list */
1291 /* Remove the CHILD from the PARENT's list of children. */
1293 remove_child_from_parent (parent
, child
)
1294 struct varobj
*parent
;
1295 struct varobj
*child
;
1297 struct varobj_child
*vc
, *prev
;
1299 /* Find the child in the parent's list */
1301 for (vc
= parent
->children
; vc
!= NULL
;)
1303 if (vc
->child
== child
)
1310 parent
->children
= vc
->next
;
1312 prev
->next
= vc
->next
;
1318 * Miscellaneous utility functions.
1321 /* Allocate memory and initialize a new variable */
1322 static struct varobj
*
1327 var
= (struct varobj
*) xmalloc (sizeof (struct varobj
));
1329 var
->obj_name
= NULL
;
1334 var
->num_children
= -1;
1336 var
->children
= NULL
;
1343 /* Allocate memory and initialize a new root variable */
1344 static struct varobj
*
1345 new_root_variable (void)
1347 struct varobj
*var
= new_variable ();
1348 var
->root
= (struct varobj_root
*) xmalloc (sizeof (struct varobj_root
));;
1349 var
->root
->lang
= NULL
;
1350 var
->root
->exp
= NULL
;
1351 var
->root
->valid_block
= NULL
;
1352 var
->root
->frame
= (CORE_ADDR
) -1;
1353 var
->root
->use_selected_frame
= 0;
1354 var
->root
->rootvar
= NULL
;
1359 /* Free any allocated memory associated with VAR. */
1364 /* Free the expression if this is a root variable. */
1365 if (var
->root
->rootvar
== var
)
1367 free_current_contents ((char **) &var
->root
->exp
);
1372 FREEIF (var
->obj_name
);
1376 /* This returns the type of the variable. This skips past typedefs
1377 and returns the real type of the variable. It also dereferences
1378 pointers and references. */
1379 static struct type
*
1386 while (type
!= NULL
&& TYPE_CODE (type
) == TYPE_CODE_TYPEDEF
)
1387 type
= TYPE_TARGET_TYPE (type
);
1392 /* This returns the type of the variable, dereferencing pointers, too. */
1393 static struct type
*
1394 get_type_deref (var
)
1399 type
= get_type (var
);
1401 if (type
!= NULL
&& (TYPE_CODE (type
) == TYPE_CODE_PTR
1402 || TYPE_CODE (type
) == TYPE_CODE_REF
))
1403 type
= get_target_type (type
);
1408 /* This returns the target type (or NULL) of TYPE, also skipping
1409 past typedefs, just like get_type (). */
1410 static struct type
*
1411 get_target_type (type
)
1416 type
= TYPE_TARGET_TYPE (type
);
1417 while (type
!= NULL
&& TYPE_CODE (type
) == TYPE_CODE_TYPEDEF
)
1418 type
= TYPE_TARGET_TYPE (type
);
1424 /* What is the default display for this variable? We assume that
1425 everything is "natural". Any exceptions? */
1426 static enum varobj_display_formats
1427 variable_default_display (var
)
1430 return FORMAT_NATURAL
;
1433 /* This function is similar to gdb's value_equal, except that this
1434 one is "safe" -- it NEVER longjmps. It determines if the VAR's
1435 value is the same as VAL2. */
1437 my_value_equal (val1
, val2
, error2
)
1445 /* Special case: NULL values. If both are null, say
1447 if (val1
== NULL
&& val2
== NULL
)
1449 else if (val1
== NULL
|| val2
== NULL
)
1452 /* This is bogus, but unfortunately necessary. We must know
1453 exactly what caused an error -- reading val1 or val2 -- so
1454 that we can really determine if we think that something has changed. */
1457 /* We do need to catch errors here because the whole purpose
1458 is to test if value_equal() has errored */
1459 if (!gdb_value_equal (val1
, val1
, &r
))
1462 if (!gdb_value_equal (val2
, val2
, &r
))
1468 if (!gdb_value_equal (val1
, val2
, &r
))
1470 /* An error occurred, this could have happened if
1471 either val1 or val2 errored. ERR1 and ERR2 tell
1472 us which of these it is. If both errored, then
1473 we assume nothing has changed. If one of them is
1474 valid, though, then something has changed. */
1477 /* both the old and new values caused errors, so
1478 we say the value did not change */
1479 /* This is indeterminate, though. Perhaps we should
1480 be safe and say, yes, it changed anyway?? */
1492 /* FIXME: The following should be generic for any pointer */
1495 struct vstack
**pstack
;
1500 s
= (struct vstack
*) xmalloc (sizeof (struct vstack
));
1506 /* FIXME: The following should be generic for any pointer */
1507 static struct varobj
*
1509 struct vstack
**pstack
;
1514 if ((*pstack
)->var
== NULL
&& (*pstack
)->next
== NULL
)
1519 *pstack
= (*pstack
)->next
;
1525 /* FIXME: The following should be generic for any pointer */
1527 cppush (pstack
, name
)
1528 struct cpstack
**pstack
;
1533 s
= (struct cpstack
*) xmalloc (sizeof (struct cpstack
));
1539 /* FIXME: The following should be generic for any pointer */
1542 struct cpstack
**pstack
;
1547 if ((*pstack
)->name
== NULL
&& (*pstack
)->next
== NULL
)
1552 *pstack
= (*pstack
)->next
;
1559 * Language-dependencies
1562 /* Common entry points */
1564 /* Get the language of variable VAR. */
1565 static enum varobj_languages
1566 variable_language (var
)
1569 enum varobj_languages lang
;
1571 switch (var
->root
->exp
->language_defn
->la_language
)
1577 case language_cplus
:
1588 /* Return the number of children for a given variable.
1589 The result of this function is defined by the language
1590 implementation. The number of children returned by this function
1591 is the number of children that the user will see in the variable
1594 number_of_children (var
)
1597 return (*var
->root
->lang
->number_of_children
) (var
);;
1600 /* What is the expression for the root varobj VAR? Returns a malloc'd string. */
1602 name_of_variable (var
)
1605 return (*var
->root
->lang
->name_of_variable
) (var
);
1608 /* What is the name of the INDEX'th child of VAR? Returns a malloc'd string. */
1610 name_of_child (var
, index
)
1614 return (*var
->root
->lang
->name_of_child
) (var
, index
);
1617 /* What is the value_ptr of the root variable VAR?
1618 TYPE_CHANGED controls what to do if the type of a
1619 use_selected_frame = 1 variable changes. On input,
1620 TYPE_CHANGED = 1 means discard the old varobj, and replace
1621 it with this one. TYPE_CHANGED = 0 means leave it around.
1622 NB: In both cases, var_handle will point to the new varobj,
1623 so if you use TYPE_CHANGED = 0, you will have to stash the
1624 old varobj pointer away somewhere before calling this.
1625 On return, TYPE_CHANGED will be 1 if the type has changed, and
1628 value_of_root (var_handle
, type_changed
)
1629 struct varobj
** var_handle
;
1634 if (var_handle
== NULL
)
1639 /* This should really be an exception, since this should
1640 only get called with a root variable. */
1642 if (var
->root
->rootvar
!= var
)
1645 if (var
->root
->use_selected_frame
)
1647 struct varobj
*tmp_var
;
1648 char *old_type
, *new_type
;
1649 old_type
= varobj_get_type (var
);
1650 tmp_var
= varobj_create (NULL
, var
->name
, (CORE_ADDR
) 0,
1651 USE_SELECTED_FRAME
);
1652 if (tmp_var
== NULL
)
1656 new_type
= varobj_get_type (tmp_var
);
1657 if (strcmp(old_type
, new_type
) == 0)
1659 varobj_delete (tmp_var
, NULL
, 0);
1667 savestring (var
->obj_name
, strlen (var
->obj_name
));
1668 uninstall_variable (var
);
1672 tmp_var
->obj_name
= varobj_gen_name ();
1674 install_variable (tmp_var
);
1675 *var_handle
= tmp_var
;
1684 return (*var
->root
->lang
->value_of_root
) (var_handle
);
1687 /* What is the value_ptr for the INDEX'th child of PARENT? */
1689 value_of_child (parent
, index
)
1690 struct varobj
*parent
;
1695 value
= (*parent
->root
->lang
->value_of_child
) (parent
, index
);
1697 /* If we're being lazy, fetch the real value of the variable. */
1698 if (value
!= NULL
&& VALUE_LAZY (value
))
1699 gdb_value_fetch_lazy (value
);
1704 /* What is the type of VAR? */
1705 static struct type
*
1710 /* If the child had no evaluation errors, var->value
1711 will be non-NULL and contain a valid type. */
1712 if (var
->value
!= NULL
)
1713 return VALUE_TYPE (var
->value
);
1715 /* Otherwise, we must compute the type. */
1716 return (*var
->root
->lang
->type_of_child
) (var
->parent
, var
->index
);
1719 /* Is this variable editable? Use the variable's type to make
1720 this determination. */
1722 variable_editable (var
)
1725 return (*var
->root
->lang
->variable_editable
) (var
);
1728 /* GDB already has a command called "value_of_variable". Sigh. */
1730 my_value_of_variable (var
)
1733 return (*var
->root
->lang
->value_of_variable
) (var
);
1736 /* Is VAR something that can change? Depending on language,
1737 some variable's values never change. For example,
1738 struct and unions never change values. */
1740 type_changeable (var
)
1746 if (CPLUS_FAKE_CHILD (var
))
1749 type
= get_type (var
);
1751 switch (TYPE_CODE (type
))
1753 case TYPE_CODE_STRUCT
:
1754 case TYPE_CODE_UNION
:
1767 c_number_of_children (var
)
1771 struct type
*target
;
1774 type
= get_type (var
);
1775 target
= get_target_type (type
);
1778 switch (TYPE_CODE (type
))
1780 case TYPE_CODE_ARRAY
:
1781 if (TYPE_LENGTH (type
) > 0 && TYPE_LENGTH (target
) > 0
1782 && TYPE_ARRAY_UPPER_BOUND_TYPE (type
) != BOUND_CANNOT_BE_DETERMINED
)
1783 children
= TYPE_LENGTH (type
) / TYPE_LENGTH (target
);
1788 case TYPE_CODE_STRUCT
:
1789 case TYPE_CODE_UNION
:
1790 children
= TYPE_NFIELDS (type
);
1794 /* This is where things get compilcated. All pointers have one child.
1795 Except, of course, for struct and union ptr, which we automagically
1796 dereference for the user and function ptrs, which have no children. */
1797 switch (TYPE_CODE (target
))
1799 case TYPE_CODE_STRUCT
:
1800 case TYPE_CODE_UNION
:
1801 children
= TYPE_NFIELDS (target
);
1804 case TYPE_CODE_FUNC
:
1809 /* Don't dereference char* or void*. */
1810 if (TYPE_NAME (target
) != NULL
1811 && (STREQ (TYPE_NAME (target
), "char")
1812 || STREQ (TYPE_NAME (target
), "void")))
1820 /* Other types have no children */
1828 c_name_of_variable (parent
)
1829 struct varobj
*parent
;
1831 return savestring (parent
->name
, strlen (parent
->name
));
1835 c_name_of_child (parent
, index
)
1836 struct varobj
*parent
;
1840 struct type
*target
;
1844 type
= get_type (parent
);
1845 target
= get_target_type (type
);
1847 switch (TYPE_CODE (type
))
1849 case TYPE_CODE_ARRAY
:
1851 /* We never get here unless parent->num_children is greater than 0... */
1853 while ((int) pow ((double) 10, (double) len
) < index
)
1855 name
= (char *) xmalloc (1 + len
* sizeof (char));
1856 sprintf (name
, "%d", index
);
1860 case TYPE_CODE_STRUCT
:
1861 case TYPE_CODE_UNION
:
1862 string
= TYPE_FIELD_NAME (type
, index
);
1863 name
= savestring (string
, strlen (string
));
1867 switch (TYPE_CODE (target
))
1869 case TYPE_CODE_STRUCT
:
1870 case TYPE_CODE_UNION
:
1871 string
= TYPE_FIELD_NAME (target
, index
);
1872 name
= savestring (string
, strlen (string
));
1876 name
= (char *) xmalloc ((strlen (parent
->name
) + 2) * sizeof (char));
1877 sprintf (name
, "*%s", parent
->name
);
1883 /* This should not happen */
1884 name
= xstrdup ("???");
1891 c_value_of_root (var_handle
)
1892 struct varobj
**var_handle
;
1895 struct varobj
*var
= *var_handle
;
1896 struct frame_info
*fi
;
1899 /* Only root variables can be updated... */
1900 if (var
->root
->rootvar
!= var
)
1901 /* Not a root var */
1905 /* Determine whether the variable is still around. */
1906 if (var
->root
->valid_block
== NULL
)
1910 reinit_frame_cache ();
1913 fi
= find_frame_addr_in_frame_chain (var
->root
->frame
);
1915 within_scope
= fi
!= NULL
;
1916 /* FIXME: select_frame could fail */
1918 select_frame (fi
, -1);
1923 /* We need to catch errors here, because if evaluate
1924 expression fails we just want to make val->error = 1 and
1926 if (gdb_evaluate_expression (var
->root
->exp
, &new_val
))
1928 if (VALUE_LAZY (new_val
))
1930 /* We need to catch errors because if
1931 value_fetch_lazy fails we still want to continue
1932 (after making val->error = 1) */
1933 /* FIXME: Shouldn't be using VALUE_CONTENTS? The
1934 comment on value_fetch_lazy() says it is only
1935 called from the macro... */
1936 if (!gdb_value_fetch_lazy (new_val
))
1945 release_value (new_val
);
1953 c_value_of_child (parent
, index
)
1954 struct varobj
*parent
;
1957 value_ptr value
, temp
;
1958 struct type
*type
, *target
;
1961 type
= get_type (parent
);
1962 target
= get_target_type (type
);
1963 name
= name_of_child (parent
, index
);
1964 temp
= parent
->value
;
1969 switch (TYPE_CODE (type
))
1971 case TYPE_CODE_ARRAY
:
1972 value
= value_slice (temp
, index
, 1);
1973 temp
= value_coerce_array (value
);
1974 gdb_value_ind (temp
, &value
);
1977 case TYPE_CODE_STRUCT
:
1978 case TYPE_CODE_UNION
:
1979 value
= value_struct_elt (&temp
, NULL
, name
, NULL
, "vstructure");
1983 switch (TYPE_CODE (target
))
1985 case TYPE_CODE_STRUCT
:
1986 case TYPE_CODE_UNION
:
1987 value
= value_struct_elt (&temp
, NULL
, name
, NULL
, "vstructure");
1991 gdb_value_ind (temp
, &value
);
2002 release_value (value
);
2007 static struct type
*
2008 c_type_of_child (parent
, index
)
2009 struct varobj
*parent
;
2013 char *name
= name_of_child (parent
, index
);
2015 switch (TYPE_CODE (parent
->type
))
2017 case TYPE_CODE_ARRAY
:
2018 type
= TYPE_TARGET_TYPE (parent
->type
);
2021 case TYPE_CODE_STRUCT
:
2022 case TYPE_CODE_UNION
:
2023 type
= lookup_struct_elt_type (parent
->type
, name
, 0);
2027 switch (TYPE_CODE (TYPE_TARGET_TYPE (parent
->type
)))
2029 case TYPE_CODE_STRUCT
:
2030 case TYPE_CODE_UNION
:
2031 type
= lookup_struct_elt_type (parent
->type
, name
, 0);
2035 type
= TYPE_TARGET_TYPE (parent
->type
);
2041 /* This should not happen as only the above types have children */
2042 warning ("Child of parent whose type does not allow children");
2043 /* FIXME: Can we still go on? */
2052 c_variable_editable (var
)
2055 switch (TYPE_CODE (get_type (var
)))
2057 case TYPE_CODE_STRUCT
:
2058 case TYPE_CODE_UNION
:
2059 case TYPE_CODE_ARRAY
:
2060 case TYPE_CODE_FUNC
:
2061 case TYPE_CODE_MEMBER
:
2062 case TYPE_CODE_METHOD
:
2073 c_value_of_variable (var
)
2079 if (var
->value
!= NULL
)
2083 /* This can happen if we attempt to get the value of a struct
2084 member when the parent is an invalid pointer. */
2085 return xstrdup ("???");
2088 /* BOGUS: if val_print sees a struct/class, it will print out its
2089 children instead of "{...}" */
2090 type
= get_type (var
);
2091 switch (TYPE_CODE (type
))
2093 case TYPE_CODE_STRUCT
:
2094 case TYPE_CODE_UNION
:
2095 return xstrdup ("{...}");
2098 case TYPE_CODE_ARRAY
:
2101 sprintf (number
, "[%d]", var
->num_children
);
2102 return xstrdup (number
);
2109 struct ui_file
*stb
= mem_fileopen ();
2110 struct cleanup
*old_chain
= make_cleanup_ui_file_delete (stb
);
2113 if (VALUE_LAZY (val
))
2114 gdb_value_fetch_lazy (val
);
2115 val_print (VALUE_TYPE (val
), VALUE_CONTENTS_RAW (val
), 0,
2116 VALUE_ADDRESS (val
),
2117 stb
, format_code
[(int) var
->format
], 1, 0, 0);
2118 thevalue
= ui_file_xstrdup (stb
, &dummy
);
2119 do_cleanups (old_chain
);
2130 cplus_number_of_children (var
)
2134 int children
, dont_know
;
2139 if (!CPLUS_FAKE_CHILD (var
))
2141 type
= get_type_deref (var
);
2143 if (((TYPE_CODE (type
)) == TYPE_CODE_STRUCT
) ||
2144 ((TYPE_CODE (type
)) == TYPE_CODE_UNION
))
2148 cplus_class_num_children (type
, kids
);
2149 if (kids
[v_public
] != 0)
2151 if (kids
[v_private
] != 0)
2153 if (kids
[v_protected
] != 0)
2156 /* Add any baseclasses */
2157 children
+= TYPE_N_BASECLASSES (type
);
2160 /* FIXME: save children in var */
2167 type
= get_type_deref (var
->parent
);
2169 cplus_class_num_children (type
, kids
);
2170 if (STREQ (var
->name
, "public"))
2171 children
= kids
[v_public
];
2172 else if (STREQ (var
->name
, "private"))
2173 children
= kids
[v_private
];
2175 children
= kids
[v_protected
];
2180 children
= c_number_of_children (var
);
2185 /* Compute # of public, private, and protected variables in this class.
2186 That means we need to descend into all baseclasses and find out
2187 how many are there, too. */
2189 cplus_class_num_children (type
, children
)
2195 children
[v_public
] = 0;
2196 children
[v_private
] = 0;
2197 children
[v_protected
] = 0;
2199 for (i
= TYPE_N_BASECLASSES (type
); i
< TYPE_NFIELDS (type
); i
++)
2201 /* If we have a virtual table pointer, omit it. */
2202 if (TYPE_VPTR_BASETYPE (type
) == type
2203 && TYPE_VPTR_FIELDNO (type
) == i
)
2206 if (TYPE_FIELD_PROTECTED (type
, i
))
2207 children
[v_protected
]++;
2208 else if (TYPE_FIELD_PRIVATE (type
, i
))
2209 children
[v_private
]++;
2211 children
[v_public
]++;
2216 cplus_name_of_variable (parent
)
2217 struct varobj
*parent
;
2219 return c_name_of_variable (parent
);
2223 cplus_name_of_child (parent
, index
)
2224 struct varobj
*parent
;
2231 if (CPLUS_FAKE_CHILD (parent
))
2233 /* Looking for children of public, private, or protected. */
2234 type
= get_type_deref (parent
->parent
);
2237 type
= get_type_deref (parent
);
2240 switch (TYPE_CODE (type
))
2242 case TYPE_CODE_STRUCT
:
2243 case TYPE_CODE_UNION
:
2244 cplus_class_num_children (type
, children
);
2246 if (CPLUS_FAKE_CHILD (parent
))
2248 /* FIXME: This assumes that type orders
2249 inherited, public, private, protected */
2250 int i
= index
+ TYPE_N_BASECLASSES (type
);
2251 if (STREQ (parent
->name
, "private") || STREQ (parent
->name
, "protected"))
2252 i
+= children
[v_public
];
2253 if (STREQ (parent
->name
, "protected"))
2254 i
+= children
[v_private
];
2256 name
= TYPE_FIELD_NAME (type
, i
);
2258 else if (index
< TYPE_N_BASECLASSES (type
))
2259 name
= TYPE_FIELD_NAME (type
, index
);
2262 /* Everything beyond the baseclasses can
2263 only be "public", "private", or "protected" */
2264 index
-= TYPE_N_BASECLASSES (type
);
2268 if (children
[v_public
] != 0)
2274 if (children
[v_private
] != 0)
2280 if (children
[v_protected
] != 0)
2297 return c_name_of_child (parent
, index
);
2301 name
= savestring (name
, strlen (name
));
2308 cplus_value_of_root (var_handle
)
2309 struct varobj
**var_handle
;
2311 return c_value_of_root (var_handle
);
2315 cplus_value_of_child (parent
, index
)
2316 struct varobj
*parent
;
2323 if (CPLUS_FAKE_CHILD (parent
))
2324 type
= get_type_deref (parent
->parent
);
2326 type
= get_type_deref (parent
);
2329 name
= name_of_child (parent
, index
);
2331 if (((TYPE_CODE (type
)) == TYPE_CODE_STRUCT
) ||
2332 ((TYPE_CODE (type
)) == TYPE_CODE_UNION
))
2334 if (CPLUS_FAKE_CHILD (parent
))
2336 value_ptr temp
= parent
->parent
->value
;
2337 value
= value_struct_elt (&temp
, NULL
, name
,
2338 NULL
, "cplus_structure");
2339 release_value (value
);
2341 else if (index
>= TYPE_N_BASECLASSES (type
))
2343 /* public, private, or protected */
2349 if (parent
->value
!= NULL
)
2353 if (TYPE_CODE (VALUE_TYPE (parent
->value
)) == TYPE_CODE_PTR
2354 || TYPE_CODE (VALUE_TYPE (parent
->value
)) == TYPE_CODE_REF
)
2355 gdb_value_ind (parent
->value
, &temp
);
2357 temp
= parent
->value
;
2359 value
= value_cast (TYPE_FIELD_TYPE (type
, index
), temp
);
2360 release_value (value
);
2366 return c_value_of_child (parent
, index
);
2371 static struct type
*
2372 cplus_type_of_child (parent
, index
)
2373 struct varobj
*parent
;
2376 struct type
*type
, *t
;
2378 t
= get_type_deref (parent
);
2380 switch (TYPE_CODE (t
))
2382 case TYPE_CODE_STRUCT
:
2383 case TYPE_CODE_UNION
:
2384 if (index
>= TYPE_N_BASECLASSES (t
))
2392 type
= TYPE_FIELD_TYPE (t
, index
);
2401 return c_type_of_child (parent
, index
);
2407 cplus_variable_editable (var
)
2410 if (CPLUS_FAKE_CHILD (var
))
2413 return c_variable_editable (var
);
2417 cplus_value_of_variable (var
)
2421 /* If we have one of our special types, don't print out
2423 if (CPLUS_FAKE_CHILD (var
))
2424 return xstrdup ("");
2426 return c_value_of_variable (var
);
2432 java_number_of_children (var
)
2435 return cplus_number_of_children (var
);
2439 java_name_of_variable (parent
)
2440 struct varobj
*parent
;
2444 name
= cplus_name_of_variable (parent
);
2445 /* If the name has "-" in it, it is because we
2446 needed to escape periods in the name... */
2449 while (*p
!= '\000')
2460 java_name_of_child (parent
, index
)
2461 struct varobj
*parent
;
2466 name
= cplus_name_of_child (parent
, index
);
2467 /* Escape any periods in the name... */
2470 while (*p
!= '\000')
2481 java_value_of_root (var_handle
)
2482 struct varobj
**var_handle
;
2484 return cplus_value_of_root (var_handle
);
2488 java_value_of_child (parent
, index
)
2489 struct varobj
*parent
;
2492 return cplus_value_of_child (parent
, index
);
2495 static struct type
*
2496 java_type_of_child (parent
, index
)
2497 struct varobj
*parent
;
2500 return cplus_type_of_child (parent
, index
);
2504 java_variable_editable (var
)
2507 return cplus_variable_editable (var
);
2511 java_value_of_variable (var
)
2514 return cplus_value_of_variable (var
);
2517 extern void _initialize_varobj (void);
2519 _initialize_varobj (void)
2521 int sizeof_table
= sizeof (struct vlist
*) * VAROBJ_TABLE_SIZE
;
2523 varobj_table
= xmalloc (sizeof_table
);
2524 memset (varobj_table
, 0, sizeof_table
);
2527 add_set_cmd ("debugvarobj", class_maintenance
, var_zinteger
,
2528 (char *) &varobjdebug
,
2529 "Set varobj debugging.\n\
2530 When non-zero, varobj debugging is enabled.", &setlist
),