1 /* Implementation of the GDB variable objects API.
3 Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
4 2009 Free Software Foundation, Inc.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 #include "exceptions.h"
22 #include "expression.h"
30 #include "gdb_assert.h"
31 #include "gdb_string.h"
35 #include "gdbthread.h"
39 #include "python/python.h"
40 #include "python/python-internal.h"
45 /* Non-zero if we want to see trace of varobj level stuff. */
49 show_varobjdebug (struct ui_file *file, int from_tty,
50 struct cmd_list_element *c, const char *value)
52 fprintf_filtered (file, _("Varobj debugging is %s.\n"), value);
55 /* String representations of gdb's format codes */
56 char *varobj_format_string[] =
57 { "natural", "binary", "decimal", "hexadecimal", "octal" };
59 /* String representations of gdb's known languages */
60 char *varobj_language_string[] = { "unknown", "C", "C++", "Java" };
64 /* Every root variable has one of these structures saved in its
65 varobj. Members which must be free'd are noted. */
69 /* Alloc'd expression for this parent. */
70 struct expression *exp;
72 /* Block for which this expression is valid */
73 struct block *valid_block;
75 /* The frame for this expression. This field is set iff valid_block is
77 struct frame_id frame;
79 /* The thread ID that this varobj_root belong to. This field
80 is only valid if valid_block is not NULL.
81 When not 0, indicates which thread 'frame' belongs to.
82 When 0, indicates that the thread list was empty when the varobj_root
86 /* If 1, the -var-update always recomputes the value in the
87 current thread and frame. Otherwise, variable object is
88 always updated in the specific scope/thread/frame */
91 /* Flag that indicates validity: set to 0 when this varobj_root refers
92 to symbols that do not exist anymore. */
95 /* Language info for this variable and its children */
96 struct language_specific *lang;
98 /* The varobj for this root node. */
99 struct varobj *rootvar;
101 /* Next root variable */
102 struct varobj_root *next;
105 /* Every variable in the system has a structure of this type defined
106 for it. This structure holds all information necessary to manipulate
107 a particular object variable. Members which must be freed are noted. */
111 /* Alloc'd name of the variable for this object.. If this variable is a
112 child, then this name will be the child's source name.
113 (bar, not foo.bar) */
114 /* NOTE: This is the "expression" */
117 /* Alloc'd expression for this child. Can be used to create a
118 root variable corresponding to this child. */
121 /* The alloc'd name for this variable's object. This is here for
122 convenience when constructing this object's children. */
125 /* Index of this variable in its parent or -1 */
128 /* The type of this variable. This can be NULL
129 for artifial variable objects -- currently, the "accessibility"
130 variable objects in C++. */
133 /* The value of this expression or subexpression. A NULL value
134 indicates there was an error getting this value.
135 Invariant: if varobj_value_is_changeable_p (this) is non-zero,
136 the value is either NULL, or not lazy. */
139 /* The number of (immediate) children this variable has */
142 /* If this object is a child, this points to its immediate parent. */
143 struct varobj *parent;
145 /* Children of this object. */
146 VEC (varobj_p) *children;
148 /* Whether the children of this varobj were requested. This field is
149 used to decide if dynamic varobj should recompute their children.
150 In the event that the frontend never asked for the children, we
152 int children_requested;
154 /* Description of the root variable. Points to root variable for children. */
155 struct varobj_root *root;
157 /* The format of the output for this object */
158 enum varobj_display_formats format;
160 /* Was this variable updated via a varobj_set_value operation */
163 /* Last print value. */
166 /* Is this variable frozen. Frozen variables are never implicitly
167 updated by -var-update *
168 or -var-update <direct-or-indirect-parent>. */
171 /* Is the value of this variable intentionally not fetched? It is
172 not fetched if either the variable is frozen, or any parents is
176 /* The pretty-printer that has been constructed. If NULL, then a
177 new printer object is needed, and one will be constructed. */
178 PyObject *pretty_printer;
184 struct cpstack *next;
187 /* A list of varobjs */
195 /* Private function prototypes */
197 /* Helper functions for the above subcommands. */
199 static int delete_variable (struct cpstack **, struct varobj *, int);
201 static void delete_variable_1 (struct cpstack **, int *,
202 struct varobj *, int, int);
204 static int install_variable (struct varobj *);
206 static void uninstall_variable (struct varobj *);
208 static struct varobj *create_child (struct varobj *, int, char *);
210 static struct varobj *
211 create_child_with_value (struct varobj *parent, int index, const char *name,
212 struct value *value);
214 /* Utility routines */
216 static struct varobj *new_variable (void);
218 static struct varobj *new_root_variable (void);
220 static void free_variable (struct varobj *var);
222 static struct cleanup *make_cleanup_free_variable (struct varobj *var);
224 static struct type *get_type (struct varobj *var);
226 static struct type *get_value_type (struct varobj *var);
228 static struct type *get_target_type (struct type *);
230 static enum varobj_display_formats variable_default_display (struct varobj *);
232 static void cppush (struct cpstack **pstack, char *name);
234 static char *cppop (struct cpstack **pstack);
236 static int install_new_value (struct varobj *var, struct value *value,
239 static void install_default_visualizer (struct varobj *var);
241 /* Language-specific routines. */
243 static enum varobj_languages variable_language (struct varobj *var);
245 static int number_of_children (struct varobj *);
247 static char *name_of_variable (struct varobj *);
249 static char *name_of_child (struct varobj *, int);
251 static struct value *value_of_root (struct varobj **var_handle, int *);
253 static struct value *value_of_child (struct varobj *parent, int index);
255 static char *my_value_of_variable (struct varobj *var,
256 enum varobj_display_formats format);
258 static char *value_get_print_value (struct value *value,
259 enum varobj_display_formats format,
262 static int varobj_value_is_changeable_p (struct varobj *var);
264 static int is_root_p (struct varobj *var);
266 static struct varobj *
267 varobj_add_child (struct varobj *var, const char *name, struct value *value);
269 /* C implementation */
271 static int c_number_of_children (struct varobj *var);
273 static char *c_name_of_variable (struct varobj *parent);
275 static char *c_name_of_child (struct varobj *parent, int index);
277 static char *c_path_expr_of_child (struct varobj *child);
279 static struct value *c_value_of_root (struct varobj **var_handle);
281 static struct value *c_value_of_child (struct varobj *parent, int index);
283 static struct type *c_type_of_child (struct varobj *parent, int index);
285 static char *c_value_of_variable (struct varobj *var,
286 enum varobj_display_formats format);
288 /* C++ implementation */
290 static int cplus_number_of_children (struct varobj *var);
292 static void cplus_class_num_children (struct type *type, int children[3]);
294 static char *cplus_name_of_variable (struct varobj *parent);
296 static char *cplus_name_of_child (struct varobj *parent, int index);
298 static char *cplus_path_expr_of_child (struct varobj *child);
300 static struct value *cplus_value_of_root (struct varobj **var_handle);
302 static struct value *cplus_value_of_child (struct varobj *parent, int index);
304 static struct type *cplus_type_of_child (struct varobj *parent, int index);
306 static char *cplus_value_of_variable (struct varobj *var,
307 enum varobj_display_formats format);
309 /* Java implementation */
311 static int java_number_of_children (struct varobj *var);
313 static char *java_name_of_variable (struct varobj *parent);
315 static char *java_name_of_child (struct varobj *parent, int index);
317 static char *java_path_expr_of_child (struct varobj *child);
319 static struct value *java_value_of_root (struct varobj **var_handle);
321 static struct value *java_value_of_child (struct varobj *parent, int index);
323 static struct type *java_type_of_child (struct varobj *parent, int index);
325 static char *java_value_of_variable (struct varobj *var,
326 enum varobj_display_formats format);
328 /* The language specific vector */
330 struct language_specific
333 /* The language of this variable */
334 enum varobj_languages language;
336 /* The number of children of PARENT. */
337 int (*number_of_children) (struct varobj * parent);
339 /* The name (expression) of a root varobj. */
340 char *(*name_of_variable) (struct varobj * parent);
342 /* The name of the INDEX'th child of PARENT. */
343 char *(*name_of_child) (struct varobj * parent, int index);
345 /* Returns the rooted expression of CHILD, which is a variable
346 obtain that has some parent. */
347 char *(*path_expr_of_child) (struct varobj * child);
349 /* The ``struct value *'' of the root variable ROOT. */
350 struct value *(*value_of_root) (struct varobj ** root_handle);
352 /* The ``struct value *'' of the INDEX'th child of PARENT. */
353 struct value *(*value_of_child) (struct varobj * parent, int index);
355 /* The type of the INDEX'th child of PARENT. */
356 struct type *(*type_of_child) (struct varobj * parent, int index);
358 /* The current value of VAR. */
359 char *(*value_of_variable) (struct varobj * var,
360 enum varobj_display_formats format);
363 /* Array of known source language routines. */
364 static struct language_specific languages[vlang_end] = {
365 /* Unknown (try treating as C */
368 c_number_of_children,
371 c_path_expr_of_child,
380 c_number_of_children,
383 c_path_expr_of_child,
392 cplus_number_of_children,
393 cplus_name_of_variable,
395 cplus_path_expr_of_child,
397 cplus_value_of_child,
399 cplus_value_of_variable}
404 java_number_of_children,
405 java_name_of_variable,
407 java_path_expr_of_child,
411 java_value_of_variable}
414 /* A little convenience enum for dealing with C++/Java */
417 v_public = 0, v_private, v_protected
422 /* Mappings of varobj_display_formats enums to gdb's format codes */
423 static int format_code[] = { 0, 't', 'd', 'x', 'o' };
425 /* Header of the list of root variable objects */
426 static struct varobj_root *rootlist;
428 /* Prime number indicating the number of buckets in the hash table */
429 /* A prime large enough to avoid too many colisions */
430 #define VAROBJ_TABLE_SIZE 227
432 /* Pointer to the varobj hash table (built at run time) */
433 static struct vlist **varobj_table;
435 /* Is the variable X one of our "fake" children? */
436 #define CPLUS_FAKE_CHILD(x) \
437 ((x) != NULL && (x)->type == NULL && (x)->value == NULL)
440 /* API Implementation */
442 is_root_p (struct varobj *var)
444 return (var->root->rootvar == var);
448 /* Helper function to install a Python environment suitable for
449 use during operations on VAR. */
451 varobj_ensure_python_env (struct varobj *var)
453 return ensure_python_env (var->root->exp->gdbarch,
454 var->root->exp->language_defn);
458 /* Creates a varobj (not its children) */
460 /* Return the full FRAME which corresponds to the given CORE_ADDR
461 or NULL if no FRAME on the chain corresponds to CORE_ADDR. */
463 static struct frame_info *
464 find_frame_addr_in_frame_chain (CORE_ADDR frame_addr)
466 struct frame_info *frame = NULL;
468 if (frame_addr == (CORE_ADDR) 0)
471 for (frame = get_current_frame ();
473 frame = get_prev_frame (frame))
475 /* The CORE_ADDR we get as argument was parsed from a string GDB
476 output as $fp. This output got truncated to gdbarch_addr_bit.
477 Truncate the frame base address in the same manner before
478 comparing it against our argument. */
479 CORE_ADDR frame_base = get_frame_base_address (frame);
480 int addr_bit = gdbarch_addr_bit (get_frame_arch (frame));
481 if (addr_bit < (sizeof (CORE_ADDR) * HOST_CHAR_BIT))
482 frame_base &= ((CORE_ADDR) 1 << addr_bit) - 1;
484 if (frame_base == frame_addr)
492 varobj_create (char *objname,
493 char *expression, CORE_ADDR frame, enum varobj_type type)
496 struct frame_info *fi;
497 struct frame_info *old_fi = NULL;
499 struct cleanup *old_chain;
501 /* Fill out a varobj structure for the (root) variable being constructed. */
502 var = new_root_variable ();
503 old_chain = make_cleanup_free_variable (var);
505 if (expression != NULL)
508 enum varobj_languages lang;
509 struct value *value = NULL;
511 /* Parse and evaluate the expression, filling in as much of the
512 variable's data as possible. */
514 if (has_stack_frames ())
516 /* Allow creator to specify context of variable */
517 if ((type == USE_CURRENT_FRAME) || (type == USE_SELECTED_FRAME))
518 fi = get_selected_frame (NULL);
520 /* FIXME: cagney/2002-11-23: This code should be doing a
521 lookup using the frame ID and not just the frame's
522 ``address''. This, of course, means an interface
523 change. However, with out that interface change ISAs,
524 such as the ia64 with its two stacks, won't work.
525 Similar goes for the case where there is a frameless
527 fi = find_frame_addr_in_frame_chain (frame);
532 /* frame = -2 means always use selected frame */
533 if (type == USE_SELECTED_FRAME)
534 var->root->floating = 1;
538 block = get_frame_block (fi, 0);
541 innermost_block = NULL;
542 /* Wrap the call to parse expression, so we can
543 return a sensible error. */
544 if (!gdb_parse_exp_1 (&p, block, 0, &var->root->exp))
549 /* Don't allow variables to be created for types. */
550 if (var->root->exp->elts[0].opcode == OP_TYPE)
552 do_cleanups (old_chain);
553 fprintf_unfiltered (gdb_stderr, "Attempt to use a type name"
554 " as an expression.\n");
558 var->format = variable_default_display (var);
559 var->root->valid_block = innermost_block;
560 var->name = xstrdup (expression);
561 /* For a root var, the name and the expr are the same. */
562 var->path_expr = xstrdup (expression);
564 /* When the frame is different from the current frame,
565 we must select the appropriate frame before parsing
566 the expression, otherwise the value will not be current.
567 Since select_frame is so benign, just call it for all cases. */
568 if (innermost_block && fi != NULL)
570 var->root->frame = get_frame_id (fi);
571 var->root->thread_id = pid_to_thread_id (inferior_ptid);
572 old_fi = get_selected_frame (NULL);
576 /* We definitely need to catch errors here.
577 If evaluate_expression succeeds we got the value we wanted.
578 But if it fails, we still go on with a call to evaluate_type() */
579 if (!gdb_evaluate_expression (var->root->exp, &value))
581 /* Error getting the value. Try to at least get the
583 struct value *type_only_value = evaluate_type (var->root->exp);
584 var->type = value_type (type_only_value);
587 var->type = value_type (value);
589 install_new_value (var, value, 1 /* Initial assignment */);
591 /* Set language info */
592 lang = variable_language (var);
593 var->root->lang = &languages[lang];
595 /* Set ourselves as our root */
596 var->root->rootvar = var;
598 /* Reset the selected frame */
600 select_frame (old_fi);
603 /* If the variable object name is null, that means this
604 is a temporary variable, so don't install it. */
606 if ((var != NULL) && (objname != NULL))
608 var->obj_name = xstrdup (objname);
610 /* If a varobj name is duplicated, the install will fail so
612 if (!install_variable (var))
614 do_cleanups (old_chain);
619 install_default_visualizer (var);
620 discard_cleanups (old_chain);
624 /* Generates an unique name that can be used for a varobj */
627 varobj_gen_name (void)
632 /* generate a name for this object */
634 obj_name = xstrprintf ("var%d", id);
639 /* Given an OBJNAME, returns the pointer to the corresponding varobj. Call
640 error if OBJNAME cannot be found. */
643 varobj_get_handle (char *objname)
647 unsigned int index = 0;
650 for (chp = objname; *chp; chp++)
652 index = (index + (i++ * (unsigned int) *chp)) % VAROBJ_TABLE_SIZE;
655 cv = *(varobj_table + index);
656 while ((cv != NULL) && (strcmp (cv->var->obj_name, objname) != 0))
660 error (_("Variable object not found"));
665 /* Given the handle, return the name of the object */
668 varobj_get_objname (struct varobj *var)
670 return var->obj_name;
673 /* Given the handle, return the expression represented by the object */
676 varobj_get_expression (struct varobj *var)
678 return name_of_variable (var);
681 /* Deletes a varobj and all its children if only_children == 0,
682 otherwise deletes only the children; returns a malloc'ed list of all the
683 (malloc'ed) names of the variables that have been deleted (NULL terminated) */
686 varobj_delete (struct varobj *var, char ***dellist, int only_children)
690 struct cpstack *result = NULL;
693 /* Initialize a stack for temporary results */
694 cppush (&result, NULL);
697 /* Delete only the variable children */
698 delcount = delete_variable (&result, var, 1 /* only the children */ );
700 /* Delete the variable and all its children */
701 delcount = delete_variable (&result, var, 0 /* parent+children */ );
703 /* We may have been asked to return a list of what has been deleted */
706 *dellist = xmalloc ((delcount + 1) * sizeof (char *));
710 *cp = cppop (&result);
711 while ((*cp != NULL) && (mycount > 0))
715 *cp = cppop (&result);
718 if (mycount || (*cp != NULL))
719 warning (_("varobj_delete: assertion failed - mycount(=%d) <> 0"),
726 /* Convenience function for varobj_set_visualizer. Instantiate a
727 pretty-printer for a given value. */
729 instantiate_pretty_printer (PyObject *constructor, struct value *value)
732 PyObject *val_obj = NULL;
734 volatile struct gdb_exception except;
736 TRY_CATCH (except, RETURN_MASK_ALL)
738 value = value_copy (value);
740 GDB_PY_HANDLE_EXCEPTION (except);
741 val_obj = value_to_value_object (value);
746 printer = PyObject_CallFunctionObjArgs (constructor, val_obj, NULL);
753 /* Set/Get variable object display format */
755 enum varobj_display_formats
756 varobj_set_display_format (struct varobj *var,
757 enum varobj_display_formats format)
764 case FORMAT_HEXADECIMAL:
766 var->format = format;
770 var->format = variable_default_display (var);
773 if (varobj_value_is_changeable_p (var)
774 && var->value && !value_lazy (var->value))
776 xfree (var->print_value);
777 var->print_value = value_get_print_value (var->value, var->format, var);
783 enum varobj_display_formats
784 varobj_get_display_format (struct varobj *var)
790 varobj_get_display_hint (struct varobj *var)
795 struct cleanup *back_to = varobj_ensure_python_env (var);
797 if (var->pretty_printer)
798 result = gdbpy_get_display_hint (var->pretty_printer);
800 do_cleanups (back_to);
806 /* If the variable object is bound to a specific thread, that
807 is its evaluation can always be done in context of a frame
808 inside that thread, returns GDB id of the thread -- which
809 is always positive. Otherwise, returns -1. */
811 varobj_get_thread_id (struct varobj *var)
813 if (var->root->valid_block && var->root->thread_id > 0)
814 return var->root->thread_id;
820 varobj_set_frozen (struct varobj *var, int frozen)
822 /* When a variable is unfrozen, we don't fetch its value.
823 The 'not_fetched' flag remains set, so next -var-update
826 We don't fetch the value, because for structures the client
827 should do -var-update anyway. It would be bad to have different
828 client-size logic for structure and other types. */
829 var->frozen = frozen;
833 varobj_get_frozen (struct varobj *var)
839 update_dynamic_varobj_children (struct varobj *var,
840 VEC (varobj_p) **changed,
841 VEC (varobj_p) **new_and_unchanged,
846 /* FIXME: we *might* want to provide this functionality as
847 a standalone function, so that other interested parties
848 than varobj code can benefit for this. */
849 struct cleanup *back_to;
853 int children_changed = 0;
854 PyObject *printer = var->pretty_printer;
856 back_to = varobj_ensure_python_env (var);
859 if (!PyObject_HasAttr (printer, gdbpy_children_cst))
861 do_cleanups (back_to);
865 children = PyObject_CallMethodObjArgs (printer, gdbpy_children_cst,
870 gdbpy_print_stack ();
871 error (_("Null value returned for children"));
874 make_cleanup_py_decref (children);
876 if (!PyIter_Check (children))
877 error (_("Returned value is not iterable"));
879 iterator = PyObject_GetIter (children);
882 gdbpy_print_stack ();
883 error (_("Could not get children iterator"));
885 make_cleanup_py_decref (iterator);
889 PyObject *item = PyIter_Next (iterator);
893 struct cleanup *inner;
897 inner = make_cleanup_py_decref (item);
899 if (!PyArg_ParseTuple (item, "sO", &name, &py_v))
900 error (_("Invalid item from the child list"));
902 v = convert_value_from_python (py_v);
904 /* TODO: This assume the name of the i-th child never changes. */
906 /* Now see what to do here. */
907 if (VEC_length (varobj_p, var->children) < i + 1)
909 /* There's no child yet. */
910 struct varobj *child = varobj_add_child (var, name, v);
911 if (new_and_unchanged)
912 VEC_safe_push (varobj_p, *new_and_unchanged, child);
913 children_changed = 1;
917 varobj_p existing = VEC_index (varobj_p, var->children, i);
918 if (install_new_value (existing, v, 0) && changed)
921 VEC_safe_push (varobj_p, *changed, existing);
925 if (new_and_unchanged)
926 VEC_safe_push (varobj_p, *new_and_unchanged, existing);
933 if (i < VEC_length (varobj_p, var->children))
936 children_changed = 1;
937 for (i = 0; i < VEC_length (varobj_p, var->children); ++i)
938 varobj_delete (VEC_index (varobj_p, var->children, i), NULL, 0);
940 VEC_truncate (varobj_p, var->children, i);
941 var->num_children = VEC_length (varobj_p, var->children);
943 do_cleanups (back_to);
945 *cchanged = children_changed;
948 gdb_assert (0 && "should never be called if Python is not enabled");
953 varobj_get_num_children (struct varobj *var)
955 if (var->num_children == -1)
958 if (!var->pretty_printer
959 || !update_dynamic_varobj_children (var, NULL, NULL, &changed))
960 var->num_children = number_of_children (var);
963 return var->num_children;
966 /* Creates a list of the immediate children of a variable object;
967 the return code is the number of such children or -1 on error */
970 varobj_list_children (struct varobj *var)
972 struct varobj *child;
974 int i, children_changed;
976 var->children_requested = 1;
978 if (var->pretty_printer
979 /* This, in theory, can result in the number of children changing without
980 frontend noticing. But well, calling -var-list-children on the same
981 varobj twice is not something a sane frontend would do. */
982 && update_dynamic_varobj_children (var, NULL, NULL, &children_changed))
983 return var->children;
985 if (var->num_children == -1)
986 var->num_children = number_of_children (var);
988 /* If that failed, give up. */
989 if (var->num_children == -1)
990 return var->children;
992 /* If we're called when the list of children is not yet initialized,
993 allocate enough elements in it. */
994 while (VEC_length (varobj_p, var->children) < var->num_children)
995 VEC_safe_push (varobj_p, var->children, NULL);
997 for (i = 0; i < var->num_children; i++)
999 varobj_p existing = VEC_index (varobj_p, var->children, i);
1001 if (existing == NULL)
1003 /* Either it's the first call to varobj_list_children for
1004 this variable object, and the child was never created,
1005 or it was explicitly deleted by the client. */
1006 name = name_of_child (var, i);
1007 existing = create_child (var, i, name);
1008 VEC_replace (varobj_p, var->children, i, existing);
1009 install_default_visualizer (existing);
1013 return var->children;
1016 static struct varobj *
1017 varobj_add_child (struct varobj *var, const char *name, struct value *value)
1019 varobj_p v = create_child_with_value (var,
1020 VEC_length (varobj_p, var->children),
1022 VEC_safe_push (varobj_p, var->children, v);
1023 install_default_visualizer (v);
1027 /* Obtain the type of an object Variable as a string similar to the one gdb
1028 prints on the console */
1031 varobj_get_type (struct varobj *var)
1033 /* For the "fake" variables, do not return a type. (It's type is
1035 Do not return a type for invalid variables as well. */
1036 if (CPLUS_FAKE_CHILD (var) || !var->root->is_valid)
1039 return type_to_string (var->type);
1042 /* Obtain the type of an object variable. */
1045 varobj_get_gdb_type (struct varobj *var)
1050 /* Return a pointer to the full rooted expression of varobj VAR.
1051 If it has not been computed yet, compute it. */
1053 varobj_get_path_expr (struct varobj *var)
1055 if (var->path_expr != NULL)
1056 return var->path_expr;
1059 /* For root varobjs, we initialize path_expr
1060 when creating varobj, so here it should be
1062 gdb_assert (!is_root_p (var));
1063 return (*var->root->lang->path_expr_of_child) (var);
1067 enum varobj_languages
1068 varobj_get_language (struct varobj *var)
1070 return variable_language (var);
1074 varobj_get_attributes (struct varobj *var)
1078 if (varobj_editable_p (var))
1079 /* FIXME: define masks for attributes */
1080 attributes |= 0x00000001; /* Editable */
1086 varobj_get_formatted_value (struct varobj *var,
1087 enum varobj_display_formats format)
1089 return my_value_of_variable (var, format);
1093 varobj_get_value (struct varobj *var)
1095 return my_value_of_variable (var, var->format);
1098 /* Set the value of an object variable (if it is editable) to the
1099 value of the given expression */
1100 /* Note: Invokes functions that can call error() */
1103 varobj_set_value (struct varobj *var, char *expression)
1109 /* The argument "expression" contains the variable's new value.
1110 We need to first construct a legal expression for this -- ugh! */
1111 /* Does this cover all the bases? */
1112 struct expression *exp;
1113 struct value *value;
1114 int saved_input_radix = input_radix;
1115 char *s = expression;
1118 gdb_assert (varobj_editable_p (var));
1120 input_radix = 10; /* ALWAYS reset to decimal temporarily */
1121 exp = parse_exp_1 (&s, 0, 0);
1122 if (!gdb_evaluate_expression (exp, &value))
1124 /* We cannot proceed without a valid expression. */
1129 /* All types that are editable must also be changeable. */
1130 gdb_assert (varobj_value_is_changeable_p (var));
1132 /* The value of a changeable variable object must not be lazy. */
1133 gdb_assert (!value_lazy (var->value));
1135 /* Need to coerce the input. We want to check if the
1136 value of the variable object will be different
1137 after assignment, and the first thing value_assign
1138 does is coerce the input.
1139 For example, if we are assigning an array to a pointer variable we
1140 should compare the pointer with the the array's address, not with the
1142 value = coerce_array (value);
1144 /* The new value may be lazy. gdb_value_assign, or
1145 rather value_contents, will take care of this.
1146 If fetching of the new value will fail, gdb_value_assign
1147 with catch the exception. */
1148 if (!gdb_value_assign (var->value, value, &val))
1151 /* If the value has changed, record it, so that next -var-update can
1152 report this change. If a variable had a value of '1', we've set it
1153 to '333' and then set again to '1', when -var-update will report this
1154 variable as changed -- because the first assignment has set the
1155 'updated' flag. There's no need to optimize that, because return value
1156 of -var-update should be considered an approximation. */
1157 var->updated = install_new_value (var, val, 0 /* Compare values. */);
1158 input_radix = saved_input_radix;
1162 /* Assign a new value to a variable object. If INITIAL is non-zero,
1163 this is the first assignement after the variable object was just
1164 created, or changed type. In that case, just assign the value
1166 Otherwise, assign the new value, and return 1 if the value is different
1167 from the current one, 0 otherwise. The comparison is done on textual
1168 representation of value. Therefore, some types need not be compared. E.g.
1169 for structures the reported value is always "{...}", so no comparison is
1170 necessary here. If the old value was NULL and new one is not, or vice versa,
1173 The VALUE parameter should not be released -- the function will
1174 take care of releasing it when needed. */
1176 install_new_value (struct varobj *var, struct value *value, int initial)
1181 int intentionally_not_fetched = 0;
1182 char *print_value = NULL;
1184 /* We need to know the varobj's type to decide if the value should
1185 be fetched or not. C++ fake children (public/protected/private) don't have
1187 gdb_assert (var->type || CPLUS_FAKE_CHILD (var));
1188 changeable = varobj_value_is_changeable_p (var);
1190 /* If the type has custom visualizer, we consider it to be always
1191 changeable. FIXME: need to make sure this behaviour will not
1192 mess up read-sensitive values. */
1193 if (var->pretty_printer)
1196 need_to_fetch = changeable;
1198 /* We are not interested in the address of references, and given
1199 that in C++ a reference is not rebindable, it cannot
1200 meaningfully change. So, get hold of the real value. */
1203 value = coerce_ref (value);
1204 release_value (value);
1207 if (var->type && TYPE_CODE (var->type) == TYPE_CODE_UNION)
1208 /* For unions, we need to fetch the value implicitly because
1209 of implementation of union member fetch. When gdb
1210 creates a value for a field and the value of the enclosing
1211 structure is not lazy, it immediately copies the necessary
1212 bytes from the enclosing values. If the enclosing value is
1213 lazy, the call to value_fetch_lazy on the field will read
1214 the data from memory. For unions, that means we'll read the
1215 same memory more than once, which is not desirable. So
1219 /* The new value might be lazy. If the type is changeable,
1220 that is we'll be comparing values of this type, fetch the
1221 value now. Otherwise, on the next update the old value
1222 will be lazy, which means we've lost that old value. */
1223 if (need_to_fetch && value && value_lazy (value))
1225 struct varobj *parent = var->parent;
1226 int frozen = var->frozen;
1227 for (; !frozen && parent; parent = parent->parent)
1228 frozen |= parent->frozen;
1230 if (frozen && initial)
1232 /* For variables that are frozen, or are children of frozen
1233 variables, we don't do fetch on initial assignment.
1234 For non-initial assignemnt we do the fetch, since it means we're
1235 explicitly asked to compare the new value with the old one. */
1236 intentionally_not_fetched = 1;
1238 else if (!gdb_value_fetch_lazy (value))
1240 /* Set the value to NULL, so that for the next -var-update,
1241 we don't try to compare the new value with this value,
1242 that we couldn't even read. */
1248 /* Below, we'll be comparing string rendering of old and new
1249 values. Don't get string rendering if the value is
1250 lazy -- if it is, the code above has decided that the value
1251 should not be fetched. */
1252 if (value && !value_lazy (value))
1253 print_value = value_get_print_value (value, var->format, var);
1255 /* If the type is changeable, compare the old and the new values.
1256 If this is the initial assignment, we don't have any old value
1258 if (!initial && changeable)
1260 /* If the value of the varobj was changed by -var-set-value, then the
1261 value in the varobj and in the target is the same. However, that value
1262 is different from the value that the varobj had after the previous
1263 -var-update. So need to the varobj as changed. */
1270 /* Try to compare the values. That requires that both
1271 values are non-lazy. */
1272 if (var->not_fetched && value_lazy (var->value))
1274 /* This is a frozen varobj and the value was never read.
1275 Presumably, UI shows some "never read" indicator.
1276 Now that we've fetched the real value, we need to report
1277 this varobj as changed so that UI can show the real
1281 else if (var->value == NULL && value == NULL)
1284 else if (var->value == NULL || value == NULL)
1290 gdb_assert (!value_lazy (var->value));
1291 gdb_assert (!value_lazy (value));
1293 gdb_assert (var->print_value != NULL && print_value != NULL);
1294 if (strcmp (var->print_value, print_value) != 0)
1300 if (!initial && !changeable)
1302 /* For values that are not changeable, we don't compare the values.
1303 However, we want to notice if a value was not NULL and now is NULL,
1304 or vise versa, so that we report when top-level varobjs come in scope
1305 and leave the scope. */
1306 changed = (var->value != NULL) != (value != NULL);
1309 /* We must always keep the new value, since children depend on it. */
1310 if (var->value != NULL && var->value != value)
1311 value_free (var->value);
1313 if (var->print_value)
1314 xfree (var->print_value);
1315 var->print_value = print_value;
1316 if (value && value_lazy (value) && intentionally_not_fetched)
1317 var->not_fetched = 1;
1319 var->not_fetched = 0;
1322 gdb_assert (!var->value || value_type (var->value));
1328 install_visualizer (struct varobj *var, PyObject *visualizer)
1331 /* If there are any children now, wipe them. */
1332 varobj_delete (var, NULL, 1 /* children only */);
1333 var->num_children = -1;
1335 Py_XDECREF (var->pretty_printer);
1336 var->pretty_printer = visualizer;
1338 install_new_value (var, var->value, 1);
1340 /* If we removed the visualizer, and the user ever requested the
1341 object's children, then we must compute the list of children.
1342 Note that we needn't do this when installing a visualizer,
1343 because updating will recompute dynamic children. */
1344 if (!visualizer && var->children_requested)
1345 varobj_list_children (var);
1347 error (_("Python support required"));
1352 install_default_visualizer (struct varobj *var)
1355 struct cleanup *cleanup;
1356 PyObject *pretty_printer = NULL;
1358 cleanup = varobj_ensure_python_env (var);
1362 pretty_printer = gdbpy_get_varobj_pretty_printer (var->value);
1363 if (! pretty_printer)
1365 gdbpy_print_stack ();
1366 error (_("Cannot instantiate printer for default visualizer"));
1370 if (pretty_printer == Py_None)
1372 Py_DECREF (pretty_printer);
1373 pretty_printer = NULL;
1376 install_visualizer (var, pretty_printer);
1377 do_cleanups (cleanup);
1379 /* No error is right as this function is inserted just as a hook. */
1384 varobj_set_visualizer (struct varobj *var, const char *visualizer)
1387 PyObject *mainmod, *globals, *pretty_printer, *constructor;
1388 struct cleanup *back_to, *value;
1390 back_to = varobj_ensure_python_env (var);
1392 mainmod = PyImport_AddModule ("__main__");
1393 globals = PyModule_GetDict (mainmod);
1394 Py_INCREF (globals);
1395 make_cleanup_py_decref (globals);
1397 constructor = PyRun_String (visualizer, Py_eval_input, globals, globals);
1399 /* Do not instantiate NoneType. */
1400 if (constructor == Py_None)
1402 pretty_printer = Py_None;
1403 Py_INCREF (pretty_printer);
1406 pretty_printer = instantiate_pretty_printer (constructor, var->value);
1408 Py_XDECREF (constructor);
1410 if (! pretty_printer)
1412 gdbpy_print_stack ();
1413 error (_("Could not evaluate visualizer expression: %s"), visualizer);
1416 if (pretty_printer == Py_None)
1418 Py_DECREF (pretty_printer);
1419 pretty_printer = NULL;
1422 install_visualizer (var, pretty_printer);
1424 do_cleanups (back_to);
1426 error (_("Python support required"));
1430 /* Update the values for a variable and its children. This is a
1431 two-pronged attack. First, re-parse the value for the root's
1432 expression to see if it's changed. Then go all the way
1433 through its children, reconstructing them and noting if they've
1436 The EXPLICIT parameter specifies if this call is result
1437 of MI request to update this specific variable, or
1438 result of implicit -var-update *. For implicit request, we don't
1439 update frozen variables.
1441 NOTE: This function may delete the caller's varobj. If it
1442 returns TYPE_CHANGED, then it has done this and VARP will be modified
1443 to point to the new varobj. */
1445 VEC(varobj_update_result) *varobj_update (struct varobj **varp, int explicit)
1448 int type_changed = 0;
1453 struct varobj **templist = NULL;
1455 VEC (varobj_update_result) *stack = NULL;
1456 VEC (varobj_update_result) *result = NULL;
1457 struct frame_info *fi;
1459 /* Frozen means frozen -- we don't check for any change in
1460 this varobj, including its going out of scope, or
1461 changing type. One use case for frozen varobjs is
1462 retaining previously evaluated expressions, and we don't
1463 want them to be reevaluated at all. */
1464 if (!explicit && (*varp)->frozen)
1467 if (!(*varp)->root->is_valid)
1469 varobj_update_result r = {*varp};
1470 r.status = VAROBJ_INVALID;
1471 VEC_safe_push (varobj_update_result, result, &r);
1475 if ((*varp)->root->rootvar == *varp)
1477 varobj_update_result r = {*varp};
1478 r.status = VAROBJ_IN_SCOPE;
1480 /* Update the root variable. value_of_root can return NULL
1481 if the variable is no longer around, i.e. we stepped out of
1482 the frame in which a local existed. We are letting the
1483 value_of_root variable dispose of the varobj if the type
1485 new = value_of_root (varp, &type_changed);
1488 r.type_changed = type_changed;
1489 if (install_new_value ((*varp), new, type_changed))
1493 r.status = VAROBJ_NOT_IN_SCOPE;
1494 r.value_installed = 1;
1496 if (r.status == VAROBJ_NOT_IN_SCOPE)
1498 if (r.type_changed || r.changed)
1499 VEC_safe_push (varobj_update_result, result, &r);
1503 VEC_safe_push (varobj_update_result, stack, &r);
1507 varobj_update_result r = {*varp};
1508 VEC_safe_push (varobj_update_result, stack, &r);
1511 /* Walk through the children, reconstructing them all. */
1512 while (!VEC_empty (varobj_update_result, stack))
1514 varobj_update_result r = *(VEC_last (varobj_update_result, stack));
1515 struct varobj *v = r.varobj;
1517 VEC_pop (varobj_update_result, stack);
1519 /* Update this variable, unless it's a root, which is already
1521 if (!r.value_installed)
1523 new = value_of_child (v->parent, v->index);
1524 if (install_new_value (v, new, 0 /* type not changed */))
1531 /* We probably should not get children of a varobj that has a
1532 pretty-printer, but for which -var-list-children was never
1533 invoked. Presumably, such varobj is not yet expanded in the
1534 UI, so we need not bother getting it. */
1535 if (v->pretty_printer)
1537 VEC (varobj_p) *changed = 0, *new_and_unchanged = 0;
1538 int i, children_changed;
1541 if (!v->children_requested)
1547 /* If update_dynamic_varobj_children returns 0, then we have
1548 a non-conforming pretty-printer, so we skip it. */
1549 if (update_dynamic_varobj_children (v, &changed, &new_and_unchanged,
1552 if (children_changed)
1553 r.children_changed = 1;
1554 for (i = 0; VEC_iterate (varobj_p, changed, i, tmp); ++i)
1556 varobj_update_result r = {tmp};
1558 r.value_installed = 1;
1559 VEC_safe_push (varobj_update_result, stack, &r);
1562 VEC_iterate (varobj_p, new_and_unchanged, i, tmp);
1565 varobj_update_result r = {tmp};
1566 r.value_installed = 1;
1567 VEC_safe_push (varobj_update_result, stack, &r);
1569 if (r.changed || r.children_changed)
1570 VEC_safe_push (varobj_update_result, result, &r);
1575 /* Push any children. Use reverse order so that the first
1576 child is popped from the work stack first, and so
1577 will be added to result first. This does not
1578 affect correctness, just "nicer". */
1579 for (i = VEC_length (varobj_p, v->children)-1; i >= 0; --i)
1581 varobj_p c = VEC_index (varobj_p, v->children, i);
1582 /* Child may be NULL if explicitly deleted by -var-delete. */
1583 if (c != NULL && !c->frozen)
1585 varobj_update_result r = {c};
1586 VEC_safe_push (varobj_update_result, stack, &r);
1590 if (r.changed || r.type_changed)
1591 VEC_safe_push (varobj_update_result, result, &r);
1594 VEC_free (varobj_update_result, stack);
1600 /* Helper functions */
1603 * Variable object construction/destruction
1607 delete_variable (struct cpstack **resultp, struct varobj *var,
1608 int only_children_p)
1612 delete_variable_1 (resultp, &delcount, var,
1613 only_children_p, 1 /* remove_from_parent_p */ );
1618 /* Delete the variable object VAR and its children */
1619 /* IMPORTANT NOTE: If we delete a variable which is a child
1620 and the parent is not removed we dump core. It must be always
1621 initially called with remove_from_parent_p set */
1623 delete_variable_1 (struct cpstack **resultp, int *delcountp,
1624 struct varobj *var, int only_children_p,
1625 int remove_from_parent_p)
1629 /* Delete any children of this variable, too. */
1630 for (i = 0; i < VEC_length (varobj_p, var->children); ++i)
1632 varobj_p child = VEC_index (varobj_p, var->children, i);
1635 if (!remove_from_parent_p)
1636 child->parent = NULL;
1637 delete_variable_1 (resultp, delcountp, child, 0, only_children_p);
1639 VEC_free (varobj_p, var->children);
1641 /* if we were called to delete only the children we are done here */
1642 if (only_children_p)
1645 /* Otherwise, add it to the list of deleted ones and proceed to do so */
1646 /* If the name is null, this is a temporary variable, that has not
1647 yet been installed, don't report it, it belongs to the caller... */
1648 if (var->obj_name != NULL)
1650 cppush (resultp, xstrdup (var->obj_name));
1651 *delcountp = *delcountp + 1;
1654 /* If this variable has a parent, remove it from its parent's list */
1655 /* OPTIMIZATION: if the parent of this variable is also being deleted,
1656 (as indicated by remove_from_parent_p) we don't bother doing an
1657 expensive list search to find the element to remove when we are
1658 discarding the list afterwards */
1659 if ((remove_from_parent_p) && (var->parent != NULL))
1661 VEC_replace (varobj_p, var->parent->children, var->index, NULL);
1664 if (var->obj_name != NULL)
1665 uninstall_variable (var);
1667 /* Free memory associated with this variable */
1668 free_variable (var);
1671 /* Install the given variable VAR with the object name VAR->OBJ_NAME. */
1673 install_variable (struct varobj *var)
1676 struct vlist *newvl;
1678 unsigned int index = 0;
1681 for (chp = var->obj_name; *chp; chp++)
1683 index = (index + (i++ * (unsigned int) *chp)) % VAROBJ_TABLE_SIZE;
1686 cv = *(varobj_table + index);
1687 while ((cv != NULL) && (strcmp (cv->var->obj_name, var->obj_name) != 0))
1691 error (_("Duplicate variable object name"));
1693 /* Add varobj to hash table */
1694 newvl = xmalloc (sizeof (struct vlist));
1695 newvl->next = *(varobj_table + index);
1697 *(varobj_table + index) = newvl;
1699 /* If root, add varobj to root list */
1700 if (is_root_p (var))
1702 /* Add to list of root variables */
1703 if (rootlist == NULL)
1704 var->root->next = NULL;
1706 var->root->next = rootlist;
1707 rootlist = var->root;
1713 /* Unistall the object VAR. */
1715 uninstall_variable (struct varobj *var)
1719 struct varobj_root *cr;
1720 struct varobj_root *prer;
1722 unsigned int index = 0;
1725 /* Remove varobj from hash table */
1726 for (chp = var->obj_name; *chp; chp++)
1728 index = (index + (i++ * (unsigned int) *chp)) % VAROBJ_TABLE_SIZE;
1731 cv = *(varobj_table + index);
1733 while ((cv != NULL) && (strcmp (cv->var->obj_name, var->obj_name) != 0))
1740 fprintf_unfiltered (gdb_stdlog, "Deleting %s\n", var->obj_name);
1745 ("Assertion failed: Could not find variable object \"%s\" to delete",
1751 *(varobj_table + index) = cv->next;
1753 prev->next = cv->next;
1757 /* If root, remove varobj from root list */
1758 if (is_root_p (var))
1760 /* Remove from list of root variables */
1761 if (rootlist == var->root)
1762 rootlist = var->root->next;
1767 while ((cr != NULL) && (cr->rootvar != var))
1775 ("Assertion failed: Could not find varobj \"%s\" in root list",
1782 prer->next = cr->next;
1788 /* Create and install a child of the parent of the given name */
1789 static struct varobj *
1790 create_child (struct varobj *parent, int index, char *name)
1792 return create_child_with_value (parent, index, name,
1793 value_of_child (parent, index));
1796 static struct varobj *
1797 create_child_with_value (struct varobj *parent, int index, const char *name,
1798 struct value *value)
1800 struct varobj *child;
1803 child = new_variable ();
1805 /* name is allocated by name_of_child */
1806 /* FIXME: xstrdup should not be here. */
1807 child->name = xstrdup (name);
1808 child->index = index;
1809 child->parent = parent;
1810 child->root = parent->root;
1811 childs_name = xstrprintf ("%s.%s", parent->obj_name, name);
1812 child->obj_name = childs_name;
1813 install_variable (child);
1815 /* Compute the type of the child. Must do this before
1816 calling install_new_value. */
1818 /* If the child had no evaluation errors, var->value
1819 will be non-NULL and contain a valid type. */
1820 child->type = value_type (value);
1822 /* Otherwise, we must compute the type. */
1823 child->type = (*child->root->lang->type_of_child) (child->parent,
1825 install_new_value (child, value, 1);
1832 * Miscellaneous utility functions.
1835 /* Allocate memory and initialize a new variable */
1836 static struct varobj *
1841 var = (struct varobj *) xmalloc (sizeof (struct varobj));
1843 var->path_expr = NULL;
1844 var->obj_name = NULL;
1848 var->num_children = -1;
1850 var->children = NULL;
1854 var->print_value = NULL;
1856 var->not_fetched = 0;
1857 var->children_requested = 0;
1858 var->pretty_printer = 0;
1863 /* Allocate memory and initialize a new root variable */
1864 static struct varobj *
1865 new_root_variable (void)
1867 struct varobj *var = new_variable ();
1868 var->root = (struct varobj_root *) xmalloc (sizeof (struct varobj_root));;
1869 var->root->lang = NULL;
1870 var->root->exp = NULL;
1871 var->root->valid_block = NULL;
1872 var->root->frame = null_frame_id;
1873 var->root->floating = 0;
1874 var->root->rootvar = NULL;
1875 var->root->is_valid = 1;
1880 /* Free any allocated memory associated with VAR. */
1882 free_variable (struct varobj *var)
1885 if (var->pretty_printer)
1887 struct cleanup *cleanup = varobj_ensure_python_env (var);
1888 Py_DECREF (var->pretty_printer);
1889 do_cleanups (cleanup);
1893 value_free (var->value);
1895 /* Free the expression if this is a root variable. */
1896 if (is_root_p (var))
1898 xfree (var->root->exp);
1903 xfree (var->obj_name);
1904 xfree (var->print_value);
1905 xfree (var->path_expr);
1910 do_free_variable_cleanup (void *var)
1912 free_variable (var);
1915 static struct cleanup *
1916 make_cleanup_free_variable (struct varobj *var)
1918 return make_cleanup (do_free_variable_cleanup, var);
1921 /* This returns the type of the variable. It also skips past typedefs
1922 to return the real type of the variable.
1924 NOTE: TYPE_TARGET_TYPE should NOT be used anywhere in this file
1925 except within get_target_type and get_type. */
1926 static struct type *
1927 get_type (struct varobj *var)
1933 type = check_typedef (type);
1938 /* Return the type of the value that's stored in VAR,
1939 or that would have being stored there if the
1940 value were accessible.
1942 This differs from VAR->type in that VAR->type is always
1943 the true type of the expession in the source language.
1944 The return value of this function is the type we're
1945 actually storing in varobj, and using for displaying
1946 the values and for comparing previous and new values.
1948 For example, top-level references are always stripped. */
1949 static struct type *
1950 get_value_type (struct varobj *var)
1955 type = value_type (var->value);
1959 type = check_typedef (type);
1961 if (TYPE_CODE (type) == TYPE_CODE_REF)
1962 type = get_target_type (type);
1964 type = check_typedef (type);
1969 /* This returns the target type (or NULL) of TYPE, also skipping
1970 past typedefs, just like get_type ().
1972 NOTE: TYPE_TARGET_TYPE should NOT be used anywhere in this file
1973 except within get_target_type and get_type. */
1974 static struct type *
1975 get_target_type (struct type *type)
1979 type = TYPE_TARGET_TYPE (type);
1981 type = check_typedef (type);
1987 /* What is the default display for this variable? We assume that
1988 everything is "natural". Any exceptions? */
1989 static enum varobj_display_formats
1990 variable_default_display (struct varobj *var)
1992 return FORMAT_NATURAL;
1995 /* FIXME: The following should be generic for any pointer */
1997 cppush (struct cpstack **pstack, char *name)
2001 s = (struct cpstack *) xmalloc (sizeof (struct cpstack));
2007 /* FIXME: The following should be generic for any pointer */
2009 cppop (struct cpstack **pstack)
2014 if ((*pstack)->name == NULL && (*pstack)->next == NULL)
2019 *pstack = (*pstack)->next;
2026 * Language-dependencies
2029 /* Common entry points */
2031 /* Get the language of variable VAR. */
2032 static enum varobj_languages
2033 variable_language (struct varobj *var)
2035 enum varobj_languages lang;
2037 switch (var->root->exp->language_defn->la_language)
2043 case language_cplus:
2054 /* Return the number of children for a given variable.
2055 The result of this function is defined by the language
2056 implementation. The number of children returned by this function
2057 is the number of children that the user will see in the variable
2060 number_of_children (struct varobj *var)
2062 return (*var->root->lang->number_of_children) (var);;
2065 /* What is the expression for the root varobj VAR? Returns a malloc'd string. */
2067 name_of_variable (struct varobj *var)
2069 return (*var->root->lang->name_of_variable) (var);
2072 /* What is the name of the INDEX'th child of VAR? Returns a malloc'd string. */
2074 name_of_child (struct varobj *var, int index)
2076 return (*var->root->lang->name_of_child) (var, index);
2079 /* What is the ``struct value *'' of the root variable VAR?
2080 For floating variable object, evaluation can get us a value
2081 of different type from what is stored in varobj already. In
2083 - *type_changed will be set to 1
2084 - old varobj will be freed, and new one will be
2085 created, with the same name.
2086 - *var_handle will be set to the new varobj
2087 Otherwise, *type_changed will be set to 0. */
2088 static struct value *
2089 value_of_root (struct varobj **var_handle, int *type_changed)
2093 if (var_handle == NULL)
2098 /* This should really be an exception, since this should
2099 only get called with a root variable. */
2101 if (!is_root_p (var))
2104 if (var->root->floating)
2106 struct varobj *tmp_var;
2107 char *old_type, *new_type;
2109 tmp_var = varobj_create (NULL, var->name, (CORE_ADDR) 0,
2110 USE_SELECTED_FRAME);
2111 if (tmp_var == NULL)
2115 old_type = varobj_get_type (var);
2116 new_type = varobj_get_type (tmp_var);
2117 if (strcmp (old_type, new_type) == 0)
2119 /* The expression presently stored inside var->root->exp
2120 remembers the locations of local variables relatively to
2121 the frame where the expression was created (in DWARF location
2122 button, for example). Naturally, those locations are not
2123 correct in other frames, so update the expression. */
2125 struct expression *tmp_exp = var->root->exp;
2126 var->root->exp = tmp_var->root->exp;
2127 tmp_var->root->exp = tmp_exp;
2129 varobj_delete (tmp_var, NULL, 0);
2134 tmp_var->obj_name = xstrdup (var->obj_name);
2135 varobj_delete (var, NULL, 0);
2137 install_variable (tmp_var);
2138 *var_handle = tmp_var;
2150 return (*var->root->lang->value_of_root) (var_handle);
2153 /* What is the ``struct value *'' for the INDEX'th child of PARENT? */
2154 static struct value *
2155 value_of_child (struct varobj *parent, int index)
2157 struct value *value;
2159 value = (*parent->root->lang->value_of_child) (parent, index);
2164 /* GDB already has a command called "value_of_variable". Sigh. */
2166 my_value_of_variable (struct varobj *var, enum varobj_display_formats format)
2168 if (var->root->is_valid)
2169 return (*var->root->lang->value_of_variable) (var, format);
2175 value_get_print_value (struct value *value, enum varobj_display_formats format,
2178 struct ui_file *stb;
2179 struct cleanup *old_chain;
2180 gdb_byte *thevalue = NULL;
2181 struct value_print_options opts;
2189 struct cleanup *back_to = varobj_ensure_python_env (var);
2190 PyObject *value_formatter = var->pretty_printer;
2192 if (value_formatter && PyObject_HasAttr (value_formatter,
2193 gdbpy_to_string_cst))
2196 struct value *replacement;
2197 int string_print = 0;
2198 PyObject *output = NULL;
2200 hint = gdbpy_get_display_hint (value_formatter);
2203 if (!strcmp (hint, "string"))
2208 output = apply_varobj_pretty_printer (value_formatter,
2212 PyObject *py_str = python_string_to_target_python_string (output);
2215 char *s = PyString_AsString (py_str);
2216 len = PyString_Size (py_str);
2217 thevalue = xmemdup (s, len + 1, len + 1);
2222 if (thevalue && !string_print)
2224 do_cleanups (back_to);
2228 value = replacement;
2230 do_cleanups (back_to);
2234 stb = mem_fileopen ();
2235 old_chain = make_cleanup_ui_file_delete (stb);
2237 get_formatted_print_options (&opts, format_code[(int) format]);
2242 struct gdbarch *gdbarch = get_type_arch (value_type (value));
2243 make_cleanup (xfree, thevalue);
2244 LA_PRINT_STRING (stb, builtin_type (gdbarch)->builtin_char,
2245 thevalue, len, 0, &opts);
2248 common_val_print (value, stb, 0, &opts, current_language);
2249 thevalue = ui_file_xstrdup (stb, NULL);
2251 do_cleanups (old_chain);
2256 varobj_editable_p (struct varobj *var)
2259 struct value *value;
2261 if (!(var->root->is_valid && var->value && VALUE_LVAL (var->value)))
2264 type = get_value_type (var);
2266 switch (TYPE_CODE (type))
2268 case TYPE_CODE_STRUCT:
2269 case TYPE_CODE_UNION:
2270 case TYPE_CODE_ARRAY:
2271 case TYPE_CODE_FUNC:
2272 case TYPE_CODE_METHOD:
2282 /* Return non-zero if changes in value of VAR
2283 must be detected and reported by -var-update.
2284 Return zero is -var-update should never report
2285 changes of such values. This makes sense for structures
2286 (since the changes in children values will be reported separately),
2287 or for artifical objects (like 'public' pseudo-field in C++).
2289 Return value of 0 means that gdb need not call value_fetch_lazy
2290 for the value of this variable object. */
2292 varobj_value_is_changeable_p (struct varobj *var)
2297 if (CPLUS_FAKE_CHILD (var))
2300 type = get_value_type (var);
2302 switch (TYPE_CODE (type))
2304 case TYPE_CODE_STRUCT:
2305 case TYPE_CODE_UNION:
2306 case TYPE_CODE_ARRAY:
2317 /* Return 1 if that varobj is floating, that is is always evaluated in the
2318 selected frame, and not bound to thread/frame. Such variable objects
2319 are created using '@' as frame specifier to -var-create. */
2321 varobj_floating_p (struct varobj *var)
2323 return var->root->floating;
2326 /* Given the value and the type of a variable object,
2327 adjust the value and type to those necessary
2328 for getting children of the variable object.
2329 This includes dereferencing top-level references
2330 to all types and dereferencing pointers to
2333 Both TYPE and *TYPE should be non-null. VALUE
2334 can be null if we want to only translate type.
2335 *VALUE can be null as well -- if the parent
2338 If WAS_PTR is not NULL, set *WAS_PTR to 0 or 1
2339 depending on whether pointer was dereferenced
2340 in this function. */
2342 adjust_value_for_child_access (struct value **value,
2346 gdb_assert (type && *type);
2351 *type = check_typedef (*type);
2353 /* The type of value stored in varobj, that is passed
2354 to us, is already supposed to be
2355 reference-stripped. */
2357 gdb_assert (TYPE_CODE (*type) != TYPE_CODE_REF);
2359 /* Pointers to structures are treated just like
2360 structures when accessing children. Don't
2361 dererences pointers to other types. */
2362 if (TYPE_CODE (*type) == TYPE_CODE_PTR)
2364 struct type *target_type = get_target_type (*type);
2365 if (TYPE_CODE (target_type) == TYPE_CODE_STRUCT
2366 || TYPE_CODE (target_type) == TYPE_CODE_UNION)
2368 if (value && *value)
2370 int success = gdb_value_ind (*value, value);
2374 *type = target_type;
2380 /* The 'get_target_type' function calls check_typedef on
2381 result, so we can immediately check type code. No
2382 need to call check_typedef here. */
2387 c_number_of_children (struct varobj *var)
2389 struct type *type = get_value_type (var);
2391 struct type *target;
2393 adjust_value_for_child_access (NULL, &type, NULL);
2394 target = get_target_type (type);
2396 switch (TYPE_CODE (type))
2398 case TYPE_CODE_ARRAY:
2399 if (TYPE_LENGTH (type) > 0 && TYPE_LENGTH (target) > 0
2400 && !TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (type))
2401 children = TYPE_LENGTH (type) / TYPE_LENGTH (target);
2403 /* If we don't know how many elements there are, don't display
2408 case TYPE_CODE_STRUCT:
2409 case TYPE_CODE_UNION:
2410 children = TYPE_NFIELDS (type);
2414 /* The type here is a pointer to non-struct. Typically, pointers
2415 have one child, except for function ptrs, which have no children,
2416 and except for void*, as we don't know what to show.
2418 We can show char* so we allow it to be dereferenced. If you decide
2419 to test for it, please mind that a little magic is necessary to
2420 properly identify it: char* has TYPE_CODE == TYPE_CODE_INT and
2421 TYPE_NAME == "char" */
2422 if (TYPE_CODE (target) == TYPE_CODE_FUNC
2423 || TYPE_CODE (target) == TYPE_CODE_VOID)
2430 /* Other types have no children */
2438 c_name_of_variable (struct varobj *parent)
2440 return xstrdup (parent->name);
2443 /* Return the value of element TYPE_INDEX of a structure
2444 value VALUE. VALUE's type should be a structure,
2445 or union, or a typedef to struct/union.
2447 Returns NULL if getting the value fails. Never throws. */
2448 static struct value *
2449 value_struct_element_index (struct value *value, int type_index)
2451 struct value *result = NULL;
2452 volatile struct gdb_exception e;
2454 struct type *type = value_type (value);
2455 type = check_typedef (type);
2457 gdb_assert (TYPE_CODE (type) == TYPE_CODE_STRUCT
2458 || TYPE_CODE (type) == TYPE_CODE_UNION);
2460 TRY_CATCH (e, RETURN_MASK_ERROR)
2462 if (field_is_static (&TYPE_FIELD (type, type_index)))
2463 result = value_static_field (type, type_index);
2465 result = value_primitive_field (value, 0, type_index, type);
2477 /* Obtain the information about child INDEX of the variable
2479 If CNAME is not null, sets *CNAME to the name of the child relative
2481 If CVALUE is not null, sets *CVALUE to the value of the child.
2482 If CTYPE is not null, sets *CTYPE to the type of the child.
2484 If any of CNAME, CVALUE, or CTYPE is not null, but the corresponding
2485 information cannot be determined, set *CNAME, *CVALUE, or *CTYPE
2488 c_describe_child (struct varobj *parent, int index,
2489 char **cname, struct value **cvalue, struct type **ctype,
2490 char **cfull_expression)
2492 struct value *value = parent->value;
2493 struct type *type = get_value_type (parent);
2494 char *parent_expression = NULL;
2503 if (cfull_expression)
2505 *cfull_expression = NULL;
2506 parent_expression = varobj_get_path_expr (parent);
2508 adjust_value_for_child_access (&value, &type, &was_ptr);
2510 switch (TYPE_CODE (type))
2512 case TYPE_CODE_ARRAY:
2514 *cname = xstrprintf ("%d", index
2515 + TYPE_LOW_BOUND (TYPE_INDEX_TYPE (type)));
2517 if (cvalue && value)
2519 int real_index = index + TYPE_LOW_BOUND (TYPE_INDEX_TYPE (type));
2520 gdb_value_subscript (value, real_index, cvalue);
2524 *ctype = get_target_type (type);
2526 if (cfull_expression)
2527 *cfull_expression = xstrprintf ("(%s)[%d]", parent_expression,
2529 + TYPE_LOW_BOUND (TYPE_INDEX_TYPE (type)));
2534 case TYPE_CODE_STRUCT:
2535 case TYPE_CODE_UNION:
2537 *cname = xstrdup (TYPE_FIELD_NAME (type, index));
2539 if (cvalue && value)
2541 /* For C, varobj index is the same as type index. */
2542 *cvalue = value_struct_element_index (value, index);
2546 *ctype = TYPE_FIELD_TYPE (type, index);
2548 if (cfull_expression)
2550 char *join = was_ptr ? "->" : ".";
2551 *cfull_expression = xstrprintf ("(%s)%s%s", parent_expression, join,
2552 TYPE_FIELD_NAME (type, index));
2559 *cname = xstrprintf ("*%s", parent->name);
2561 if (cvalue && value)
2563 int success = gdb_value_ind (value, cvalue);
2568 /* Don't use get_target_type because it calls
2569 check_typedef and here, we want to show the true
2570 declared type of the variable. */
2572 *ctype = TYPE_TARGET_TYPE (type);
2574 if (cfull_expression)
2575 *cfull_expression = xstrprintf ("*(%s)", parent_expression);
2580 /* This should not happen */
2582 *cname = xstrdup ("???");
2583 if (cfull_expression)
2584 *cfull_expression = xstrdup ("???");
2585 /* Don't set value and type, we don't know then. */
2590 c_name_of_child (struct varobj *parent, int index)
2593 c_describe_child (parent, index, &name, NULL, NULL, NULL);
2598 c_path_expr_of_child (struct varobj *child)
2600 c_describe_child (child->parent, child->index, NULL, NULL, NULL,
2602 return child->path_expr;
2605 /* If frame associated with VAR can be found, switch
2606 to it and return 1. Otherwise, return 0. */
2608 check_scope (struct varobj *var)
2610 struct frame_info *fi;
2613 fi = frame_find_by_id (var->root->frame);
2618 CORE_ADDR pc = get_frame_pc (fi);
2619 if (pc < BLOCK_START (var->root->valid_block) ||
2620 pc >= BLOCK_END (var->root->valid_block))
2628 static struct value *
2629 c_value_of_root (struct varobj **var_handle)
2631 struct value *new_val = NULL;
2632 struct varobj *var = *var_handle;
2633 struct frame_info *fi;
2634 int within_scope = 0;
2635 struct cleanup *back_to;
2637 /* Only root variables can be updated... */
2638 if (!is_root_p (var))
2639 /* Not a root var */
2642 back_to = make_cleanup_restore_current_thread ();
2644 /* Determine whether the variable is still around. */
2645 if (var->root->valid_block == NULL || var->root->floating)
2647 else if (var->root->thread_id == 0)
2649 /* The program was single-threaded when the variable object was
2650 created. Technically, it's possible that the program became
2651 multi-threaded since then, but we don't support such
2653 within_scope = check_scope (var);
2657 ptid_t ptid = thread_id_to_pid (var->root->thread_id);
2658 if (in_thread_list (ptid))
2660 switch_to_thread (ptid);
2661 within_scope = check_scope (var);
2667 /* We need to catch errors here, because if evaluate
2668 expression fails we want to just return NULL. */
2669 gdb_evaluate_expression (var->root->exp, &new_val);
2673 do_cleanups (back_to);
2678 static struct value *
2679 c_value_of_child (struct varobj *parent, int index)
2681 struct value *value = NULL;
2682 c_describe_child (parent, index, NULL, &value, NULL, NULL);
2687 static struct type *
2688 c_type_of_child (struct varobj *parent, int index)
2690 struct type *type = NULL;
2691 c_describe_child (parent, index, NULL, NULL, &type, NULL);
2696 c_value_of_variable (struct varobj *var, enum varobj_display_formats format)
2698 /* BOGUS: if val_print sees a struct/class, or a reference to one,
2699 it will print out its children instead of "{...}". So we need to
2700 catch that case explicitly. */
2701 struct type *type = get_type (var);
2703 /* If we have a custom formatter, return whatever string it has
2705 if (var->pretty_printer && var->print_value)
2706 return xstrdup (var->print_value);
2708 /* Strip top-level references. */
2709 while (TYPE_CODE (type) == TYPE_CODE_REF)
2710 type = check_typedef (TYPE_TARGET_TYPE (type));
2712 switch (TYPE_CODE (type))
2714 case TYPE_CODE_STRUCT:
2715 case TYPE_CODE_UNION:
2716 return xstrdup ("{...}");
2719 case TYPE_CODE_ARRAY:
2722 number = xstrprintf ("[%d]", var->num_children);
2729 if (var->value == NULL)
2731 /* This can happen if we attempt to get the value of a struct
2732 member when the parent is an invalid pointer. This is an
2733 error condition, so we should tell the caller. */
2738 if (var->not_fetched && value_lazy (var->value))
2739 /* Frozen variable and no value yet. We don't
2740 implicitly fetch the value. MI response will
2741 use empty string for the value, which is OK. */
2744 gdb_assert (varobj_value_is_changeable_p (var));
2745 gdb_assert (!value_lazy (var->value));
2747 /* If the specified format is the current one,
2748 we can reuse print_value */
2749 if (format == var->format)
2750 return xstrdup (var->print_value);
2752 return value_get_print_value (var->value, format, var);
2762 cplus_number_of_children (struct varobj *var)
2765 int children, dont_know;
2770 if (!CPLUS_FAKE_CHILD (var))
2772 type = get_value_type (var);
2773 adjust_value_for_child_access (NULL, &type, NULL);
2775 if (((TYPE_CODE (type)) == TYPE_CODE_STRUCT) ||
2776 ((TYPE_CODE (type)) == TYPE_CODE_UNION))
2780 cplus_class_num_children (type, kids);
2781 if (kids[v_public] != 0)
2783 if (kids[v_private] != 0)
2785 if (kids[v_protected] != 0)
2788 /* Add any baseclasses */
2789 children += TYPE_N_BASECLASSES (type);
2792 /* FIXME: save children in var */
2799 type = get_value_type (var->parent);
2800 adjust_value_for_child_access (NULL, &type, NULL);
2802 cplus_class_num_children (type, kids);
2803 if (strcmp (var->name, "public") == 0)
2804 children = kids[v_public];
2805 else if (strcmp (var->name, "private") == 0)
2806 children = kids[v_private];
2808 children = kids[v_protected];
2813 children = c_number_of_children (var);
2818 /* Compute # of public, private, and protected variables in this class.
2819 That means we need to descend into all baseclasses and find out
2820 how many are there, too. */
2822 cplus_class_num_children (struct type *type, int children[3])
2826 children[v_public] = 0;
2827 children[v_private] = 0;
2828 children[v_protected] = 0;
2830 for (i = TYPE_N_BASECLASSES (type); i < TYPE_NFIELDS (type); i++)
2832 /* If we have a virtual table pointer, omit it. */
2833 if (TYPE_VPTR_BASETYPE (type) == type && TYPE_VPTR_FIELDNO (type) == i)
2836 if (TYPE_FIELD_PROTECTED (type, i))
2837 children[v_protected]++;
2838 else if (TYPE_FIELD_PRIVATE (type, i))
2839 children[v_private]++;
2841 children[v_public]++;
2846 cplus_name_of_variable (struct varobj *parent)
2848 return c_name_of_variable (parent);
2851 enum accessibility { private_field, protected_field, public_field };
2853 /* Check if field INDEX of TYPE has the specified accessibility.
2854 Return 0 if so and 1 otherwise. */
2856 match_accessibility (struct type *type, int index, enum accessibility acc)
2858 if (acc == private_field && TYPE_FIELD_PRIVATE (type, index))
2860 else if (acc == protected_field && TYPE_FIELD_PROTECTED (type, index))
2862 else if (acc == public_field && !TYPE_FIELD_PRIVATE (type, index)
2863 && !TYPE_FIELD_PROTECTED (type, index))
2870 cplus_describe_child (struct varobj *parent, int index,
2871 char **cname, struct value **cvalue, struct type **ctype,
2872 char **cfull_expression)
2875 struct value *value;
2878 char *parent_expression = NULL;
2886 if (cfull_expression)
2887 *cfull_expression = NULL;
2889 if (CPLUS_FAKE_CHILD (parent))
2891 value = parent->parent->value;
2892 type = get_value_type (parent->parent);
2893 if (cfull_expression)
2894 parent_expression = varobj_get_path_expr (parent->parent);
2898 value = parent->value;
2899 type = get_value_type (parent);
2900 if (cfull_expression)
2901 parent_expression = varobj_get_path_expr (parent);
2904 adjust_value_for_child_access (&value, &type, &was_ptr);
2906 if (TYPE_CODE (type) == TYPE_CODE_STRUCT
2907 || TYPE_CODE (type) == TYPE_CODE_UNION)
2909 char *join = was_ptr ? "->" : ".";
2910 if (CPLUS_FAKE_CHILD (parent))
2912 /* The fields of the class type are ordered as they
2913 appear in the class. We are given an index for a
2914 particular access control type ("public","protected",
2915 or "private"). We must skip over fields that don't
2916 have the access control we are looking for to properly
2917 find the indexed field. */
2918 int type_index = TYPE_N_BASECLASSES (type);
2919 enum accessibility acc = public_field;
2920 if (strcmp (parent->name, "private") == 0)
2921 acc = private_field;
2922 else if (strcmp (parent->name, "protected") == 0)
2923 acc = protected_field;
2927 if (TYPE_VPTR_BASETYPE (type) == type
2928 && type_index == TYPE_VPTR_FIELDNO (type))
2930 else if (match_accessibility (type, type_index, acc))
2937 *cname = xstrdup (TYPE_FIELD_NAME (type, type_index));
2939 if (cvalue && value)
2940 *cvalue = value_struct_element_index (value, type_index);
2943 *ctype = TYPE_FIELD_TYPE (type, type_index);
2945 if (cfull_expression)
2946 *cfull_expression = xstrprintf ("((%s)%s%s)", parent_expression,
2948 TYPE_FIELD_NAME (type, type_index));
2950 else if (index < TYPE_N_BASECLASSES (type))
2952 /* This is a baseclass. */
2954 *cname = xstrdup (TYPE_FIELD_NAME (type, index));
2956 if (cvalue && value)
2958 *cvalue = value_cast (TYPE_FIELD_TYPE (type, index), value);
2959 release_value (*cvalue);
2964 *ctype = TYPE_FIELD_TYPE (type, index);
2967 if (cfull_expression)
2969 char *ptr = was_ptr ? "*" : "";
2970 /* Cast the parent to the base' type. Note that in gdb,
2973 will create an lvalue, for all appearences, so we don't
2974 need to use more fancy:
2977 *cfull_expression = xstrprintf ("(%s(%s%s) %s)",
2979 TYPE_FIELD_NAME (type, index),
2986 char *access = NULL;
2988 cplus_class_num_children (type, children);
2990 /* Everything beyond the baseclasses can
2991 only be "public", "private", or "protected"
2993 The special "fake" children are always output by varobj in
2994 this order. So if INDEX == 2, it MUST be "protected". */
2995 index -= TYPE_N_BASECLASSES (type);
2999 if (children[v_public] > 0)
3001 else if (children[v_private] > 0)
3004 access = "protected";
3007 if (children[v_public] > 0)
3009 if (children[v_private] > 0)
3012 access = "protected";
3014 else if (children[v_private] > 0)
3015 access = "protected";
3018 /* Must be protected */
3019 access = "protected";
3026 gdb_assert (access);
3028 *cname = xstrdup (access);
3030 /* Value and type and full expression are null here. */
3035 c_describe_child (parent, index, cname, cvalue, ctype, cfull_expression);
3040 cplus_name_of_child (struct varobj *parent, int index)
3043 cplus_describe_child (parent, index, &name, NULL, NULL, NULL);
3048 cplus_path_expr_of_child (struct varobj *child)
3050 cplus_describe_child (child->parent, child->index, NULL, NULL, NULL,
3052 return child->path_expr;
3055 static struct value *
3056 cplus_value_of_root (struct varobj **var_handle)
3058 return c_value_of_root (var_handle);
3061 static struct value *
3062 cplus_value_of_child (struct varobj *parent, int index)
3064 struct value *value = NULL;
3065 cplus_describe_child (parent, index, NULL, &value, NULL, NULL);
3069 static struct type *
3070 cplus_type_of_child (struct varobj *parent, int index)
3072 struct type *type = NULL;
3073 cplus_describe_child (parent, index, NULL, NULL, &type, NULL);
3078 cplus_value_of_variable (struct varobj *var, enum varobj_display_formats format)
3081 /* If we have one of our special types, don't print out
3083 if (CPLUS_FAKE_CHILD (var))
3084 return xstrdup ("");
3086 return c_value_of_variable (var, format);
3092 java_number_of_children (struct varobj *var)
3094 return cplus_number_of_children (var);
3098 java_name_of_variable (struct varobj *parent)
3102 name = cplus_name_of_variable (parent);
3103 /* If the name has "-" in it, it is because we
3104 needed to escape periods in the name... */
3107 while (*p != '\000')
3118 java_name_of_child (struct varobj *parent, int index)
3122 name = cplus_name_of_child (parent, index);
3123 /* Escape any periods in the name... */
3126 while (*p != '\000')
3137 java_path_expr_of_child (struct varobj *child)
3142 static struct value *
3143 java_value_of_root (struct varobj **var_handle)
3145 return cplus_value_of_root (var_handle);
3148 static struct value *
3149 java_value_of_child (struct varobj *parent, int index)
3151 return cplus_value_of_child (parent, index);
3154 static struct type *
3155 java_type_of_child (struct varobj *parent, int index)
3157 return cplus_type_of_child (parent, index);
3161 java_value_of_variable (struct varobj *var, enum varobj_display_formats format)
3163 return cplus_value_of_variable (var, format);
3166 /* Iterate all the existing _root_ VAROBJs and call the FUNC callback for them
3167 with an arbitrary caller supplied DATA pointer. */
3170 all_root_varobjs (void (*func) (struct varobj *var, void *data), void *data)
3172 struct varobj_root *var_root, *var_root_next;
3174 /* Iterate "safely" - handle if the callee deletes its passed VAROBJ. */
3176 for (var_root = rootlist; var_root != NULL; var_root = var_root_next)
3178 var_root_next = var_root->next;
3180 (*func) (var_root->rootvar, data);
3184 extern void _initialize_varobj (void);
3186 _initialize_varobj (void)
3188 int sizeof_table = sizeof (struct vlist *) * VAROBJ_TABLE_SIZE;
3190 varobj_table = xmalloc (sizeof_table);
3191 memset (varobj_table, 0, sizeof_table);
3193 add_setshow_zinteger_cmd ("debugvarobj", class_maintenance,
3195 Set varobj debugging."), _("\
3196 Show varobj debugging."), _("\
3197 When non-zero, varobj debugging is enabled."),
3200 &setlist, &showlist);
3203 /* Invalidate varobj VAR if it is tied to locals and re-create it if it is
3204 defined on globals. It is a helper for varobj_invalidate. */
3207 varobj_invalidate_iter (struct varobj *var, void *unused)
3209 /* Floating varobjs are reparsed on each stop, so we don't care if the
3210 presently parsed expression refers to something that's gone. */
3211 if (var->root->floating)
3214 /* global var must be re-evaluated. */
3215 if (var->root->valid_block == NULL)
3217 struct varobj *tmp_var;
3219 /* Try to create a varobj with same expression. If we succeed
3220 replace the old varobj, otherwise invalidate it. */
3221 tmp_var = varobj_create (NULL, var->name, (CORE_ADDR) 0,
3223 if (tmp_var != NULL)
3225 tmp_var->obj_name = xstrdup (var->obj_name);
3226 varobj_delete (var, NULL, 0);
3227 install_variable (tmp_var);
3230 var->root->is_valid = 0;
3232 else /* locals must be invalidated. */
3233 var->root->is_valid = 0;
3236 /* Invalidate the varobjs that are tied to locals and re-create the ones that
3237 are defined on globals.
3238 Invalidated varobjs will be always printed in_scope="invalid". */
3241 varobj_invalidate (void)
3243 all_root_varobjs (varobj_invalidate_iter, NULL);