1 /* Implementation of the GDB variable objects API.
3 Copyright (C) 1999-2012 Free Software Foundation, Inc.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19 #include "exceptions.h"
21 #include "expression.h"
28 #include "gdb_assert.h"
29 #include "gdb_string.h"
30 #include "gdb_regex.h"
34 #include "gdbthread.h"
36 #include "ada-varobj.h"
40 #include "python/python.h"
41 #include "python/python-internal.h"
46 /* The names of varobjs representing anonymous structs or unions. */
47 #define ANONYMOUS_STRUCT_NAME _("<anonymous struct>")
48 #define ANONYMOUS_UNION_NAME _("<anonymous union>")
50 /* Non-zero if we want to see trace of varobj level stuff. */
54 show_varobjdebug (struct ui_file
*file
, int from_tty
,
55 struct cmd_list_element
*c
, const char *value
)
57 fprintf_filtered (file
, _("Varobj debugging is %s.\n"), value
);
60 /* String representations of gdb's format codes. */
61 char *varobj_format_string
[] =
62 { "natural", "binary", "decimal", "hexadecimal", "octal" };
64 /* String representations of gdb's known languages. */
65 char *varobj_language_string
[] = { "unknown", "C", "C++", "Java" };
67 /* True if we want to allow Python-based pretty-printing. */
68 static int pretty_printing
= 0;
71 varobj_enable_pretty_printing (void)
78 /* Every root variable has one of these structures saved in its
79 varobj. Members which must be free'd are noted. */
83 /* Alloc'd expression for this parent. */
84 struct expression
*exp
;
86 /* Block for which this expression is valid. */
87 struct block
*valid_block
;
89 /* The frame for this expression. This field is set iff valid_block is
91 struct frame_id frame
;
93 /* The thread ID that this varobj_root belong to. This field
94 is only valid if valid_block is not NULL.
95 When not 0, indicates which thread 'frame' belongs to.
96 When 0, indicates that the thread list was empty when the varobj_root
100 /* If 1, the -var-update always recomputes the value in the
101 current thread and frame. Otherwise, variable object is
102 always updated in the specific scope/thread/frame. */
105 /* Flag that indicates validity: set to 0 when this varobj_root refers
106 to symbols that do not exist anymore. */
109 /* Language info for this variable and its children. */
110 struct language_specific
*lang
;
112 /* The varobj for this root node. */
113 struct varobj
*rootvar
;
115 /* Next root variable */
116 struct varobj_root
*next
;
119 /* Every variable in the system has a structure of this type defined
120 for it. This structure holds all information necessary to manipulate
121 a particular object variable. Members which must be freed are noted. */
125 /* Alloc'd name of the variable for this object. If this variable is a
126 child, then this name will be the child's source name.
127 (bar, not foo.bar). */
128 /* NOTE: This is the "expression". */
131 /* Alloc'd expression for this child. Can be used to create a
132 root variable corresponding to this child. */
135 /* The alloc'd name for this variable's object. This is here for
136 convenience when constructing this object's children. */
139 /* Index of this variable in its parent or -1. */
142 /* The type of this variable. This can be NULL
143 for artifial variable objects -- currently, the "accessibility"
144 variable objects in C++. */
147 /* The value of this expression or subexpression. A NULL value
148 indicates there was an error getting this value.
149 Invariant: if varobj_value_is_changeable_p (this) is non-zero,
150 the value is either NULL, or not lazy. */
153 /* The number of (immediate) children this variable has. */
156 /* If this object is a child, this points to its immediate parent. */
157 struct varobj
*parent
;
159 /* Children of this object. */
160 VEC (varobj_p
) *children
;
162 /* Whether the children of this varobj were requested. This field is
163 used to decide if dynamic varobj should recompute their children.
164 In the event that the frontend never asked for the children, we
166 int children_requested
;
168 /* Description of the root variable. Points to root variable for
170 struct varobj_root
*root
;
172 /* The format of the output for this object. */
173 enum varobj_display_formats format
;
175 /* Was this variable updated via a varobj_set_value operation. */
178 /* Last print value. */
181 /* Is this variable frozen. Frozen variables are never implicitly
182 updated by -var-update *
183 or -var-update <direct-or-indirect-parent>. */
186 /* Is the value of this variable intentionally not fetched? It is
187 not fetched if either the variable is frozen, or any parents is
191 /* Sub-range of children which the MI consumer has requested. If
192 FROM < 0 or TO < 0, means that all children have been
197 /* The pretty-printer constructor. If NULL, then the default
198 pretty-printer will be looked up. If None, then no
199 pretty-printer will be installed. */
200 PyObject
*constructor
;
202 /* The pretty-printer that has been constructed. If NULL, then a
203 new printer object is needed, and one will be constructed. */
204 PyObject
*pretty_printer
;
206 /* The iterator returned by the printer's 'children' method, or NULL
208 PyObject
*child_iter
;
210 /* We request one extra item from the iterator, so that we can
211 report to the caller whether there are more items than we have
212 already reported. However, we don't want to install this value
213 when we read it, because that will mess up future updates. So,
214 we stash it here instead. */
215 PyObject
*saved_item
;
221 struct cpstack
*next
;
224 /* A list of varobjs */
232 /* Private function prototypes */
234 /* Helper functions for the above subcommands. */
236 static int delete_variable (struct cpstack
**, struct varobj
*, int);
238 static void delete_variable_1 (struct cpstack
**, int *,
239 struct varobj
*, int, int);
241 static int install_variable (struct varobj
*);
243 static void uninstall_variable (struct varobj
*);
245 static struct varobj
*create_child (struct varobj
*, int, char *);
247 static struct varobj
*
248 create_child_with_value (struct varobj
*parent
, int index
, const char *name
,
249 struct value
*value
);
251 /* Utility routines */
253 static struct varobj
*new_variable (void);
255 static struct varobj
*new_root_variable (void);
257 static void free_variable (struct varobj
*var
);
259 static struct cleanup
*make_cleanup_free_variable (struct varobj
*var
);
261 static struct type
*get_type (struct varobj
*var
);
263 static struct type
*get_value_type (struct varobj
*var
);
265 static struct type
*get_target_type (struct type
*);
267 static enum varobj_display_formats
variable_default_display (struct varobj
*);
269 static void cppush (struct cpstack
**pstack
, char *name
);
271 static char *cppop (struct cpstack
**pstack
);
273 static int install_new_value (struct varobj
*var
, struct value
*value
,
276 /* Language-specific routines. */
278 static enum varobj_languages
variable_language (struct varobj
*var
);
280 static int number_of_children (struct varobj
*);
282 static char *name_of_variable (struct varobj
*);
284 static char *name_of_child (struct varobj
*, int);
286 static struct value
*value_of_root (struct varobj
**var_handle
, int *);
288 static struct value
*value_of_child (struct varobj
*parent
, int index
);
290 static char *my_value_of_variable (struct varobj
*var
,
291 enum varobj_display_formats format
);
293 static char *value_get_print_value (struct value
*value
,
294 enum varobj_display_formats format
,
297 static int varobj_value_is_changeable_p (struct varobj
*var
);
299 static int is_root_p (struct varobj
*var
);
303 static struct varobj
*varobj_add_child (struct varobj
*var
,
305 struct value
*value
);
307 #endif /* HAVE_PYTHON */
309 /* C implementation */
311 static int c_number_of_children (struct varobj
*var
);
313 static char *c_name_of_variable (struct varobj
*parent
);
315 static char *c_name_of_child (struct varobj
*parent
, int index
);
317 static char *c_path_expr_of_child (struct varobj
*child
);
319 static struct value
*c_value_of_root (struct varobj
**var_handle
);
321 static struct value
*c_value_of_child (struct varobj
*parent
, int index
);
323 static struct type
*c_type_of_child (struct varobj
*parent
, int index
);
325 static char *c_value_of_variable (struct varobj
*var
,
326 enum varobj_display_formats format
);
328 /* C++ implementation */
330 static int cplus_number_of_children (struct varobj
*var
);
332 static void cplus_class_num_children (struct type
*type
, int children
[3]);
334 static char *cplus_name_of_variable (struct varobj
*parent
);
336 static char *cplus_name_of_child (struct varobj
*parent
, int index
);
338 static char *cplus_path_expr_of_child (struct varobj
*child
);
340 static struct value
*cplus_value_of_root (struct varobj
**var_handle
);
342 static struct value
*cplus_value_of_child (struct varobj
*parent
, int index
);
344 static struct type
*cplus_type_of_child (struct varobj
*parent
, int index
);
346 static char *cplus_value_of_variable (struct varobj
*var
,
347 enum varobj_display_formats format
);
349 /* Java implementation */
351 static int java_number_of_children (struct varobj
*var
);
353 static char *java_name_of_variable (struct varobj
*parent
);
355 static char *java_name_of_child (struct varobj
*parent
, int index
);
357 static char *java_path_expr_of_child (struct varobj
*child
);
359 static struct value
*java_value_of_root (struct varobj
**var_handle
);
361 static struct value
*java_value_of_child (struct varobj
*parent
, int index
);
363 static struct type
*java_type_of_child (struct varobj
*parent
, int index
);
365 static char *java_value_of_variable (struct varobj
*var
,
366 enum varobj_display_formats format
);
368 /* Ada implementation */
370 static int ada_number_of_children (struct varobj
*var
);
372 static char *ada_name_of_variable (struct varobj
*parent
);
374 static char *ada_name_of_child (struct varobj
*parent
, int index
);
376 static char *ada_path_expr_of_child (struct varobj
*child
);
378 static struct value
*ada_value_of_root (struct varobj
**var_handle
);
380 static struct value
*ada_value_of_child (struct varobj
*parent
, int index
);
382 static struct type
*ada_type_of_child (struct varobj
*parent
, int index
);
384 static char *ada_value_of_variable (struct varobj
*var
,
385 enum varobj_display_formats format
);
387 static int ada_value_has_mutated (struct varobj
*var
, struct value
*new_val
,
388 struct type
*new_type
);
390 /* The language specific vector */
392 struct language_specific
395 /* The language of this variable. */
396 enum varobj_languages language
;
398 /* The number of children of PARENT. */
399 int (*number_of_children
) (struct varobj
* parent
);
401 /* The name (expression) of a root varobj. */
402 char *(*name_of_variable
) (struct varobj
* parent
);
404 /* The name of the INDEX'th child of PARENT. */
405 char *(*name_of_child
) (struct varobj
* parent
, int index
);
407 /* Returns the rooted expression of CHILD, which is a variable
408 obtain that has some parent. */
409 char *(*path_expr_of_child
) (struct varobj
* child
);
411 /* The ``struct value *'' of the root variable ROOT. */
412 struct value
*(*value_of_root
) (struct varobj
** root_handle
);
414 /* The ``struct value *'' of the INDEX'th child of PARENT. */
415 struct value
*(*value_of_child
) (struct varobj
* parent
, int index
);
417 /* The type of the INDEX'th child of PARENT. */
418 struct type
*(*type_of_child
) (struct varobj
* parent
, int index
);
420 /* The current value of VAR. */
421 char *(*value_of_variable
) (struct varobj
* var
,
422 enum varobj_display_formats format
);
424 /* Return nonzero if the type of VAR has mutated.
426 VAR's value is still the varobj's previous value, while NEW_VALUE
427 is VAR's new value and NEW_TYPE is the var's new type. NEW_VALUE
428 may be NULL indicating that there is no value available (the varobj
429 may be out of scope, of may be the child of a null pointer, for
430 instance). NEW_TYPE, on the other hand, must never be NULL.
432 This function should also be able to assume that var's number of
433 children is set (not < 0).
435 Languages where types do not mutate can set this to NULL. */
436 int (*value_has_mutated
) (struct varobj
*var
, struct value
*new_value
,
437 struct type
*new_type
);
440 /* Array of known source language routines. */
441 static struct language_specific languages
[vlang_end
] = {
442 /* Unknown (try treating as C). */
445 c_number_of_children
,
448 c_path_expr_of_child
,
453 NULL
/* value_has_mutated */}
458 c_number_of_children
,
461 c_path_expr_of_child
,
466 NULL
/* value_has_mutated */}
471 cplus_number_of_children
,
472 cplus_name_of_variable
,
474 cplus_path_expr_of_child
,
476 cplus_value_of_child
,
478 cplus_value_of_variable
,
479 NULL
/* value_has_mutated */}
484 java_number_of_children
,
485 java_name_of_variable
,
487 java_path_expr_of_child
,
491 java_value_of_variable
,
492 NULL
/* value_has_mutated */},
496 ada_number_of_children
,
497 ada_name_of_variable
,
499 ada_path_expr_of_child
,
503 ada_value_of_variable
,
504 ada_value_has_mutated
}
507 /* A little convenience enum for dealing with C++/Java. */
510 v_public
= 0, v_private
, v_protected
515 /* Mappings of varobj_display_formats enums to gdb's format codes. */
516 static int format_code
[] = { 0, 't', 'd', 'x', 'o' };
518 /* Header of the list of root variable objects. */
519 static struct varobj_root
*rootlist
;
521 /* Prime number indicating the number of buckets in the hash table. */
522 /* A prime large enough to avoid too many colisions. */
523 #define VAROBJ_TABLE_SIZE 227
525 /* Pointer to the varobj hash table (built at run time). */
526 static struct vlist
**varobj_table
;
528 /* Is the variable X one of our "fake" children? */
529 #define CPLUS_FAKE_CHILD(x) \
530 ((x) != NULL && (x)->type == NULL && (x)->value == NULL)
533 /* API Implementation */
535 is_root_p (struct varobj
*var
)
537 return (var
->root
->rootvar
== var
);
541 /* Helper function to install a Python environment suitable for
542 use during operations on VAR. */
543 static struct cleanup
*
544 varobj_ensure_python_env (struct varobj
*var
)
546 return ensure_python_env (var
->root
->exp
->gdbarch
,
547 var
->root
->exp
->language_defn
);
551 /* Creates a varobj (not its children). */
553 /* Return the full FRAME which corresponds to the given CORE_ADDR
554 or NULL if no FRAME on the chain corresponds to CORE_ADDR. */
556 static struct frame_info
*
557 find_frame_addr_in_frame_chain (CORE_ADDR frame_addr
)
559 struct frame_info
*frame
= NULL
;
561 if (frame_addr
== (CORE_ADDR
) 0)
564 for (frame
= get_current_frame ();
566 frame
= get_prev_frame (frame
))
568 /* The CORE_ADDR we get as argument was parsed from a string GDB
569 output as $fp. This output got truncated to gdbarch_addr_bit.
570 Truncate the frame base address in the same manner before
571 comparing it against our argument. */
572 CORE_ADDR frame_base
= get_frame_base_address (frame
);
573 int addr_bit
= gdbarch_addr_bit (get_frame_arch (frame
));
575 if (addr_bit
< (sizeof (CORE_ADDR
) * HOST_CHAR_BIT
))
576 frame_base
&= ((CORE_ADDR
) 1 << addr_bit
) - 1;
578 if (frame_base
== frame_addr
)
586 varobj_create (char *objname
,
587 char *expression
, CORE_ADDR frame
, enum varobj_type type
)
590 struct cleanup
*old_chain
;
592 /* Fill out a varobj structure for the (root) variable being constructed. */
593 var
= new_root_variable ();
594 old_chain
= make_cleanup_free_variable (var
);
596 if (expression
!= NULL
)
598 struct frame_info
*fi
;
599 struct frame_id old_id
= null_frame_id
;
602 enum varobj_languages lang
;
603 struct value
*value
= NULL
;
604 volatile struct gdb_exception except
;
606 /* Parse and evaluate the expression, filling in as much of the
607 variable's data as possible. */
609 if (has_stack_frames ())
611 /* Allow creator to specify context of variable. */
612 if ((type
== USE_CURRENT_FRAME
) || (type
== USE_SELECTED_FRAME
))
613 fi
= get_selected_frame (NULL
);
615 /* FIXME: cagney/2002-11-23: This code should be doing a
616 lookup using the frame ID and not just the frame's
617 ``address''. This, of course, means an interface
618 change. However, with out that interface change ISAs,
619 such as the ia64 with its two stacks, won't work.
620 Similar goes for the case where there is a frameless
622 fi
= find_frame_addr_in_frame_chain (frame
);
627 /* frame = -2 means always use selected frame. */
628 if (type
== USE_SELECTED_FRAME
)
629 var
->root
->floating
= 1;
633 block
= get_frame_block (fi
, 0);
636 innermost_block
= NULL
;
637 /* Wrap the call to parse expression, so we can
638 return a sensible error. */
639 TRY_CATCH (except
, RETURN_MASK_ERROR
)
641 var
->root
->exp
= parse_exp_1 (&p
, block
, 0);
644 if (except
.reason
< 0)
646 do_cleanups (old_chain
);
650 /* Don't allow variables to be created for types. */
651 if (var
->root
->exp
->elts
[0].opcode
== OP_TYPE
)
653 do_cleanups (old_chain
);
654 fprintf_unfiltered (gdb_stderr
, "Attempt to use a type name"
655 " as an expression.\n");
659 var
->format
= variable_default_display (var
);
660 var
->root
->valid_block
= innermost_block
;
661 var
->name
= xstrdup (expression
);
662 /* For a root var, the name and the expr are the same. */
663 var
->path_expr
= xstrdup (expression
);
665 /* When the frame is different from the current frame,
666 we must select the appropriate frame before parsing
667 the expression, otherwise the value will not be current.
668 Since select_frame is so benign, just call it for all cases. */
671 /* User could specify explicit FRAME-ADDR which was not found but
672 EXPRESSION is frame specific and we would not be able to evaluate
673 it correctly next time. With VALID_BLOCK set we must also set
674 FRAME and THREAD_ID. */
676 error (_("Failed to find the specified frame"));
678 var
->root
->frame
= get_frame_id (fi
);
679 var
->root
->thread_id
= pid_to_thread_id (inferior_ptid
);
680 old_id
= get_frame_id (get_selected_frame (NULL
));
684 /* We definitely need to catch errors here.
685 If evaluate_expression succeeds we got the value we wanted.
686 But if it fails, we still go on with a call to evaluate_type(). */
687 TRY_CATCH (except
, RETURN_MASK_ERROR
)
689 value
= evaluate_expression (var
->root
->exp
);
692 if (except
.reason
< 0)
694 /* Error getting the value. Try to at least get the
696 struct value
*type_only_value
= evaluate_type (var
->root
->exp
);
698 var
->type
= value_type (type_only_value
);
701 var
->type
= value_type (value
);
703 install_new_value (var
, value
, 1 /* Initial assignment */);
705 /* Set language info */
706 lang
= variable_language (var
);
707 var
->root
->lang
= &languages
[lang
];
709 /* Set ourselves as our root. */
710 var
->root
->rootvar
= var
;
712 /* Reset the selected frame. */
713 if (frame_id_p (old_id
))
714 select_frame (frame_find_by_id (old_id
));
717 /* If the variable object name is null, that means this
718 is a temporary variable, so don't install it. */
720 if ((var
!= NULL
) && (objname
!= NULL
))
722 var
->obj_name
= xstrdup (objname
);
724 /* If a varobj name is duplicated, the install will fail so
726 if (!install_variable (var
))
728 do_cleanups (old_chain
);
733 discard_cleanups (old_chain
);
737 /* Generates an unique name that can be used for a varobj. */
740 varobj_gen_name (void)
745 /* Generate a name for this object. */
747 obj_name
= xstrprintf ("var%d", id
);
752 /* Given an OBJNAME, returns the pointer to the corresponding varobj. Call
753 error if OBJNAME cannot be found. */
756 varobj_get_handle (char *objname
)
760 unsigned int index
= 0;
763 for (chp
= objname
; *chp
; chp
++)
765 index
= (index
+ (i
++ * (unsigned int) *chp
)) % VAROBJ_TABLE_SIZE
;
768 cv
= *(varobj_table
+ index
);
769 while ((cv
!= NULL
) && (strcmp (cv
->var
->obj_name
, objname
) != 0))
773 error (_("Variable object not found"));
778 /* Given the handle, return the name of the object. */
781 varobj_get_objname (struct varobj
*var
)
783 return var
->obj_name
;
786 /* Given the handle, return the expression represented by the object. */
789 varobj_get_expression (struct varobj
*var
)
791 return name_of_variable (var
);
794 /* Deletes a varobj and all its children if only_children == 0,
795 otherwise deletes only the children; returns a malloc'ed list of
796 all the (malloc'ed) names of the variables that have been deleted
797 (NULL terminated). */
800 varobj_delete (struct varobj
*var
, char ***dellist
, int only_children
)
804 struct cpstack
*result
= NULL
;
807 /* Initialize a stack for temporary results. */
808 cppush (&result
, NULL
);
811 /* Delete only the variable children. */
812 delcount
= delete_variable (&result
, var
, 1 /* only the children */ );
814 /* Delete the variable and all its children. */
815 delcount
= delete_variable (&result
, var
, 0 /* parent+children */ );
817 /* We may have been asked to return a list of what has been deleted. */
820 *dellist
= xmalloc ((delcount
+ 1) * sizeof (char *));
824 *cp
= cppop (&result
);
825 while ((*cp
!= NULL
) && (mycount
> 0))
829 *cp
= cppop (&result
);
832 if (mycount
|| (*cp
!= NULL
))
833 warning (_("varobj_delete: assertion failed - mycount(=%d) <> 0"),
842 /* Convenience function for varobj_set_visualizer. Instantiate a
843 pretty-printer for a given value. */
845 instantiate_pretty_printer (PyObject
*constructor
, struct value
*value
)
847 PyObject
*val_obj
= NULL
;
850 val_obj
= value_to_value_object (value
);
854 printer
= PyObject_CallFunctionObjArgs (constructor
, val_obj
, NULL
);
861 /* Set/Get variable object display format. */
863 enum varobj_display_formats
864 varobj_set_display_format (struct varobj
*var
,
865 enum varobj_display_formats format
)
872 case FORMAT_HEXADECIMAL
:
874 var
->format
= format
;
878 var
->format
= variable_default_display (var
);
881 if (varobj_value_is_changeable_p (var
)
882 && var
->value
&& !value_lazy (var
->value
))
884 xfree (var
->print_value
);
885 var
->print_value
= value_get_print_value (var
->value
, var
->format
, var
);
891 enum varobj_display_formats
892 varobj_get_display_format (struct varobj
*var
)
898 varobj_get_display_hint (struct varobj
*var
)
903 struct cleanup
*back_to
= varobj_ensure_python_env (var
);
905 if (var
->pretty_printer
)
906 result
= gdbpy_get_display_hint (var
->pretty_printer
);
908 do_cleanups (back_to
);
914 /* Return true if the varobj has items after TO, false otherwise. */
917 varobj_has_more (struct varobj
*var
, int to
)
919 if (VEC_length (varobj_p
, var
->children
) > to
)
921 return ((to
== -1 || VEC_length (varobj_p
, var
->children
) == to
)
922 && var
->saved_item
!= NULL
);
925 /* If the variable object is bound to a specific thread, that
926 is its evaluation can always be done in context of a frame
927 inside that thread, returns GDB id of the thread -- which
928 is always positive. Otherwise, returns -1. */
930 varobj_get_thread_id (struct varobj
*var
)
932 if (var
->root
->valid_block
&& var
->root
->thread_id
> 0)
933 return var
->root
->thread_id
;
939 varobj_set_frozen (struct varobj
*var
, int frozen
)
941 /* When a variable is unfrozen, we don't fetch its value.
942 The 'not_fetched' flag remains set, so next -var-update
945 We don't fetch the value, because for structures the client
946 should do -var-update anyway. It would be bad to have different
947 client-size logic for structure and other types. */
948 var
->frozen
= frozen
;
952 varobj_get_frozen (struct varobj
*var
)
957 /* A helper function that restricts a range to what is actually
958 available in a VEC. This follows the usual rules for the meaning
959 of FROM and TO -- if either is negative, the entire range is
963 restrict_range (VEC (varobj_p
) *children
, int *from
, int *to
)
965 if (*from
< 0 || *to
< 0)
968 *to
= VEC_length (varobj_p
, children
);
972 if (*from
> VEC_length (varobj_p
, children
))
973 *from
= VEC_length (varobj_p
, children
);
974 if (*to
> VEC_length (varobj_p
, children
))
975 *to
= VEC_length (varobj_p
, children
);
983 /* A helper for update_dynamic_varobj_children that installs a new
984 child when needed. */
987 install_dynamic_child (struct varobj
*var
,
988 VEC (varobj_p
) **changed
,
989 VEC (varobj_p
) **new,
990 VEC (varobj_p
) **unchanged
,
996 if (VEC_length (varobj_p
, var
->children
) < index
+ 1)
998 /* There's no child yet. */
999 struct varobj
*child
= varobj_add_child (var
, name
, value
);
1003 VEC_safe_push (varobj_p
, *new, child
);
1009 varobj_p existing
= VEC_index (varobj_p
, var
->children
, index
);
1011 if (install_new_value (existing
, value
, 0))
1014 VEC_safe_push (varobj_p
, *changed
, existing
);
1017 VEC_safe_push (varobj_p
, *unchanged
, existing
);
1022 dynamic_varobj_has_child_method (struct varobj
*var
)
1024 struct cleanup
*back_to
;
1025 PyObject
*printer
= var
->pretty_printer
;
1028 back_to
= varobj_ensure_python_env (var
);
1029 result
= PyObject_HasAttr (printer
, gdbpy_children_cst
);
1030 do_cleanups (back_to
);
1037 update_dynamic_varobj_children (struct varobj
*var
,
1038 VEC (varobj_p
) **changed
,
1039 VEC (varobj_p
) **new,
1040 VEC (varobj_p
) **unchanged
,
1042 int update_children
,
1047 struct cleanup
*back_to
;
1050 PyObject
*printer
= var
->pretty_printer
;
1052 back_to
= varobj_ensure_python_env (var
);
1055 if (!PyObject_HasAttr (printer
, gdbpy_children_cst
))
1057 do_cleanups (back_to
);
1061 if (update_children
|| !var
->child_iter
)
1063 children
= PyObject_CallMethodObjArgs (printer
, gdbpy_children_cst
,
1068 gdbpy_print_stack ();
1069 error (_("Null value returned for children"));
1072 make_cleanup_py_decref (children
);
1074 if (!PyIter_Check (children
))
1075 error (_("Returned value is not iterable"));
1077 Py_XDECREF (var
->child_iter
);
1078 var
->child_iter
= PyObject_GetIter (children
);
1079 if (!var
->child_iter
)
1081 gdbpy_print_stack ();
1082 error (_("Could not get children iterator"));
1085 Py_XDECREF (var
->saved_item
);
1086 var
->saved_item
= NULL
;
1091 i
= VEC_length (varobj_p
, var
->children
);
1093 /* We ask for one extra child, so that MI can report whether there
1094 are more children. */
1095 for (; to
< 0 || i
< to
+ 1; ++i
)
1100 /* See if there was a leftover from last time. */
1101 if (var
->saved_item
)
1103 item
= var
->saved_item
;
1104 var
->saved_item
= NULL
;
1107 item
= PyIter_Next (var
->child_iter
);
1111 /* Normal end of iteration. */
1112 if (!PyErr_Occurred ())
1115 /* If we got a memory error, just use the text as the
1117 if (PyErr_ExceptionMatches (gdbpy_gdb_memory_error
))
1119 PyObject
*type
, *value
, *trace
;
1120 char *name_str
, *value_str
;
1122 PyErr_Fetch (&type
, &value
, &trace
);
1123 value_str
= gdbpy_exception_to_string (type
, value
);
1129 gdbpy_print_stack ();
1133 name_str
= xstrprintf ("<error at %d>", i
);
1134 item
= Py_BuildValue ("(ss)", name_str
, value_str
);
1139 gdbpy_print_stack ();
1147 /* Any other kind of error. */
1148 gdbpy_print_stack ();
1153 /* We don't want to push the extra child on any report list. */
1154 if (to
< 0 || i
< to
)
1159 struct cleanup
*inner
;
1160 int can_mention
= from
< 0 || i
>= from
;
1162 inner
= make_cleanup_py_decref (item
);
1164 if (!PyArg_ParseTuple (item
, "sO", &name
, &py_v
))
1166 gdbpy_print_stack ();
1167 error (_("Invalid item from the child list"));
1170 v
= convert_value_from_python (py_v
);
1172 gdbpy_print_stack ();
1173 install_dynamic_child (var
, can_mention
? changed
: NULL
,
1174 can_mention
? new : NULL
,
1175 can_mention
? unchanged
: NULL
,
1176 can_mention
? cchanged
: NULL
, i
, name
, v
);
1177 do_cleanups (inner
);
1181 Py_XDECREF (var
->saved_item
);
1182 var
->saved_item
= item
;
1184 /* We want to truncate the child list just before this
1193 if (i
< VEC_length (varobj_p
, var
->children
))
1198 for (j
= i
; j
< VEC_length (varobj_p
, var
->children
); ++j
)
1199 varobj_delete (VEC_index (varobj_p
, var
->children
, j
), NULL
, 0);
1200 VEC_truncate (varobj_p
, var
->children
, i
);
1203 /* If there are fewer children than requested, note that the list of
1204 children changed. */
1205 if (to
>= 0 && VEC_length (varobj_p
, var
->children
) < to
)
1208 var
->num_children
= VEC_length (varobj_p
, var
->children
);
1210 do_cleanups (back_to
);
1214 gdb_assert (0 && "should never be called if Python is not enabled");
1219 varobj_get_num_children (struct varobj
*var
)
1221 if (var
->num_children
== -1)
1223 if (var
->pretty_printer
)
1227 /* If we have a dynamic varobj, don't report -1 children.
1228 So, try to fetch some children first. */
1229 update_dynamic_varobj_children (var
, NULL
, NULL
, NULL
, &dummy
,
1233 var
->num_children
= number_of_children (var
);
1236 return var
->num_children
>= 0 ? var
->num_children
: 0;
1239 /* Creates a list of the immediate children of a variable object;
1240 the return code is the number of such children or -1 on error. */
1243 varobj_list_children (struct varobj
*var
, int *from
, int *to
)
1246 int i
, children_changed
;
1248 var
->children_requested
= 1;
1250 if (var
->pretty_printer
)
1252 /* This, in theory, can result in the number of children changing without
1253 frontend noticing. But well, calling -var-list-children on the same
1254 varobj twice is not something a sane frontend would do. */
1255 update_dynamic_varobj_children (var
, NULL
, NULL
, NULL
, &children_changed
,
1257 restrict_range (var
->children
, from
, to
);
1258 return var
->children
;
1261 if (var
->num_children
== -1)
1262 var
->num_children
= number_of_children (var
);
1264 /* If that failed, give up. */
1265 if (var
->num_children
== -1)
1266 return var
->children
;
1268 /* If we're called when the list of children is not yet initialized,
1269 allocate enough elements in it. */
1270 while (VEC_length (varobj_p
, var
->children
) < var
->num_children
)
1271 VEC_safe_push (varobj_p
, var
->children
, NULL
);
1273 for (i
= 0; i
< var
->num_children
; i
++)
1275 varobj_p existing
= VEC_index (varobj_p
, var
->children
, i
);
1277 if (existing
== NULL
)
1279 /* Either it's the first call to varobj_list_children for
1280 this variable object, and the child was never created,
1281 or it was explicitly deleted by the client. */
1282 name
= name_of_child (var
, i
);
1283 existing
= create_child (var
, i
, name
);
1284 VEC_replace (varobj_p
, var
->children
, i
, existing
);
1288 restrict_range (var
->children
, from
, to
);
1289 return var
->children
;
1294 static struct varobj
*
1295 varobj_add_child (struct varobj
*var
, const char *name
, struct value
*value
)
1297 varobj_p v
= create_child_with_value (var
,
1298 VEC_length (varobj_p
, var
->children
),
1301 VEC_safe_push (varobj_p
, var
->children
, v
);
1305 #endif /* HAVE_PYTHON */
1307 /* Obtain the type of an object Variable as a string similar to the one gdb
1308 prints on the console. */
1311 varobj_get_type (struct varobj
*var
)
1313 /* For the "fake" variables, do not return a type. (It's type is
1315 Do not return a type for invalid variables as well. */
1316 if (CPLUS_FAKE_CHILD (var
) || !var
->root
->is_valid
)
1319 return type_to_string (var
->type
);
1322 /* Obtain the type of an object variable. */
1325 varobj_get_gdb_type (struct varobj
*var
)
1330 /* Is VAR a path expression parent, i.e., can it be used to construct
1331 a valid path expression? */
1334 is_path_expr_parent (struct varobj
*var
)
1338 /* "Fake" children are not path_expr parents. */
1339 if (CPLUS_FAKE_CHILD (var
))
1342 type
= get_value_type (var
);
1344 /* Anonymous unions and structs are also not path_expr parents. */
1345 return !((TYPE_CODE (type
) == TYPE_CODE_STRUCT
1346 || TYPE_CODE (type
) == TYPE_CODE_UNION
)
1347 && TYPE_NAME (type
) == NULL
);
1350 /* Return the path expression parent for VAR. */
1352 static struct varobj
*
1353 get_path_expr_parent (struct varobj
*var
)
1355 struct varobj
*parent
= var
;
1357 while (!is_root_p (parent
) && !is_path_expr_parent (parent
))
1358 parent
= parent
->parent
;
1363 /* Return a pointer to the full rooted expression of varobj VAR.
1364 If it has not been computed yet, compute it. */
1366 varobj_get_path_expr (struct varobj
*var
)
1368 if (var
->path_expr
!= NULL
)
1369 return var
->path_expr
;
1372 /* For root varobjs, we initialize path_expr
1373 when creating varobj, so here it should be
1375 gdb_assert (!is_root_p (var
));
1376 return (*var
->root
->lang
->path_expr_of_child
) (var
);
1380 enum varobj_languages
1381 varobj_get_language (struct varobj
*var
)
1383 return variable_language (var
);
1387 varobj_get_attributes (struct varobj
*var
)
1391 if (varobj_editable_p (var
))
1392 /* FIXME: define masks for attributes. */
1393 attributes
|= 0x00000001; /* Editable */
1399 varobj_pretty_printed_p (struct varobj
*var
)
1401 return var
->pretty_printer
!= NULL
;
1405 varobj_get_formatted_value (struct varobj
*var
,
1406 enum varobj_display_formats format
)
1408 return my_value_of_variable (var
, format
);
1412 varobj_get_value (struct varobj
*var
)
1414 return my_value_of_variable (var
, var
->format
);
1417 /* Set the value of an object variable (if it is editable) to the
1418 value of the given expression. */
1419 /* Note: Invokes functions that can call error(). */
1422 varobj_set_value (struct varobj
*var
, char *expression
)
1424 struct value
*val
= NULL
; /* Initialize to keep gcc happy. */
1425 /* The argument "expression" contains the variable's new value.
1426 We need to first construct a legal expression for this -- ugh! */
1427 /* Does this cover all the bases? */
1428 struct expression
*exp
;
1429 struct value
*value
= NULL
; /* Initialize to keep gcc happy. */
1430 int saved_input_radix
= input_radix
;
1431 char *s
= expression
;
1432 volatile struct gdb_exception except
;
1434 gdb_assert (varobj_editable_p (var
));
1436 input_radix
= 10; /* ALWAYS reset to decimal temporarily. */
1437 exp
= parse_exp_1 (&s
, 0, 0);
1438 TRY_CATCH (except
, RETURN_MASK_ERROR
)
1440 value
= evaluate_expression (exp
);
1443 if (except
.reason
< 0)
1445 /* We cannot proceed without a valid expression. */
1450 /* All types that are editable must also be changeable. */
1451 gdb_assert (varobj_value_is_changeable_p (var
));
1453 /* The value of a changeable variable object must not be lazy. */
1454 gdb_assert (!value_lazy (var
->value
));
1456 /* Need to coerce the input. We want to check if the
1457 value of the variable object will be different
1458 after assignment, and the first thing value_assign
1459 does is coerce the input.
1460 For example, if we are assigning an array to a pointer variable we
1461 should compare the pointer with the array's address, not with the
1463 value
= coerce_array (value
);
1465 /* The new value may be lazy. value_assign, or
1466 rather value_contents, will take care of this. */
1467 TRY_CATCH (except
, RETURN_MASK_ERROR
)
1469 val
= value_assign (var
->value
, value
);
1472 if (except
.reason
< 0)
1475 /* If the value has changed, record it, so that next -var-update can
1476 report this change. If a variable had a value of '1', we've set it
1477 to '333' and then set again to '1', when -var-update will report this
1478 variable as changed -- because the first assignment has set the
1479 'updated' flag. There's no need to optimize that, because return value
1480 of -var-update should be considered an approximation. */
1481 var
->updated
= install_new_value (var
, val
, 0 /* Compare values. */);
1482 input_radix
= saved_input_radix
;
1488 /* A helper function to install a constructor function and visualizer
1492 install_visualizer (struct varobj
*var
, PyObject
*constructor
,
1493 PyObject
*visualizer
)
1495 Py_XDECREF (var
->constructor
);
1496 var
->constructor
= constructor
;
1498 Py_XDECREF (var
->pretty_printer
);
1499 var
->pretty_printer
= visualizer
;
1501 Py_XDECREF (var
->child_iter
);
1502 var
->child_iter
= NULL
;
1505 /* Install the default visualizer for VAR. */
1508 install_default_visualizer (struct varobj
*var
)
1510 /* Do not install a visualizer on a CPLUS_FAKE_CHILD. */
1511 if (CPLUS_FAKE_CHILD (var
))
1514 if (pretty_printing
)
1516 PyObject
*pretty_printer
= NULL
;
1520 pretty_printer
= gdbpy_get_varobj_pretty_printer (var
->value
);
1521 if (! pretty_printer
)
1523 gdbpy_print_stack ();
1524 error (_("Cannot instantiate printer for default visualizer"));
1528 if (pretty_printer
== Py_None
)
1530 Py_DECREF (pretty_printer
);
1531 pretty_printer
= NULL
;
1534 install_visualizer (var
, NULL
, pretty_printer
);
1538 /* Instantiate and install a visualizer for VAR using CONSTRUCTOR to
1539 make a new object. */
1542 construct_visualizer (struct varobj
*var
, PyObject
*constructor
)
1544 PyObject
*pretty_printer
;
1546 /* Do not install a visualizer on a CPLUS_FAKE_CHILD. */
1547 if (CPLUS_FAKE_CHILD (var
))
1550 Py_INCREF (constructor
);
1551 if (constructor
== Py_None
)
1552 pretty_printer
= NULL
;
1555 pretty_printer
= instantiate_pretty_printer (constructor
, var
->value
);
1556 if (! pretty_printer
)
1558 gdbpy_print_stack ();
1559 Py_DECREF (constructor
);
1560 constructor
= Py_None
;
1561 Py_INCREF (constructor
);
1564 if (pretty_printer
== Py_None
)
1566 Py_DECREF (pretty_printer
);
1567 pretty_printer
= NULL
;
1571 install_visualizer (var
, constructor
, pretty_printer
);
1574 #endif /* HAVE_PYTHON */
1576 /* A helper function for install_new_value. This creates and installs
1577 a visualizer for VAR, if appropriate. */
1580 install_new_value_visualizer (struct varobj
*var
)
1583 /* If the constructor is None, then we want the raw value. If VAR
1584 does not have a value, just skip this. */
1585 if (var
->constructor
!= Py_None
&& var
->value
)
1587 struct cleanup
*cleanup
;
1589 cleanup
= varobj_ensure_python_env (var
);
1591 if (!var
->constructor
)
1592 install_default_visualizer (var
);
1594 construct_visualizer (var
, var
->constructor
);
1596 do_cleanups (cleanup
);
1603 /* Assign a new value to a variable object. If INITIAL is non-zero,
1604 this is the first assignement after the variable object was just
1605 created, or changed type. In that case, just assign the value
1607 Otherwise, assign the new value, and return 1 if the value is
1608 different from the current one, 0 otherwise. The comparison is
1609 done on textual representation of value. Therefore, some types
1610 need not be compared. E.g. for structures the reported value is
1611 always "{...}", so no comparison is necessary here. If the old
1612 value was NULL and new one is not, or vice versa, we always return 1.
1614 The VALUE parameter should not be released -- the function will
1615 take care of releasing it when needed. */
1617 install_new_value (struct varobj
*var
, struct value
*value
, int initial
)
1622 int intentionally_not_fetched
= 0;
1623 char *print_value
= NULL
;
1625 /* We need to know the varobj's type to decide if the value should
1626 be fetched or not. C++ fake children (public/protected/private)
1627 don't have a type. */
1628 gdb_assert (var
->type
|| CPLUS_FAKE_CHILD (var
));
1629 changeable
= varobj_value_is_changeable_p (var
);
1631 /* If the type has custom visualizer, we consider it to be always
1632 changeable. FIXME: need to make sure this behaviour will not
1633 mess up read-sensitive values. */
1634 if (var
->pretty_printer
)
1637 need_to_fetch
= changeable
;
1639 /* We are not interested in the address of references, and given
1640 that in C++ a reference is not rebindable, it cannot
1641 meaningfully change. So, get hold of the real value. */
1643 value
= coerce_ref (value
);
1645 if (var
->type
&& TYPE_CODE (var
->type
) == TYPE_CODE_UNION
)
1646 /* For unions, we need to fetch the value implicitly because
1647 of implementation of union member fetch. When gdb
1648 creates a value for a field and the value of the enclosing
1649 structure is not lazy, it immediately copies the necessary
1650 bytes from the enclosing values. If the enclosing value is
1651 lazy, the call to value_fetch_lazy on the field will read
1652 the data from memory. For unions, that means we'll read the
1653 same memory more than once, which is not desirable. So
1657 /* The new value might be lazy. If the type is changeable,
1658 that is we'll be comparing values of this type, fetch the
1659 value now. Otherwise, on the next update the old value
1660 will be lazy, which means we've lost that old value. */
1661 if (need_to_fetch
&& value
&& value_lazy (value
))
1663 struct varobj
*parent
= var
->parent
;
1664 int frozen
= var
->frozen
;
1666 for (; !frozen
&& parent
; parent
= parent
->parent
)
1667 frozen
|= parent
->frozen
;
1669 if (frozen
&& initial
)
1671 /* For variables that are frozen, or are children of frozen
1672 variables, we don't do fetch on initial assignment.
1673 For non-initial assignemnt we do the fetch, since it means we're
1674 explicitly asked to compare the new value with the old one. */
1675 intentionally_not_fetched
= 1;
1679 volatile struct gdb_exception except
;
1681 TRY_CATCH (except
, RETURN_MASK_ERROR
)
1683 value_fetch_lazy (value
);
1686 if (except
.reason
< 0)
1688 /* Set the value to NULL, so that for the next -var-update,
1689 we don't try to compare the new value with this value,
1690 that we couldn't even read. */
1696 /* Get a reference now, before possibly passing it to any Python
1697 code that might release it. */
1699 value_incref (value
);
1701 /* Below, we'll be comparing string rendering of old and new
1702 values. Don't get string rendering if the value is
1703 lazy -- if it is, the code above has decided that the value
1704 should not be fetched. */
1705 if (value
&& !value_lazy (value
) && !var
->pretty_printer
)
1706 print_value
= value_get_print_value (value
, var
->format
, var
);
1708 /* If the type is changeable, compare the old and the new values.
1709 If this is the initial assignment, we don't have any old value
1711 if (!initial
&& changeable
)
1713 /* If the value of the varobj was changed by -var-set-value,
1714 then the value in the varobj and in the target is the same.
1715 However, that value is different from the value that the
1716 varobj had after the previous -var-update. So need to the
1717 varobj as changed. */
1722 else if (! var
->pretty_printer
)
1724 /* Try to compare the values. That requires that both
1725 values are non-lazy. */
1726 if (var
->not_fetched
&& value_lazy (var
->value
))
1728 /* This is a frozen varobj and the value was never read.
1729 Presumably, UI shows some "never read" indicator.
1730 Now that we've fetched the real value, we need to report
1731 this varobj as changed so that UI can show the real
1735 else if (var
->value
== NULL
&& value
== NULL
)
1738 else if (var
->value
== NULL
|| value
== NULL
)
1744 gdb_assert (!value_lazy (var
->value
));
1745 gdb_assert (!value_lazy (value
));
1747 gdb_assert (var
->print_value
!= NULL
&& print_value
!= NULL
);
1748 if (strcmp (var
->print_value
, print_value
) != 0)
1754 if (!initial
&& !changeable
)
1756 /* For values that are not changeable, we don't compare the values.
1757 However, we want to notice if a value was not NULL and now is NULL,
1758 or vise versa, so that we report when top-level varobjs come in scope
1759 and leave the scope. */
1760 changed
= (var
->value
!= NULL
) != (value
!= NULL
);
1763 /* We must always keep the new value, since children depend on it. */
1764 if (var
->value
!= NULL
&& var
->value
!= value
)
1765 value_free (var
->value
);
1767 if (value
&& value_lazy (value
) && intentionally_not_fetched
)
1768 var
->not_fetched
= 1;
1770 var
->not_fetched
= 0;
1773 install_new_value_visualizer (var
);
1775 /* If we installed a pretty-printer, re-compare the printed version
1776 to see if the variable changed. */
1777 if (var
->pretty_printer
)
1779 xfree (print_value
);
1780 print_value
= value_get_print_value (var
->value
, var
->format
, var
);
1781 if ((var
->print_value
== NULL
&& print_value
!= NULL
)
1782 || (var
->print_value
!= NULL
&& print_value
== NULL
)
1783 || (var
->print_value
!= NULL
&& print_value
!= NULL
1784 && strcmp (var
->print_value
, print_value
) != 0))
1787 if (var
->print_value
)
1788 xfree (var
->print_value
);
1789 var
->print_value
= print_value
;
1791 gdb_assert (!var
->value
|| value_type (var
->value
));
1796 /* Return the requested range for a varobj. VAR is the varobj. FROM
1797 and TO are out parameters; *FROM and *TO will be set to the
1798 selected sub-range of VAR. If no range was selected using
1799 -var-set-update-range, then both will be -1. */
1801 varobj_get_child_range (struct varobj
*var
, int *from
, int *to
)
1807 /* Set the selected sub-range of children of VAR to start at index
1808 FROM and end at index TO. If either FROM or TO is less than zero,
1809 this is interpreted as a request for all children. */
1811 varobj_set_child_range (struct varobj
*var
, int from
, int to
)
1818 varobj_set_visualizer (struct varobj
*var
, const char *visualizer
)
1821 PyObject
*mainmod
, *globals
, *constructor
;
1822 struct cleanup
*back_to
;
1824 back_to
= varobj_ensure_python_env (var
);
1826 mainmod
= PyImport_AddModule ("__main__");
1827 globals
= PyModule_GetDict (mainmod
);
1828 Py_INCREF (globals
);
1829 make_cleanup_py_decref (globals
);
1831 constructor
= PyRun_String (visualizer
, Py_eval_input
, globals
, globals
);
1835 gdbpy_print_stack ();
1836 error (_("Could not evaluate visualizer expression: %s"), visualizer
);
1839 construct_visualizer (var
, constructor
);
1840 Py_XDECREF (constructor
);
1842 /* If there are any children now, wipe them. */
1843 varobj_delete (var
, NULL
, 1 /* children only */);
1844 var
->num_children
= -1;
1846 do_cleanups (back_to
);
1848 error (_("Python support required"));
1852 /* If NEW_VALUE is the new value of the given varobj (var), return
1853 non-zero if var has mutated. In other words, if the type of
1854 the new value is different from the type of the varobj's old
1857 NEW_VALUE may be NULL, if the varobj is now out of scope. */
1860 varobj_value_has_mutated (struct varobj
*var
, struct value
*new_value
,
1861 struct type
*new_type
)
1863 /* If we haven't previously computed the number of children in var,
1864 it does not matter from the front-end's perspective whether
1865 the type has mutated or not. For all intents and purposes,
1866 it has not mutated. */
1867 if (var
->num_children
< 0)
1870 if (var
->root
->lang
->value_has_mutated
)
1871 return var
->root
->lang
->value_has_mutated (var
, new_value
, new_type
);
1876 /* Update the values for a variable and its children. This is a
1877 two-pronged attack. First, re-parse the value for the root's
1878 expression to see if it's changed. Then go all the way
1879 through its children, reconstructing them and noting if they've
1882 The EXPLICIT parameter specifies if this call is result
1883 of MI request to update this specific variable, or
1884 result of implicit -var-update *. For implicit request, we don't
1885 update frozen variables.
1887 NOTE: This function may delete the caller's varobj. If it
1888 returns TYPE_CHANGED, then it has done this and VARP will be modified
1889 to point to the new varobj. */
1891 VEC(varobj_update_result
) *
1892 varobj_update (struct varobj
**varp
, int explicit)
1895 int type_changed
= 0;
1898 VEC (varobj_update_result
) *stack
= NULL
;
1899 VEC (varobj_update_result
) *result
= NULL
;
1901 /* Frozen means frozen -- we don't check for any change in
1902 this varobj, including its going out of scope, or
1903 changing type. One use case for frozen varobjs is
1904 retaining previously evaluated expressions, and we don't
1905 want them to be reevaluated at all. */
1906 if (!explicit && (*varp
)->frozen
)
1909 if (!(*varp
)->root
->is_valid
)
1911 varobj_update_result r
= {0};
1914 r
.status
= VAROBJ_INVALID
;
1915 VEC_safe_push (varobj_update_result
, result
, &r
);
1919 if ((*varp
)->root
->rootvar
== *varp
)
1921 varobj_update_result r
= {0};
1924 r
.status
= VAROBJ_IN_SCOPE
;
1926 /* Update the root variable. value_of_root can return NULL
1927 if the variable is no longer around, i.e. we stepped out of
1928 the frame in which a local existed. We are letting the
1929 value_of_root variable dispose of the varobj if the type
1931 new = value_of_root (varp
, &type_changed
);
1934 r
.type_changed
= type_changed
;
1935 if (install_new_value ((*varp
), new, type_changed
))
1939 r
.status
= VAROBJ_NOT_IN_SCOPE
;
1940 r
.value_installed
= 1;
1942 if (r
.status
== VAROBJ_NOT_IN_SCOPE
)
1944 if (r
.type_changed
|| r
.changed
)
1945 VEC_safe_push (varobj_update_result
, result
, &r
);
1949 VEC_safe_push (varobj_update_result
, stack
, &r
);
1953 varobj_update_result r
= {0};
1956 VEC_safe_push (varobj_update_result
, stack
, &r
);
1959 /* Walk through the children, reconstructing them all. */
1960 while (!VEC_empty (varobj_update_result
, stack
))
1962 varobj_update_result r
= *(VEC_last (varobj_update_result
, stack
));
1963 struct varobj
*v
= r
.varobj
;
1965 VEC_pop (varobj_update_result
, stack
);
1967 /* Update this variable, unless it's a root, which is already
1969 if (!r
.value_installed
)
1971 struct type
*new_type
;
1973 new = value_of_child (v
->parent
, v
->index
);
1975 new_type
= value_type (new);
1977 new_type
= v
->root
->lang
->type_of_child (v
->parent
, v
->index
);
1979 if (varobj_value_has_mutated (v
, new, new_type
))
1981 /* The children are no longer valid; delete them now.
1982 Report the fact that its type changed as well. */
1983 varobj_delete (v
, NULL
, 1 /* only_children */);
1984 v
->num_children
= -1;
1991 if (install_new_value (v
, new, r
.type_changed
))
1998 /* We probably should not get children of a varobj that has a
1999 pretty-printer, but for which -var-list-children was never
2001 if (v
->pretty_printer
)
2003 VEC (varobj_p
) *changed
= 0, *new = 0, *unchanged
= 0;
2004 int i
, children_changed
= 0;
2009 if (!v
->children_requested
)
2013 /* If we initially did not have potential children, but
2014 now we do, consider the varobj as changed.
2015 Otherwise, if children were never requested, consider
2016 it as unchanged -- presumably, such varobj is not yet
2017 expanded in the UI, so we need not bother getting
2019 if (!varobj_has_more (v
, 0))
2021 update_dynamic_varobj_children (v
, NULL
, NULL
, NULL
,
2023 if (varobj_has_more (v
, 0))
2028 VEC_safe_push (varobj_update_result
, result
, &r
);
2033 /* If update_dynamic_varobj_children returns 0, then we have
2034 a non-conforming pretty-printer, so we skip it. */
2035 if (update_dynamic_varobj_children (v
, &changed
, &new, &unchanged
,
2036 &children_changed
, 1,
2039 if (children_changed
|| new)
2041 r
.children_changed
= 1;
2044 /* Push in reverse order so that the first child is
2045 popped from the work stack first, and so will be
2046 added to result first. This does not affect
2047 correctness, just "nicer". */
2048 for (i
= VEC_length (varobj_p
, changed
) - 1; i
>= 0; --i
)
2050 varobj_p tmp
= VEC_index (varobj_p
, changed
, i
);
2051 varobj_update_result r
= {0};
2055 r
.value_installed
= 1;
2056 VEC_safe_push (varobj_update_result
, stack
, &r
);
2058 for (i
= VEC_length (varobj_p
, unchanged
) - 1; i
>= 0; --i
)
2060 varobj_p tmp
= VEC_index (varobj_p
, unchanged
, i
);
2064 varobj_update_result r
= {0};
2067 r
.value_installed
= 1;
2068 VEC_safe_push (varobj_update_result
, stack
, &r
);
2071 if (r
.changed
|| r
.children_changed
)
2072 VEC_safe_push (varobj_update_result
, result
, &r
);
2074 /* Free CHANGED and UNCHANGED, but not NEW, because NEW
2075 has been put into the result vector. */
2076 VEC_free (varobj_p
, changed
);
2077 VEC_free (varobj_p
, unchanged
);
2083 /* Push any children. Use reverse order so that the first
2084 child is popped from the work stack first, and so
2085 will be added to result first. This does not
2086 affect correctness, just "nicer". */
2087 for (i
= VEC_length (varobj_p
, v
->children
)-1; i
>= 0; --i
)
2089 varobj_p c
= VEC_index (varobj_p
, v
->children
, i
);
2091 /* Child may be NULL if explicitly deleted by -var-delete. */
2092 if (c
!= NULL
&& !c
->frozen
)
2094 varobj_update_result r
= {0};
2097 VEC_safe_push (varobj_update_result
, stack
, &r
);
2101 if (r
.changed
|| r
.type_changed
)
2102 VEC_safe_push (varobj_update_result
, result
, &r
);
2105 VEC_free (varobj_update_result
, stack
);
2111 /* Helper functions */
2114 * Variable object construction/destruction
2118 delete_variable (struct cpstack
**resultp
, struct varobj
*var
,
2119 int only_children_p
)
2123 delete_variable_1 (resultp
, &delcount
, var
,
2124 only_children_p
, 1 /* remove_from_parent_p */ );
2129 /* Delete the variable object VAR and its children. */
2130 /* IMPORTANT NOTE: If we delete a variable which is a child
2131 and the parent is not removed we dump core. It must be always
2132 initially called with remove_from_parent_p set. */
2134 delete_variable_1 (struct cpstack
**resultp
, int *delcountp
,
2135 struct varobj
*var
, int only_children_p
,
2136 int remove_from_parent_p
)
2140 /* Delete any children of this variable, too. */
2141 for (i
= 0; i
< VEC_length (varobj_p
, var
->children
); ++i
)
2143 varobj_p child
= VEC_index (varobj_p
, var
->children
, i
);
2147 if (!remove_from_parent_p
)
2148 child
->parent
= NULL
;
2149 delete_variable_1 (resultp
, delcountp
, child
, 0, only_children_p
);
2151 VEC_free (varobj_p
, var
->children
);
2153 /* if we were called to delete only the children we are done here. */
2154 if (only_children_p
)
2157 /* Otherwise, add it to the list of deleted ones and proceed to do so. */
2158 /* If the name is null, this is a temporary variable, that has not
2159 yet been installed, don't report it, it belongs to the caller... */
2160 if (var
->obj_name
!= NULL
)
2162 cppush (resultp
, xstrdup (var
->obj_name
));
2163 *delcountp
= *delcountp
+ 1;
2166 /* If this variable has a parent, remove it from its parent's list. */
2167 /* OPTIMIZATION: if the parent of this variable is also being deleted,
2168 (as indicated by remove_from_parent_p) we don't bother doing an
2169 expensive list search to find the element to remove when we are
2170 discarding the list afterwards. */
2171 if ((remove_from_parent_p
) && (var
->parent
!= NULL
))
2173 VEC_replace (varobj_p
, var
->parent
->children
, var
->index
, NULL
);
2176 if (var
->obj_name
!= NULL
)
2177 uninstall_variable (var
);
2179 /* Free memory associated with this variable. */
2180 free_variable (var
);
2183 /* Install the given variable VAR with the object name VAR->OBJ_NAME. */
2185 install_variable (struct varobj
*var
)
2188 struct vlist
*newvl
;
2190 unsigned int index
= 0;
2193 for (chp
= var
->obj_name
; *chp
; chp
++)
2195 index
= (index
+ (i
++ * (unsigned int) *chp
)) % VAROBJ_TABLE_SIZE
;
2198 cv
= *(varobj_table
+ index
);
2199 while ((cv
!= NULL
) && (strcmp (cv
->var
->obj_name
, var
->obj_name
) != 0))
2203 error (_("Duplicate variable object name"));
2205 /* Add varobj to hash table. */
2206 newvl
= xmalloc (sizeof (struct vlist
));
2207 newvl
->next
= *(varobj_table
+ index
);
2209 *(varobj_table
+ index
) = newvl
;
2211 /* If root, add varobj to root list. */
2212 if (is_root_p (var
))
2214 /* Add to list of root variables. */
2215 if (rootlist
== NULL
)
2216 var
->root
->next
= NULL
;
2218 var
->root
->next
= rootlist
;
2219 rootlist
= var
->root
;
2225 /* Unistall the object VAR. */
2227 uninstall_variable (struct varobj
*var
)
2231 struct varobj_root
*cr
;
2232 struct varobj_root
*prer
;
2234 unsigned int index
= 0;
2237 /* Remove varobj from hash table. */
2238 for (chp
= var
->obj_name
; *chp
; chp
++)
2240 index
= (index
+ (i
++ * (unsigned int) *chp
)) % VAROBJ_TABLE_SIZE
;
2243 cv
= *(varobj_table
+ index
);
2245 while ((cv
!= NULL
) && (strcmp (cv
->var
->obj_name
, var
->obj_name
) != 0))
2252 fprintf_unfiltered (gdb_stdlog
, "Deleting %s\n", var
->obj_name
);
2257 ("Assertion failed: Could not find variable object \"%s\" to delete",
2263 *(varobj_table
+ index
) = cv
->next
;
2265 prev
->next
= cv
->next
;
2269 /* If root, remove varobj from root list. */
2270 if (is_root_p (var
))
2272 /* Remove from list of root variables. */
2273 if (rootlist
== var
->root
)
2274 rootlist
= var
->root
->next
;
2279 while ((cr
!= NULL
) && (cr
->rootvar
!= var
))
2286 warning (_("Assertion failed: Could not find "
2287 "varobj \"%s\" in root list"),
2294 prer
->next
= cr
->next
;
2300 /* Create and install a child of the parent of the given name. */
2301 static struct varobj
*
2302 create_child (struct varobj
*parent
, int index
, char *name
)
2304 return create_child_with_value (parent
, index
, name
,
2305 value_of_child (parent
, index
));
2308 /* Does CHILD represent a child with no name? This happens when
2309 the child is an anonmous struct or union and it has no field name
2310 in its parent variable.
2312 This has already been determined by *_describe_child. The easiest
2313 thing to do is to compare the child's name with ANONYMOUS_*_NAME. */
2316 is_anonymous_child (struct varobj
*child
)
2318 return (strcmp (child
->name
, ANONYMOUS_STRUCT_NAME
) == 0
2319 || strcmp (child
->name
, ANONYMOUS_UNION_NAME
) == 0);
2322 static struct varobj
*
2323 create_child_with_value (struct varobj
*parent
, int index
, const char *name
,
2324 struct value
*value
)
2326 struct varobj
*child
;
2329 child
= new_variable ();
2331 /* Name is allocated by name_of_child. */
2332 /* FIXME: xstrdup should not be here. */
2333 child
->name
= xstrdup (name
);
2334 child
->index
= index
;
2335 child
->parent
= parent
;
2336 child
->root
= parent
->root
;
2338 if (is_anonymous_child (child
))
2339 childs_name
= xstrprintf ("%s.%d_anonymous", parent
->obj_name
, index
);
2341 childs_name
= xstrprintf ("%s.%s", parent
->obj_name
, name
);
2342 child
->obj_name
= childs_name
;
2344 install_variable (child
);
2346 /* Compute the type of the child. Must do this before
2347 calling install_new_value. */
2349 /* If the child had no evaluation errors, var->value
2350 will be non-NULL and contain a valid type. */
2351 child
->type
= value_type (value
);
2353 /* Otherwise, we must compute the type. */
2354 child
->type
= (*child
->root
->lang
->type_of_child
) (child
->parent
,
2356 install_new_value (child
, value
, 1);
2363 * Miscellaneous utility functions.
2366 /* Allocate memory and initialize a new variable. */
2367 static struct varobj
*
2372 var
= (struct varobj
*) xmalloc (sizeof (struct varobj
));
2374 var
->path_expr
= NULL
;
2375 var
->obj_name
= NULL
;
2379 var
->num_children
= -1;
2381 var
->children
= NULL
;
2385 var
->print_value
= NULL
;
2387 var
->not_fetched
= 0;
2388 var
->children_requested
= 0;
2391 var
->constructor
= 0;
2392 var
->pretty_printer
= 0;
2393 var
->child_iter
= 0;
2394 var
->saved_item
= 0;
2399 /* Allocate memory and initialize a new root variable. */
2400 static struct varobj
*
2401 new_root_variable (void)
2403 struct varobj
*var
= new_variable ();
2405 var
->root
= (struct varobj_root
*) xmalloc (sizeof (struct varobj_root
));
2406 var
->root
->lang
= NULL
;
2407 var
->root
->exp
= NULL
;
2408 var
->root
->valid_block
= NULL
;
2409 var
->root
->frame
= null_frame_id
;
2410 var
->root
->floating
= 0;
2411 var
->root
->rootvar
= NULL
;
2412 var
->root
->is_valid
= 1;
2417 /* Free any allocated memory associated with VAR. */
2419 free_variable (struct varobj
*var
)
2422 if (var
->pretty_printer
)
2424 struct cleanup
*cleanup
= varobj_ensure_python_env (var
);
2425 Py_XDECREF (var
->constructor
);
2426 Py_XDECREF (var
->pretty_printer
);
2427 Py_XDECREF (var
->child_iter
);
2428 Py_XDECREF (var
->saved_item
);
2429 do_cleanups (cleanup
);
2433 value_free (var
->value
);
2435 /* Free the expression if this is a root variable. */
2436 if (is_root_p (var
))
2438 xfree (var
->root
->exp
);
2443 xfree (var
->obj_name
);
2444 xfree (var
->print_value
);
2445 xfree (var
->path_expr
);
2450 do_free_variable_cleanup (void *var
)
2452 free_variable (var
);
2455 static struct cleanup
*
2456 make_cleanup_free_variable (struct varobj
*var
)
2458 return make_cleanup (do_free_variable_cleanup
, var
);
2461 /* This returns the type of the variable. It also skips past typedefs
2462 to return the real type of the variable.
2464 NOTE: TYPE_TARGET_TYPE should NOT be used anywhere in this file
2465 except within get_target_type and get_type. */
2466 static struct type
*
2467 get_type (struct varobj
*var
)
2473 type
= check_typedef (type
);
2478 /* Return the type of the value that's stored in VAR,
2479 or that would have being stored there if the
2480 value were accessible.
2482 This differs from VAR->type in that VAR->type is always
2483 the true type of the expession in the source language.
2484 The return value of this function is the type we're
2485 actually storing in varobj, and using for displaying
2486 the values and for comparing previous and new values.
2488 For example, top-level references are always stripped. */
2489 static struct type
*
2490 get_value_type (struct varobj
*var
)
2495 type
= value_type (var
->value
);
2499 type
= check_typedef (type
);
2501 if (TYPE_CODE (type
) == TYPE_CODE_REF
)
2502 type
= get_target_type (type
);
2504 type
= check_typedef (type
);
2509 /* This returns the target type (or NULL) of TYPE, also skipping
2510 past typedefs, just like get_type ().
2512 NOTE: TYPE_TARGET_TYPE should NOT be used anywhere in this file
2513 except within get_target_type and get_type. */
2514 static struct type
*
2515 get_target_type (struct type
*type
)
2519 type
= TYPE_TARGET_TYPE (type
);
2521 type
= check_typedef (type
);
2527 /* What is the default display for this variable? We assume that
2528 everything is "natural". Any exceptions? */
2529 static enum varobj_display_formats
2530 variable_default_display (struct varobj
*var
)
2532 return FORMAT_NATURAL
;
2535 /* FIXME: The following should be generic for any pointer. */
2537 cppush (struct cpstack
**pstack
, char *name
)
2541 s
= (struct cpstack
*) xmalloc (sizeof (struct cpstack
));
2547 /* FIXME: The following should be generic for any pointer. */
2549 cppop (struct cpstack
**pstack
)
2554 if ((*pstack
)->name
== NULL
&& (*pstack
)->next
== NULL
)
2559 *pstack
= (*pstack
)->next
;
2566 * Language-dependencies
2569 /* Common entry points */
2571 /* Get the language of variable VAR. */
2572 static enum varobj_languages
2573 variable_language (struct varobj
*var
)
2575 enum varobj_languages lang
;
2577 switch (var
->root
->exp
->language_defn
->la_language
)
2583 case language_cplus
:
2597 /* Return the number of children for a given variable.
2598 The result of this function is defined by the language
2599 implementation. The number of children returned by this function
2600 is the number of children that the user will see in the variable
2603 number_of_children (struct varobj
*var
)
2605 return (*var
->root
->lang
->number_of_children
) (var
);
2608 /* What is the expression for the root varobj VAR? Returns a malloc'd
2611 name_of_variable (struct varobj
*var
)
2613 return (*var
->root
->lang
->name_of_variable
) (var
);
2616 /* What is the name of the INDEX'th child of VAR? Returns a malloc'd
2619 name_of_child (struct varobj
*var
, int index
)
2621 return (*var
->root
->lang
->name_of_child
) (var
, index
);
2624 /* What is the ``struct value *'' of the root variable VAR?
2625 For floating variable object, evaluation can get us a value
2626 of different type from what is stored in varobj already. In
2628 - *type_changed will be set to 1
2629 - old varobj will be freed, and new one will be
2630 created, with the same name.
2631 - *var_handle will be set to the new varobj
2632 Otherwise, *type_changed will be set to 0. */
2633 static struct value
*
2634 value_of_root (struct varobj
**var_handle
, int *type_changed
)
2638 if (var_handle
== NULL
)
2643 /* This should really be an exception, since this should
2644 only get called with a root variable. */
2646 if (!is_root_p (var
))
2649 if (var
->root
->floating
)
2651 struct varobj
*tmp_var
;
2652 char *old_type
, *new_type
;
2654 tmp_var
= varobj_create (NULL
, var
->name
, (CORE_ADDR
) 0,
2655 USE_SELECTED_FRAME
);
2656 if (tmp_var
== NULL
)
2660 old_type
= varobj_get_type (var
);
2661 new_type
= varobj_get_type (tmp_var
);
2662 if (strcmp (old_type
, new_type
) == 0)
2664 /* The expression presently stored inside var->root->exp
2665 remembers the locations of local variables relatively to
2666 the frame where the expression was created (in DWARF location
2667 button, for example). Naturally, those locations are not
2668 correct in other frames, so update the expression. */
2670 struct expression
*tmp_exp
= var
->root
->exp
;
2672 var
->root
->exp
= tmp_var
->root
->exp
;
2673 tmp_var
->root
->exp
= tmp_exp
;
2675 varobj_delete (tmp_var
, NULL
, 0);
2680 tmp_var
->obj_name
= xstrdup (var
->obj_name
);
2681 tmp_var
->from
= var
->from
;
2682 tmp_var
->to
= var
->to
;
2683 varobj_delete (var
, NULL
, 0);
2685 install_variable (tmp_var
);
2686 *var_handle
= tmp_var
;
2699 struct value
*value
;
2701 value
= (*var
->root
->lang
->value_of_root
) (var_handle
);
2702 if (var
->value
== NULL
|| value
== NULL
)
2704 /* For root varobj-s, a NULL value indicates a scoping issue.
2705 So, nothing to do in terms of checking for mutations. */
2707 else if (varobj_value_has_mutated (var
, value
, value_type (value
)))
2709 /* The type has mutated, so the children are no longer valid.
2710 Just delete them, and tell our caller that the type has
2712 varobj_delete (var
, NULL
, 1 /* only_children */);
2713 var
->num_children
= -1;
2722 /* What is the ``struct value *'' for the INDEX'th child of PARENT? */
2723 static struct value
*
2724 value_of_child (struct varobj
*parent
, int index
)
2726 struct value
*value
;
2728 value
= (*parent
->root
->lang
->value_of_child
) (parent
, index
);
2733 /* GDB already has a command called "value_of_variable". Sigh. */
2735 my_value_of_variable (struct varobj
*var
, enum varobj_display_formats format
)
2737 if (var
->root
->is_valid
)
2739 if (var
->pretty_printer
)
2740 return value_get_print_value (var
->value
, var
->format
, var
);
2741 return (*var
->root
->lang
->value_of_variable
) (var
, format
);
2748 value_get_print_value (struct value
*value
, enum varobj_display_formats format
,
2751 struct ui_file
*stb
;
2752 struct cleanup
*old_chain
;
2753 gdb_byte
*thevalue
= NULL
;
2754 struct value_print_options opts
;
2755 struct type
*type
= NULL
;
2757 char *encoding
= NULL
;
2758 struct gdbarch
*gdbarch
= NULL
;
2759 /* Initialize it just to avoid a GCC false warning. */
2760 CORE_ADDR str_addr
= 0;
2761 int string_print
= 0;
2766 stb
= mem_fileopen ();
2767 old_chain
= make_cleanup_ui_file_delete (stb
);
2769 gdbarch
= get_type_arch (value_type (value
));
2772 PyObject
*value_formatter
= var
->pretty_printer
;
2774 varobj_ensure_python_env (var
);
2776 if (value_formatter
)
2778 /* First check to see if we have any children at all. If so,
2779 we simply return {...}. */
2780 if (dynamic_varobj_has_child_method (var
))
2782 do_cleanups (old_chain
);
2783 return xstrdup ("{...}");
2786 if (PyObject_HasAttr (value_formatter
, gdbpy_to_string_cst
))
2788 struct value
*replacement
;
2789 PyObject
*output
= NULL
;
2791 output
= apply_varobj_pretty_printer (value_formatter
,
2795 /* If we have string like output ... */
2798 make_cleanup_py_decref (output
);
2800 /* If this is a lazy string, extract it. For lazy
2801 strings we always print as a string, so set
2803 if (gdbpy_is_lazy_string (output
))
2805 gdbpy_extract_lazy_string (output
, &str_addr
, &type
,
2807 make_cleanup (free_current_contents
, &encoding
);
2812 /* If it is a regular (non-lazy) string, extract
2813 it and copy the contents into THEVALUE. If the
2814 hint says to print it as a string, set
2815 string_print. Otherwise just return the extracted
2816 string as a value. */
2819 = python_string_to_target_python_string (output
);
2823 char *s
= PyString_AsString (py_str
);
2826 hint
= gdbpy_get_display_hint (value_formatter
);
2829 if (!strcmp (hint
, "string"))
2834 len
= PyString_Size (py_str
);
2835 thevalue
= xmemdup (s
, len
+ 1, len
+ 1);
2836 type
= builtin_type (gdbarch
)->builtin_char
;
2841 do_cleanups (old_chain
);
2845 make_cleanup (xfree
, thevalue
);
2848 gdbpy_print_stack ();
2851 /* If the printer returned a replacement value, set VALUE
2852 to REPLACEMENT. If there is not a replacement value,
2853 just use the value passed to this function. */
2855 value
= replacement
;
2861 get_formatted_print_options (&opts
, format_code
[(int) format
]);
2865 /* If the THEVALUE has contents, it is a regular string. */
2867 LA_PRINT_STRING (stb
, type
, thevalue
, len
, encoding
, 0, &opts
);
2868 else if (string_print
)
2869 /* Otherwise, if string_print is set, and it is not a regular
2870 string, it is a lazy string. */
2871 val_print_string (type
, encoding
, str_addr
, len
, stb
, &opts
);
2873 /* All other cases. */
2874 common_val_print (value
, stb
, 0, &opts
, current_language
);
2876 thevalue
= ui_file_xstrdup (stb
, NULL
);
2878 do_cleanups (old_chain
);
2883 varobj_editable_p (struct varobj
*var
)
2887 if (!(var
->root
->is_valid
&& var
->value
&& VALUE_LVAL (var
->value
)))
2890 type
= get_value_type (var
);
2892 switch (TYPE_CODE (type
))
2894 case TYPE_CODE_STRUCT
:
2895 case TYPE_CODE_UNION
:
2896 case TYPE_CODE_ARRAY
:
2897 case TYPE_CODE_FUNC
:
2898 case TYPE_CODE_METHOD
:
2908 /* Return non-zero if changes in value of VAR
2909 must be detected and reported by -var-update.
2910 Return zero is -var-update should never report
2911 changes of such values. This makes sense for structures
2912 (since the changes in children values will be reported separately),
2913 or for artifical objects (like 'public' pseudo-field in C++).
2915 Return value of 0 means that gdb need not call value_fetch_lazy
2916 for the value of this variable object. */
2918 varobj_value_is_changeable_p (struct varobj
*var
)
2923 if (CPLUS_FAKE_CHILD (var
))
2926 /* FIXME: This, and the check above, show that this routine
2927 should be language-specific. */
2928 if (variable_language (var
) == vlang_ada
)
2930 struct type
*type
= var
->value
? value_type (var
->value
) : var
->type
;
2932 if (ada_is_array_descriptor_type (type
)
2933 && TYPE_CODE (type
) == TYPE_CODE_TYPEDEF
)
2935 /* This is in reality a pointer to an unconstrained array.
2936 its value is changeable. */
2940 if (ada_is_string_type (type
))
2942 /* We display the contents of the string in the array's
2943 "value" field. The contents can change, so consider
2944 that the array is changeable. */
2949 type
= get_value_type (var
);
2951 switch (TYPE_CODE (type
))
2953 case TYPE_CODE_STRUCT
:
2954 case TYPE_CODE_UNION
:
2955 case TYPE_CODE_ARRAY
:
2966 /* Return 1 if that varobj is floating, that is is always evaluated in the
2967 selected frame, and not bound to thread/frame. Such variable objects
2968 are created using '@' as frame specifier to -var-create. */
2970 varobj_floating_p (struct varobj
*var
)
2972 return var
->root
->floating
;
2975 /* Given the value and the type of a variable object,
2976 adjust the value and type to those necessary
2977 for getting children of the variable object.
2978 This includes dereferencing top-level references
2979 to all types and dereferencing pointers to
2982 Both TYPE and *TYPE should be non-null. VALUE
2983 can be null if we want to only translate type.
2984 *VALUE can be null as well -- if the parent
2987 If WAS_PTR is not NULL, set *WAS_PTR to 0 or 1
2988 depending on whether pointer was dereferenced
2989 in this function. */
2991 adjust_value_for_child_access (struct value
**value
,
2995 gdb_assert (type
&& *type
);
3000 *type
= check_typedef (*type
);
3002 /* The type of value stored in varobj, that is passed
3003 to us, is already supposed to be
3004 reference-stripped. */
3006 gdb_assert (TYPE_CODE (*type
) != TYPE_CODE_REF
);
3008 /* Pointers to structures are treated just like
3009 structures when accessing children. Don't
3010 dererences pointers to other types. */
3011 if (TYPE_CODE (*type
) == TYPE_CODE_PTR
)
3013 struct type
*target_type
= get_target_type (*type
);
3014 if (TYPE_CODE (target_type
) == TYPE_CODE_STRUCT
3015 || TYPE_CODE (target_type
) == TYPE_CODE_UNION
)
3017 if (value
&& *value
)
3019 volatile struct gdb_exception except
;
3021 TRY_CATCH (except
, RETURN_MASK_ERROR
)
3023 *value
= value_ind (*value
);
3026 if (except
.reason
< 0)
3029 *type
= target_type
;
3035 /* The 'get_target_type' function calls check_typedef on
3036 result, so we can immediately check type code. No
3037 need to call check_typedef here. */
3042 c_number_of_children (struct varobj
*var
)
3044 struct type
*type
= get_value_type (var
);
3046 struct type
*target
;
3048 adjust_value_for_child_access (NULL
, &type
, NULL
);
3049 target
= get_target_type (type
);
3051 switch (TYPE_CODE (type
))
3053 case TYPE_CODE_ARRAY
:
3054 if (TYPE_LENGTH (type
) > 0 && TYPE_LENGTH (target
) > 0
3055 && !TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (type
))
3056 children
= TYPE_LENGTH (type
) / TYPE_LENGTH (target
);
3058 /* If we don't know how many elements there are, don't display
3063 case TYPE_CODE_STRUCT
:
3064 case TYPE_CODE_UNION
:
3065 children
= TYPE_NFIELDS (type
);
3069 /* The type here is a pointer to non-struct. Typically, pointers
3070 have one child, except for function ptrs, which have no children,
3071 and except for void*, as we don't know what to show.
3073 We can show char* so we allow it to be dereferenced. If you decide
3074 to test for it, please mind that a little magic is necessary to
3075 properly identify it: char* has TYPE_CODE == TYPE_CODE_INT and
3076 TYPE_NAME == "char". */
3077 if (TYPE_CODE (target
) == TYPE_CODE_FUNC
3078 || TYPE_CODE (target
) == TYPE_CODE_VOID
)
3085 /* Other types have no children. */
3093 c_name_of_variable (struct varobj
*parent
)
3095 return xstrdup (parent
->name
);
3098 /* Return the value of element TYPE_INDEX of a structure
3099 value VALUE. VALUE's type should be a structure,
3100 or union, or a typedef to struct/union.
3102 Returns NULL if getting the value fails. Never throws. */
3103 static struct value
*
3104 value_struct_element_index (struct value
*value
, int type_index
)
3106 struct value
*result
= NULL
;
3107 volatile struct gdb_exception e
;
3108 struct type
*type
= value_type (value
);
3110 type
= check_typedef (type
);
3112 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_STRUCT
3113 || TYPE_CODE (type
) == TYPE_CODE_UNION
);
3115 TRY_CATCH (e
, RETURN_MASK_ERROR
)
3117 if (field_is_static (&TYPE_FIELD (type
, type_index
)))
3118 result
= value_static_field (type
, type_index
);
3120 result
= value_primitive_field (value
, 0, type_index
, type
);
3132 /* Obtain the information about child INDEX of the variable
3134 If CNAME is not null, sets *CNAME to the name of the child relative
3136 If CVALUE is not null, sets *CVALUE to the value of the child.
3137 If CTYPE is not null, sets *CTYPE to the type of the child.
3139 If any of CNAME, CVALUE, or CTYPE is not null, but the corresponding
3140 information cannot be determined, set *CNAME, *CVALUE, or *CTYPE
3143 c_describe_child (struct varobj
*parent
, int index
,
3144 char **cname
, struct value
**cvalue
, struct type
**ctype
,
3145 char **cfull_expression
)
3147 struct value
*value
= parent
->value
;
3148 struct type
*type
= get_value_type (parent
);
3149 char *parent_expression
= NULL
;
3151 volatile struct gdb_exception except
;
3159 if (cfull_expression
)
3161 *cfull_expression
= NULL
;
3162 parent_expression
= varobj_get_path_expr (get_path_expr_parent (parent
));
3164 adjust_value_for_child_access (&value
, &type
, &was_ptr
);
3166 switch (TYPE_CODE (type
))
3168 case TYPE_CODE_ARRAY
:
3171 = xstrdup (int_string (index
3172 + TYPE_LOW_BOUND (TYPE_INDEX_TYPE (type
)),
3175 if (cvalue
&& value
)
3177 int real_index
= index
+ TYPE_LOW_BOUND (TYPE_INDEX_TYPE (type
));
3179 TRY_CATCH (except
, RETURN_MASK_ERROR
)
3181 *cvalue
= value_subscript (value
, real_index
);
3186 *ctype
= get_target_type (type
);
3188 if (cfull_expression
)
3190 xstrprintf ("(%s)[%s]", parent_expression
,
3192 + TYPE_LOW_BOUND (TYPE_INDEX_TYPE (type
)),
3198 case TYPE_CODE_STRUCT
:
3199 case TYPE_CODE_UNION
:
3201 const char *field_name
;
3203 /* If the type is anonymous and the field has no name,
3204 set an appropriate name. */
3205 field_name
= TYPE_FIELD_NAME (type
, index
);
3206 if (field_name
== NULL
|| *field_name
== '\0')
3210 if (TYPE_CODE (TYPE_FIELD_TYPE (type
, index
))
3211 == TYPE_CODE_STRUCT
)
3212 *cname
= xstrdup (ANONYMOUS_STRUCT_NAME
);
3214 *cname
= xstrdup (ANONYMOUS_UNION_NAME
);
3217 if (cfull_expression
)
3218 *cfull_expression
= xstrdup ("");
3223 *cname
= xstrdup (field_name
);
3225 if (cfull_expression
)
3227 char *join
= was_ptr
? "->" : ".";
3229 *cfull_expression
= xstrprintf ("(%s)%s%s", parent_expression
,
3234 if (cvalue
&& value
)
3236 /* For C, varobj index is the same as type index. */
3237 *cvalue
= value_struct_element_index (value
, index
);
3241 *ctype
= TYPE_FIELD_TYPE (type
, index
);
3247 *cname
= xstrprintf ("*%s", parent
->name
);
3249 if (cvalue
&& value
)
3251 TRY_CATCH (except
, RETURN_MASK_ERROR
)
3253 *cvalue
= value_ind (value
);
3256 if (except
.reason
< 0)
3260 /* Don't use get_target_type because it calls
3261 check_typedef and here, we want to show the true
3262 declared type of the variable. */
3264 *ctype
= TYPE_TARGET_TYPE (type
);
3266 if (cfull_expression
)
3267 *cfull_expression
= xstrprintf ("*(%s)", parent_expression
);
3272 /* This should not happen. */
3274 *cname
= xstrdup ("???");
3275 if (cfull_expression
)
3276 *cfull_expression
= xstrdup ("???");
3277 /* Don't set value and type, we don't know then. */
3282 c_name_of_child (struct varobj
*parent
, int index
)
3286 c_describe_child (parent
, index
, &name
, NULL
, NULL
, NULL
);
3291 c_path_expr_of_child (struct varobj
*child
)
3293 c_describe_child (child
->parent
, child
->index
, NULL
, NULL
, NULL
,
3295 return child
->path_expr
;
3298 /* If frame associated with VAR can be found, switch
3299 to it and return 1. Otherwise, return 0. */
3301 check_scope (struct varobj
*var
)
3303 struct frame_info
*fi
;
3306 fi
= frame_find_by_id (var
->root
->frame
);
3311 CORE_ADDR pc
= get_frame_pc (fi
);
3313 if (pc
< BLOCK_START (var
->root
->valid_block
) ||
3314 pc
>= BLOCK_END (var
->root
->valid_block
))
3322 static struct value
*
3323 c_value_of_root (struct varobj
**var_handle
)
3325 struct value
*new_val
= NULL
;
3326 struct varobj
*var
= *var_handle
;
3327 int within_scope
= 0;
3328 struct cleanup
*back_to
;
3330 /* Only root variables can be updated... */
3331 if (!is_root_p (var
))
3332 /* Not a root var. */
3335 back_to
= make_cleanup_restore_current_thread ();
3337 /* Determine whether the variable is still around. */
3338 if (var
->root
->valid_block
== NULL
|| var
->root
->floating
)
3340 else if (var
->root
->thread_id
== 0)
3342 /* The program was single-threaded when the variable object was
3343 created. Technically, it's possible that the program became
3344 multi-threaded since then, but we don't support such
3346 within_scope
= check_scope (var
);
3350 ptid_t ptid
= thread_id_to_pid (var
->root
->thread_id
);
3351 if (in_thread_list (ptid
))
3353 switch_to_thread (ptid
);
3354 within_scope
= check_scope (var
);
3360 volatile struct gdb_exception except
;
3362 /* We need to catch errors here, because if evaluate
3363 expression fails we want to just return NULL. */
3364 TRY_CATCH (except
, RETURN_MASK_ERROR
)
3366 new_val
= evaluate_expression (var
->root
->exp
);
3372 do_cleanups (back_to
);
3377 static struct value
*
3378 c_value_of_child (struct varobj
*parent
, int index
)
3380 struct value
*value
= NULL
;
3382 c_describe_child (parent
, index
, NULL
, &value
, NULL
, NULL
);
3386 static struct type
*
3387 c_type_of_child (struct varobj
*parent
, int index
)
3389 struct type
*type
= NULL
;
3391 c_describe_child (parent
, index
, NULL
, NULL
, &type
, NULL
);
3396 c_value_of_variable (struct varobj
*var
, enum varobj_display_formats format
)
3398 /* BOGUS: if val_print sees a struct/class, or a reference to one,
3399 it will print out its children instead of "{...}". So we need to
3400 catch that case explicitly. */
3401 struct type
*type
= get_type (var
);
3403 /* Strip top-level references. */
3404 while (TYPE_CODE (type
) == TYPE_CODE_REF
)
3405 type
= check_typedef (TYPE_TARGET_TYPE (type
));
3407 switch (TYPE_CODE (type
))
3409 case TYPE_CODE_STRUCT
:
3410 case TYPE_CODE_UNION
:
3411 return xstrdup ("{...}");
3414 case TYPE_CODE_ARRAY
:
3418 number
= xstrprintf ("[%d]", var
->num_children
);
3425 if (var
->value
== NULL
)
3427 /* This can happen if we attempt to get the value of a struct
3428 member when the parent is an invalid pointer. This is an
3429 error condition, so we should tell the caller. */
3434 if (var
->not_fetched
&& value_lazy (var
->value
))
3435 /* Frozen variable and no value yet. We don't
3436 implicitly fetch the value. MI response will
3437 use empty string for the value, which is OK. */
3440 gdb_assert (varobj_value_is_changeable_p (var
));
3441 gdb_assert (!value_lazy (var
->value
));
3443 /* If the specified format is the current one,
3444 we can reuse print_value. */
3445 if (format
== var
->format
)
3446 return xstrdup (var
->print_value
);
3448 return value_get_print_value (var
->value
, format
, var
);
3458 cplus_number_of_children (struct varobj
*var
)
3461 int children
, dont_know
;
3466 if (!CPLUS_FAKE_CHILD (var
))
3468 type
= get_value_type (var
);
3469 adjust_value_for_child_access (NULL
, &type
, NULL
);
3471 if (((TYPE_CODE (type
)) == TYPE_CODE_STRUCT
) ||
3472 ((TYPE_CODE (type
)) == TYPE_CODE_UNION
))
3476 cplus_class_num_children (type
, kids
);
3477 if (kids
[v_public
] != 0)
3479 if (kids
[v_private
] != 0)
3481 if (kids
[v_protected
] != 0)
3484 /* Add any baseclasses. */
3485 children
+= TYPE_N_BASECLASSES (type
);
3488 /* FIXME: save children in var. */
3495 type
= get_value_type (var
->parent
);
3496 adjust_value_for_child_access (NULL
, &type
, NULL
);
3498 cplus_class_num_children (type
, kids
);
3499 if (strcmp (var
->name
, "public") == 0)
3500 children
= kids
[v_public
];
3501 else if (strcmp (var
->name
, "private") == 0)
3502 children
= kids
[v_private
];
3504 children
= kids
[v_protected
];
3509 children
= c_number_of_children (var
);
3514 /* Compute # of public, private, and protected variables in this class.
3515 That means we need to descend into all baseclasses and find out
3516 how many are there, too. */
3518 cplus_class_num_children (struct type
*type
, int children
[3])
3520 int i
, vptr_fieldno
;
3521 struct type
*basetype
= NULL
;
3523 children
[v_public
] = 0;
3524 children
[v_private
] = 0;
3525 children
[v_protected
] = 0;
3527 vptr_fieldno
= get_vptr_fieldno (type
, &basetype
);
3528 for (i
= TYPE_N_BASECLASSES (type
); i
< TYPE_NFIELDS (type
); i
++)
3530 /* If we have a virtual table pointer, omit it. Even if virtual
3531 table pointers are not specifically marked in the debug info,
3532 they should be artificial. */
3533 if ((type
== basetype
&& i
== vptr_fieldno
)
3534 || TYPE_FIELD_ARTIFICIAL (type
, i
))
3537 if (TYPE_FIELD_PROTECTED (type
, i
))
3538 children
[v_protected
]++;
3539 else if (TYPE_FIELD_PRIVATE (type
, i
))
3540 children
[v_private
]++;
3542 children
[v_public
]++;
3547 cplus_name_of_variable (struct varobj
*parent
)
3549 return c_name_of_variable (parent
);
3552 enum accessibility
{ private_field
, protected_field
, public_field
};
3554 /* Check if field INDEX of TYPE has the specified accessibility.
3555 Return 0 if so and 1 otherwise. */
3557 match_accessibility (struct type
*type
, int index
, enum accessibility acc
)
3559 if (acc
== private_field
&& TYPE_FIELD_PRIVATE (type
, index
))
3561 else if (acc
== protected_field
&& TYPE_FIELD_PROTECTED (type
, index
))
3563 else if (acc
== public_field
&& !TYPE_FIELD_PRIVATE (type
, index
)
3564 && !TYPE_FIELD_PROTECTED (type
, index
))
3571 cplus_describe_child (struct varobj
*parent
, int index
,
3572 char **cname
, struct value
**cvalue
, struct type
**ctype
,
3573 char **cfull_expression
)
3575 struct value
*value
;
3578 char *parent_expression
= NULL
;
3586 if (cfull_expression
)
3587 *cfull_expression
= NULL
;
3589 if (CPLUS_FAKE_CHILD (parent
))
3591 value
= parent
->parent
->value
;
3592 type
= get_value_type (parent
->parent
);
3593 if (cfull_expression
)
3595 = varobj_get_path_expr (get_path_expr_parent (parent
->parent
));
3599 value
= parent
->value
;
3600 type
= get_value_type (parent
);
3601 if (cfull_expression
)
3603 = varobj_get_path_expr (get_path_expr_parent (parent
));
3606 adjust_value_for_child_access (&value
, &type
, &was_ptr
);
3608 if (TYPE_CODE (type
) == TYPE_CODE_STRUCT
3609 || TYPE_CODE (type
) == TYPE_CODE_UNION
)
3611 char *join
= was_ptr
? "->" : ".";
3613 if (CPLUS_FAKE_CHILD (parent
))
3615 /* The fields of the class type are ordered as they
3616 appear in the class. We are given an index for a
3617 particular access control type ("public","protected",
3618 or "private"). We must skip over fields that don't
3619 have the access control we are looking for to properly
3620 find the indexed field. */
3621 int type_index
= TYPE_N_BASECLASSES (type
);
3622 enum accessibility acc
= public_field
;
3624 struct type
*basetype
= NULL
;
3625 const char *field_name
;
3627 vptr_fieldno
= get_vptr_fieldno (type
, &basetype
);
3628 if (strcmp (parent
->name
, "private") == 0)
3629 acc
= private_field
;
3630 else if (strcmp (parent
->name
, "protected") == 0)
3631 acc
= protected_field
;
3635 if ((type
== basetype
&& type_index
== vptr_fieldno
)
3636 || TYPE_FIELD_ARTIFICIAL (type
, type_index
))
3638 else if (match_accessibility (type
, type_index
, acc
))
3644 /* If the type is anonymous and the field has no name,
3645 set an appopriate name. */
3646 field_name
= TYPE_FIELD_NAME (type
, type_index
);
3647 if (field_name
== NULL
|| *field_name
== '\0')
3651 if (TYPE_CODE (TYPE_FIELD_TYPE (type
, type_index
))
3652 == TYPE_CODE_STRUCT
)
3653 *cname
= xstrdup (ANONYMOUS_STRUCT_NAME
);
3654 else if (TYPE_CODE (TYPE_FIELD_TYPE (type
, type_index
))
3656 *cname
= xstrdup (ANONYMOUS_UNION_NAME
);
3659 if (cfull_expression
)
3660 *cfull_expression
= xstrdup ("");
3665 *cname
= xstrdup (TYPE_FIELD_NAME (type
, type_index
));
3667 if (cfull_expression
)
3669 = xstrprintf ("((%s)%s%s)", parent_expression
, join
,
3673 if (cvalue
&& value
)
3674 *cvalue
= value_struct_element_index (value
, type_index
);
3677 *ctype
= TYPE_FIELD_TYPE (type
, type_index
);
3679 else if (index
< TYPE_N_BASECLASSES (type
))
3681 /* This is a baseclass. */
3683 *cname
= xstrdup (TYPE_FIELD_NAME (type
, index
));
3685 if (cvalue
&& value
)
3686 *cvalue
= value_cast (TYPE_FIELD_TYPE (type
, index
), value
);
3690 *ctype
= TYPE_FIELD_TYPE (type
, index
);
3693 if (cfull_expression
)
3695 char *ptr
= was_ptr
? "*" : "";
3697 /* Cast the parent to the base' type. Note that in gdb,
3700 will create an lvalue, for all appearences, so we don't
3701 need to use more fancy:
3705 When we are in the scope of the base class or of one
3706 of its children, the type field name will be interpreted
3707 as a constructor, if it exists. Therefore, we must
3708 indicate that the name is a class name by using the
3709 'class' keyword. See PR mi/11912 */
3710 *cfull_expression
= xstrprintf ("(%s(class %s%s) %s)",
3712 TYPE_FIELD_NAME (type
, index
),
3719 char *access
= NULL
;
3722 cplus_class_num_children (type
, children
);
3724 /* Everything beyond the baseclasses can
3725 only be "public", "private", or "protected"
3727 The special "fake" children are always output by varobj in
3728 this order. So if INDEX == 2, it MUST be "protected". */
3729 index
-= TYPE_N_BASECLASSES (type
);
3733 if (children
[v_public
] > 0)
3735 else if (children
[v_private
] > 0)
3738 access
= "protected";
3741 if (children
[v_public
] > 0)
3743 if (children
[v_private
] > 0)
3746 access
= "protected";
3748 else if (children
[v_private
] > 0)
3749 access
= "protected";
3752 /* Must be protected. */
3753 access
= "protected";
3760 gdb_assert (access
);
3762 *cname
= xstrdup (access
);
3764 /* Value and type and full expression are null here. */
3769 c_describe_child (parent
, index
, cname
, cvalue
, ctype
, cfull_expression
);
3774 cplus_name_of_child (struct varobj
*parent
, int index
)
3778 cplus_describe_child (parent
, index
, &name
, NULL
, NULL
, NULL
);
3783 cplus_path_expr_of_child (struct varobj
*child
)
3785 cplus_describe_child (child
->parent
, child
->index
, NULL
, NULL
, NULL
,
3787 return child
->path_expr
;
3790 static struct value
*
3791 cplus_value_of_root (struct varobj
**var_handle
)
3793 return c_value_of_root (var_handle
);
3796 static struct value
*
3797 cplus_value_of_child (struct varobj
*parent
, int index
)
3799 struct value
*value
= NULL
;
3801 cplus_describe_child (parent
, index
, NULL
, &value
, NULL
, NULL
);
3805 static struct type
*
3806 cplus_type_of_child (struct varobj
*parent
, int index
)
3808 struct type
*type
= NULL
;
3810 cplus_describe_child (parent
, index
, NULL
, NULL
, &type
, NULL
);
3815 cplus_value_of_variable (struct varobj
*var
,
3816 enum varobj_display_formats format
)
3819 /* If we have one of our special types, don't print out
3821 if (CPLUS_FAKE_CHILD (var
))
3822 return xstrdup ("");
3824 return c_value_of_variable (var
, format
);
3830 java_number_of_children (struct varobj
*var
)
3832 return cplus_number_of_children (var
);
3836 java_name_of_variable (struct varobj
*parent
)
3840 name
= cplus_name_of_variable (parent
);
3841 /* If the name has "-" in it, it is because we
3842 needed to escape periods in the name... */
3845 while (*p
!= '\000')
3856 java_name_of_child (struct varobj
*parent
, int index
)
3860 name
= cplus_name_of_child (parent
, index
);
3861 /* Escape any periods in the name... */
3864 while (*p
!= '\000')
3875 java_path_expr_of_child (struct varobj
*child
)
3880 static struct value
*
3881 java_value_of_root (struct varobj
**var_handle
)
3883 return cplus_value_of_root (var_handle
);
3886 static struct value
*
3887 java_value_of_child (struct varobj
*parent
, int index
)
3889 return cplus_value_of_child (parent
, index
);
3892 static struct type
*
3893 java_type_of_child (struct varobj
*parent
, int index
)
3895 return cplus_type_of_child (parent
, index
);
3899 java_value_of_variable (struct varobj
*var
, enum varobj_display_formats format
)
3901 return cplus_value_of_variable (var
, format
);
3904 /* Ada specific callbacks for VAROBJs. */
3907 ada_number_of_children (struct varobj
*var
)
3909 return ada_varobj_get_number_of_children (var
->value
, var
->type
);
3913 ada_name_of_variable (struct varobj
*parent
)
3915 return c_name_of_variable (parent
);
3919 ada_name_of_child (struct varobj
*parent
, int index
)
3921 return ada_varobj_get_name_of_child (parent
->value
, parent
->type
,
3922 parent
->name
, index
);
3926 ada_path_expr_of_child (struct varobj
*child
)
3928 struct varobj
*parent
= child
->parent
;
3929 const char *parent_path_expr
= varobj_get_path_expr (parent
);
3931 return ada_varobj_get_path_expr_of_child (parent
->value
,
3938 static struct value
*
3939 ada_value_of_root (struct varobj
**var_handle
)
3941 return c_value_of_root (var_handle
);
3944 static struct value
*
3945 ada_value_of_child (struct varobj
*parent
, int index
)
3947 return ada_varobj_get_value_of_child (parent
->value
, parent
->type
,
3948 parent
->name
, index
);
3951 static struct type
*
3952 ada_type_of_child (struct varobj
*parent
, int index
)
3954 return ada_varobj_get_type_of_child (parent
->value
, parent
->type
,
3959 ada_value_of_variable (struct varobj
*var
, enum varobj_display_formats format
)
3961 struct value_print_options opts
;
3963 get_formatted_print_options (&opts
, format_code
[(int) format
]);
3967 return ada_varobj_get_value_of_variable (var
->value
, var
->type
, &opts
);
3970 /* Implement the "value_has_mutated" routine for Ada. */
3973 ada_value_has_mutated (struct varobj
*var
, struct value
*new_val
,
3974 struct type
*new_type
)
3980 /* If the number of fields have changed, then for sure the type
3982 if (ada_varobj_get_number_of_children (new_val
, new_type
)
3983 != var
->num_children
)
3986 /* If the number of fields have remained the same, then we need
3987 to check the name of each field. If they remain the same,
3988 then chances are the type hasn't mutated. This is technically
3989 an incomplete test, as the child's type might have changed
3990 despite the fact that the name remains the same. But we'll
3991 handle this situation by saying that the child has mutated,
3994 If only part (or none!) of the children have been fetched,
3995 then only check the ones we fetched. It does not matter
3996 to the frontend whether a child that it has not fetched yet
3997 has mutated or not. So just assume it hasn't. */
3999 restrict_range (var
->children
, &from
, &to
);
4000 for (i
= from
; i
< to
; i
++)
4001 if (strcmp (ada_varobj_get_name_of_child (new_val
, new_type
,
4003 VEC_index (varobj_p
, var
->children
, i
)->name
) != 0)
4009 /* Iterate all the existing _root_ VAROBJs and call the FUNC callback for them
4010 with an arbitrary caller supplied DATA pointer. */
4013 all_root_varobjs (void (*func
) (struct varobj
*var
, void *data
), void *data
)
4015 struct varobj_root
*var_root
, *var_root_next
;
4017 /* Iterate "safely" - handle if the callee deletes its passed VAROBJ. */
4019 for (var_root
= rootlist
; var_root
!= NULL
; var_root
= var_root_next
)
4021 var_root_next
= var_root
->next
;
4023 (*func
) (var_root
->rootvar
, data
);
4027 extern void _initialize_varobj (void);
4029 _initialize_varobj (void)
4031 int sizeof_table
= sizeof (struct vlist
*) * VAROBJ_TABLE_SIZE
;
4033 varobj_table
= xmalloc (sizeof_table
);
4034 memset (varobj_table
, 0, sizeof_table
);
4036 add_setshow_zinteger_cmd ("debugvarobj", class_maintenance
,
4038 _("Set varobj debugging."),
4039 _("Show varobj debugging."),
4040 _("When non-zero, varobj debugging is enabled."),
4041 NULL
, show_varobjdebug
,
4042 &setlist
, &showlist
);
4045 /* Invalidate varobj VAR if it is tied to locals and re-create it if it is
4046 defined on globals. It is a helper for varobj_invalidate. */
4049 varobj_invalidate_iter (struct varobj
*var
, void *unused
)
4051 /* Floating varobjs are reparsed on each stop, so we don't care if the
4052 presently parsed expression refers to something that's gone. */
4053 if (var
->root
->floating
)
4056 /* global var must be re-evaluated. */
4057 if (var
->root
->valid_block
== NULL
)
4059 struct varobj
*tmp_var
;
4061 /* Try to create a varobj with same expression. If we succeed
4062 replace the old varobj, otherwise invalidate it. */
4063 tmp_var
= varobj_create (NULL
, var
->name
, (CORE_ADDR
) 0,
4065 if (tmp_var
!= NULL
)
4067 tmp_var
->obj_name
= xstrdup (var
->obj_name
);
4068 varobj_delete (var
, NULL
, 0);
4069 install_variable (tmp_var
);
4072 var
->root
->is_valid
= 0;
4074 else /* locals must be invalidated. */
4075 var
->root
->is_valid
= 0;
4078 /* Invalidate the varobjs that are tied to locals and re-create the ones that
4079 are defined on globals.
4080 Invalidated varobjs will be always printed in_scope="invalid". */
4083 varobj_invalidate (void)
4085 all_root_varobjs (varobj_invalidate_iter
, NULL
);