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 /* Language info for this variable and its children */
60 struct language_specific
*lang
;
62 /* The varobj for this root node. */
63 struct varobj
*rootvar
;
65 /* Next root variable */
66 struct varobj_root
*next
;
69 /* Every variable in the system has a structure of this type defined
70 for it. This structure holds all information necessary to manipulate
71 a particular object variable. Members which must be freed are noted. */
75 /* Alloc'd name of the variable for this object.. If this variable is a
76 child, then this name will be the child's source name.
78 /* NOTE: This is the "expression" */
81 /* The alloc'd name for this variable's object. This is here for
82 convenience when constructing this object's children. */
85 /* Index of this variable in its parent or -1 */
88 /* The type of this variable. This may NEVER be NULL. */
91 /* The value of this expression or subexpression. This may be NULL. */
94 /* Did an error occur evaluating the expression or getting its value? */
97 /* The number of (immediate) children this variable has */
100 /* If this object is a child, this points to its immediate parent. */
101 struct varobj
*parent
;
103 /* A list of this object's children */
104 struct varobj_child
*children
;
106 /* Description of the root variable. Points to root variable for children. */
107 struct varobj_root
*root
;
109 /* The format of the output for this object */
110 enum varobj_display_formats format
;
113 /* Every variable keeps a linked list of its children, described
114 by the following structure. */
115 /* FIXME: Deprecated. All should use vlist instead */
120 /* Pointer to the child's data */
121 struct varobj
*child
;
123 /* Pointer to the next child */
124 struct varobj_child
*next
;
127 /* A stack of varobjs */
128 /* FIXME: Deprecated. All should use vlist instead */
139 struct cpstack
*next
;
142 /* A list of varobjs */
150 /* Private function prototypes */
152 /* Helper functions for the above subcommands. */
154 static int delete_variable
PARAMS ((struct cpstack
**, struct varobj
*, int));
156 static void delete_variable_1
PARAMS ((struct cpstack
**, int *,
157 struct varobj
*, int, int));
159 static int install_variable
PARAMS ((struct varobj
*));
161 static void uninstall_variable
PARAMS ((struct varobj
*));
163 static struct varobj
*child_exists
PARAMS ((struct varobj
*, char *));
165 static struct varobj
*create_child
PARAMS ((struct varobj
*, int, char *));
167 static void save_child_in_parent
PARAMS ((struct varobj
*, struct varobj
*));
169 static void remove_child_from_parent
PARAMS ((struct varobj
*, struct varobj
*));
171 /* Utility routines */
173 static struct varobj
*new_variable
PARAMS ((void));
175 static struct varobj
*new_root_variable
PARAMS ((void));
177 static void free_variable
PARAMS ((struct varobj
* var
));
179 static struct type
*get_type
PARAMS ((struct varobj
* var
));
181 static struct type
*get_type_deref
PARAMS ((struct varobj
* var
));
183 static struct type
*get_target_type
PARAMS ((struct type
*));
185 static enum varobj_display_formats variable_default_display
PARAMS ((struct varobj
*));
187 static int my_value_equal
PARAMS ((value_ptr
, value_ptr
, int *));
189 static void vpush
PARAMS ((struct vstack
** pstack
, struct varobj
* var
));
191 static struct varobj
*vpop
PARAMS ((struct vstack
** pstack
));
193 static void cppush
PARAMS ((struct cpstack
** pstack
, char *name
));
195 static char *cppop
PARAMS ((struct cpstack
** pstack
));
197 /* Language-specific routines. */
199 static enum varobj_languages variable_language
PARAMS ((struct varobj
* var
));
201 static int number_of_children
PARAMS ((struct varobj
*));
203 static char *name_of_variable
PARAMS ((struct varobj
*));
205 static char *name_of_child
PARAMS ((struct varobj
*, int));
207 static value_ptr value_of_root
PARAMS ((struct varobj
* var
));
209 static value_ptr value_of_child
PARAMS ((struct varobj
* parent
, int index
));
211 static struct type
*type_of_child
PARAMS ((struct varobj
* var
));
213 static int variable_editable
PARAMS ((struct varobj
* var
));
215 static char *my_value_of_variable
PARAMS ((struct varobj
* var
));
217 static int type_changeable
PARAMS ((struct varobj
* var
));
219 /* C implementation */
221 static int c_number_of_children
PARAMS ((struct varobj
* var
));
223 static char *c_name_of_variable
PARAMS ((struct varobj
* parent
));
225 static char *c_name_of_child
PARAMS ((struct varobj
* parent
, int index
));
227 static value_ptr c_value_of_root
PARAMS ((struct varobj
* var
));
229 static value_ptr c_value_of_child
PARAMS ((struct varobj
* parent
, int index
));
231 static struct type
*c_type_of_child
PARAMS ((struct varobj
* parent
, int index
));
233 static int c_variable_editable
PARAMS ((struct varobj
* var
));
235 static char *c_value_of_variable
PARAMS ((struct varobj
* var
));
237 /* C++ implementation */
239 static int cplus_number_of_children
PARAMS ((struct varobj
* var
));
241 static void cplus_class_num_children
PARAMS ((struct type
* type
, int children
[3]));
243 static char *cplus_name_of_variable
PARAMS ((struct varobj
* parent
));
245 static char *cplus_name_of_child
PARAMS ((struct varobj
* parent
, int index
));
247 static value_ptr cplus_value_of_root
PARAMS ((struct varobj
* var
));
249 static value_ptr cplus_value_of_child
PARAMS ((struct varobj
* parent
, int index
));
251 static struct type
*cplus_type_of_child
PARAMS ((struct varobj
* parent
, int index
));
253 static int cplus_variable_editable
PARAMS ((struct varobj
* var
));
255 static char *cplus_value_of_variable
PARAMS ((struct varobj
* var
));
257 /* Java implementation */
259 static int java_number_of_children
PARAMS ((struct varobj
* var
));
261 static char *java_name_of_variable
PARAMS ((struct varobj
* parent
));
263 static char *java_name_of_child
PARAMS ((struct varobj
* parent
, int index
));
265 static value_ptr java_value_of_root
PARAMS ((struct varobj
* var
));
267 static value_ptr java_value_of_child
PARAMS ((struct varobj
* parent
, int index
));
269 static struct type
*java_type_of_child
PARAMS ((struct varobj
* parent
, int index
));
271 static int java_variable_editable
PARAMS ((struct varobj
* var
));
273 static char *java_value_of_variable
PARAMS ((struct varobj
* var
));
275 /* The language specific vector */
277 struct language_specific
280 /* The language of this variable */
281 enum varobj_languages language
;
283 /* The number of children of PARENT. */
284 int (*number_of_children
) PARAMS ((struct varobj
* parent
));
286 /* The name (expression) of a root varobj. */
287 char *(*name_of_variable
) PARAMS ((struct varobj
* parent
));
289 /* The name of the INDEX'th child of PARENT. */
290 char *(*name_of_child
) PARAMS ((struct varobj
* parent
, int index
));
292 /* The value_ptr of the root variable ROOT. */
293 value_ptr (*value_of_root
) PARAMS ((struct varobj
* root
));
295 /* The value_ptr of the INDEX'th child of PARENT. */
296 value_ptr (*value_of_child
) PARAMS ((struct varobj
* parent
, int index
));
298 /* The type of the INDEX'th child of PARENT. */
299 struct type
*(*type_of_child
) PARAMS ((struct varobj
* parent
, int index
));
301 /* Is VAR editable? */
302 int (*variable_editable
) PARAMS ((struct varobj
* var
));
304 /* The current value of VAR. */
305 char *(*value_of_variable
) PARAMS ((struct varobj
* var
));
308 /* Array of known source language routines. */
309 static struct language_specific
310 languages
[vlang_end
][sizeof (struct language_specific
)] =
312 /* Unknown (try treating as C */
315 c_number_of_children
,
328 c_number_of_children
,
341 cplus_number_of_children
,
342 cplus_name_of_variable
,
345 cplus_value_of_child
,
347 cplus_variable_editable
,
348 cplus_value_of_variable
354 java_number_of_children
,
355 java_name_of_variable
,
360 java_variable_editable
,
361 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
[] =
375 {0, 't', 'd', 'x', 'o'};
377 /* Header of the list of root variable objects */
378 static struct varobj_root
*rootlist
;
379 static int rootcount
= 0; /* number of root varobjs in the list */
381 /* Prime number indicating the number of buckets in the hash table */
382 /* A prime large enough to avoid too many colisions */
383 #define VAROBJ_TABLE_SIZE 227
385 /* Pointer to the varobj hash table (built at run time) */
386 static struct vlist
**varobj_table
;
391 #define FREEIF(x) if (x != NULL) free((char *) (x))
393 /* Is the variable X one of our "fake" children? */
394 #define CPLUS_FAKE_CHILD(x) \
395 ((x) != NULL && (x)->type == NULL && (x)->value == NULL)
398 /* API Implementation */
400 /* Creates a varobj (not its children) */
403 varobj_create (char *objname
,
404 char *expression
, CORE_ADDR frame
)
407 struct frame_info
*fi
, *old_fi
;
409 struct cleanup
*old_chain
;
411 /* Fill out a varobj structure for the (root) variable being constructed. */
412 var
= new_root_variable ();
413 old_chain
= make_cleanup ((make_cleanup_func
) free_variable
, var
);
415 if (expression
!= NULL
)
418 enum varobj_languages lang
;
420 /* Parse and evaluate the expression, filling in as much
421 of the variable's data as possible */
423 /* Allow creator to specify context of variable */
424 if (frame
== (CORE_ADDR
) -1)
427 fi
= find_frame_addr_in_frame_chain (frame
);
431 block
= get_frame_block (fi
);
434 innermost_block
= NULL
;
435 /* Callee may longjump */
436 var
->root
->exp
= parse_exp_1 (&p
, block
, 0);
438 /* Don't allow variables to be created for types. */
439 if (var
->root
->exp
->elts
[0].opcode
== OP_TYPE
)
441 do_cleanups (old_chain
);
442 fprintf_unfiltered (gdb_stderr
,
443 "Attempt to use a type name as an expression.");
447 var
->format
= variable_default_display (var
);
448 var
->root
->valid_block
= innermost_block
;
449 var
->name
= savestring (expression
, strlen (expression
));
451 /* When the frame is different from the current frame,
452 we must select the appropriate frame before parsing
453 the expression, otherwise the value will not be current.
454 Since select_frame is so benign, just call it for all cases. */
457 var
->root
->frame
= FRAME_FP (fi
);
458 old_fi
= selected_frame
;
459 select_frame (fi
, -1);
462 /* We definitively need to catch errors here.
463 If evaluate_expression succeeds we got the value we wanted.
464 But if it fails, we still go on with a call to evaluate_type() */
465 if (gdb_evaluate_expression (var
->root
->exp
, &var
->value
))
468 release_value (var
->value
);
469 if (VALUE_LAZY (var
->value
))
470 gdb_value_fetch_lazy (var
->value
);
473 var
->value
= evaluate_type (var
->root
->exp
);
475 var
->type
= VALUE_TYPE (var
->value
);
477 /* Set language info */
478 lang
= variable_language (var
);
479 var
->root
->lang
= languages
[lang
];
481 /* Set ourselves as our root */
482 var
->root
->rootvar
= var
;
484 /* Reset the selected frame */
486 select_frame (old_fi
, -1);
491 var
->obj_name
= savestring (objname
, strlen (objname
));
493 /* If a varobj name is duplicated, the install will fail so
495 if (!install_variable (var
))
497 do_cleanups (old_chain
);
502 discard_cleanups (old_chain
);
506 /* Generates an unique name that can be used for a varobj */
509 varobj_gen_name (void)
514 /* generate a name for this object */
516 sprintf (obj_name
, "var%d", id
);
518 return xstrdup (obj_name
);
521 /* Given an "objname", returns the pointer to the corresponding varobj
522 or NULL if not found */
525 varobj_get_handle (char *objname
)
529 unsigned int index
= 0;
532 for (chp
= objname
; *chp
; chp
++)
534 index
= (index
+ (i
++ * (unsigned int) *chp
)) % VAROBJ_TABLE_SIZE
;
537 cv
= *(varobj_table
+ index
);
538 while ((cv
!= NULL
) && (strcmp (cv
->var
->obj_name
, objname
) != 0))
542 error ("Variable object not found");
547 /* Given the handle, return the name of the object */
550 varobj_get_objname (struct varobj
*var
)
552 return var
->obj_name
;
555 /* Given the handle, return the expression represented by the object */
558 varobj_get_expression (struct varobj
*var
)
560 return name_of_variable (var
);
563 /* Deletes a varobj and all its children if only_children == 0,
564 otherwise deletes only the children; returns a malloc'ed list of all the
565 (malloc'ed) names of the variables that have been deleted (NULL terminated) */
568 varobj_delete (struct varobj
*var
, char ***dellist
, int only_children
)
572 struct cpstack
*result
= NULL
;
575 /* Initialize a stack for temporary results */
576 cppush (&result
, NULL
);
579 /* Delete only the variable children */
580 delcount
= delete_variable (&result
, var
, 1 /* only the children */ );
582 /* Delete the variable and all its children */
583 delcount
= delete_variable (&result
, var
, 0 /* parent+children */ );
585 /* We may have been asked to return a list of what has been deleted */
588 *dellist
= xmalloc ((delcount
+ 1) * sizeof (char *));
592 *cp
= cppop (&result
);
593 while ((*cp
!= NULL
) && (mycount
> 0))
597 *cp
= cppop (&result
);
600 if (mycount
|| (*cp
!= NULL
))
601 warning ("varobj_delete: assertion failed - mycount(=%d) <> 0", mycount
);
607 /* Set/Get variable object display format */
609 enum varobj_display_formats
610 varobj_set_display_format (struct varobj
*var
,
611 enum varobj_display_formats format
)
618 case FORMAT_HEXADECIMAL
:
620 var
->format
= format
;
624 var
->format
= variable_default_display (var
);
630 enum varobj_display_formats
631 varobj_get_display_format (struct varobj
*var
)
637 varobj_get_num_children (struct varobj
*var
)
639 if (var
->num_children
== -1)
640 var
->num_children
= number_of_children (var
);
642 return var
->num_children
;
645 /* Creates a list of the immediate children of a variable object;
646 the return code is the number of such children or -1 on error */
649 varobj_list_children (struct varobj
*var
, struct varobj
***childlist
)
651 struct varobj
*child
;
655 /* sanity check: have we been passed a pointer? */
656 if (childlist
== NULL
)
661 if (var
->num_children
== -1)
662 var
->num_children
= number_of_children (var
);
664 /* List of children */
665 *childlist
= xmalloc ((var
->num_children
+ 1) * sizeof (struct varobj
*));
667 for (i
= 0; i
< var
->num_children
; i
++)
669 /* Mark as the end in case we bail out */
670 *((*childlist
) + i
) = NULL
;
672 /* check if child exists, if not create */
673 name
= name_of_child (var
, i
);
674 child
= child_exists (var
, name
);
676 child
= create_child (var
, i
, name
);
678 *((*childlist
) + i
) = child
;
681 /* End of list is marked by a NULL pointer */
682 *((*childlist
) + i
) = NULL
;
684 return var
->num_children
;
687 /* Obtain the type of an object Variable as a string similar to the one gdb
688 prints on the console */
691 varobj_get_type (struct varobj
*var
)
694 struct cleanup
*old_chain
;
699 /* For the "fake" variables, do not return a type. (It's type is
701 if (CPLUS_FAKE_CHILD (var
))
704 stb
= mem_fileopen ();
705 old_chain
= make_cleanup_ui_file_delete (stb
);
707 /* To print the type, we simply create a zero value_ptr and
708 cast it to our type. We then typeprint this variable. */
709 val
= value_zero (var
->type
, not_lval
);
710 type_print (VALUE_TYPE (val
), "", stb
, -1);
712 thetype
= ui_file_xstrdup (stb
, &length
);
713 do_cleanups (old_chain
);
717 enum varobj_languages
718 varobj_get_language (struct varobj
*var
)
720 return variable_language (var
);
724 varobj_get_attributes (struct varobj
*var
)
728 if (variable_editable (var
))
729 /* FIXME: define masks for attributes */
730 attributes
|= 0x00000001; /* Editable */
736 varobj_get_value (struct varobj
*var
)
738 return my_value_of_variable (var
);
741 /* Set the value of an object variable (if it is editable) to the
742 value of the given expression */
743 /* Note: Invokes functions that can call error() */
746 varobj_set_value (struct varobj
*var
, char *expression
)
751 /* The argument "expression" contains the variable's new value.
752 We need to first construct a legal expression for this -- ugh! */
753 /* Does this cover all the bases? */
754 struct expression
*exp
;
756 int saved_input_radix
= input_radix
;
758 if (variable_editable (var
) && !var
->error
)
760 char *s
= expression
;
764 input_radix
= 10; /* ALWAYS reset to decimal temporarily */
765 /* FIXME: Callee may longjump */
766 exp
= parse_exp_1 (&s
, 0, 0);
767 if (!gdb_evaluate_expression (exp
, &value
))
769 /* We cannot proceed without a valid expression. */
774 /* If our parent is "public", "private", or "protected", we could
775 be asking to modify the value of a baseclass. If so, we need to
776 adjust our address by the offset of our baseclass in the subclass,
777 since VALUE_ADDRESS (var->value) points at the start of the subclass.
778 For some reason, value_cast doesn't take care of this properly. */
780 if (var
->parent
!= NULL
&& CPLUS_FAKE_CHILD (var
->parent
))
782 struct varobj
*super
, *sub
;
784 super
= var
->parent
->parent
;
788 /* Yes, it is a baseclass */
789 type
= get_type_deref (sub
);
791 if (super
->index
< TYPE_N_BASECLASSES (type
))
793 temp
= value_copy (var
->value
);
794 for (i
= 0; i
< super
->index
; i
++)
795 offset
+= TYPE_LENGTH (TYPE_FIELD_TYPE (type
, i
));
800 VALUE_ADDRESS (temp
) += offset
;
801 val
= value_assign (temp
, value
);
802 VALUE_ADDRESS (val
) -= offset
;
803 value_free (var
->value
);
806 input_radix
= saved_input_radix
;
813 /* Returns a malloc'ed list with all root variable objects */
815 varobj_list (struct varobj
***varlist
)
818 struct varobj_root
*croot
;
819 int mycount
= rootcount
;
821 /* Alloc (rootcount + 1) entries for the result */
822 *varlist
= xmalloc ((rootcount
+ 1) * sizeof (struct varobj
*));
826 while ((croot
!= NULL
) && (mycount
> 0))
828 *cv
= croot
->rootvar
;
833 /* Mark the end of the list */
836 if (mycount
|| (croot
!= NULL
))
837 warning ("varobj_list: assertion failed - wrong tally of root vars (%d:%d)",
843 /* Update the values for a variable and its children. This is a
844 two-pronged attack. First, re-parse the value for the root's
845 expression to see if it's changed. Then go all the way
846 through its children, reconstructing them and noting if they've
849 Only root variables can be updated... */
852 varobj_update (struct varobj
*var
, struct varobj
***changelist
)
860 struct varobj
**templist
;
862 struct vstack
*stack
= NULL
;
863 struct vstack
*result
= NULL
;
864 struct frame_info
*old_fi
;
866 /* sanity check: have we been passed a pointer? */
867 if (changelist
== NULL
)
870 /* Only root variables can be updated... */
871 if (var
->root
->rootvar
!= var
)
875 /* Save the selected stack frame, since we will need to change it
876 in order to evaluate expressions. */
877 old_fi
= selected_frame
;
879 /* Update the root variable. value_of_root can return NULL
880 if the variable is no longer around, i.e. we stepped out of
881 the frame in which a local existed. */
882 new = value_of_root (var
);
886 /* Initialize a stack for temporary results */
887 vpush (&result
, NULL
);
889 if (!my_value_equal (var
->value
, new, &error2
))
891 /* Note that it's changed There a couple of exceptions here,
892 though. We don't want some types to be reported as "changed". */
893 if (type_changeable (var
))
895 vpush (&result
, var
);
899 /* error2 replaces var->error since this new value
900 WILL replace the old one. */
903 /* We must always keep around the new value for this root
904 variable expression, or we lose the updated children! */
905 value_free (var
->value
);
908 /* Initialize a stack */
909 vpush (&stack
, NULL
);
911 /* Push the root's children */
912 if (var
->children
!= NULL
)
914 struct varobj_child
*c
;
915 for (c
= var
->children
; c
!= NULL
; c
= c
->next
)
916 vpush (&stack
, c
->child
);
919 /* Walk through the children, reconstructing them all. */
923 /* Push any children */
924 if (v
->children
!= NULL
)
926 struct varobj_child
*c
;
927 for (c
= v
->children
; c
!= NULL
; c
= c
->next
)
928 vpush (&stack
, c
->child
);
931 /* Update this variable */
932 new = value_of_child (v
->parent
, v
->index
);
933 if (type_changeable (v
) && !my_value_equal (v
->value
, new, &error2
))
935 /* Note that it's changed */
939 /* error2 replaces v->error since this new value
940 WILL replace the old one. */
943 /* We must always keep new values, since children depend on it. */
944 if (v
->value
!= NULL
)
945 value_free (v
->value
);
952 /* Alloc (changed + 1) list entries */
953 /* FIXME: add a cleanup for the allocated list(s)
954 because one day the select_frame called below can longjump */
955 *changelist
= xmalloc ((changed
+ 1) * sizeof (struct varobj
*));
958 templist
= xmalloc ((changed
+ 1) * sizeof (struct varobj
*));
964 /* Copy from result stack to list */
966 *cv
= vpop (&result
);
967 while ((*cv
!= NULL
) && (vleft
> 0))
971 *cv
= vpop (&result
);
974 warning ("varobj_update: assertion failed - vleft <> 0");
978 /* Now we revert the order. */
979 for (i
=0; i
< changed
; i
++)
980 *(*changelist
+ i
) = *(templist
+ changed
-1 - i
);
981 *(*changelist
+ changed
) = NULL
;
984 /* Restore selected frame */
985 select_frame (old_fi
, -1);
991 /* Helper functions */
994 * Variable object construction/destruction
998 delete_variable (resultp
, var
, only_children_p
)
999 struct cpstack
**resultp
;
1001 int only_children_p
;
1005 delete_variable_1 (resultp
, &delcount
, var
,
1006 only_children_p
, 1 /* remove_from_parent_p */ );
1011 /* Delete the variable object VAR and its children */
1012 /* IMPORTANT NOTE: If we delete a variable which is a child
1013 and the parent is not removed we dump core. It must be always
1014 initially called with remove_from_parent_p set */
1016 delete_variable_1 (resultp
, delcountp
, var
,
1017 only_children_p
, remove_from_parent_p
)
1018 struct cpstack
**resultp
;
1021 int only_children_p
;
1022 int remove_from_parent_p
;
1024 struct varobj_child
*vc
;
1025 struct varobj_child
*next
;
1027 /* Delete any children of this variable, too. */
1028 for (vc
= var
->children
; vc
!= NULL
; vc
= next
)
1030 if (!remove_from_parent_p
)
1031 vc
->child
->parent
= NULL
;
1032 delete_variable_1 (resultp
, delcountp
, vc
->child
, 0, only_children_p
);
1037 /* if we were called to delete only the children we are done here */
1038 if (only_children_p
)
1041 /* Otherwise, add it to the list of deleted ones and proceed to do so */
1042 if (var
->obj_name
== NULL
)
1043 warning ("Assertion failed: NULL var->obj_name unexpectdly found");
1046 cppush (resultp
, strdup (var
->obj_name
));
1047 *delcountp
= *delcountp
+ 1;
1050 /* If this variable has a parent, remove it from its parent's list */
1051 /* OPTIMIZATION: if the parent of this variable is also being deleted,
1052 (as indicated by remove_from_parent_p) we don't bother doing an
1053 expensive list search to find the element to remove when we are
1054 discarding the list afterwards */
1055 if ((remove_from_parent_p
) &&
1056 (var
->parent
!= NULL
))
1058 remove_child_from_parent (var
->parent
, var
);
1061 uninstall_variable (var
);
1063 /* Free memory associated with this variable */
1064 free_variable (var
);
1067 /* Install the given variable VAR with the object name VAR->OBJ_NAME. */
1069 install_variable (var
)
1073 struct vlist
*newvl
;
1075 unsigned int index
= 0;
1078 for (chp
= var
->obj_name
; *chp
; chp
++)
1080 index
= (index
+ (i
++ * (unsigned int) *chp
)) % VAROBJ_TABLE_SIZE
;
1083 cv
= *(varobj_table
+ index
);
1084 while ((cv
!= NULL
) && (strcmp (cv
->var
->obj_name
, var
->obj_name
) != 0))
1088 error ("Duplicate variable object name");
1090 /* Add varobj to hash table */
1091 newvl
= xmalloc (sizeof (struct vlist
));
1092 newvl
->next
= *(varobj_table
+ index
);
1094 *(varobj_table
+ index
) = newvl
;
1096 /* If root, add varobj to root list */
1097 if (var
->root
->rootvar
== var
)
1099 /* Add to list of root variables */
1100 if (rootlist
== NULL
)
1101 var
->root
->next
= NULL
;
1103 var
->root
->next
= rootlist
;
1104 rootlist
= var
->root
;
1111 /* Unistall the object VAR. */
1113 uninstall_variable (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
);
1143 warning ("Assertion failed: Could not find variable object \"%s\" to delete", var
->obj_name
);
1148 *(varobj_table
+ index
) = cv
->next
;
1150 prev
->next
= cv
->next
;
1154 /* If root, remove varobj from root list */
1155 if (var
->root
->rootvar
== var
)
1157 /* Remove from list of root variables */
1158 if (rootlist
== var
->root
)
1159 rootlist
= var
->root
->next
;
1164 while ((cr
!= NULL
) && (cr
->rootvar
!= var
))
1171 warning ("Assertion failed: Could not find varobj \"%s\" in root list", var
->obj_name
);
1177 prer
->next
= cr
->next
;
1184 /* Does a child with the name NAME exist in VAR? If so, return its data.
1185 If not, return NULL. */
1186 static struct varobj
*
1187 child_exists (var
, name
)
1188 struct varobj
*var
; /* Parent */
1189 char *name
; /* name of child */
1191 struct varobj_child
*vc
;
1193 for (vc
= var
->children
; vc
!= NULL
; vc
= vc
->next
)
1195 if (STREQ (vc
->child
->name
, name
))
1202 /* Create and install a child of the parent of the given name */
1203 static struct varobj
*
1204 create_child (parent
, index
, name
)
1205 struct varobj
*parent
;
1209 struct varobj
*child
;
1212 child
= new_variable ();
1214 /* name is allocated by name_of_child */
1216 child
->index
= index
;
1217 child
->value
= value_of_child (parent
, index
);
1218 if (child
->value
== NULL
|| parent
->error
)
1220 child
->parent
= parent
;
1221 child
->root
= parent
->root
;
1222 childs_name
= (char *) xmalloc ((strlen (parent
->obj_name
) + strlen (name
) + 2)
1224 sprintf (childs_name
, "%s.%s", parent
->obj_name
, name
);
1225 child
->obj_name
= childs_name
;
1226 install_variable (child
);
1228 /* Save a pointer to this child in the parent */
1229 save_child_in_parent (parent
, child
);
1231 /* Note the type of this child */
1232 child
->type
= type_of_child (child
);
1237 /* FIXME: This should be a generic add to list */
1238 /* Save CHILD in the PARENT's data. */
1240 save_child_in_parent (parent
, child
)
1241 struct varobj
*parent
;
1242 struct varobj
*child
;
1244 struct varobj_child
*vc
;
1246 /* Insert the child at the top */
1247 vc
= parent
->children
;
1249 (struct varobj_child
*) xmalloc (sizeof (struct varobj_child
));
1251 parent
->children
->next
= vc
;
1252 parent
->children
->child
= child
;
1255 /* FIXME: This should be a generic remove from list */
1256 /* Remove the CHILD from the PARENT's list of children. */
1258 remove_child_from_parent (parent
, child
)
1259 struct varobj
*parent
;
1260 struct varobj
*child
;
1262 struct varobj_child
*vc
, *prev
;
1264 /* Find the child in the parent's list */
1266 for (vc
= parent
->children
; vc
!= NULL
;)
1268 if (vc
->child
== child
)
1275 parent
->children
= vc
->next
;
1277 prev
->next
= vc
->next
;
1283 * Miscellaneous utility functions.
1286 /* Allocate memory and initialize a new variable */
1287 static struct varobj
*
1292 var
= (struct varobj
*) xmalloc (sizeof (struct varobj
));
1294 var
->obj_name
= NULL
;
1299 var
->num_children
= -1;
1301 var
->children
= NULL
;
1308 /* Allocate memory and initialize a new root variable */
1309 static struct varobj
*
1310 new_root_variable (void)
1312 struct varobj
*var
= new_variable ();
1313 var
->root
= (struct varobj_root
*) xmalloc (sizeof (struct varobj_root
));;
1314 var
->root
->lang
= NULL
;
1315 var
->root
->exp
= NULL
;
1316 var
->root
->valid_block
= NULL
;
1317 var
->root
->frame
= (CORE_ADDR
) -1;
1318 var
->root
->rootvar
= NULL
;
1323 /* Free any allocated memory associated with VAR. */
1328 /* Free the expression if this is a root variable. */
1329 if (var
->root
->rootvar
== var
)
1331 free_current_contents ((char **) &var
->root
->exp
);
1336 FREEIF (var
->obj_name
);
1340 /* This returns the type of the variable. This skips past typedefs
1341 and returns the real type of the variable. It also dereferences
1342 pointers and references. */
1343 static struct type
*
1350 while (type
!= NULL
&& TYPE_CODE (type
) == TYPE_CODE_TYPEDEF
)
1351 type
= TYPE_TARGET_TYPE (type
);
1356 /* This returns the type of the variable, dereferencing pointers, too. */
1357 static struct type
*
1358 get_type_deref (var
)
1363 type
= get_type (var
);
1365 if (type
!= NULL
&& (TYPE_CODE (type
) == TYPE_CODE_PTR
1366 || TYPE_CODE (type
) == TYPE_CODE_REF
))
1367 type
= get_target_type (type
);
1372 /* This returns the target type (or NULL) of TYPE, also skipping
1373 past typedefs, just like get_type (). */
1374 static struct type
*
1375 get_target_type (type
)
1380 type
= TYPE_TARGET_TYPE (type
);
1381 while (type
!= NULL
&& TYPE_CODE (type
) == TYPE_CODE_TYPEDEF
)
1382 type
= TYPE_TARGET_TYPE (type
);
1388 /* What is the default display for this variable? We assume that
1389 everything is "natural". Any exceptions? */
1390 static enum varobj_display_formats
1391 variable_default_display (var
)
1394 return FORMAT_NATURAL
;
1397 /* This function is similar to gdb's value_equal, except that this
1398 one is "safe" -- it NEVER longjmps. It determines if the VAR's
1399 value is the same as VAL2. */
1401 my_value_equal (val1
, val2
, error2
)
1409 /* Special case: NULL values. If both are null, say
1411 if (val1
== NULL
&& val2
== NULL
)
1413 else if (val1
== NULL
|| val2
== NULL
)
1416 /* This is bogus, but unfortunately necessary. We must know
1417 exactly what caused an error -- reading val1 or val2 -- so
1418 that we can really determine if we think that something has changed. */
1421 /* We do need to catch errors here because the whole purpose
1422 is to test if value_equal() has errored */
1423 if (!gdb_value_equal (val1
, val1
, &r
))
1426 if (!gdb_value_equal (val2
, val2
, &r
))
1432 if (!gdb_value_equal (val1
, val2
, &r
))
1434 /* An error occurred, this could have happened if
1435 either val1 or val2 errored. ERR1 and ERR2 tell
1436 us which of these it is. If both errored, then
1437 we assume nothing has changed. If one of them is
1438 valid, though, then something has changed. */
1441 /* both the old and new values caused errors, so
1442 we say the value did not change */
1443 /* This is indeterminate, though. Perhaps we should
1444 be safe and say, yes, it changed anyway?? */
1456 /* FIXME: The following should be generic for any pointer */
1459 struct vstack
**pstack
;
1464 s
= (struct vstack
*) xmalloc (sizeof (struct vstack
));
1470 /* FIXME: The following should be generic for any pointer */
1471 static struct varobj
*
1473 struct vstack
**pstack
;
1478 if ((*pstack
)->var
== NULL
&& (*pstack
)->next
== NULL
)
1483 *pstack
= (*pstack
)->next
;
1489 /* FIXME: The following should be generic for any pointer */
1491 cppush (pstack
, name
)
1492 struct cpstack
**pstack
;
1497 s
= (struct cpstack
*) xmalloc (sizeof (struct cpstack
));
1503 /* FIXME: The following should be generic for any pointer */
1506 struct cpstack
**pstack
;
1511 if ((*pstack
)->name
== NULL
&& (*pstack
)->next
== NULL
)
1516 *pstack
= (*pstack
)->next
;
1523 * Language-dependencies
1526 /* Common entry points */
1528 /* Get the language of variable VAR. */
1529 static enum varobj_languages
1530 variable_language (var
)
1533 enum varobj_languages lang
;
1535 switch (var
->root
->exp
->language_defn
->la_language
)
1541 case language_cplus
:
1552 /* Return the number of children for a given variable.
1553 The result of this function is defined by the language
1554 implementation. The number of children returned by this function
1555 is the number of children that the user will see in the variable
1558 number_of_children (var
)
1561 return (*var
->root
->lang
->number_of_children
) (var
);;
1564 /* What is the expression for the root varobj VAR? Returns a malloc'd string. */
1566 name_of_variable (var
)
1569 return (*var
->root
->lang
->name_of_variable
) (var
);
1572 /* What is the name of the INDEX'th child of VAR? Returns a malloc'd string. */
1574 name_of_child (var
, index
)
1578 return (*var
->root
->lang
->name_of_child
) (var
, index
);
1581 /* What is the value_ptr of the root variable VAR? */
1586 return (*var
->root
->lang
->value_of_root
) (var
);
1589 /* What is the value_ptr for the INDEX'th child of PARENT? */
1591 value_of_child (parent
, index
)
1592 struct varobj
*parent
;
1597 value
= (*parent
->root
->lang
->value_of_child
) (parent
, index
);
1599 /* If we're being lazy, fetch the real value of the variable. */
1600 if (value
!= NULL
&& VALUE_LAZY (value
))
1601 gdb_value_fetch_lazy (value
);
1606 /* What is the type of VAR? */
1607 static struct type
*
1612 /* If the child had no evaluation errors, var->value
1613 will be non-NULL and contain a valid type. */
1614 if (var
->value
!= NULL
)
1615 return VALUE_TYPE (var
->value
);
1617 /* Otherwise, we must compute the type. */
1618 return (*var
->root
->lang
->type_of_child
) (var
->parent
, var
->index
);
1621 /* Is this variable editable? Use the variable's type to make
1622 this determination. */
1624 variable_editable (var
)
1627 return (*var
->root
->lang
->variable_editable
) (var
);
1630 /* GDB already has a command called "value_of_variable". Sigh. */
1632 my_value_of_variable (var
)
1635 return (*var
->root
->lang
->value_of_variable
) (var
);
1638 /* Is VAR something that can change? Depending on language,
1639 some variable's values never change. For example,
1640 struct and unions never change values. */
1642 type_changeable (var
)
1648 if (CPLUS_FAKE_CHILD (var
))
1651 type
= get_type (var
);
1653 switch (TYPE_CODE (type
))
1655 case TYPE_CODE_STRUCT
:
1656 case TYPE_CODE_UNION
:
1669 c_number_of_children (var
)
1673 struct type
*target
;
1676 type
= get_type (var
);
1677 target
= get_target_type (type
);
1680 switch (TYPE_CODE (type
))
1682 case TYPE_CODE_ARRAY
:
1683 if (TYPE_LENGTH (type
) > 0 && TYPE_LENGTH (target
) > 0
1684 && TYPE_ARRAY_UPPER_BOUND_TYPE (type
) != BOUND_CANNOT_BE_DETERMINED
)
1685 children
= TYPE_LENGTH (type
) / TYPE_LENGTH (target
);
1690 case TYPE_CODE_STRUCT
:
1691 case TYPE_CODE_UNION
:
1692 children
= TYPE_NFIELDS (type
);
1696 /* This is where things get compilcated. All pointers have one child.
1697 Except, of course, for struct and union ptr, which we automagically
1698 dereference for the user and function ptrs, which have no children. */
1699 switch (TYPE_CODE (target
))
1701 case TYPE_CODE_STRUCT
:
1702 case TYPE_CODE_UNION
:
1703 children
= TYPE_NFIELDS (target
);
1706 case TYPE_CODE_FUNC
:
1711 /* Don't dereference char* or void*. */
1712 if (TYPE_NAME (target
) != NULL
1713 && (STREQ (TYPE_NAME (target
), "char")
1714 || STREQ (TYPE_NAME (target
), "void")))
1722 /* Other types have no children */
1730 c_name_of_variable (parent
)
1731 struct varobj
*parent
;
1733 return savestring (parent
->name
, strlen (parent
->name
));
1737 c_name_of_child (parent
, index
)
1738 struct varobj
*parent
;
1742 struct type
*target
;
1746 type
= get_type (parent
);
1747 target
= get_target_type (type
);
1749 switch (TYPE_CODE (type
))
1751 case TYPE_CODE_ARRAY
:
1753 /* We never get here unless parent->num_children is greater than 0... */
1755 while ((int) pow ((double) 10, (double) len
) < index
)
1757 name
= (char *) xmalloc (1 + len
* sizeof (char));
1758 sprintf (name
, "%d", index
);
1762 case TYPE_CODE_STRUCT
:
1763 case TYPE_CODE_UNION
:
1764 string
= TYPE_FIELD_NAME (type
, index
);
1765 name
= savestring (string
, strlen (string
));
1769 switch (TYPE_CODE (target
))
1771 case TYPE_CODE_STRUCT
:
1772 case TYPE_CODE_UNION
:
1773 string
= TYPE_FIELD_NAME (target
, index
);
1774 name
= savestring (string
, strlen (string
));
1778 name
= (char *) xmalloc ((strlen (parent
->name
) + 2) * sizeof (char));
1779 sprintf (name
, "*%s", parent
->name
);
1785 /* This should not happen */
1786 name
= xstrdup ("???");
1793 c_value_of_root (var
)
1797 struct frame_info
*fi
;
1800 /* Determine whether the variable is still around. */
1801 if (var
->root
->valid_block
== NULL
)
1805 reinit_frame_cache ();
1806 fi
= find_frame_addr_in_frame_chain (var
->root
->frame
);
1807 within_scope
= fi
!= NULL
;
1808 /* FIXME: select_frame could fail */
1810 select_frame (fi
, -1);
1815 /* We need to catch errors here, because if evaluate expression fails
1816 we just want to make val->error = 1 and go on */
1817 if (gdb_evaluate_expression (var
->root
->exp
, &new_val
))
1819 if (VALUE_LAZY (new_val
))
1821 /* We need to catch errors because if value_fetch_lazy fails we
1822 still want to continue (after making val->error = 1) */
1823 /* FIXME: Shouldn't be using VALUE_CONTENTS? The comment on
1824 value_fetch_lazy() says it is only called from the macro... */
1825 if (!gdb_value_fetch_lazy (new_val
))
1834 release_value (new_val
);
1842 c_value_of_child (parent
, index
)
1843 struct varobj
*parent
;
1846 value_ptr value
, temp
;
1847 struct type
*type
, *target
;
1850 type
= get_type (parent
);
1851 target
= get_target_type (type
);
1852 name
= name_of_child (parent
, index
);
1853 temp
= parent
->value
;
1858 switch (TYPE_CODE (type
))
1860 case TYPE_CODE_ARRAY
:
1861 value
= value_slice (temp
, index
, 1);
1862 temp
= value_coerce_array (value
);
1863 gdb_value_ind (temp
, &value
);
1866 case TYPE_CODE_STRUCT
:
1867 case TYPE_CODE_UNION
:
1868 value
= value_struct_elt (&temp
, NULL
, name
, NULL
, "vstructure");
1872 switch (TYPE_CODE (target
))
1874 case TYPE_CODE_STRUCT
:
1875 case TYPE_CODE_UNION
:
1876 value
= value_struct_elt (&temp
, NULL
, name
, NULL
, "vstructure");
1880 gdb_value_ind (temp
, &value
);
1891 release_value (value
);
1896 static struct type
*
1897 c_type_of_child (parent
, index
)
1898 struct varobj
*parent
;
1902 char *name
= name_of_child (parent
, index
);
1904 switch (TYPE_CODE (parent
->type
))
1906 case TYPE_CODE_ARRAY
:
1907 type
= TYPE_TARGET_TYPE (parent
->type
);
1910 case TYPE_CODE_STRUCT
:
1911 case TYPE_CODE_UNION
:
1912 type
= lookup_struct_elt_type (parent
->type
, name
, 0);
1916 switch (TYPE_CODE (TYPE_TARGET_TYPE (parent
->type
)))
1918 case TYPE_CODE_STRUCT
:
1919 case TYPE_CODE_UNION
:
1920 type
= lookup_struct_elt_type (parent
->type
, name
, 0);
1924 type
= TYPE_TARGET_TYPE (parent
->type
);
1930 /* This should not happen as only the above types have children */
1931 warning ("Child of parent whose type does not allow children");
1932 /* FIXME: Can we still go on? */
1941 c_variable_editable (var
)
1944 switch (TYPE_CODE (get_type (var
)))
1946 case TYPE_CODE_STRUCT
:
1947 case TYPE_CODE_UNION
:
1948 case TYPE_CODE_ARRAY
:
1949 case TYPE_CODE_FUNC
:
1950 case TYPE_CODE_MEMBER
:
1951 case TYPE_CODE_METHOD
:
1962 c_value_of_variable (var
)
1968 if (var
->value
!= NULL
)
1972 /* This can happen if we attempt to get the value of a struct
1973 member when the parent is an invalid pointer. */
1974 return xstrdup ("???");
1977 /* BOGUS: if val_print sees a struct/class, it will print out its
1978 children instead of "{...}" */
1979 type
= get_type (var
);
1980 switch (TYPE_CODE (type
))
1982 case TYPE_CODE_STRUCT
:
1983 case TYPE_CODE_UNION
:
1984 return xstrdup ("{...}");
1987 case TYPE_CODE_ARRAY
:
1990 sprintf (number
, "[%d]", var
->num_children
);
1991 return xstrdup (number
);
1998 struct ui_file
*stb
= mem_fileopen ();
1999 struct cleanup
*old_chain
= make_cleanup_ui_file_delete (stb
);
2002 if (VALUE_LAZY (val
))
2003 gdb_value_fetch_lazy (val
);
2004 val_print (VALUE_TYPE (val
), VALUE_CONTENTS_RAW (val
), 0,
2005 VALUE_ADDRESS (val
),
2006 stb
, format_code
[(int) var
->format
], 1, 0, 0);
2007 thevalue
= ui_file_xstrdup (stb
, &dummy
);
2008 do_cleanups (old_chain
);
2019 cplus_number_of_children (var
)
2023 int children
, dont_know
;
2028 if (!CPLUS_FAKE_CHILD (var
))
2030 type
= get_type_deref (var
);
2032 if (((TYPE_CODE (type
)) == TYPE_CODE_STRUCT
) ||
2033 ((TYPE_CODE (type
)) == TYPE_CODE_UNION
))
2037 cplus_class_num_children (type
, kids
);
2038 if (kids
[v_public
] != 0)
2040 if (kids
[v_private
] != 0)
2042 if (kids
[v_protected
] != 0)
2045 /* Add any baseclasses */
2046 children
+= TYPE_N_BASECLASSES (type
);
2049 /* FIXME: save children in var */
2056 type
= get_type_deref (var
->parent
);
2058 cplus_class_num_children (type
, kids
);
2059 if (STREQ (var
->name
, "public"))
2060 children
= kids
[v_public
];
2061 else if (STREQ (var
->name
, "private"))
2062 children
= kids
[v_private
];
2064 children
= kids
[v_protected
];
2069 children
= c_number_of_children (var
);
2074 /* Compute # of public, private, and protected variables in this class.
2075 That means we need to descend into all baseclasses and find out
2076 how many are there, too. */
2078 cplus_class_num_children (type
, children
)
2084 children
[v_public
] = 0;
2085 children
[v_private
] = 0;
2086 children
[v_protected
] = 0;
2088 for (i
= TYPE_N_BASECLASSES (type
); i
< TYPE_NFIELDS (type
); i
++)
2090 /* If we have a virtual table pointer, omit it. */
2091 if (TYPE_VPTR_BASETYPE (type
) == type
2092 && TYPE_VPTR_FIELDNO (type
) == i
)
2095 if (TYPE_FIELD_PROTECTED (type
, i
))
2096 children
[v_protected
]++;
2097 else if (TYPE_FIELD_PRIVATE (type
, i
))
2098 children
[v_private
]++;
2100 children
[v_public
]++;
2105 cplus_name_of_variable (parent
)
2106 struct varobj
*parent
;
2108 return c_name_of_variable (parent
);
2112 cplus_name_of_child (parent
, index
)
2113 struct varobj
*parent
;
2120 if (CPLUS_FAKE_CHILD (parent
))
2122 /* Looking for children of public, private, or protected. */
2123 type
= get_type_deref (parent
->parent
);
2126 type
= get_type_deref (parent
);
2129 switch (TYPE_CODE (type
))
2131 case TYPE_CODE_STRUCT
:
2132 case TYPE_CODE_UNION
:
2133 cplus_class_num_children (type
, children
);
2135 if (CPLUS_FAKE_CHILD (parent
))
2137 /* FIXME: This assumes that type orders
2138 inherited, public, private, protected */
2139 int i
= index
+ TYPE_N_BASECLASSES (type
);
2140 if (STREQ (parent
->name
, "private") || STREQ (parent
->name
, "protected"))
2141 i
+= children
[v_public
];
2142 if (STREQ (parent
->name
, "protected"))
2143 i
+= children
[v_private
];
2145 name
= TYPE_FIELD_NAME (type
, i
);
2147 else if (index
< TYPE_N_BASECLASSES (type
))
2148 name
= TYPE_FIELD_NAME (type
, index
);
2151 /* Everything beyond the baseclasses can
2152 only be "public", "private", or "protected" */
2153 index
-= TYPE_N_BASECLASSES (type
);
2157 if (children
[v_public
] != 0)
2163 if (children
[v_private
] != 0)
2169 if (children
[v_protected
] != 0)
2186 return c_name_of_child (parent
, index
);
2190 name
= savestring (name
, strlen (name
));
2197 cplus_value_of_root (var
)
2200 return c_value_of_root (var
);
2204 cplus_value_of_child (parent
, index
)
2205 struct varobj
*parent
;
2212 if (CPLUS_FAKE_CHILD (parent
))
2213 type
= get_type_deref (parent
->parent
);
2215 type
= get_type_deref (parent
);
2218 name
= name_of_child (parent
, index
);
2220 if (((TYPE_CODE (type
)) == TYPE_CODE_STRUCT
) ||
2221 ((TYPE_CODE (type
)) == TYPE_CODE_UNION
))
2223 if (CPLUS_FAKE_CHILD (parent
))
2225 value_ptr temp
= parent
->parent
->value
;
2226 value
= value_struct_elt (&temp
, NULL
, name
,
2227 NULL
, "cplus_structure");
2228 release_value (value
);
2230 else if (index
>= TYPE_N_BASECLASSES (type
))
2232 /* public, private, or protected */
2238 if (parent
->value
!= NULL
)
2242 if (TYPE_CODE (VALUE_TYPE (parent
->value
)) == TYPE_CODE_PTR
2243 || TYPE_CODE (VALUE_TYPE (parent
->value
)) == TYPE_CODE_REF
)
2244 gdb_value_ind (parent
->value
, &temp
);
2246 temp
= parent
->value
;
2248 value
= value_cast (TYPE_FIELD_TYPE (type
, index
), temp
);
2249 release_value (value
);
2255 return c_value_of_child (parent
, index
);
2260 static struct type
*
2261 cplus_type_of_child (parent
, index
)
2262 struct varobj
*parent
;
2265 struct type
*type
, *t
;
2267 t
= get_type_deref (parent
);
2269 switch (TYPE_CODE (t
))
2271 case TYPE_CODE_STRUCT
:
2272 case TYPE_CODE_UNION
:
2273 if (index
>= TYPE_N_BASECLASSES (t
))
2281 type
= TYPE_FIELD_TYPE (t
, index
);
2290 return c_type_of_child (parent
, index
);
2296 cplus_variable_editable (var
)
2299 if (CPLUS_FAKE_CHILD (var
))
2302 return c_variable_editable (var
);
2306 cplus_value_of_variable (var
)
2310 /* If we have one of our special types, don't print out
2312 if (CPLUS_FAKE_CHILD (var
))
2313 return xstrdup ("");
2315 return c_value_of_variable (var
);
2321 java_number_of_children (var
)
2324 return cplus_number_of_children (var
);
2328 java_name_of_variable (parent
)
2329 struct varobj
*parent
;
2333 name
= cplus_name_of_variable (parent
);
2334 /* If the name has "-" in it, it is because we
2335 needed to escape periods in the name... */
2338 while (*p
!= '\000')
2349 java_name_of_child (parent
, index
)
2350 struct varobj
*parent
;
2355 name
= cplus_name_of_child (parent
, index
);
2356 /* Escape any periods in the name... */
2359 while (*p
!= '\000')
2370 java_value_of_root (var
)
2373 return cplus_value_of_root (var
);
2377 java_value_of_child (parent
, index
)
2378 struct varobj
*parent
;
2381 return cplus_value_of_child (parent
, index
);
2384 static struct type
*
2385 java_type_of_child (parent
, index
)
2386 struct varobj
*parent
;
2389 return cplus_type_of_child (parent
, index
);
2393 java_variable_editable (var
)
2396 return cplus_variable_editable (var
);
2400 java_value_of_variable (var
)
2403 return cplus_value_of_variable (var
);
2406 extern void _initialize_varobj (void);
2408 _initialize_varobj (void)
2410 int sizeof_table
= sizeof (struct vlist
*) * VAROBJ_TABLE_SIZE
;
2412 varobj_table
= xmalloc (sizeof_table
);
2413 memset (varobj_table
, 0, sizeof_table
);
2416 add_set_cmd ("debugvarobj", class_maintenance
, var_zinteger
,
2417 (char *) &varobjdebug
,
2418 "Set varobj debugging.\n\
2419 When non-zero, varobj debugging is enabled.", &setlist
),