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"
37 #include "typeprint.h"
40 #include "python/python.h"
41 #include "python/python-internal.h"
46 /* Non-zero if we want to see trace of varobj level stuff. */
50 show_varobjdebug (struct ui_file *file, int from_tty,
51 struct cmd_list_element *c, const char *value)
53 fprintf_filtered (file, _("Varobj debugging is %s.\n"), value);
56 /* String representations of gdb's format codes */
57 char *varobj_format_string[] =
58 { "natural", "binary", "decimal", "hexadecimal", "octal" };
60 /* String representations of gdb's known languages */
61 char *varobj_language_string[] = { "unknown", "C", "C++", "Java" };
65 /* Every root variable has one of these structures saved in its
66 varobj. Members which must be free'd are noted. */
70 /* Alloc'd expression for this parent. */
71 struct expression *exp;
73 /* Block for which this expression is valid */
74 struct block *valid_block;
76 /* The frame for this expression. This field is set iff valid_block is
78 struct frame_id frame;
80 /* The thread ID that this varobj_root belong to. This field
81 is only valid if valid_block is not NULL.
82 When not 0, indicates which thread 'frame' belongs to.
83 When 0, indicates that the thread list was empty when the varobj_root
87 /* If 1, the -var-update always recomputes the value in the
88 current thread and frame. Otherwise, variable object is
89 always updated in the specific scope/thread/frame */
92 /* Flag that indicates validity: set to 0 when this varobj_root refers
93 to symbols that do not exist anymore. */
96 /* Language info for this variable and its children */
97 struct language_specific *lang;
99 /* The varobj for this root node. */
100 struct varobj *rootvar;
102 /* Next root variable */
103 struct varobj_root *next;
106 /* Every variable in the system has a structure of this type defined
107 for it. This structure holds all information necessary to manipulate
108 a particular object variable. Members which must be freed are noted. */
112 /* Alloc'd name of the variable for this object.. If this variable is a
113 child, then this name will be the child's source name.
114 (bar, not foo.bar) */
115 /* NOTE: This is the "expression" */
118 /* Alloc'd expression for this child. Can be used to create a
119 root variable corresponding to this child. */
122 /* The alloc'd name for this variable's object. This is here for
123 convenience when constructing this object's children. */
126 /* Index of this variable in its parent or -1 */
129 /* The type of this variable. This can be NULL
130 for artifial variable objects -- currently, the "accessibility"
131 variable objects in C++. */
134 /* The value of this expression or subexpression. A NULL value
135 indicates there was an error getting this value.
136 Invariant: if varobj_value_is_changeable_p (this) is non-zero,
137 the value is either NULL, or not lazy. */
140 /* The number of (immediate) children this variable has */
143 /* If this object is a child, this points to its immediate parent. */
144 struct varobj *parent;
146 /* Children of this object. */
147 VEC (varobj_p) *children;
149 /* Whether the children of this varobj were requested. This field is
150 used to decide if dynamic varobj should recompute their children.
151 In the event that the frontend never asked for the children, we
153 int children_requested;
155 /* Description of the root variable. Points to root variable for children. */
156 struct varobj_root *root;
158 /* The format of the output for this object */
159 enum varobj_display_formats format;
161 /* Was this variable updated via a varobj_set_value operation */
164 /* Last print value. */
167 /* Is this variable frozen. Frozen variables are never implicitly
168 updated by -var-update *
169 or -var-update <direct-or-indirect-parent>. */
172 /* Is the value of this variable intentionally not fetched? It is
173 not fetched if either the variable is frozen, or any parents is
177 /* The pretty-printer that has been constructed. If NULL, then a
178 new printer object is needed, and one will be constructed. */
179 PyObject *pretty_printer;
185 struct cpstack *next;
188 /* A list of varobjs */
196 /* Private function prototypes */
198 /* Helper functions for the above subcommands. */
200 static int delete_variable (struct cpstack **, struct varobj *, int);
202 static void delete_variable_1 (struct cpstack **, int *,
203 struct varobj *, int, int);
205 static int install_variable (struct varobj *);
207 static void uninstall_variable (struct varobj *);
209 static struct varobj *create_child (struct varobj *, int, char *);
211 static struct varobj *
212 create_child_with_value (struct varobj *parent, int index, const char *name,
213 struct value *value);
215 /* Utility routines */
217 static struct varobj *new_variable (void);
219 static struct varobj *new_root_variable (void);
221 static void free_variable (struct varobj *var);
223 static struct cleanup *make_cleanup_free_variable (struct varobj *var);
225 static struct type *get_type (struct varobj *var);
227 static struct type *get_value_type (struct varobj *var);
229 static struct type *get_target_type (struct type *);
231 static enum varobj_display_formats variable_default_display (struct varobj *);
233 static void cppush (struct cpstack **pstack, char *name);
235 static char *cppop (struct cpstack **pstack);
237 static int install_new_value (struct varobj *var, struct value *value,
240 static void install_default_visualizer (struct varobj *var);
242 /* Language-specific routines. */
244 static enum varobj_languages variable_language (struct varobj *var);
246 static int number_of_children (struct varobj *);
248 static char *name_of_variable (struct varobj *);
250 static char *name_of_child (struct varobj *, int);
252 static struct value *value_of_root (struct varobj **var_handle, int *);
254 static struct value *value_of_child (struct varobj *parent, int index);
256 static char *my_value_of_variable (struct varobj *var,
257 enum varobj_display_formats format);
259 static char *value_get_print_value (struct value *value,
260 enum varobj_display_formats format,
261 PyObject *value_formatter);
263 static int varobj_value_is_changeable_p (struct varobj *var);
265 static int is_root_p (struct varobj *var);
267 static struct varobj *
268 varobj_add_child (struct varobj *var, const char *name, struct value *value);
270 /* C implementation */
272 static int c_number_of_children (struct varobj *var);
274 static char *c_name_of_variable (struct varobj *parent);
276 static char *c_name_of_child (struct varobj *parent, int index);
278 static char *c_path_expr_of_child (struct varobj *child);
280 static struct value *c_value_of_root (struct varobj **var_handle);
282 static struct value *c_value_of_child (struct varobj *parent, int index);
284 static struct type *c_type_of_child (struct varobj *parent, int index);
286 static char *c_value_of_variable (struct varobj *var,
287 enum varobj_display_formats format);
289 /* C++ implementation */
291 static int cplus_number_of_children (struct varobj *var);
293 static void cplus_class_num_children (struct type *type, int children[3]);
295 static char *cplus_name_of_variable (struct varobj *parent);
297 static char *cplus_name_of_child (struct varobj *parent, int index);
299 static char *cplus_path_expr_of_child (struct varobj *child);
301 static struct value *cplus_value_of_root (struct varobj **var_handle);
303 static struct value *cplus_value_of_child (struct varobj *parent, int index);
305 static struct type *cplus_type_of_child (struct varobj *parent, int index);
307 static char *cplus_value_of_variable (struct varobj *var,
308 enum varobj_display_formats format);
310 /* Java implementation */
312 static int java_number_of_children (struct varobj *var);
314 static char *java_name_of_variable (struct varobj *parent);
316 static char *java_name_of_child (struct varobj *parent, int index);
318 static char *java_path_expr_of_child (struct varobj *child);
320 static struct value *java_value_of_root (struct varobj **var_handle);
322 static struct value *java_value_of_child (struct varobj *parent, int index);
324 static struct type *java_type_of_child (struct varobj *parent, int index);
326 static char *java_value_of_variable (struct varobj *var,
327 enum varobj_display_formats format);
329 /* The language specific vector */
331 struct language_specific
334 /* The language of this variable */
335 enum varobj_languages language;
337 /* The number of children of PARENT. */
338 int (*number_of_children) (struct varobj * parent);
340 /* The name (expression) of a root varobj. */
341 char *(*name_of_variable) (struct varobj * parent);
343 /* The name of the INDEX'th child of PARENT. */
344 char *(*name_of_child) (struct varobj * parent, int index);
346 /* Returns the rooted expression of CHILD, which is a variable
347 obtain that has some parent. */
348 char *(*path_expr_of_child) (struct varobj * child);
350 /* The ``struct value *'' of the root variable ROOT. */
351 struct value *(*value_of_root) (struct varobj ** root_handle);
353 /* The ``struct value *'' of the INDEX'th child of PARENT. */
354 struct value *(*value_of_child) (struct varobj * parent, int index);
356 /* The type of the INDEX'th child of PARENT. */
357 struct type *(*type_of_child) (struct varobj * parent, int index);
359 /* The current value of VAR. */
360 char *(*value_of_variable) (struct varobj * var,
361 enum varobj_display_formats format);
364 /* Array of known source language routines. */
365 static struct language_specific languages[vlang_end] = {
366 /* Unknown (try treating as C */
369 c_number_of_children,
372 c_path_expr_of_child,
381 c_number_of_children,
384 c_path_expr_of_child,
393 cplus_number_of_children,
394 cplus_name_of_variable,
396 cplus_path_expr_of_child,
398 cplus_value_of_child,
400 cplus_value_of_variable}
405 java_number_of_children,
406 java_name_of_variable,
408 java_path_expr_of_child,
412 java_value_of_variable}
415 /* A little convenience enum for dealing with C++/Java */
418 v_public = 0, v_private, v_protected
423 /* Mappings of varobj_display_formats enums to gdb's format codes */
424 static int format_code[] = { 0, 't', 'd', 'x', 'o' };
426 /* Header of the list of root variable objects */
427 static struct varobj_root *rootlist;
428 static int rootcount = 0; /* number of root varobjs in the list */
430 /* Prime number indicating the number of buckets in the hash table */
431 /* A prime large enough to avoid too many colisions */
432 #define VAROBJ_TABLE_SIZE 227
434 /* Pointer to the varobj hash table (built at run time) */
435 static struct vlist **varobj_table;
437 /* Is the variable X one of our "fake" children? */
438 #define CPLUS_FAKE_CHILD(x) \
439 ((x) != NULL && (x)->type == NULL && (x)->value == NULL)
442 /* API Implementation */
444 is_root_p (struct varobj *var)
446 return (var->root->rootvar == var);
449 /* Creates a varobj (not its children) */
451 /* Return the full FRAME which corresponds to the given CORE_ADDR
452 or NULL if no FRAME on the chain corresponds to CORE_ADDR. */
454 static struct frame_info *
455 find_frame_addr_in_frame_chain (CORE_ADDR frame_addr)
457 struct frame_info *frame = NULL;
459 if (frame_addr == (CORE_ADDR) 0)
462 for (frame = get_current_frame ();
464 frame = get_prev_frame (frame))
466 /* The CORE_ADDR we get as argument was parsed from a string GDB
467 output as $fp. This output got truncated to gdbarch_addr_bit.
468 Truncate the frame base address in the same manner before
469 comparing it against our argument. */
470 CORE_ADDR frame_base = get_frame_base_address (frame);
471 int addr_bit = gdbarch_addr_bit (get_frame_arch (frame));
472 if (addr_bit < (sizeof (CORE_ADDR) * HOST_CHAR_BIT))
473 frame_base &= ((CORE_ADDR) 1 << addr_bit) - 1;
475 if (frame_base == frame_addr)
483 varobj_create (char *objname,
484 char *expression, CORE_ADDR frame, enum varobj_type type)
487 struct frame_info *fi;
488 struct frame_info *old_fi = NULL;
490 struct cleanup *old_chain;
492 /* Fill out a varobj structure for the (root) variable being constructed. */
493 var = new_root_variable ();
494 old_chain = make_cleanup_free_variable (var);
496 if (expression != NULL)
499 enum varobj_languages lang;
500 struct value *value = NULL;
502 /* Parse and evaluate the expression, filling in as much of the
503 variable's data as possible. */
505 if (has_stack_frames ())
507 /* Allow creator to specify context of variable */
508 if ((type == USE_CURRENT_FRAME) || (type == USE_SELECTED_FRAME))
509 fi = get_selected_frame (NULL);
511 /* FIXME: cagney/2002-11-23: This code should be doing a
512 lookup using the frame ID and not just the frame's
513 ``address''. This, of course, means an interface
514 change. However, with out that interface change ISAs,
515 such as the ia64 with its two stacks, won't work.
516 Similar goes for the case where there is a frameless
518 fi = find_frame_addr_in_frame_chain (frame);
523 /* frame = -2 means always use selected frame */
524 if (type == USE_SELECTED_FRAME)
525 var->root->floating = 1;
529 block = get_frame_block (fi, 0);
532 innermost_block = NULL;
533 /* Wrap the call to parse expression, so we can
534 return a sensible error. */
535 if (!gdb_parse_exp_1 (&p, block, 0, &var->root->exp))
540 /* Don't allow variables to be created for types. */
541 if (var->root->exp->elts[0].opcode == OP_TYPE)
543 do_cleanups (old_chain);
544 fprintf_unfiltered (gdb_stderr, "Attempt to use a type name"
545 " as an expression.\n");
549 var->format = variable_default_display (var);
550 var->root->valid_block = innermost_block;
551 var->name = xstrdup (expression);
552 /* For a root var, the name and the expr are the same. */
553 var->path_expr = xstrdup (expression);
555 /* When the frame is different from the current frame,
556 we must select the appropriate frame before parsing
557 the expression, otherwise the value will not be current.
558 Since select_frame is so benign, just call it for all cases. */
559 if (innermost_block && fi != NULL)
561 var->root->frame = get_frame_id (fi);
562 var->root->thread_id = pid_to_thread_id (inferior_ptid);
563 old_fi = get_selected_frame (NULL);
567 /* We definitely need to catch errors here.
568 If evaluate_expression succeeds we got the value we wanted.
569 But if it fails, we still go on with a call to evaluate_type() */
570 if (!gdb_evaluate_expression (var->root->exp, &value))
572 /* Error getting the value. Try to at least get the
574 struct value *type_only_value = evaluate_type (var->root->exp);
575 var->type = value_type (type_only_value);
578 var->type = value_type (value);
580 install_new_value (var, value, 1 /* Initial assignment */);
582 /* Set language info */
583 lang = variable_language (var);
584 var->root->lang = &languages[lang];
586 /* Set ourselves as our root */
587 var->root->rootvar = var;
589 /* Reset the selected frame */
591 select_frame (old_fi);
594 /* If the variable object name is null, that means this
595 is a temporary variable, so don't install it. */
597 if ((var != NULL) && (objname != NULL))
599 var->obj_name = xstrdup (objname);
601 /* If a varobj name is duplicated, the install will fail so
603 if (!install_variable (var))
605 do_cleanups (old_chain);
610 install_default_visualizer (var);
611 discard_cleanups (old_chain);
615 /* Generates an unique name that can be used for a varobj */
618 varobj_gen_name (void)
623 /* generate a name for this object */
625 obj_name = xstrprintf ("var%d", id);
630 /* Given an OBJNAME, returns the pointer to the corresponding varobj. Call
631 error if OBJNAME cannot be found. */
634 varobj_get_handle (char *objname)
638 unsigned int index = 0;
641 for (chp = objname; *chp; chp++)
643 index = (index + (i++ * (unsigned int) *chp)) % VAROBJ_TABLE_SIZE;
646 cv = *(varobj_table + index);
647 while ((cv != NULL) && (strcmp (cv->var->obj_name, objname) != 0))
651 error (_("Variable object not found"));
656 /* Given the handle, return the name of the object */
659 varobj_get_objname (struct varobj *var)
661 return var->obj_name;
664 /* Given the handle, return the expression represented by the object */
667 varobj_get_expression (struct varobj *var)
669 return name_of_variable (var);
672 /* Deletes a varobj and all its children if only_children == 0,
673 otherwise deletes only the children; returns a malloc'ed list of all the
674 (malloc'ed) names of the variables that have been deleted (NULL terminated) */
677 varobj_delete (struct varobj *var, char ***dellist, int only_children)
681 struct cpstack *result = NULL;
684 /* Initialize a stack for temporary results */
685 cppush (&result, NULL);
688 /* Delete only the variable children */
689 delcount = delete_variable (&result, var, 1 /* only the children */ );
691 /* Delete the variable and all its children */
692 delcount = delete_variable (&result, var, 0 /* parent+children */ );
694 /* We may have been asked to return a list of what has been deleted */
697 *dellist = xmalloc ((delcount + 1) * sizeof (char *));
701 *cp = cppop (&result);
702 while ((*cp != NULL) && (mycount > 0))
706 *cp = cppop (&result);
709 if (mycount || (*cp != NULL))
710 warning (_("varobj_delete: assertion failed - mycount(=%d) <> 0"),
717 /* Convenience function for varobj_set_visualizer. Instantiate a
718 pretty-printer for a given value. */
720 instantiate_pretty_printer (PyObject *constructor, struct value *value)
723 PyObject *val_obj = NULL;
725 volatile struct gdb_exception except;
727 TRY_CATCH (except, RETURN_MASK_ALL)
729 value = value_copy (value);
731 GDB_PY_HANDLE_EXCEPTION (except);
732 val_obj = value_to_value_object (value);
737 printer = PyObject_CallFunctionObjArgs (constructor, val_obj, NULL);
744 /* Set/Get variable object display format */
746 enum varobj_display_formats
747 varobj_set_display_format (struct varobj *var,
748 enum varobj_display_formats format)
755 case FORMAT_HEXADECIMAL:
757 var->format = format;
761 var->format = variable_default_display (var);
764 if (varobj_value_is_changeable_p (var)
765 && var->value && !value_lazy (var->value))
767 xfree (var->print_value);
768 var->print_value = value_get_print_value (var->value, var->format,
769 var->pretty_printer);
775 enum varobj_display_formats
776 varobj_get_display_format (struct varobj *var)
782 varobj_get_display_hint (struct varobj *var)
787 PyGILState_STATE state = PyGILState_Ensure ();
788 if (var->pretty_printer)
789 result = gdbpy_get_display_hint (var->pretty_printer);
790 PyGILState_Release (state);
796 /* If the variable object is bound to a specific thread, that
797 is its evaluation can always be done in context of a frame
798 inside that thread, returns GDB id of the thread -- which
799 is always positive. Otherwise, returns -1. */
801 varobj_get_thread_id (struct varobj *var)
803 if (var->root->valid_block && var->root->thread_id > 0)
804 return var->root->thread_id;
810 varobj_set_frozen (struct varobj *var, int frozen)
812 /* When a variable is unfrozen, we don't fetch its value.
813 The 'not_fetched' flag remains set, so next -var-update
816 We don't fetch the value, because for structures the client
817 should do -var-update anyway. It would be bad to have different
818 client-size logic for structure and other types. */
819 var->frozen = frozen;
823 varobj_get_frozen (struct varobj *var)
829 update_dynamic_varobj_children (struct varobj *var,
830 VEC (varobj_p) **changed,
831 VEC (varobj_p) **new_and_unchanged,
836 /* FIXME: we *might* want to provide this functionality as
837 a standalone function, so that other interested parties
838 than varobj code can benefit for this. */
839 struct cleanup *back_to;
843 int children_changed = 0;
844 PyObject *printer = var->pretty_printer;
845 PyGILState_STATE state;
847 state = PyGILState_Ensure ();
848 back_to = make_cleanup_py_restore_gil (&state);
851 if (!PyObject_HasAttr (printer, gdbpy_children_cst))
853 do_cleanups (back_to);
857 children = PyObject_CallMethodObjArgs (printer, gdbpy_children_cst,
862 gdbpy_print_stack ();
863 error (_("Null value returned for children"));
866 make_cleanup_py_decref (children);
868 if (!PyIter_Check (children))
869 error (_("Returned value is not iterable"));
871 iterator = PyObject_GetIter (children);
874 gdbpy_print_stack ();
875 error (_("Could not get children iterator"));
877 make_cleanup_py_decref (iterator);
881 PyObject *item = PyIter_Next (iterator);
885 struct cleanup *inner;
889 inner = make_cleanup_py_decref (item);
891 if (!PyArg_ParseTuple (item, "sO", &name, &py_v))
892 error (_("Invalid item from the child list"));
894 if (PyObject_TypeCheck (py_v, &value_object_type))
896 /* If we just call convert_value_from_python for this type,
897 we won't know who owns the result. For this one case we
898 need to copy the resulting value. */
899 v = value_object_to_value (py_v);
903 v = convert_value_from_python (py_v);
905 /* TODO: This assume the name of the i-th child never changes. */
907 /* Now see what to do here. */
908 if (VEC_length (varobj_p, var->children) < i + 1)
910 /* There's no child yet. */
911 struct varobj *child = varobj_add_child (var, name, v);
912 if (new_and_unchanged)
913 VEC_safe_push (varobj_p, *new_and_unchanged, child);
914 children_changed = 1;
918 varobj_p existing = VEC_index (varobj_p, var->children, i);
919 if (install_new_value (existing, v, 0) && changed)
922 VEC_safe_push (varobj_p, *changed, existing);
926 if (new_and_unchanged)
927 VEC_safe_push (varobj_p, *new_and_unchanged, existing);
934 if (i < VEC_length (varobj_p, var->children))
937 children_changed = 1;
938 for (i = 0; i < VEC_length (varobj_p, var->children); ++i)
939 varobj_delete (VEC_index (varobj_p, var->children, i), NULL, 0);
941 VEC_truncate (varobj_p, var->children, i);
942 var->num_children = VEC_length (varobj_p, var->children);
944 do_cleanups (back_to);
946 *cchanged = children_changed;
949 gdb_assert (0 && "should never be called if Python is not enabled");
954 varobj_get_num_children (struct varobj *var)
956 if (var->num_children == -1)
959 if (!var->pretty_printer
960 || !update_dynamic_varobj_children (var, NULL, NULL, &changed))
961 var->num_children = number_of_children (var);
964 return var->num_children;
967 /* Creates a list of the immediate children of a variable object;
968 the return code is the number of such children or -1 on error */
971 varobj_list_children (struct varobj *var)
973 struct varobj *child;
975 int i, children_changed;
977 var->children_requested = 1;
979 if (var->pretty_printer
980 /* This, in theory, can result in the number of children changing without
981 frontend noticing. But well, calling -var-list-children on the same
982 varobj twice is not something a sane frontend would do. */
983 && update_dynamic_varobj_children (var, NULL, NULL, &children_changed))
984 return var->children;
986 if (var->num_children == -1)
987 var->num_children = number_of_children (var);
989 /* If that failed, give up. */
990 if (var->num_children == -1)
991 return var->children;
993 /* If we're called when the list of children is not yet initialized,
994 allocate enough elements in it. */
995 while (VEC_length (varobj_p, var->children) < var->num_children)
996 VEC_safe_push (varobj_p, var->children, NULL);
998 for (i = 0; i < var->num_children; i++)
1000 varobj_p existing = VEC_index (varobj_p, var->children, i);
1002 if (existing == NULL)
1004 /* Either it's the first call to varobj_list_children for
1005 this variable object, and the child was never created,
1006 or it was explicitly deleted by the client. */
1007 name = name_of_child (var, i);
1008 existing = create_child (var, i, name);
1009 VEC_replace (varobj_p, var->children, i, existing);
1010 install_default_visualizer (existing);
1014 return var->children;
1017 static struct varobj *
1018 varobj_add_child (struct varobj *var, const char *name, struct value *value)
1020 varobj_p v = create_child_with_value (var,
1021 VEC_length (varobj_p, var->children),
1023 VEC_safe_push (varobj_p, var->children, v);
1024 install_default_visualizer (v);
1028 /* Obtain the type of an object Variable as a string similar to the one gdb
1029 prints on the console */
1032 varobj_get_type (struct varobj *var)
1034 /* For the "fake" variables, do not return a type. (It's type is
1036 Do not return a type for invalid variables as well. */
1037 if (CPLUS_FAKE_CHILD (var) || !var->root->is_valid)
1040 return type_to_string (var->type);
1043 /* Obtain the type of an object variable. */
1046 varobj_get_gdb_type (struct varobj *var)
1051 /* Return a pointer to the full rooted expression of varobj VAR.
1052 If it has not been computed yet, compute it. */
1054 varobj_get_path_expr (struct varobj *var)
1056 if (var->path_expr != NULL)
1057 return var->path_expr;
1060 /* For root varobjs, we initialize path_expr
1061 when creating varobj, so here it should be
1063 gdb_assert (!is_root_p (var));
1064 return (*var->root->lang->path_expr_of_child) (var);
1068 enum varobj_languages
1069 varobj_get_language (struct varobj *var)
1071 return variable_language (var);
1075 varobj_get_attributes (struct varobj *var)
1079 if (varobj_editable_p (var))
1080 /* FIXME: define masks for attributes */
1081 attributes |= 0x00000001; /* Editable */
1087 varobj_get_formatted_value (struct varobj *var,
1088 enum varobj_display_formats format)
1090 return my_value_of_variable (var, format);
1094 varobj_get_value (struct varobj *var)
1096 return my_value_of_variable (var, var->format);
1099 /* Set the value of an object variable (if it is editable) to the
1100 value of the given expression */
1101 /* Note: Invokes functions that can call error() */
1104 varobj_set_value (struct varobj *var, char *expression)
1110 /* The argument "expression" contains the variable's new value.
1111 We need to first construct a legal expression for this -- ugh! */
1112 /* Does this cover all the bases? */
1113 struct expression *exp;
1114 struct value *value;
1115 int saved_input_radix = input_radix;
1116 char *s = expression;
1119 gdb_assert (varobj_editable_p (var));
1121 input_radix = 10; /* ALWAYS reset to decimal temporarily */
1122 exp = parse_exp_1 (&s, 0, 0);
1123 if (!gdb_evaluate_expression (exp, &value))
1125 /* We cannot proceed without a valid expression. */
1130 /* All types that are editable must also be changeable. */
1131 gdb_assert (varobj_value_is_changeable_p (var));
1133 /* The value of a changeable variable object must not be lazy. */
1134 gdb_assert (!value_lazy (var->value));
1136 /* Need to coerce the input. We want to check if the
1137 value of the variable object will be different
1138 after assignment, and the first thing value_assign
1139 does is coerce the input.
1140 For example, if we are assigning an array to a pointer variable we
1141 should compare the pointer with the the array's address, not with the
1143 value = coerce_array (value);
1145 /* The new value may be lazy. gdb_value_assign, or
1146 rather value_contents, will take care of this.
1147 If fetching of the new value will fail, gdb_value_assign
1148 with catch the exception. */
1149 if (!gdb_value_assign (var->value, value, &val))
1152 /* If the value has changed, record it, so that next -var-update can
1153 report this change. If a variable had a value of '1', we've set it
1154 to '333' and then set again to '1', when -var-update will report this
1155 variable as changed -- because the first assignment has set the
1156 'updated' flag. There's no need to optimize that, because return value
1157 of -var-update should be considered an approximation. */
1158 var->updated = install_new_value (var, val, 0 /* Compare values. */);
1159 input_radix = saved_input_radix;
1163 /* Returns a malloc'ed list with all root variable objects */
1165 varobj_list (struct varobj ***varlist)
1168 struct varobj_root *croot;
1169 int mycount = rootcount;
1171 /* Alloc (rootcount + 1) entries for the result */
1172 *varlist = xmalloc ((rootcount + 1) * sizeof (struct varobj *));
1176 while ((croot != NULL) && (mycount > 0))
1178 *cv = croot->rootvar;
1181 croot = croot->next;
1183 /* Mark the end of the list */
1186 if (mycount || (croot != NULL))
1188 ("varobj_list: assertion failed - wrong tally of root vars (%d:%d)",
1189 rootcount, mycount);
1194 /* Assign a new value to a variable object. If INITIAL is non-zero,
1195 this is the first assignement after the variable object was just
1196 created, or changed type. In that case, just assign the value
1198 Otherwise, assign the new value, and return 1 if the value is different
1199 from the current one, 0 otherwise. The comparison is done on textual
1200 representation of value. Therefore, some types need not be compared. E.g.
1201 for structures the reported value is always "{...}", so no comparison is
1202 necessary here. If the old value was NULL and new one is not, or vice versa,
1205 The VALUE parameter should not be released -- the function will
1206 take care of releasing it when needed. */
1208 install_new_value (struct varobj *var, struct value *value, int initial)
1213 int intentionally_not_fetched = 0;
1214 char *print_value = NULL;
1216 /* We need to know the varobj's type to decide if the value should
1217 be fetched or not. C++ fake children (public/protected/private) don't have
1219 gdb_assert (var->type || CPLUS_FAKE_CHILD (var));
1220 changeable = varobj_value_is_changeable_p (var);
1222 /* If the type has custom visualizer, we consider it to be always
1223 changeable. FIXME: need to make sure this behaviour will not
1224 mess up read-sensitive values. */
1225 if (var->pretty_printer)
1228 need_to_fetch = changeable;
1230 /* We are not interested in the address of references, and given
1231 that in C++ a reference is not rebindable, it cannot
1232 meaningfully change. So, get hold of the real value. */
1235 value = coerce_ref (value);
1236 release_value (value);
1239 if (var->type && TYPE_CODE (var->type) == TYPE_CODE_UNION)
1240 /* For unions, we need to fetch the value implicitly because
1241 of implementation of union member fetch. When gdb
1242 creates a value for a field and the value of the enclosing
1243 structure is not lazy, it immediately copies the necessary
1244 bytes from the enclosing values. If the enclosing value is
1245 lazy, the call to value_fetch_lazy on the field will read
1246 the data from memory. For unions, that means we'll read the
1247 same memory more than once, which is not desirable. So
1251 /* The new value might be lazy. If the type is changeable,
1252 that is we'll be comparing values of this type, fetch the
1253 value now. Otherwise, on the next update the old value
1254 will be lazy, which means we've lost that old value. */
1255 if (need_to_fetch && value && value_lazy (value))
1257 struct varobj *parent = var->parent;
1258 int frozen = var->frozen;
1259 for (; !frozen && parent; parent = parent->parent)
1260 frozen |= parent->frozen;
1262 if (frozen && initial)
1264 /* For variables that are frozen, or are children of frozen
1265 variables, we don't do fetch on initial assignment.
1266 For non-initial assignemnt we do the fetch, since it means we're
1267 explicitly asked to compare the new value with the old one. */
1268 intentionally_not_fetched = 1;
1270 else if (!gdb_value_fetch_lazy (value))
1272 /* Set the value to NULL, so that for the next -var-update,
1273 we don't try to compare the new value with this value,
1274 that we couldn't even read. */
1280 /* Below, we'll be comparing string rendering of old and new
1281 values. Don't get string rendering if the value is
1282 lazy -- if it is, the code above has decided that the value
1283 should not be fetched. */
1284 if (value && !value_lazy (value))
1285 print_value = value_get_print_value (value, var->format,
1286 var->pretty_printer);
1288 /* If the type is changeable, compare the old and the new values.
1289 If this is the initial assignment, we don't have any old value
1291 if (!initial && changeable)
1293 /* If the value of the varobj was changed by -var-set-value, then the
1294 value in the varobj and in the target is the same. However, that value
1295 is different from the value that the varobj had after the previous
1296 -var-update. So need to the varobj as changed. */
1303 /* Try to compare the values. That requires that both
1304 values are non-lazy. */
1305 if (var->not_fetched && value_lazy (var->value))
1307 /* This is a frozen varobj and the value was never read.
1308 Presumably, UI shows some "never read" indicator.
1309 Now that we've fetched the real value, we need to report
1310 this varobj as changed so that UI can show the real
1314 else if (var->value == NULL && value == NULL)
1317 else if (var->value == NULL || value == NULL)
1323 gdb_assert (!value_lazy (var->value));
1324 gdb_assert (!value_lazy (value));
1326 gdb_assert (var->print_value != NULL && print_value != NULL);
1327 if (strcmp (var->print_value, print_value) != 0)
1333 if (!initial && !changeable)
1335 /* For values that are not changeable, we don't compare the values.
1336 However, we want to notice if a value was not NULL and now is NULL,
1337 or vise versa, so that we report when top-level varobjs come in scope
1338 and leave the scope. */
1339 changed = (var->value != NULL) != (value != NULL);
1342 /* We must always keep the new value, since children depend on it. */
1343 if (var->value != NULL && var->value != value)
1344 value_free (var->value);
1346 if (var->print_value)
1347 xfree (var->print_value);
1348 var->print_value = print_value;
1349 if (value && value_lazy (value) && intentionally_not_fetched)
1350 var->not_fetched = 1;
1352 var->not_fetched = 0;
1355 gdb_assert (!var->value || value_type (var->value));
1361 install_visualizer (struct varobj *var, PyObject *visualizer)
1364 /* If there are any children now, wipe them. */
1365 varobj_delete (var, NULL, 1 /* children only */);
1366 var->num_children = -1;
1368 Py_XDECREF (var->pretty_printer);
1369 var->pretty_printer = visualizer;
1371 install_new_value (var, var->value, 1);
1373 /* If we removed the visualizer, and the user ever requested the
1374 object's children, then we must compute the list of children.
1375 Note that we needn't do this when installing a visualizer,
1376 because updating will recompute dynamic children. */
1377 if (!visualizer && var->children_requested)
1378 varobj_list_children (var);
1380 error (_("Python support required"));
1385 install_default_visualizer (struct varobj *var)
1388 struct cleanup *cleanup;
1389 PyGILState_STATE state;
1390 PyObject *pretty_printer = NULL;
1392 state = PyGILState_Ensure ();
1393 cleanup = make_cleanup_py_restore_gil (&state);
1397 pretty_printer = gdbpy_get_varobj_pretty_printer (var->value);
1398 if (! pretty_printer)
1400 gdbpy_print_stack ();
1401 error (_("Cannot instantiate printer for default visualizer"));
1405 if (pretty_printer == Py_None)
1407 Py_DECREF (pretty_printer);
1408 pretty_printer = NULL;
1411 install_visualizer (var, pretty_printer);
1412 do_cleanups (cleanup);
1414 /* No error is right as this function is inserted just as a hook. */
1419 varobj_set_visualizer (struct varobj *var, const char *visualizer)
1422 PyObject *mainmod, *globals, *pretty_printer, *constructor;
1423 struct cleanup *back_to, *value;
1424 PyGILState_STATE state;
1427 state = PyGILState_Ensure ();
1428 back_to = make_cleanup_py_restore_gil (&state);
1430 mainmod = PyImport_AddModule ("__main__");
1431 globals = PyModule_GetDict (mainmod);
1432 Py_INCREF (globals);
1433 make_cleanup_py_decref (globals);
1435 constructor = PyRun_String (visualizer, Py_eval_input, globals, globals);
1437 /* Do not instantiate NoneType. */
1438 if (constructor == Py_None)
1440 pretty_printer = Py_None;
1441 Py_INCREF (pretty_printer);
1444 pretty_printer = instantiate_pretty_printer (constructor, var->value);
1446 Py_XDECREF (constructor);
1448 if (! pretty_printer)
1450 gdbpy_print_stack ();
1451 error (_("Could not evaluate visualizer expression: %s"), visualizer);
1454 if (pretty_printer == Py_None)
1456 Py_DECREF (pretty_printer);
1457 pretty_printer = NULL;
1460 install_visualizer (var, pretty_printer);
1462 do_cleanups (back_to);
1464 error (_("Python support required"));
1468 /* Update the values for a variable and its children. This is a
1469 two-pronged attack. First, re-parse the value for the root's
1470 expression to see if it's changed. Then go all the way
1471 through its children, reconstructing them and noting if they've
1474 The EXPLICIT parameter specifies if this call is result
1475 of MI request to update this specific variable, or
1476 result of implicit -var-update *. For implicit request, we don't
1477 update frozen variables.
1479 NOTE: This function may delete the caller's varobj. If it
1480 returns TYPE_CHANGED, then it has done this and VARP will be modified
1481 to point to the new varobj. */
1483 VEC(varobj_update_result) *varobj_update (struct varobj **varp, int explicit)
1486 int type_changed = 0;
1491 struct varobj **templist = NULL;
1493 VEC (varobj_update_result) *stack = NULL;
1494 VEC (varobj_update_result) *result = NULL;
1495 struct frame_info *fi;
1497 /* Frozen means frozen -- we don't check for any change in
1498 this varobj, including its going out of scope, or
1499 changing type. One use case for frozen varobjs is
1500 retaining previously evaluated expressions, and we don't
1501 want them to be reevaluated at all. */
1502 if (!explicit && (*varp)->frozen)
1505 if (!(*varp)->root->is_valid)
1507 varobj_update_result r = {*varp};
1508 r.status = VAROBJ_INVALID;
1509 VEC_safe_push (varobj_update_result, result, &r);
1513 if ((*varp)->root->rootvar == *varp)
1515 varobj_update_result r = {*varp};
1516 r.status = VAROBJ_IN_SCOPE;
1518 /* Update the root variable. value_of_root can return NULL
1519 if the variable is no longer around, i.e. we stepped out of
1520 the frame in which a local existed. We are letting the
1521 value_of_root variable dispose of the varobj if the type
1523 new = value_of_root (varp, &type_changed);
1526 r.type_changed = type_changed;
1527 if (install_new_value ((*varp), new, type_changed))
1531 r.status = VAROBJ_NOT_IN_SCOPE;
1532 r.value_installed = 1;
1534 if (r.status == VAROBJ_NOT_IN_SCOPE)
1536 if (r.type_changed || r.changed)
1537 VEC_safe_push (varobj_update_result, result, &r);
1541 VEC_safe_push (varobj_update_result, stack, &r);
1545 varobj_update_result r = {*varp};
1546 VEC_safe_push (varobj_update_result, stack, &r);
1549 /* Walk through the children, reconstructing them all. */
1550 while (!VEC_empty (varobj_update_result, stack))
1552 varobj_update_result r = *(VEC_last (varobj_update_result, stack));
1553 struct varobj *v = r.varobj;
1555 VEC_pop (varobj_update_result, stack);
1557 /* Update this variable, unless it's a root, which is already
1559 if (!r.value_installed)
1561 new = value_of_child (v->parent, v->index);
1562 if (install_new_value (v, new, 0 /* type not changed */))
1569 /* We probably should not get children of a varobj that has a
1570 pretty-printer, but for which -var-list-children was never
1571 invoked. Presumably, such varobj is not yet expanded in the
1572 UI, so we need not bother getting it. */
1573 if (v->pretty_printer)
1575 VEC (varobj_p) *changed = 0, *new_and_unchanged = 0;
1576 int i, children_changed;
1579 if (!v->children_requested)
1585 /* If update_dynamic_varobj_children returns 0, then we have
1586 a non-conforming pretty-printer, so we skip it. */
1587 if (update_dynamic_varobj_children (v, &changed, &new_and_unchanged,
1590 if (children_changed)
1591 r.children_changed = 1;
1592 for (i = 0; VEC_iterate (varobj_p, changed, i, tmp); ++i)
1594 varobj_update_result r = {tmp};
1596 r.value_installed = 1;
1597 VEC_safe_push (varobj_update_result, stack, &r);
1600 VEC_iterate (varobj_p, new_and_unchanged, i, tmp);
1603 varobj_update_result r = {tmp};
1604 r.value_installed = 1;
1605 VEC_safe_push (varobj_update_result, stack, &r);
1607 if (r.changed || r.children_changed)
1608 VEC_safe_push (varobj_update_result, result, &r);
1613 /* Push any children. Use reverse order so that the first
1614 child is popped from the work stack first, and so
1615 will be added to result first. This does not
1616 affect correctness, just "nicer". */
1617 for (i = VEC_length (varobj_p, v->children)-1; i >= 0; --i)
1619 varobj_p c = VEC_index (varobj_p, v->children, i);
1620 /* Child may be NULL if explicitly deleted by -var-delete. */
1621 if (c != NULL && !c->frozen)
1623 varobj_update_result r = {c};
1624 VEC_safe_push (varobj_update_result, stack, &r);
1628 if (r.changed || r.type_changed)
1629 VEC_safe_push (varobj_update_result, result, &r);
1632 VEC_free (varobj_update_result, stack);
1638 /* Helper functions */
1641 * Variable object construction/destruction
1645 delete_variable (struct cpstack **resultp, struct varobj *var,
1646 int only_children_p)
1650 delete_variable_1 (resultp, &delcount, var,
1651 only_children_p, 1 /* remove_from_parent_p */ );
1656 /* Delete the variable object VAR and its children */
1657 /* IMPORTANT NOTE: If we delete a variable which is a child
1658 and the parent is not removed we dump core. It must be always
1659 initially called with remove_from_parent_p set */
1661 delete_variable_1 (struct cpstack **resultp, int *delcountp,
1662 struct varobj *var, int only_children_p,
1663 int remove_from_parent_p)
1667 /* Delete any children of this variable, too. */
1668 for (i = 0; i < VEC_length (varobj_p, var->children); ++i)
1670 varobj_p child = VEC_index (varobj_p, var->children, i);
1673 if (!remove_from_parent_p)
1674 child->parent = NULL;
1675 delete_variable_1 (resultp, delcountp, child, 0, only_children_p);
1677 VEC_free (varobj_p, var->children);
1679 /* if we were called to delete only the children we are done here */
1680 if (only_children_p)
1683 /* Otherwise, add it to the list of deleted ones and proceed to do so */
1684 /* If the name is null, this is a temporary variable, that has not
1685 yet been installed, don't report it, it belongs to the caller... */
1686 if (var->obj_name != NULL)
1688 cppush (resultp, xstrdup (var->obj_name));
1689 *delcountp = *delcountp + 1;
1692 /* If this variable has a parent, remove it from its parent's list */
1693 /* OPTIMIZATION: if the parent of this variable is also being deleted,
1694 (as indicated by remove_from_parent_p) we don't bother doing an
1695 expensive list search to find the element to remove when we are
1696 discarding the list afterwards */
1697 if ((remove_from_parent_p) && (var->parent != NULL))
1699 VEC_replace (varobj_p, var->parent->children, var->index, NULL);
1702 if (var->obj_name != NULL)
1703 uninstall_variable (var);
1705 /* Free memory associated with this variable */
1706 free_variable (var);
1709 /* Install the given variable VAR with the object name VAR->OBJ_NAME. */
1711 install_variable (struct varobj *var)
1714 struct vlist *newvl;
1716 unsigned int index = 0;
1719 for (chp = var->obj_name; *chp; chp++)
1721 index = (index + (i++ * (unsigned int) *chp)) % VAROBJ_TABLE_SIZE;
1724 cv = *(varobj_table + index);
1725 while ((cv != NULL) && (strcmp (cv->var->obj_name, var->obj_name) != 0))
1729 error (_("Duplicate variable object name"));
1731 /* Add varobj to hash table */
1732 newvl = xmalloc (sizeof (struct vlist));
1733 newvl->next = *(varobj_table + index);
1735 *(varobj_table + index) = newvl;
1737 /* If root, add varobj to root list */
1738 if (is_root_p (var))
1740 /* Add to list of root variables */
1741 if (rootlist == NULL)
1742 var->root->next = NULL;
1744 var->root->next = rootlist;
1745 rootlist = var->root;
1752 /* Unistall the object VAR. */
1754 uninstall_variable (struct varobj *var)
1758 struct varobj_root *cr;
1759 struct varobj_root *prer;
1761 unsigned int index = 0;
1764 /* Remove varobj from hash table */
1765 for (chp = var->obj_name; *chp; chp++)
1767 index = (index + (i++ * (unsigned int) *chp)) % VAROBJ_TABLE_SIZE;
1770 cv = *(varobj_table + index);
1772 while ((cv != NULL) && (strcmp (cv->var->obj_name, var->obj_name) != 0))
1779 fprintf_unfiltered (gdb_stdlog, "Deleting %s\n", var->obj_name);
1784 ("Assertion failed: Could not find variable object \"%s\" to delete",
1790 *(varobj_table + index) = cv->next;
1792 prev->next = cv->next;
1796 /* If root, remove varobj from root list */
1797 if (is_root_p (var))
1799 /* Remove from list of root variables */
1800 if (rootlist == var->root)
1801 rootlist = var->root->next;
1806 while ((cr != NULL) && (cr->rootvar != var))
1814 ("Assertion failed: Could not find varobj \"%s\" in root list",
1821 prer->next = cr->next;
1828 /* Create and install a child of the parent of the given name */
1829 static struct varobj *
1830 create_child (struct varobj *parent, int index, char *name)
1832 return create_child_with_value (parent, index, name,
1833 value_of_child (parent, index));
1836 static struct varobj *
1837 create_child_with_value (struct varobj *parent, int index, const char *name,
1838 struct value *value)
1840 struct varobj *child;
1843 child = new_variable ();
1845 /* name is allocated by name_of_child */
1846 /* FIXME: xstrdup should not be here. */
1847 child->name = xstrdup (name);
1848 child->index = index;
1849 child->parent = parent;
1850 child->root = parent->root;
1851 childs_name = xstrprintf ("%s.%s", parent->obj_name, name);
1852 child->obj_name = childs_name;
1853 install_variable (child);
1855 /* Compute the type of the child. Must do this before
1856 calling install_new_value. */
1858 /* If the child had no evaluation errors, var->value
1859 will be non-NULL and contain a valid type. */
1860 child->type = value_type (value);
1862 /* Otherwise, we must compute the type. */
1863 child->type = (*child->root->lang->type_of_child) (child->parent,
1865 install_new_value (child, value, 1);
1872 * Miscellaneous utility functions.
1875 /* Allocate memory and initialize a new variable */
1876 static struct varobj *
1881 var = (struct varobj *) xmalloc (sizeof (struct varobj));
1883 var->path_expr = NULL;
1884 var->obj_name = NULL;
1888 var->num_children = -1;
1890 var->children = NULL;
1894 var->print_value = NULL;
1896 var->not_fetched = 0;
1897 var->children_requested = 0;
1898 var->pretty_printer = 0;
1903 /* Allocate memory and initialize a new root variable */
1904 static struct varobj *
1905 new_root_variable (void)
1907 struct varobj *var = new_variable ();
1908 var->root = (struct varobj_root *) xmalloc (sizeof (struct varobj_root));;
1909 var->root->lang = NULL;
1910 var->root->exp = NULL;
1911 var->root->valid_block = NULL;
1912 var->root->frame = null_frame_id;
1913 var->root->floating = 0;
1914 var->root->rootvar = NULL;
1915 var->root->is_valid = 1;
1920 /* Free any allocated memory associated with VAR. */
1922 free_variable (struct varobj *var)
1924 value_free (var->value);
1926 /* Free the expression if this is a root variable. */
1927 if (is_root_p (var))
1929 xfree (var->root->exp);
1935 PyGILState_STATE state = PyGILState_Ensure ();
1936 Py_XDECREF (var->pretty_printer);
1937 PyGILState_Release (state);
1942 xfree (var->obj_name);
1943 xfree (var->print_value);
1944 xfree (var->path_expr);
1949 do_free_variable_cleanup (void *var)
1951 free_variable (var);
1954 static struct cleanup *
1955 make_cleanup_free_variable (struct varobj *var)
1957 return make_cleanup (do_free_variable_cleanup, var);
1960 /* This returns the type of the variable. It also skips past typedefs
1961 to return the real type of the variable.
1963 NOTE: TYPE_TARGET_TYPE should NOT be used anywhere in this file
1964 except within get_target_type and get_type. */
1965 static struct type *
1966 get_type (struct varobj *var)
1972 type = check_typedef (type);
1977 /* Return the type of the value that's stored in VAR,
1978 or that would have being stored there if the
1979 value were accessible.
1981 This differs from VAR->type in that VAR->type is always
1982 the true type of the expession in the source language.
1983 The return value of this function is the type we're
1984 actually storing in varobj, and using for displaying
1985 the values and for comparing previous and new values.
1987 For example, top-level references are always stripped. */
1988 static struct type *
1989 get_value_type (struct varobj *var)
1994 type = value_type (var->value);
1998 type = check_typedef (type);
2000 if (TYPE_CODE (type) == TYPE_CODE_REF)
2001 type = get_target_type (type);
2003 type = check_typedef (type);
2008 /* This returns the target type (or NULL) of TYPE, also skipping
2009 past typedefs, just like get_type ().
2011 NOTE: TYPE_TARGET_TYPE should NOT be used anywhere in this file
2012 except within get_target_type and get_type. */
2013 static struct type *
2014 get_target_type (struct type *type)
2018 type = TYPE_TARGET_TYPE (type);
2020 type = check_typedef (type);
2026 /* What is the default display for this variable? We assume that
2027 everything is "natural". Any exceptions? */
2028 static enum varobj_display_formats
2029 variable_default_display (struct varobj *var)
2031 return FORMAT_NATURAL;
2034 /* FIXME: The following should be generic for any pointer */
2036 cppush (struct cpstack **pstack, char *name)
2040 s = (struct cpstack *) xmalloc (sizeof (struct cpstack));
2046 /* FIXME: The following should be generic for any pointer */
2048 cppop (struct cpstack **pstack)
2053 if ((*pstack)->name == NULL && (*pstack)->next == NULL)
2058 *pstack = (*pstack)->next;
2065 * Language-dependencies
2068 /* Common entry points */
2070 /* Get the language of variable VAR. */
2071 static enum varobj_languages
2072 variable_language (struct varobj *var)
2074 enum varobj_languages lang;
2076 switch (var->root->exp->language_defn->la_language)
2082 case language_cplus:
2093 /* Return the number of children for a given variable.
2094 The result of this function is defined by the language
2095 implementation. The number of children returned by this function
2096 is the number of children that the user will see in the variable
2099 number_of_children (struct varobj *var)
2101 return (*var->root->lang->number_of_children) (var);;
2104 /* What is the expression for the root varobj VAR? Returns a malloc'd string. */
2106 name_of_variable (struct varobj *var)
2108 return (*var->root->lang->name_of_variable) (var);
2111 /* What is the name of the INDEX'th child of VAR? Returns a malloc'd string. */
2113 name_of_child (struct varobj *var, int index)
2115 return (*var->root->lang->name_of_child) (var, index);
2118 /* What is the ``struct value *'' of the root variable VAR?
2119 For floating variable object, evaluation can get us a value
2120 of different type from what is stored in varobj already. In
2122 - *type_changed will be set to 1
2123 - old varobj will be freed, and new one will be
2124 created, with the same name.
2125 - *var_handle will be set to the new varobj
2126 Otherwise, *type_changed will be set to 0. */
2127 static struct value *
2128 value_of_root (struct varobj **var_handle, int *type_changed)
2132 if (var_handle == NULL)
2137 /* This should really be an exception, since this should
2138 only get called with a root variable. */
2140 if (!is_root_p (var))
2143 if (var->root->floating)
2145 struct varobj *tmp_var;
2146 char *old_type, *new_type;
2148 tmp_var = varobj_create (NULL, var->name, (CORE_ADDR) 0,
2149 USE_SELECTED_FRAME);
2150 if (tmp_var == NULL)
2154 old_type = varobj_get_type (var);
2155 new_type = varobj_get_type (tmp_var);
2156 if (strcmp (old_type, new_type) == 0)
2158 /* The expression presently stored inside var->root->exp
2159 remembers the locations of local variables relatively to
2160 the frame where the expression was created (in DWARF location
2161 button, for example). Naturally, those locations are not
2162 correct in other frames, so update the expression. */
2164 struct expression *tmp_exp = var->root->exp;
2165 var->root->exp = tmp_var->root->exp;
2166 tmp_var->root->exp = tmp_exp;
2168 varobj_delete (tmp_var, NULL, 0);
2173 tmp_var->obj_name = xstrdup (var->obj_name);
2174 varobj_delete (var, NULL, 0);
2176 install_variable (tmp_var);
2177 *var_handle = tmp_var;
2189 return (*var->root->lang->value_of_root) (var_handle);
2192 /* What is the ``struct value *'' for the INDEX'th child of PARENT? */
2193 static struct value *
2194 value_of_child (struct varobj *parent, int index)
2196 struct value *value;
2198 value = (*parent->root->lang->value_of_child) (parent, index);
2203 /* GDB already has a command called "value_of_variable". Sigh. */
2205 my_value_of_variable (struct varobj *var, enum varobj_display_formats format)
2207 if (var->root->is_valid)
2208 return (*var->root->lang->value_of_variable) (var, format);
2214 value_get_print_value (struct value *value, enum varobj_display_formats format,
2215 PyObject *value_formatter)
2218 struct ui_file *stb;
2219 struct cleanup *old_chain;
2220 char *thevalue = NULL;
2221 struct value_print_options opts;
2228 PyGILState_STATE state = PyGILState_Ensure ();
2229 if (value_formatter && PyObject_HasAttr (value_formatter,
2230 gdbpy_to_string_cst))
2233 struct value *replacement;
2234 int string_print = 0;
2236 hint = gdbpy_get_display_hint (value_formatter);
2239 if (!strcmp (hint, "string"))
2244 thevalue = apply_varobj_pretty_printer (value_formatter,
2246 if (thevalue && !string_print)
2248 PyGILState_Release (state);
2252 value = replacement;
2254 PyGILState_Release (state);
2258 stb = mem_fileopen ();
2259 old_chain = make_cleanup_ui_file_delete (stb);
2261 get_formatted_print_options (&opts, format_code[(int) format]);
2266 struct gdbarch *gdbarch = get_type_arch (value_type (value));
2267 make_cleanup (xfree, thevalue);
2268 LA_PRINT_STRING (stb, builtin_type (gdbarch)->builtin_char,
2269 (gdb_byte *) thevalue, strlen (thevalue),
2273 common_val_print (value, stb, 0, &opts, current_language);
2274 thevalue = ui_file_xstrdup (stb, &dummy);
2276 do_cleanups (old_chain);
2281 varobj_editable_p (struct varobj *var)
2284 struct value *value;
2286 if (!(var->root->is_valid && var->value && VALUE_LVAL (var->value)))
2289 type = get_value_type (var);
2291 switch (TYPE_CODE (type))
2293 case TYPE_CODE_STRUCT:
2294 case TYPE_CODE_UNION:
2295 case TYPE_CODE_ARRAY:
2296 case TYPE_CODE_FUNC:
2297 case TYPE_CODE_METHOD:
2307 /* Return non-zero if changes in value of VAR
2308 must be detected and reported by -var-update.
2309 Return zero is -var-update should never report
2310 changes of such values. This makes sense for structures
2311 (since the changes in children values will be reported separately),
2312 or for artifical objects (like 'public' pseudo-field in C++).
2314 Return value of 0 means that gdb need not call value_fetch_lazy
2315 for the value of this variable object. */
2317 varobj_value_is_changeable_p (struct varobj *var)
2322 if (CPLUS_FAKE_CHILD (var))
2325 type = get_value_type (var);
2327 switch (TYPE_CODE (type))
2329 case TYPE_CODE_STRUCT:
2330 case TYPE_CODE_UNION:
2331 case TYPE_CODE_ARRAY:
2342 /* Return 1 if that varobj is floating, that is is always evaluated in the
2343 selected frame, and not bound to thread/frame. Such variable objects
2344 are created using '@' as frame specifier to -var-create. */
2346 varobj_floating_p (struct varobj *var)
2348 return var->root->floating;
2351 /* Given the value and the type of a variable object,
2352 adjust the value and type to those necessary
2353 for getting children of the variable object.
2354 This includes dereferencing top-level references
2355 to all types and dereferencing pointers to
2358 Both TYPE and *TYPE should be non-null. VALUE
2359 can be null if we want to only translate type.
2360 *VALUE can be null as well -- if the parent
2363 If WAS_PTR is not NULL, set *WAS_PTR to 0 or 1
2364 depending on whether pointer was dereferenced
2365 in this function. */
2367 adjust_value_for_child_access (struct value **value,
2371 gdb_assert (type && *type);
2376 *type = check_typedef (*type);
2378 /* The type of value stored in varobj, that is passed
2379 to us, is already supposed to be
2380 reference-stripped. */
2382 gdb_assert (TYPE_CODE (*type) != TYPE_CODE_REF);
2384 /* Pointers to structures are treated just like
2385 structures when accessing children. Don't
2386 dererences pointers to other types. */
2387 if (TYPE_CODE (*type) == TYPE_CODE_PTR)
2389 struct type *target_type = get_target_type (*type);
2390 if (TYPE_CODE (target_type) == TYPE_CODE_STRUCT
2391 || TYPE_CODE (target_type) == TYPE_CODE_UNION)
2393 if (value && *value)
2395 int success = gdb_value_ind (*value, value);
2399 *type = target_type;
2405 /* The 'get_target_type' function calls check_typedef on
2406 result, so we can immediately check type code. No
2407 need to call check_typedef here. */
2412 c_number_of_children (struct varobj *var)
2414 struct type *type = get_value_type (var);
2416 struct type *target;
2418 adjust_value_for_child_access (NULL, &type, NULL);
2419 target = get_target_type (type);
2421 switch (TYPE_CODE (type))
2423 case TYPE_CODE_ARRAY:
2424 if (TYPE_LENGTH (type) > 0 && TYPE_LENGTH (target) > 0
2425 && !TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (type))
2426 children = TYPE_LENGTH (type) / TYPE_LENGTH (target);
2428 /* If we don't know how many elements there are, don't display
2433 case TYPE_CODE_STRUCT:
2434 case TYPE_CODE_UNION:
2435 children = TYPE_NFIELDS (type);
2439 /* The type here is a pointer to non-struct. Typically, pointers
2440 have one child, except for function ptrs, which have no children,
2441 and except for void*, as we don't know what to show.
2443 We can show char* so we allow it to be dereferenced. If you decide
2444 to test for it, please mind that a little magic is necessary to
2445 properly identify it: char* has TYPE_CODE == TYPE_CODE_INT and
2446 TYPE_NAME == "char" */
2447 if (TYPE_CODE (target) == TYPE_CODE_FUNC
2448 || TYPE_CODE (target) == TYPE_CODE_VOID)
2455 /* Other types have no children */
2463 c_name_of_variable (struct varobj *parent)
2465 return xstrdup (parent->name);
2468 /* Return the value of element TYPE_INDEX of a structure
2469 value VALUE. VALUE's type should be a structure,
2470 or union, or a typedef to struct/union.
2472 Returns NULL if getting the value fails. Never throws. */
2473 static struct value *
2474 value_struct_element_index (struct value *value, int type_index)
2476 struct value *result = NULL;
2477 volatile struct gdb_exception e;
2479 struct type *type = value_type (value);
2480 type = check_typedef (type);
2482 gdb_assert (TYPE_CODE (type) == TYPE_CODE_STRUCT
2483 || TYPE_CODE (type) == TYPE_CODE_UNION);
2485 TRY_CATCH (e, RETURN_MASK_ERROR)
2487 if (field_is_static (&TYPE_FIELD (type, type_index)))
2488 result = value_static_field (type, type_index);
2490 result = value_primitive_field (value, 0, type_index, type);
2502 /* Obtain the information about child INDEX of the variable
2504 If CNAME is not null, sets *CNAME to the name of the child relative
2506 If CVALUE is not null, sets *CVALUE to the value of the child.
2507 If CTYPE is not null, sets *CTYPE to the type of the child.
2509 If any of CNAME, CVALUE, or CTYPE is not null, but the corresponding
2510 information cannot be determined, set *CNAME, *CVALUE, or *CTYPE
2513 c_describe_child (struct varobj *parent, int index,
2514 char **cname, struct value **cvalue, struct type **ctype,
2515 char **cfull_expression)
2517 struct value *value = parent->value;
2518 struct type *type = get_value_type (parent);
2519 char *parent_expression = NULL;
2528 if (cfull_expression)
2530 *cfull_expression = NULL;
2531 parent_expression = varobj_get_path_expr (parent);
2533 adjust_value_for_child_access (&value, &type, &was_ptr);
2535 switch (TYPE_CODE (type))
2537 case TYPE_CODE_ARRAY:
2539 *cname = xstrprintf ("%d", index
2540 + TYPE_LOW_BOUND (TYPE_INDEX_TYPE (type)));
2542 if (cvalue && value)
2544 int real_index = index + TYPE_LOW_BOUND (TYPE_INDEX_TYPE (type));
2545 gdb_value_subscript (value, real_index, cvalue);
2549 *ctype = get_target_type (type);
2551 if (cfull_expression)
2552 *cfull_expression = xstrprintf ("(%s)[%d]", parent_expression,
2554 + TYPE_LOW_BOUND (TYPE_INDEX_TYPE (type)));
2559 case TYPE_CODE_STRUCT:
2560 case TYPE_CODE_UNION:
2562 *cname = xstrdup (TYPE_FIELD_NAME (type, index));
2564 if (cvalue && value)
2566 /* For C, varobj index is the same as type index. */
2567 *cvalue = value_struct_element_index (value, index);
2571 *ctype = TYPE_FIELD_TYPE (type, index);
2573 if (cfull_expression)
2575 char *join = was_ptr ? "->" : ".";
2576 *cfull_expression = xstrprintf ("(%s)%s%s", parent_expression, join,
2577 TYPE_FIELD_NAME (type, index));
2584 *cname = xstrprintf ("*%s", parent->name);
2586 if (cvalue && value)
2588 int success = gdb_value_ind (value, cvalue);
2593 /* Don't use get_target_type because it calls
2594 check_typedef and here, we want to show the true
2595 declared type of the variable. */
2597 *ctype = TYPE_TARGET_TYPE (type);
2599 if (cfull_expression)
2600 *cfull_expression = xstrprintf ("*(%s)", parent_expression);
2605 /* This should not happen */
2607 *cname = xstrdup ("???");
2608 if (cfull_expression)
2609 *cfull_expression = xstrdup ("???");
2610 /* Don't set value and type, we don't know then. */
2615 c_name_of_child (struct varobj *parent, int index)
2618 c_describe_child (parent, index, &name, NULL, NULL, NULL);
2623 c_path_expr_of_child (struct varobj *child)
2625 c_describe_child (child->parent, child->index, NULL, NULL, NULL,
2627 return child->path_expr;
2630 /* If frame associated with VAR can be found, switch
2631 to it and return 1. Otherwise, return 0. */
2633 check_scope (struct varobj *var)
2635 struct frame_info *fi;
2638 fi = frame_find_by_id (var->root->frame);
2643 CORE_ADDR pc = get_frame_pc (fi);
2644 if (pc < BLOCK_START (var->root->valid_block) ||
2645 pc >= BLOCK_END (var->root->valid_block))
2653 static struct value *
2654 c_value_of_root (struct varobj **var_handle)
2656 struct value *new_val = NULL;
2657 struct varobj *var = *var_handle;
2658 struct frame_info *fi;
2659 int within_scope = 0;
2660 struct cleanup *back_to;
2662 /* Only root variables can be updated... */
2663 if (!is_root_p (var))
2664 /* Not a root var */
2667 back_to = make_cleanup_restore_current_thread ();
2669 /* Determine whether the variable is still around. */
2670 if (var->root->valid_block == NULL || var->root->floating)
2672 else if (var->root->thread_id == 0)
2674 /* The program was single-threaded when the variable object was
2675 created. Technically, it's possible that the program became
2676 multi-threaded since then, but we don't support such
2678 within_scope = check_scope (var);
2682 ptid_t ptid = thread_id_to_pid (var->root->thread_id);
2683 if (in_thread_list (ptid))
2685 switch_to_thread (ptid);
2686 within_scope = check_scope (var);
2692 /* We need to catch errors here, because if evaluate
2693 expression fails we want to just return NULL. */
2694 gdb_evaluate_expression (var->root->exp, &new_val);
2698 do_cleanups (back_to);
2703 static struct value *
2704 c_value_of_child (struct varobj *parent, int index)
2706 struct value *value = NULL;
2707 c_describe_child (parent, index, NULL, &value, NULL, NULL);
2712 static struct type *
2713 c_type_of_child (struct varobj *parent, int index)
2715 struct type *type = NULL;
2716 c_describe_child (parent, index, NULL, NULL, &type, NULL);
2721 c_value_of_variable (struct varobj *var, enum varobj_display_formats format)
2723 /* BOGUS: if val_print sees a struct/class, or a reference to one,
2724 it will print out its children instead of "{...}". So we need to
2725 catch that case explicitly. */
2726 struct type *type = get_type (var);
2728 /* If we have a custom formatter, return whatever string it has
2730 if (var->pretty_printer && var->print_value)
2731 return xstrdup (var->print_value);
2733 /* Strip top-level references. */
2734 while (TYPE_CODE (type) == TYPE_CODE_REF)
2735 type = check_typedef (TYPE_TARGET_TYPE (type));
2737 switch (TYPE_CODE (type))
2739 case TYPE_CODE_STRUCT:
2740 case TYPE_CODE_UNION:
2741 return xstrdup ("{...}");
2744 case TYPE_CODE_ARRAY:
2747 number = xstrprintf ("[%d]", var->num_children);
2754 if (var->value == NULL)
2756 /* This can happen if we attempt to get the value of a struct
2757 member when the parent is an invalid pointer. This is an
2758 error condition, so we should tell the caller. */
2763 if (var->not_fetched && value_lazy (var->value))
2764 /* Frozen variable and no value yet. We don't
2765 implicitly fetch the value. MI response will
2766 use empty string for the value, which is OK. */
2769 gdb_assert (varobj_value_is_changeable_p (var));
2770 gdb_assert (!value_lazy (var->value));
2772 /* If the specified format is the current one,
2773 we can reuse print_value */
2774 if (format == var->format)
2775 return xstrdup (var->print_value);
2777 return value_get_print_value (var->value, format,
2778 var->pretty_printer);
2788 cplus_number_of_children (struct varobj *var)
2791 int children, dont_know;
2796 if (!CPLUS_FAKE_CHILD (var))
2798 type = get_value_type (var);
2799 adjust_value_for_child_access (NULL, &type, NULL);
2801 if (((TYPE_CODE (type)) == TYPE_CODE_STRUCT) ||
2802 ((TYPE_CODE (type)) == TYPE_CODE_UNION))
2806 cplus_class_num_children (type, kids);
2807 if (kids[v_public] != 0)
2809 if (kids[v_private] != 0)
2811 if (kids[v_protected] != 0)
2814 /* Add any baseclasses */
2815 children += TYPE_N_BASECLASSES (type);
2818 /* FIXME: save children in var */
2825 type = get_value_type (var->parent);
2826 adjust_value_for_child_access (NULL, &type, NULL);
2828 cplus_class_num_children (type, kids);
2829 if (strcmp (var->name, "public") == 0)
2830 children = kids[v_public];
2831 else if (strcmp (var->name, "private") == 0)
2832 children = kids[v_private];
2834 children = kids[v_protected];
2839 children = c_number_of_children (var);
2844 /* Compute # of public, private, and protected variables in this class.
2845 That means we need to descend into all baseclasses and find out
2846 how many are there, too. */
2848 cplus_class_num_children (struct type *type, int children[3])
2852 children[v_public] = 0;
2853 children[v_private] = 0;
2854 children[v_protected] = 0;
2856 for (i = TYPE_N_BASECLASSES (type); i < TYPE_NFIELDS (type); i++)
2858 /* If we have a virtual table pointer, omit it. */
2859 if (TYPE_VPTR_BASETYPE (type) == type && TYPE_VPTR_FIELDNO (type) == i)
2862 if (TYPE_FIELD_PROTECTED (type, i))
2863 children[v_protected]++;
2864 else if (TYPE_FIELD_PRIVATE (type, i))
2865 children[v_private]++;
2867 children[v_public]++;
2872 cplus_name_of_variable (struct varobj *parent)
2874 return c_name_of_variable (parent);
2877 enum accessibility { private_field, protected_field, public_field };
2879 /* Check if field INDEX of TYPE has the specified accessibility.
2880 Return 0 if so and 1 otherwise. */
2882 match_accessibility (struct type *type, int index, enum accessibility acc)
2884 if (acc == private_field && TYPE_FIELD_PRIVATE (type, index))
2886 else if (acc == protected_field && TYPE_FIELD_PROTECTED (type, index))
2888 else if (acc == public_field && !TYPE_FIELD_PRIVATE (type, index)
2889 && !TYPE_FIELD_PROTECTED (type, index))
2896 cplus_describe_child (struct varobj *parent, int index,
2897 char **cname, struct value **cvalue, struct type **ctype,
2898 char **cfull_expression)
2901 struct value *value;
2904 char *parent_expression = NULL;
2912 if (cfull_expression)
2913 *cfull_expression = NULL;
2915 if (CPLUS_FAKE_CHILD (parent))
2917 value = parent->parent->value;
2918 type = get_value_type (parent->parent);
2919 if (cfull_expression)
2920 parent_expression = varobj_get_path_expr (parent->parent);
2924 value = parent->value;
2925 type = get_value_type (parent);
2926 if (cfull_expression)
2927 parent_expression = varobj_get_path_expr (parent);
2930 adjust_value_for_child_access (&value, &type, &was_ptr);
2932 if (TYPE_CODE (type) == TYPE_CODE_STRUCT
2933 || TYPE_CODE (type) == TYPE_CODE_UNION)
2935 char *join = was_ptr ? "->" : ".";
2936 if (CPLUS_FAKE_CHILD (parent))
2938 /* The fields of the class type are ordered as they
2939 appear in the class. We are given an index for a
2940 particular access control type ("public","protected",
2941 or "private"). We must skip over fields that don't
2942 have the access control we are looking for to properly
2943 find the indexed field. */
2944 int type_index = TYPE_N_BASECLASSES (type);
2945 enum accessibility acc = public_field;
2946 if (strcmp (parent->name, "private") == 0)
2947 acc = private_field;
2948 else if (strcmp (parent->name, "protected") == 0)
2949 acc = protected_field;
2953 if (TYPE_VPTR_BASETYPE (type) == type
2954 && type_index == TYPE_VPTR_FIELDNO (type))
2956 else if (match_accessibility (type, type_index, acc))
2963 *cname = xstrdup (TYPE_FIELD_NAME (type, type_index));
2965 if (cvalue && value)
2966 *cvalue = value_struct_element_index (value, type_index);
2969 *ctype = TYPE_FIELD_TYPE (type, type_index);
2971 if (cfull_expression)
2972 *cfull_expression = xstrprintf ("((%s)%s%s)", parent_expression,
2974 TYPE_FIELD_NAME (type, type_index));
2976 else if (index < TYPE_N_BASECLASSES (type))
2978 /* This is a baseclass. */
2980 *cname = xstrdup (TYPE_FIELD_NAME (type, index));
2982 if (cvalue && value)
2984 *cvalue = value_cast (TYPE_FIELD_TYPE (type, index), value);
2985 release_value (*cvalue);
2990 *ctype = TYPE_FIELD_TYPE (type, index);
2993 if (cfull_expression)
2995 char *ptr = was_ptr ? "*" : "";
2996 /* Cast the parent to the base' type. Note that in gdb,
2999 will create an lvalue, for all appearences, so we don't
3000 need to use more fancy:
3003 *cfull_expression = xstrprintf ("(%s(%s%s) %s)",
3005 TYPE_FIELD_NAME (type, index),
3012 char *access = NULL;
3014 cplus_class_num_children (type, children);
3016 /* Everything beyond the baseclasses can
3017 only be "public", "private", or "protected"
3019 The special "fake" children are always output by varobj in
3020 this order. So if INDEX == 2, it MUST be "protected". */
3021 index -= TYPE_N_BASECLASSES (type);
3025 if (children[v_public] > 0)
3027 else if (children[v_private] > 0)
3030 access = "protected";
3033 if (children[v_public] > 0)
3035 if (children[v_private] > 0)
3038 access = "protected";
3040 else if (children[v_private] > 0)
3041 access = "protected";
3044 /* Must be protected */
3045 access = "protected";
3052 gdb_assert (access);
3054 *cname = xstrdup (access);
3056 /* Value and type and full expression are null here. */
3061 c_describe_child (parent, index, cname, cvalue, ctype, cfull_expression);
3066 cplus_name_of_child (struct varobj *parent, int index)
3069 cplus_describe_child (parent, index, &name, NULL, NULL, NULL);
3074 cplus_path_expr_of_child (struct varobj *child)
3076 cplus_describe_child (child->parent, child->index, NULL, NULL, NULL,
3078 return child->path_expr;
3081 static struct value *
3082 cplus_value_of_root (struct varobj **var_handle)
3084 return c_value_of_root (var_handle);
3087 static struct value *
3088 cplus_value_of_child (struct varobj *parent, int index)
3090 struct value *value = NULL;
3091 cplus_describe_child (parent, index, NULL, &value, NULL, NULL);
3095 static struct type *
3096 cplus_type_of_child (struct varobj *parent, int index)
3098 struct type *type = NULL;
3099 cplus_describe_child (parent, index, NULL, NULL, &type, NULL);
3104 cplus_value_of_variable (struct varobj *var, enum varobj_display_formats format)
3107 /* If we have one of our special types, don't print out
3109 if (CPLUS_FAKE_CHILD (var))
3110 return xstrdup ("");
3112 return c_value_of_variable (var, format);
3118 java_number_of_children (struct varobj *var)
3120 return cplus_number_of_children (var);
3124 java_name_of_variable (struct varobj *parent)
3128 name = cplus_name_of_variable (parent);
3129 /* If the name has "-" in it, it is because we
3130 needed to escape periods in the name... */
3133 while (*p != '\000')
3144 java_name_of_child (struct varobj *parent, int index)
3148 name = cplus_name_of_child (parent, index);
3149 /* Escape any periods in the name... */
3152 while (*p != '\000')
3163 java_path_expr_of_child (struct varobj *child)
3168 static struct value *
3169 java_value_of_root (struct varobj **var_handle)
3171 return cplus_value_of_root (var_handle);
3174 static struct value *
3175 java_value_of_child (struct varobj *parent, int index)
3177 return cplus_value_of_child (parent, index);
3180 static struct type *
3181 java_type_of_child (struct varobj *parent, int index)
3183 return cplus_type_of_child (parent, index);
3187 java_value_of_variable (struct varobj *var, enum varobj_display_formats format)
3189 return cplus_value_of_variable (var, format);
3192 extern void _initialize_varobj (void);
3194 _initialize_varobj (void)
3196 int sizeof_table = sizeof (struct vlist *) * VAROBJ_TABLE_SIZE;
3198 varobj_table = xmalloc (sizeof_table);
3199 memset (varobj_table, 0, sizeof_table);
3201 add_setshow_zinteger_cmd ("debugvarobj", class_maintenance,
3203 Set varobj debugging."), _("\
3204 Show varobj debugging."), _("\
3205 When non-zero, varobj debugging is enabled."),
3208 &setlist, &showlist);
3211 /* Invalidate the varobjs that are tied to locals and re-create the ones that
3212 are defined on globals.
3213 Invalidated varobjs will be always printed in_scope="invalid". */
3216 varobj_invalidate (void)
3218 struct varobj **all_rootvarobj;
3219 struct varobj **varp;
3221 if (varobj_list (&all_rootvarobj) > 0)
3223 varp = all_rootvarobj;
3224 while (*varp != NULL)
3226 /* Floating varobjs are reparsed on each stop, so we don't care if
3227 the presently parsed expression refers to something that's gone.
3229 if ((*varp)->root->floating)
3232 /* global var must be re-evaluated. */
3233 if ((*varp)->root->valid_block == NULL)
3235 struct varobj *tmp_var;
3237 /* Try to create a varobj with same expression. If we succeed
3238 replace the old varobj, otherwise invalidate it. */
3239 tmp_var = varobj_create (NULL, (*varp)->name, (CORE_ADDR) 0,
3241 if (tmp_var != NULL)
3243 tmp_var->obj_name = xstrdup ((*varp)->obj_name);
3244 varobj_delete (*varp, NULL, 0);
3245 install_variable (tmp_var);
3248 (*varp)->root->is_valid = 0;
3250 else /* locals must be invalidated. */
3251 (*varp)->root->is_valid = 0;
3256 xfree (all_rootvarobj);