*** empty log message ***
[deliverable/binutils-gdb.git] / gdb / varobj.c
1 /* Implementation of the GDB variable objects API.
2
3 Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
4 2009 Free Software Foundation, Inc.
5
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.
10
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.
15
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/>. */
18
19 #include "defs.h"
20 #include "exceptions.h"
21 #include "value.h"
22 #include "expression.h"
23 #include "frame.h"
24 #include "language.h"
25 #include "wrapper.h"
26 #include "gdbcmd.h"
27 #include "block.h"
28 #include "valprint.h"
29
30 #include "gdb_assert.h"
31 #include "gdb_string.h"
32
33 #include "varobj.h"
34 #include "vec.h"
35 #include "gdbthread.h"
36 #include "inferior.h"
37 #include "typeprint.h"
38
39 #if HAVE_PYTHON
40 #include "python/python.h"
41 #include "python/python-internal.h"
42 #else
43 typedef int PyObject;
44 #endif
45
46 /* Non-zero if we want to see trace of varobj level stuff. */
47
48 int varobjdebug = 0;
49 static void
50 show_varobjdebug (struct ui_file *file, int from_tty,
51 struct cmd_list_element *c, const char *value)
52 {
53 fprintf_filtered (file, _("Varobj debugging is %s.\n"), value);
54 }
55
56 /* String representations of gdb's format codes */
57 char *varobj_format_string[] =
58 { "natural", "binary", "decimal", "hexadecimal", "octal" };
59
60 /* String representations of gdb's known languages */
61 char *varobj_language_string[] = { "unknown", "C", "C++", "Java" };
62
63 /* Data structures */
64
65 /* Every root variable has one of these structures saved in its
66 varobj. Members which must be free'd are noted. */
67 struct varobj_root
68 {
69
70 /* Alloc'd expression for this parent. */
71 struct expression *exp;
72
73 /* Block for which this expression is valid */
74 struct block *valid_block;
75
76 /* The frame for this expression. This field is set iff valid_block is
77 not NULL. */
78 struct frame_id frame;
79
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
84 was created. */
85 int thread_id;
86
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 */
90 int floating;
91
92 /* Flag that indicates validity: set to 0 when this varobj_root refers
93 to symbols that do not exist anymore. */
94 int is_valid;
95
96 /* Language info for this variable and its children */
97 struct language_specific *lang;
98
99 /* The varobj for this root node. */
100 struct varobj *rootvar;
101
102 /* Next root variable */
103 struct varobj_root *next;
104 };
105
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. */
109 struct varobj
110 {
111
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" */
116 char *name;
117
118 /* Alloc'd expression for this child. Can be used to create a
119 root variable corresponding to this child. */
120 char *path_expr;
121
122 /* The alloc'd name for this variable's object. This is here for
123 convenience when constructing this object's children. */
124 char *obj_name;
125
126 /* Index of this variable in its parent or -1 */
127 int index;
128
129 /* The type of this variable. This can be NULL
130 for artifial variable objects -- currently, the "accessibility"
131 variable objects in C++. */
132 struct type *type;
133
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. */
138 struct value *value;
139
140 /* The number of (immediate) children this variable has */
141 int num_children;
142
143 /* If this object is a child, this points to its immediate parent. */
144 struct varobj *parent;
145
146 /* Children of this object. */
147 VEC (varobj_p) *children;
148
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
152 can avoid that. */
153 int children_requested;
154
155 /* Description of the root variable. Points to root variable for children. */
156 struct varobj_root *root;
157
158 /* The format of the output for this object */
159 enum varobj_display_formats format;
160
161 /* Was this variable updated via a varobj_set_value operation */
162 int updated;
163
164 /* Last print value. */
165 char *print_value;
166
167 /* Is this variable frozen. Frozen variables are never implicitly
168 updated by -var-update *
169 or -var-update <direct-or-indirect-parent>. */
170 int frozen;
171
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
174 frozen. */
175 int not_fetched;
176
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;
180 };
181
182 struct cpstack
183 {
184 char *name;
185 struct cpstack *next;
186 };
187
188 /* A list of varobjs */
189
190 struct vlist
191 {
192 struct varobj *var;
193 struct vlist *next;
194 };
195
196 /* Private function prototypes */
197
198 /* Helper functions for the above subcommands. */
199
200 static int delete_variable (struct cpstack **, struct varobj *, int);
201
202 static void delete_variable_1 (struct cpstack **, int *,
203 struct varobj *, int, int);
204
205 static int install_variable (struct varobj *);
206
207 static void uninstall_variable (struct varobj *);
208
209 static struct varobj *create_child (struct varobj *, int, char *);
210
211 static struct varobj *
212 create_child_with_value (struct varobj *parent, int index, const char *name,
213 struct value *value);
214
215 /* Utility routines */
216
217 static struct varobj *new_variable (void);
218
219 static struct varobj *new_root_variable (void);
220
221 static void free_variable (struct varobj *var);
222
223 static struct cleanup *make_cleanup_free_variable (struct varobj *var);
224
225 static struct type *get_type (struct varobj *var);
226
227 static struct type *get_value_type (struct varobj *var);
228
229 static struct type *get_target_type (struct type *);
230
231 static enum varobj_display_formats variable_default_display (struct varobj *);
232
233 static void cppush (struct cpstack **pstack, char *name);
234
235 static char *cppop (struct cpstack **pstack);
236
237 static int install_new_value (struct varobj *var, struct value *value,
238 int initial);
239
240 static void install_default_visualizer (struct varobj *var);
241
242 /* Language-specific routines. */
243
244 static enum varobj_languages variable_language (struct varobj *var);
245
246 static int number_of_children (struct varobj *);
247
248 static char *name_of_variable (struct varobj *);
249
250 static char *name_of_child (struct varobj *, int);
251
252 static struct value *value_of_root (struct varobj **var_handle, int *);
253
254 static struct value *value_of_child (struct varobj *parent, int index);
255
256 static char *my_value_of_variable (struct varobj *var,
257 enum varobj_display_formats format);
258
259 static char *value_get_print_value (struct value *value,
260 enum varobj_display_formats format,
261 struct varobj *var);
262
263 static int varobj_value_is_changeable_p (struct varobj *var);
264
265 static int is_root_p (struct varobj *var);
266
267 static struct varobj *
268 varobj_add_child (struct varobj *var, const char *name, struct value *value);
269
270 /* C implementation */
271
272 static int c_number_of_children (struct varobj *var);
273
274 static char *c_name_of_variable (struct varobj *parent);
275
276 static char *c_name_of_child (struct varobj *parent, int index);
277
278 static char *c_path_expr_of_child (struct varobj *child);
279
280 static struct value *c_value_of_root (struct varobj **var_handle);
281
282 static struct value *c_value_of_child (struct varobj *parent, int index);
283
284 static struct type *c_type_of_child (struct varobj *parent, int index);
285
286 static char *c_value_of_variable (struct varobj *var,
287 enum varobj_display_formats format);
288
289 /* C++ implementation */
290
291 static int cplus_number_of_children (struct varobj *var);
292
293 static void cplus_class_num_children (struct type *type, int children[3]);
294
295 static char *cplus_name_of_variable (struct varobj *parent);
296
297 static char *cplus_name_of_child (struct varobj *parent, int index);
298
299 static char *cplus_path_expr_of_child (struct varobj *child);
300
301 static struct value *cplus_value_of_root (struct varobj **var_handle);
302
303 static struct value *cplus_value_of_child (struct varobj *parent, int index);
304
305 static struct type *cplus_type_of_child (struct varobj *parent, int index);
306
307 static char *cplus_value_of_variable (struct varobj *var,
308 enum varobj_display_formats format);
309
310 /* Java implementation */
311
312 static int java_number_of_children (struct varobj *var);
313
314 static char *java_name_of_variable (struct varobj *parent);
315
316 static char *java_name_of_child (struct varobj *parent, int index);
317
318 static char *java_path_expr_of_child (struct varobj *child);
319
320 static struct value *java_value_of_root (struct varobj **var_handle);
321
322 static struct value *java_value_of_child (struct varobj *parent, int index);
323
324 static struct type *java_type_of_child (struct varobj *parent, int index);
325
326 static char *java_value_of_variable (struct varobj *var,
327 enum varobj_display_formats format);
328
329 /* The language specific vector */
330
331 struct language_specific
332 {
333
334 /* The language of this variable */
335 enum varobj_languages language;
336
337 /* The number of children of PARENT. */
338 int (*number_of_children) (struct varobj * parent);
339
340 /* The name (expression) of a root varobj. */
341 char *(*name_of_variable) (struct varobj * parent);
342
343 /* The name of the INDEX'th child of PARENT. */
344 char *(*name_of_child) (struct varobj * parent, int index);
345
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);
349
350 /* The ``struct value *'' of the root variable ROOT. */
351 struct value *(*value_of_root) (struct varobj ** root_handle);
352
353 /* The ``struct value *'' of the INDEX'th child of PARENT. */
354 struct value *(*value_of_child) (struct varobj * parent, int index);
355
356 /* The type of the INDEX'th child of PARENT. */
357 struct type *(*type_of_child) (struct varobj * parent, int index);
358
359 /* The current value of VAR. */
360 char *(*value_of_variable) (struct varobj * var,
361 enum varobj_display_formats format);
362 };
363
364 /* Array of known source language routines. */
365 static struct language_specific languages[vlang_end] = {
366 /* Unknown (try treating as C */
367 {
368 vlang_unknown,
369 c_number_of_children,
370 c_name_of_variable,
371 c_name_of_child,
372 c_path_expr_of_child,
373 c_value_of_root,
374 c_value_of_child,
375 c_type_of_child,
376 c_value_of_variable}
377 ,
378 /* C */
379 {
380 vlang_c,
381 c_number_of_children,
382 c_name_of_variable,
383 c_name_of_child,
384 c_path_expr_of_child,
385 c_value_of_root,
386 c_value_of_child,
387 c_type_of_child,
388 c_value_of_variable}
389 ,
390 /* C++ */
391 {
392 vlang_cplus,
393 cplus_number_of_children,
394 cplus_name_of_variable,
395 cplus_name_of_child,
396 cplus_path_expr_of_child,
397 cplus_value_of_root,
398 cplus_value_of_child,
399 cplus_type_of_child,
400 cplus_value_of_variable}
401 ,
402 /* Java */
403 {
404 vlang_java,
405 java_number_of_children,
406 java_name_of_variable,
407 java_name_of_child,
408 java_path_expr_of_child,
409 java_value_of_root,
410 java_value_of_child,
411 java_type_of_child,
412 java_value_of_variable}
413 };
414
415 /* A little convenience enum for dealing with C++/Java */
416 enum vsections
417 {
418 v_public = 0, v_private, v_protected
419 };
420
421 /* Private data */
422
423 /* Mappings of varobj_display_formats enums to gdb's format codes */
424 static int format_code[] = { 0, 't', 'd', 'x', 'o' };
425
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 */
429
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
433
434 /* Pointer to the varobj hash table (built at run time) */
435 static struct vlist **varobj_table;
436
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)
440 \f
441
442 /* API Implementation */
443 static int
444 is_root_p (struct varobj *var)
445 {
446 return (var->root->rootvar == var);
447 }
448
449 #ifdef HAVE_PYTHON
450 /* Helper function to install a Python environment suitable for
451 use during operations on VAR. */
452 struct cleanup *
453 varobj_ensure_python_env (struct varobj *var)
454 {
455 return ensure_python_env (var->root->exp->gdbarch,
456 var->root->exp->language_defn);
457 }
458 #endif
459
460 /* Creates a varobj (not its children) */
461
462 /* Return the full FRAME which corresponds to the given CORE_ADDR
463 or NULL if no FRAME on the chain corresponds to CORE_ADDR. */
464
465 static struct frame_info *
466 find_frame_addr_in_frame_chain (CORE_ADDR frame_addr)
467 {
468 struct frame_info *frame = NULL;
469
470 if (frame_addr == (CORE_ADDR) 0)
471 return NULL;
472
473 for (frame = get_current_frame ();
474 frame != NULL;
475 frame = get_prev_frame (frame))
476 {
477 /* The CORE_ADDR we get as argument was parsed from a string GDB
478 output as $fp. This output got truncated to gdbarch_addr_bit.
479 Truncate the frame base address in the same manner before
480 comparing it against our argument. */
481 CORE_ADDR frame_base = get_frame_base_address (frame);
482 int addr_bit = gdbarch_addr_bit (get_frame_arch (frame));
483 if (addr_bit < (sizeof (CORE_ADDR) * HOST_CHAR_BIT))
484 frame_base &= ((CORE_ADDR) 1 << addr_bit) - 1;
485
486 if (frame_base == frame_addr)
487 return frame;
488 }
489
490 return NULL;
491 }
492
493 struct varobj *
494 varobj_create (char *objname,
495 char *expression, CORE_ADDR frame, enum varobj_type type)
496 {
497 struct varobj *var;
498 struct frame_info *fi;
499 struct frame_info *old_fi = NULL;
500 struct block *block;
501 struct cleanup *old_chain;
502
503 /* Fill out a varobj structure for the (root) variable being constructed. */
504 var = new_root_variable ();
505 old_chain = make_cleanup_free_variable (var);
506
507 if (expression != NULL)
508 {
509 char *p;
510 enum varobj_languages lang;
511 struct value *value = NULL;
512
513 /* Parse and evaluate the expression, filling in as much of the
514 variable's data as possible. */
515
516 if (has_stack_frames ())
517 {
518 /* Allow creator to specify context of variable */
519 if ((type == USE_CURRENT_FRAME) || (type == USE_SELECTED_FRAME))
520 fi = get_selected_frame (NULL);
521 else
522 /* FIXME: cagney/2002-11-23: This code should be doing a
523 lookup using the frame ID and not just the frame's
524 ``address''. This, of course, means an interface
525 change. However, with out that interface change ISAs,
526 such as the ia64 with its two stacks, won't work.
527 Similar goes for the case where there is a frameless
528 function. */
529 fi = find_frame_addr_in_frame_chain (frame);
530 }
531 else
532 fi = NULL;
533
534 /* frame = -2 means always use selected frame */
535 if (type == USE_SELECTED_FRAME)
536 var->root->floating = 1;
537
538 block = NULL;
539 if (fi != NULL)
540 block = get_frame_block (fi, 0);
541
542 p = expression;
543 innermost_block = NULL;
544 /* Wrap the call to parse expression, so we can
545 return a sensible error. */
546 if (!gdb_parse_exp_1 (&p, block, 0, &var->root->exp))
547 {
548 return NULL;
549 }
550
551 /* Don't allow variables to be created for types. */
552 if (var->root->exp->elts[0].opcode == OP_TYPE)
553 {
554 do_cleanups (old_chain);
555 fprintf_unfiltered (gdb_stderr, "Attempt to use a type name"
556 " as an expression.\n");
557 return NULL;
558 }
559
560 var->format = variable_default_display (var);
561 var->root->valid_block = innermost_block;
562 var->name = xstrdup (expression);
563 /* For a root var, the name and the expr are the same. */
564 var->path_expr = xstrdup (expression);
565
566 /* When the frame is different from the current frame,
567 we must select the appropriate frame before parsing
568 the expression, otherwise the value will not be current.
569 Since select_frame is so benign, just call it for all cases. */
570 if (innermost_block && fi != NULL)
571 {
572 var->root->frame = get_frame_id (fi);
573 var->root->thread_id = pid_to_thread_id (inferior_ptid);
574 old_fi = get_selected_frame (NULL);
575 select_frame (fi);
576 }
577
578 /* We definitely need to catch errors here.
579 If evaluate_expression succeeds we got the value we wanted.
580 But if it fails, we still go on with a call to evaluate_type() */
581 if (!gdb_evaluate_expression (var->root->exp, &value))
582 {
583 /* Error getting the value. Try to at least get the
584 right type. */
585 struct value *type_only_value = evaluate_type (var->root->exp);
586 var->type = value_type (type_only_value);
587 }
588 else
589 var->type = value_type (value);
590
591 install_new_value (var, value, 1 /* Initial assignment */);
592
593 /* Set language info */
594 lang = variable_language (var);
595 var->root->lang = &languages[lang];
596
597 /* Set ourselves as our root */
598 var->root->rootvar = var;
599
600 /* Reset the selected frame */
601 if (old_fi != NULL)
602 select_frame (old_fi);
603 }
604
605 /* If the variable object name is null, that means this
606 is a temporary variable, so don't install it. */
607
608 if ((var != NULL) && (objname != NULL))
609 {
610 var->obj_name = xstrdup (objname);
611
612 /* If a varobj name is duplicated, the install will fail so
613 we must clenup */
614 if (!install_variable (var))
615 {
616 do_cleanups (old_chain);
617 return NULL;
618 }
619 }
620
621 install_default_visualizer (var);
622 discard_cleanups (old_chain);
623 return var;
624 }
625
626 /* Generates an unique name that can be used for a varobj */
627
628 char *
629 varobj_gen_name (void)
630 {
631 static int id = 0;
632 char *obj_name;
633
634 /* generate a name for this object */
635 id++;
636 obj_name = xstrprintf ("var%d", id);
637
638 return obj_name;
639 }
640
641 /* Given an OBJNAME, returns the pointer to the corresponding varobj. Call
642 error if OBJNAME cannot be found. */
643
644 struct varobj *
645 varobj_get_handle (char *objname)
646 {
647 struct vlist *cv;
648 const char *chp;
649 unsigned int index = 0;
650 unsigned int i = 1;
651
652 for (chp = objname; *chp; chp++)
653 {
654 index = (index + (i++ * (unsigned int) *chp)) % VAROBJ_TABLE_SIZE;
655 }
656
657 cv = *(varobj_table + index);
658 while ((cv != NULL) && (strcmp (cv->var->obj_name, objname) != 0))
659 cv = cv->next;
660
661 if (cv == NULL)
662 error (_("Variable object not found"));
663
664 return cv->var;
665 }
666
667 /* Given the handle, return the name of the object */
668
669 char *
670 varobj_get_objname (struct varobj *var)
671 {
672 return var->obj_name;
673 }
674
675 /* Given the handle, return the expression represented by the object */
676
677 char *
678 varobj_get_expression (struct varobj *var)
679 {
680 return name_of_variable (var);
681 }
682
683 /* Deletes a varobj and all its children if only_children == 0,
684 otherwise deletes only the children; returns a malloc'ed list of all the
685 (malloc'ed) names of the variables that have been deleted (NULL terminated) */
686
687 int
688 varobj_delete (struct varobj *var, char ***dellist, int only_children)
689 {
690 int delcount;
691 int mycount;
692 struct cpstack *result = NULL;
693 char **cp;
694
695 /* Initialize a stack for temporary results */
696 cppush (&result, NULL);
697
698 if (only_children)
699 /* Delete only the variable children */
700 delcount = delete_variable (&result, var, 1 /* only the children */ );
701 else
702 /* Delete the variable and all its children */
703 delcount = delete_variable (&result, var, 0 /* parent+children */ );
704
705 /* We may have been asked to return a list of what has been deleted */
706 if (dellist != NULL)
707 {
708 *dellist = xmalloc ((delcount + 1) * sizeof (char *));
709
710 cp = *dellist;
711 mycount = delcount;
712 *cp = cppop (&result);
713 while ((*cp != NULL) && (mycount > 0))
714 {
715 mycount--;
716 cp++;
717 *cp = cppop (&result);
718 }
719
720 if (mycount || (*cp != NULL))
721 warning (_("varobj_delete: assertion failed - mycount(=%d) <> 0"),
722 mycount);
723 }
724
725 return delcount;
726 }
727
728 /* Convenience function for varobj_set_visualizer. Instantiate a
729 pretty-printer for a given value. */
730 static PyObject *
731 instantiate_pretty_printer (PyObject *constructor, struct value *value)
732 {
733 #if HAVE_PYTHON
734 PyObject *val_obj = NULL;
735 PyObject *printer;
736 volatile struct gdb_exception except;
737
738 TRY_CATCH (except, RETURN_MASK_ALL)
739 {
740 value = value_copy (value);
741 }
742 GDB_PY_HANDLE_EXCEPTION (except);
743 val_obj = value_to_value_object (value);
744
745 if (! val_obj)
746 return NULL;
747
748 printer = PyObject_CallFunctionObjArgs (constructor, val_obj, NULL);
749 Py_DECREF (val_obj);
750 return printer;
751 #endif
752 return NULL;
753 }
754
755 /* Set/Get variable object display format */
756
757 enum varobj_display_formats
758 varobj_set_display_format (struct varobj *var,
759 enum varobj_display_formats format)
760 {
761 switch (format)
762 {
763 case FORMAT_NATURAL:
764 case FORMAT_BINARY:
765 case FORMAT_DECIMAL:
766 case FORMAT_HEXADECIMAL:
767 case FORMAT_OCTAL:
768 var->format = format;
769 break;
770
771 default:
772 var->format = variable_default_display (var);
773 }
774
775 if (varobj_value_is_changeable_p (var)
776 && var->value && !value_lazy (var->value))
777 {
778 xfree (var->print_value);
779 var->print_value = value_get_print_value (var->value, var->format, var);
780 }
781
782 return var->format;
783 }
784
785 enum varobj_display_formats
786 varobj_get_display_format (struct varobj *var)
787 {
788 return var->format;
789 }
790
791 char *
792 varobj_get_display_hint (struct varobj *var)
793 {
794 char *result = NULL;
795
796 #if HAVE_PYTHON
797 struct cleanup *back_to = varobj_ensure_python_env (var);
798
799 if (var->pretty_printer)
800 result = gdbpy_get_display_hint (var->pretty_printer);
801
802 do_cleanups (back_to);
803 #endif
804
805 return result;
806 }
807
808 /* If the variable object is bound to a specific thread, that
809 is its evaluation can always be done in context of a frame
810 inside that thread, returns GDB id of the thread -- which
811 is always positive. Otherwise, returns -1. */
812 int
813 varobj_get_thread_id (struct varobj *var)
814 {
815 if (var->root->valid_block && var->root->thread_id > 0)
816 return var->root->thread_id;
817 else
818 return -1;
819 }
820
821 void
822 varobj_set_frozen (struct varobj *var, int frozen)
823 {
824 /* When a variable is unfrozen, we don't fetch its value.
825 The 'not_fetched' flag remains set, so next -var-update
826 won't complain.
827
828 We don't fetch the value, because for structures the client
829 should do -var-update anyway. It would be bad to have different
830 client-size logic for structure and other types. */
831 var->frozen = frozen;
832 }
833
834 int
835 varobj_get_frozen (struct varobj *var)
836 {
837 return var->frozen;
838 }
839
840 static int
841 update_dynamic_varobj_children (struct varobj *var,
842 VEC (varobj_p) **changed,
843 VEC (varobj_p) **new_and_unchanged,
844 int *cchanged)
845
846 {
847 #if HAVE_PYTHON
848 /* FIXME: we *might* want to provide this functionality as
849 a standalone function, so that other interested parties
850 than varobj code can benefit for this. */
851 struct cleanup *back_to;
852 PyObject *children;
853 PyObject *iterator;
854 int i;
855 int children_changed = 0;
856 PyObject *printer = var->pretty_printer;
857
858 back_to = varobj_ensure_python_env (var);
859
860 *cchanged = 0;
861 if (!PyObject_HasAttr (printer, gdbpy_children_cst))
862 {
863 do_cleanups (back_to);
864 return 0;
865 }
866
867 children = PyObject_CallMethodObjArgs (printer, gdbpy_children_cst,
868 NULL);
869
870 if (!children)
871 {
872 gdbpy_print_stack ();
873 error (_("Null value returned for children"));
874 }
875
876 make_cleanup_py_decref (children);
877
878 if (!PyIter_Check (children))
879 error (_("Returned value is not iterable"));
880
881 iterator = PyObject_GetIter (children);
882 if (!iterator)
883 {
884 gdbpy_print_stack ();
885 error (_("Could not get children iterator"));
886 }
887 make_cleanup_py_decref (iterator);
888
889 for (i = 0; ; ++i)
890 {
891 PyObject *item = PyIter_Next (iterator);
892 PyObject *py_v;
893 struct value *v;
894 char *name;
895 struct cleanup *inner;
896
897 if (!item)
898 break;
899 inner = make_cleanup_py_decref (item);
900
901 if (!PyArg_ParseTuple (item, "sO", &name, &py_v))
902 error (_("Invalid item from the child list"));
903
904 if (PyObject_TypeCheck (py_v, &value_object_type))
905 {
906 /* If we just call convert_value_from_python for this type,
907 we won't know who owns the result. For this one case we
908 need to copy the resulting value. */
909 v = value_object_to_value (py_v);
910 v = value_copy (v);
911 }
912 else
913 v = convert_value_from_python (py_v);
914
915 /* TODO: This assume the name of the i-th child never changes. */
916
917 /* Now see what to do here. */
918 if (VEC_length (varobj_p, var->children) < i + 1)
919 {
920 /* There's no child yet. */
921 struct varobj *child = varobj_add_child (var, name, v);
922 if (new_and_unchanged)
923 VEC_safe_push (varobj_p, *new_and_unchanged, child);
924 children_changed = 1;
925 }
926 else
927 {
928 varobj_p existing = VEC_index (varobj_p, var->children, i);
929 if (install_new_value (existing, v, 0) && changed)
930 {
931 if (changed)
932 VEC_safe_push (varobj_p, *changed, existing);
933 }
934 else
935 {
936 if (new_and_unchanged)
937 VEC_safe_push (varobj_p, *new_and_unchanged, existing);
938 }
939 }
940
941 do_cleanups (inner);
942 }
943
944 if (i < VEC_length (varobj_p, var->children))
945 {
946 int i;
947 children_changed = 1;
948 for (i = 0; i < VEC_length (varobj_p, var->children); ++i)
949 varobj_delete (VEC_index (varobj_p, var->children, i), NULL, 0);
950 }
951 VEC_truncate (varobj_p, var->children, i);
952 var->num_children = VEC_length (varobj_p, var->children);
953
954 do_cleanups (back_to);
955
956 *cchanged = children_changed;
957 return 1;
958 #else
959 gdb_assert (0 && "should never be called if Python is not enabled");
960 #endif
961 }
962
963 int
964 varobj_get_num_children (struct varobj *var)
965 {
966 if (var->num_children == -1)
967 {
968 int changed;
969 if (!var->pretty_printer
970 || !update_dynamic_varobj_children (var, NULL, NULL, &changed))
971 var->num_children = number_of_children (var);
972 }
973
974 return var->num_children;
975 }
976
977 /* Creates a list of the immediate children of a variable object;
978 the return code is the number of such children or -1 on error */
979
980 VEC (varobj_p)*
981 varobj_list_children (struct varobj *var)
982 {
983 struct varobj *child;
984 char *name;
985 int i, children_changed;
986
987 var->children_requested = 1;
988
989 if (var->pretty_printer
990 /* This, in theory, can result in the number of children changing without
991 frontend noticing. But well, calling -var-list-children on the same
992 varobj twice is not something a sane frontend would do. */
993 && update_dynamic_varobj_children (var, NULL, NULL, &children_changed))
994 return var->children;
995
996 if (var->num_children == -1)
997 var->num_children = number_of_children (var);
998
999 /* If that failed, give up. */
1000 if (var->num_children == -1)
1001 return var->children;
1002
1003 /* If we're called when the list of children is not yet initialized,
1004 allocate enough elements in it. */
1005 while (VEC_length (varobj_p, var->children) < var->num_children)
1006 VEC_safe_push (varobj_p, var->children, NULL);
1007
1008 for (i = 0; i < var->num_children; i++)
1009 {
1010 varobj_p existing = VEC_index (varobj_p, var->children, i);
1011
1012 if (existing == NULL)
1013 {
1014 /* Either it's the first call to varobj_list_children for
1015 this variable object, and the child was never created,
1016 or it was explicitly deleted by the client. */
1017 name = name_of_child (var, i);
1018 existing = create_child (var, i, name);
1019 VEC_replace (varobj_p, var->children, i, existing);
1020 install_default_visualizer (existing);
1021 }
1022 }
1023
1024 return var->children;
1025 }
1026
1027 static struct varobj *
1028 varobj_add_child (struct varobj *var, const char *name, struct value *value)
1029 {
1030 varobj_p v = create_child_with_value (var,
1031 VEC_length (varobj_p, var->children),
1032 name, value);
1033 VEC_safe_push (varobj_p, var->children, v);
1034 install_default_visualizer (v);
1035 return v;
1036 }
1037
1038 /* Obtain the type of an object Variable as a string similar to the one gdb
1039 prints on the console */
1040
1041 char *
1042 varobj_get_type (struct varobj *var)
1043 {
1044 /* For the "fake" variables, do not return a type. (It's type is
1045 NULL, too.)
1046 Do not return a type for invalid variables as well. */
1047 if (CPLUS_FAKE_CHILD (var) || !var->root->is_valid)
1048 return NULL;
1049
1050 return type_to_string (var->type);
1051 }
1052
1053 /* Obtain the type of an object variable. */
1054
1055 struct type *
1056 varobj_get_gdb_type (struct varobj *var)
1057 {
1058 return var->type;
1059 }
1060
1061 /* Return a pointer to the full rooted expression of varobj VAR.
1062 If it has not been computed yet, compute it. */
1063 char *
1064 varobj_get_path_expr (struct varobj *var)
1065 {
1066 if (var->path_expr != NULL)
1067 return var->path_expr;
1068 else
1069 {
1070 /* For root varobjs, we initialize path_expr
1071 when creating varobj, so here it should be
1072 child varobj. */
1073 gdb_assert (!is_root_p (var));
1074 return (*var->root->lang->path_expr_of_child) (var);
1075 }
1076 }
1077
1078 enum varobj_languages
1079 varobj_get_language (struct varobj *var)
1080 {
1081 return variable_language (var);
1082 }
1083
1084 int
1085 varobj_get_attributes (struct varobj *var)
1086 {
1087 int attributes = 0;
1088
1089 if (varobj_editable_p (var))
1090 /* FIXME: define masks for attributes */
1091 attributes |= 0x00000001; /* Editable */
1092
1093 return attributes;
1094 }
1095
1096 char *
1097 varobj_get_formatted_value (struct varobj *var,
1098 enum varobj_display_formats format)
1099 {
1100 return my_value_of_variable (var, format);
1101 }
1102
1103 char *
1104 varobj_get_value (struct varobj *var)
1105 {
1106 return my_value_of_variable (var, var->format);
1107 }
1108
1109 /* Set the value of an object variable (if it is editable) to the
1110 value of the given expression */
1111 /* Note: Invokes functions that can call error() */
1112
1113 int
1114 varobj_set_value (struct varobj *var, char *expression)
1115 {
1116 struct value *val;
1117 int offset = 0;
1118 int error = 0;
1119
1120 /* The argument "expression" contains the variable's new value.
1121 We need to first construct a legal expression for this -- ugh! */
1122 /* Does this cover all the bases? */
1123 struct expression *exp;
1124 struct value *value;
1125 int saved_input_radix = input_radix;
1126 char *s = expression;
1127 int i;
1128
1129 gdb_assert (varobj_editable_p (var));
1130
1131 input_radix = 10; /* ALWAYS reset to decimal temporarily */
1132 exp = parse_exp_1 (&s, 0, 0);
1133 if (!gdb_evaluate_expression (exp, &value))
1134 {
1135 /* We cannot proceed without a valid expression. */
1136 xfree (exp);
1137 return 0;
1138 }
1139
1140 /* All types that are editable must also be changeable. */
1141 gdb_assert (varobj_value_is_changeable_p (var));
1142
1143 /* The value of a changeable variable object must not be lazy. */
1144 gdb_assert (!value_lazy (var->value));
1145
1146 /* Need to coerce the input. We want to check if the
1147 value of the variable object will be different
1148 after assignment, and the first thing value_assign
1149 does is coerce the input.
1150 For example, if we are assigning an array to a pointer variable we
1151 should compare the pointer with the the array's address, not with the
1152 array's content. */
1153 value = coerce_array (value);
1154
1155 /* The new value may be lazy. gdb_value_assign, or
1156 rather value_contents, will take care of this.
1157 If fetching of the new value will fail, gdb_value_assign
1158 with catch the exception. */
1159 if (!gdb_value_assign (var->value, value, &val))
1160 return 0;
1161
1162 /* If the value has changed, record it, so that next -var-update can
1163 report this change. If a variable had a value of '1', we've set it
1164 to '333' and then set again to '1', when -var-update will report this
1165 variable as changed -- because the first assignment has set the
1166 'updated' flag. There's no need to optimize that, because return value
1167 of -var-update should be considered an approximation. */
1168 var->updated = install_new_value (var, val, 0 /* Compare values. */);
1169 input_radix = saved_input_radix;
1170 return 1;
1171 }
1172
1173 /* Returns a malloc'ed list with all root variable objects */
1174 int
1175 varobj_list (struct varobj ***varlist)
1176 {
1177 struct varobj **cv;
1178 struct varobj_root *croot;
1179 int mycount = rootcount;
1180
1181 /* Alloc (rootcount + 1) entries for the result */
1182 *varlist = xmalloc ((rootcount + 1) * sizeof (struct varobj *));
1183
1184 cv = *varlist;
1185 croot = rootlist;
1186 while ((croot != NULL) && (mycount > 0))
1187 {
1188 *cv = croot->rootvar;
1189 mycount--;
1190 cv++;
1191 croot = croot->next;
1192 }
1193 /* Mark the end of the list */
1194 *cv = NULL;
1195
1196 if (mycount || (croot != NULL))
1197 warning
1198 ("varobj_list: assertion failed - wrong tally of root vars (%d:%d)",
1199 rootcount, mycount);
1200
1201 return rootcount;
1202 }
1203
1204 /* Assign a new value to a variable object. If INITIAL is non-zero,
1205 this is the first assignement after the variable object was just
1206 created, or changed type. In that case, just assign the value
1207 and return 0.
1208 Otherwise, assign the new value, and return 1 if the value is different
1209 from the current one, 0 otherwise. The comparison is done on textual
1210 representation of value. Therefore, some types need not be compared. E.g.
1211 for structures the reported value is always "{...}", so no comparison is
1212 necessary here. If the old value was NULL and new one is not, or vice versa,
1213 we always return 1.
1214
1215 The VALUE parameter should not be released -- the function will
1216 take care of releasing it when needed. */
1217 static int
1218 install_new_value (struct varobj *var, struct value *value, int initial)
1219 {
1220 int changeable;
1221 int need_to_fetch;
1222 int changed = 0;
1223 int intentionally_not_fetched = 0;
1224 char *print_value = NULL;
1225
1226 /* We need to know the varobj's type to decide if the value should
1227 be fetched or not. C++ fake children (public/protected/private) don't have
1228 a type. */
1229 gdb_assert (var->type || CPLUS_FAKE_CHILD (var));
1230 changeable = varobj_value_is_changeable_p (var);
1231
1232 /* If the type has custom visualizer, we consider it to be always
1233 changeable. FIXME: need to make sure this behaviour will not
1234 mess up read-sensitive values. */
1235 if (var->pretty_printer)
1236 changeable = 1;
1237
1238 need_to_fetch = changeable;
1239
1240 /* We are not interested in the address of references, and given
1241 that in C++ a reference is not rebindable, it cannot
1242 meaningfully change. So, get hold of the real value. */
1243 if (value)
1244 {
1245 value = coerce_ref (value);
1246 release_value (value);
1247 }
1248
1249 if (var->type && TYPE_CODE (var->type) == TYPE_CODE_UNION)
1250 /* For unions, we need to fetch the value implicitly because
1251 of implementation of union member fetch. When gdb
1252 creates a value for a field and the value of the enclosing
1253 structure is not lazy, it immediately copies the necessary
1254 bytes from the enclosing values. If the enclosing value is
1255 lazy, the call to value_fetch_lazy on the field will read
1256 the data from memory. For unions, that means we'll read the
1257 same memory more than once, which is not desirable. So
1258 fetch now. */
1259 need_to_fetch = 1;
1260
1261 /* The new value might be lazy. If the type is changeable,
1262 that is we'll be comparing values of this type, fetch the
1263 value now. Otherwise, on the next update the old value
1264 will be lazy, which means we've lost that old value. */
1265 if (need_to_fetch && value && value_lazy (value))
1266 {
1267 struct varobj *parent = var->parent;
1268 int frozen = var->frozen;
1269 for (; !frozen && parent; parent = parent->parent)
1270 frozen |= parent->frozen;
1271
1272 if (frozen && initial)
1273 {
1274 /* For variables that are frozen, or are children of frozen
1275 variables, we don't do fetch on initial assignment.
1276 For non-initial assignemnt we do the fetch, since it means we're
1277 explicitly asked to compare the new value with the old one. */
1278 intentionally_not_fetched = 1;
1279 }
1280 else if (!gdb_value_fetch_lazy (value))
1281 {
1282 /* Set the value to NULL, so that for the next -var-update,
1283 we don't try to compare the new value with this value,
1284 that we couldn't even read. */
1285 value = NULL;
1286 }
1287 }
1288
1289
1290 /* Below, we'll be comparing string rendering of old and new
1291 values. Don't get string rendering if the value is
1292 lazy -- if it is, the code above has decided that the value
1293 should not be fetched. */
1294 if (value && !value_lazy (value))
1295 print_value = value_get_print_value (value, var->format, var);
1296
1297 /* If the type is changeable, compare the old and the new values.
1298 If this is the initial assignment, we don't have any old value
1299 to compare with. */
1300 if (!initial && changeable)
1301 {
1302 /* If the value of the varobj was changed by -var-set-value, then the
1303 value in the varobj and in the target is the same. However, that value
1304 is different from the value that the varobj had after the previous
1305 -var-update. So need to the varobj as changed. */
1306 if (var->updated)
1307 {
1308 changed = 1;
1309 }
1310 else
1311 {
1312 /* Try to compare the values. That requires that both
1313 values are non-lazy. */
1314 if (var->not_fetched && value_lazy (var->value))
1315 {
1316 /* This is a frozen varobj and the value was never read.
1317 Presumably, UI shows some "never read" indicator.
1318 Now that we've fetched the real value, we need to report
1319 this varobj as changed so that UI can show the real
1320 value. */
1321 changed = 1;
1322 }
1323 else if (var->value == NULL && value == NULL)
1324 /* Equal. */
1325 ;
1326 else if (var->value == NULL || value == NULL)
1327 {
1328 changed = 1;
1329 }
1330 else
1331 {
1332 gdb_assert (!value_lazy (var->value));
1333 gdb_assert (!value_lazy (value));
1334
1335 gdb_assert (var->print_value != NULL && print_value != NULL);
1336 if (strcmp (var->print_value, print_value) != 0)
1337 changed = 1;
1338 }
1339 }
1340 }
1341
1342 if (!initial && !changeable)
1343 {
1344 /* For values that are not changeable, we don't compare the values.
1345 However, we want to notice if a value was not NULL and now is NULL,
1346 or vise versa, so that we report when top-level varobjs come in scope
1347 and leave the scope. */
1348 changed = (var->value != NULL) != (value != NULL);
1349 }
1350
1351 /* We must always keep the new value, since children depend on it. */
1352 if (var->value != NULL && var->value != value)
1353 value_free (var->value);
1354 var->value = value;
1355 if (var->print_value)
1356 xfree (var->print_value);
1357 var->print_value = print_value;
1358 if (value && value_lazy (value) && intentionally_not_fetched)
1359 var->not_fetched = 1;
1360 else
1361 var->not_fetched = 0;
1362 var->updated = 0;
1363
1364 gdb_assert (!var->value || value_type (var->value));
1365
1366 return changed;
1367 }
1368
1369 static void
1370 install_visualizer (struct varobj *var, PyObject *visualizer)
1371 {
1372 #if HAVE_PYTHON
1373 /* If there are any children now, wipe them. */
1374 varobj_delete (var, NULL, 1 /* children only */);
1375 var->num_children = -1;
1376
1377 Py_XDECREF (var->pretty_printer);
1378 var->pretty_printer = visualizer;
1379
1380 install_new_value (var, var->value, 1);
1381
1382 /* If we removed the visualizer, and the user ever requested the
1383 object's children, then we must compute the list of children.
1384 Note that we needn't do this when installing a visualizer,
1385 because updating will recompute dynamic children. */
1386 if (!visualizer && var->children_requested)
1387 varobj_list_children (var);
1388 #else
1389 error (_("Python support required"));
1390 #endif
1391 }
1392
1393 static void
1394 install_default_visualizer (struct varobj *var)
1395 {
1396 #if HAVE_PYTHON
1397 struct cleanup *cleanup;
1398 PyObject *pretty_printer = NULL;
1399
1400 cleanup = varobj_ensure_python_env (var);
1401
1402 if (var->value)
1403 {
1404 pretty_printer = gdbpy_get_varobj_pretty_printer (var->value);
1405 if (! pretty_printer)
1406 {
1407 gdbpy_print_stack ();
1408 error (_("Cannot instantiate printer for default visualizer"));
1409 }
1410 }
1411
1412 if (pretty_printer == Py_None)
1413 {
1414 Py_DECREF (pretty_printer);
1415 pretty_printer = NULL;
1416 }
1417
1418 install_visualizer (var, pretty_printer);
1419 do_cleanups (cleanup);
1420 #else
1421 /* No error is right as this function is inserted just as a hook. */
1422 #endif
1423 }
1424
1425 void
1426 varobj_set_visualizer (struct varobj *var, const char *visualizer)
1427 {
1428 #if HAVE_PYTHON
1429 PyObject *mainmod, *globals, *pretty_printer, *constructor;
1430 struct cleanup *back_to, *value;
1431
1432 back_to = varobj_ensure_python_env (var);
1433
1434 mainmod = PyImport_AddModule ("__main__");
1435 globals = PyModule_GetDict (mainmod);
1436 Py_INCREF (globals);
1437 make_cleanup_py_decref (globals);
1438
1439 constructor = PyRun_String (visualizer, Py_eval_input, globals, globals);
1440
1441 /* Do not instantiate NoneType. */
1442 if (constructor == Py_None)
1443 {
1444 pretty_printer = Py_None;
1445 Py_INCREF (pretty_printer);
1446 }
1447 else
1448 pretty_printer = instantiate_pretty_printer (constructor, var->value);
1449
1450 Py_XDECREF (constructor);
1451
1452 if (! pretty_printer)
1453 {
1454 gdbpy_print_stack ();
1455 error (_("Could not evaluate visualizer expression: %s"), visualizer);
1456 }
1457
1458 if (pretty_printer == Py_None)
1459 {
1460 Py_DECREF (pretty_printer);
1461 pretty_printer = NULL;
1462 }
1463
1464 install_visualizer (var, pretty_printer);
1465
1466 do_cleanups (back_to);
1467 #else
1468 error (_("Python support required"));
1469 #endif
1470 }
1471
1472 /* Update the values for a variable and its children. This is a
1473 two-pronged attack. First, re-parse the value for the root's
1474 expression to see if it's changed. Then go all the way
1475 through its children, reconstructing them and noting if they've
1476 changed.
1477
1478 The EXPLICIT parameter specifies if this call is result
1479 of MI request to update this specific variable, or
1480 result of implicit -var-update *. For implicit request, we don't
1481 update frozen variables.
1482
1483 NOTE: This function may delete the caller's varobj. If it
1484 returns TYPE_CHANGED, then it has done this and VARP will be modified
1485 to point to the new varobj. */
1486
1487 VEC(varobj_update_result) *varobj_update (struct varobj **varp, int explicit)
1488 {
1489 int changed = 0;
1490 int type_changed = 0;
1491 int i;
1492 int vleft;
1493 struct varobj *v;
1494 struct varobj **cv;
1495 struct varobj **templist = NULL;
1496 struct value *new;
1497 VEC (varobj_update_result) *stack = NULL;
1498 VEC (varobj_update_result) *result = NULL;
1499 struct frame_info *fi;
1500
1501 /* Frozen means frozen -- we don't check for any change in
1502 this varobj, including its going out of scope, or
1503 changing type. One use case for frozen varobjs is
1504 retaining previously evaluated expressions, and we don't
1505 want them to be reevaluated at all. */
1506 if (!explicit && (*varp)->frozen)
1507 return result;
1508
1509 if (!(*varp)->root->is_valid)
1510 {
1511 varobj_update_result r = {*varp};
1512 r.status = VAROBJ_INVALID;
1513 VEC_safe_push (varobj_update_result, result, &r);
1514 return result;
1515 }
1516
1517 if ((*varp)->root->rootvar == *varp)
1518 {
1519 varobj_update_result r = {*varp};
1520 r.status = VAROBJ_IN_SCOPE;
1521
1522 /* Update the root variable. value_of_root can return NULL
1523 if the variable is no longer around, i.e. we stepped out of
1524 the frame in which a local existed. We are letting the
1525 value_of_root variable dispose of the varobj if the type
1526 has changed. */
1527 new = value_of_root (varp, &type_changed);
1528 r.varobj = *varp;
1529
1530 r.type_changed = type_changed;
1531 if (install_new_value ((*varp), new, type_changed))
1532 r.changed = 1;
1533
1534 if (new == NULL)
1535 r.status = VAROBJ_NOT_IN_SCOPE;
1536 r.value_installed = 1;
1537
1538 if (r.status == VAROBJ_NOT_IN_SCOPE)
1539 {
1540 if (r.type_changed || r.changed)
1541 VEC_safe_push (varobj_update_result, result, &r);
1542 return result;
1543 }
1544
1545 VEC_safe_push (varobj_update_result, stack, &r);
1546 }
1547 else
1548 {
1549 varobj_update_result r = {*varp};
1550 VEC_safe_push (varobj_update_result, stack, &r);
1551 }
1552
1553 /* Walk through the children, reconstructing them all. */
1554 while (!VEC_empty (varobj_update_result, stack))
1555 {
1556 varobj_update_result r = *(VEC_last (varobj_update_result, stack));
1557 struct varobj *v = r.varobj;
1558
1559 VEC_pop (varobj_update_result, stack);
1560
1561 /* Update this variable, unless it's a root, which is already
1562 updated. */
1563 if (!r.value_installed)
1564 {
1565 new = value_of_child (v->parent, v->index);
1566 if (install_new_value (v, new, 0 /* type not changed */))
1567 {
1568 r.changed = 1;
1569 v->updated = 0;
1570 }
1571 }
1572
1573 /* We probably should not get children of a varobj that has a
1574 pretty-printer, but for which -var-list-children was never
1575 invoked. Presumably, such varobj is not yet expanded in the
1576 UI, so we need not bother getting it. */
1577 if (v->pretty_printer)
1578 {
1579 VEC (varobj_p) *changed = 0, *new_and_unchanged = 0;
1580 int i, children_changed;
1581 varobj_p tmp;
1582
1583 if (!v->children_requested)
1584 continue;
1585
1586 if (v->frozen)
1587 continue;
1588
1589 /* If update_dynamic_varobj_children returns 0, then we have
1590 a non-conforming pretty-printer, so we skip it. */
1591 if (update_dynamic_varobj_children (v, &changed, &new_and_unchanged,
1592 &children_changed))
1593 {
1594 if (children_changed)
1595 r.children_changed = 1;
1596 for (i = 0; VEC_iterate (varobj_p, changed, i, tmp); ++i)
1597 {
1598 varobj_update_result r = {tmp};
1599 r.changed = 1;
1600 r.value_installed = 1;
1601 VEC_safe_push (varobj_update_result, stack, &r);
1602 }
1603 for (i = 0;
1604 VEC_iterate (varobj_p, new_and_unchanged, i, tmp);
1605 ++i)
1606 {
1607 varobj_update_result r = {tmp};
1608 r.value_installed = 1;
1609 VEC_safe_push (varobj_update_result, stack, &r);
1610 }
1611 if (r.changed || r.children_changed)
1612 VEC_safe_push (varobj_update_result, result, &r);
1613 continue;
1614 }
1615 }
1616
1617 /* Push any children. Use reverse order so that the first
1618 child is popped from the work stack first, and so
1619 will be added to result first. This does not
1620 affect correctness, just "nicer". */
1621 for (i = VEC_length (varobj_p, v->children)-1; i >= 0; --i)
1622 {
1623 varobj_p c = VEC_index (varobj_p, v->children, i);
1624 /* Child may be NULL if explicitly deleted by -var-delete. */
1625 if (c != NULL && !c->frozen)
1626 {
1627 varobj_update_result r = {c};
1628 VEC_safe_push (varobj_update_result, stack, &r);
1629 }
1630 }
1631
1632 if (r.changed || r.type_changed)
1633 VEC_safe_push (varobj_update_result, result, &r);
1634 }
1635
1636 VEC_free (varobj_update_result, stack);
1637
1638 return result;
1639 }
1640 \f
1641
1642 /* Helper functions */
1643
1644 /*
1645 * Variable object construction/destruction
1646 */
1647
1648 static int
1649 delete_variable (struct cpstack **resultp, struct varobj *var,
1650 int only_children_p)
1651 {
1652 int delcount = 0;
1653
1654 delete_variable_1 (resultp, &delcount, var,
1655 only_children_p, 1 /* remove_from_parent_p */ );
1656
1657 return delcount;
1658 }
1659
1660 /* Delete the variable object VAR and its children */
1661 /* IMPORTANT NOTE: If we delete a variable which is a child
1662 and the parent is not removed we dump core. It must be always
1663 initially called with remove_from_parent_p set */
1664 static void
1665 delete_variable_1 (struct cpstack **resultp, int *delcountp,
1666 struct varobj *var, int only_children_p,
1667 int remove_from_parent_p)
1668 {
1669 int i;
1670
1671 /* Delete any children of this variable, too. */
1672 for (i = 0; i < VEC_length (varobj_p, var->children); ++i)
1673 {
1674 varobj_p child = VEC_index (varobj_p, var->children, i);
1675 if (!child)
1676 continue;
1677 if (!remove_from_parent_p)
1678 child->parent = NULL;
1679 delete_variable_1 (resultp, delcountp, child, 0, only_children_p);
1680 }
1681 VEC_free (varobj_p, var->children);
1682
1683 /* if we were called to delete only the children we are done here */
1684 if (only_children_p)
1685 return;
1686
1687 /* Otherwise, add it to the list of deleted ones and proceed to do so */
1688 /* If the name is null, this is a temporary variable, that has not
1689 yet been installed, don't report it, it belongs to the caller... */
1690 if (var->obj_name != NULL)
1691 {
1692 cppush (resultp, xstrdup (var->obj_name));
1693 *delcountp = *delcountp + 1;
1694 }
1695
1696 /* If this variable has a parent, remove it from its parent's list */
1697 /* OPTIMIZATION: if the parent of this variable is also being deleted,
1698 (as indicated by remove_from_parent_p) we don't bother doing an
1699 expensive list search to find the element to remove when we are
1700 discarding the list afterwards */
1701 if ((remove_from_parent_p) && (var->parent != NULL))
1702 {
1703 VEC_replace (varobj_p, var->parent->children, var->index, NULL);
1704 }
1705
1706 if (var->obj_name != NULL)
1707 uninstall_variable (var);
1708
1709 /* Free memory associated with this variable */
1710 free_variable (var);
1711 }
1712
1713 /* Install the given variable VAR with the object name VAR->OBJ_NAME. */
1714 static int
1715 install_variable (struct varobj *var)
1716 {
1717 struct vlist *cv;
1718 struct vlist *newvl;
1719 const char *chp;
1720 unsigned int index = 0;
1721 unsigned int i = 1;
1722
1723 for (chp = var->obj_name; *chp; chp++)
1724 {
1725 index = (index + (i++ * (unsigned int) *chp)) % VAROBJ_TABLE_SIZE;
1726 }
1727
1728 cv = *(varobj_table + index);
1729 while ((cv != NULL) && (strcmp (cv->var->obj_name, var->obj_name) != 0))
1730 cv = cv->next;
1731
1732 if (cv != NULL)
1733 error (_("Duplicate variable object name"));
1734
1735 /* Add varobj to hash table */
1736 newvl = xmalloc (sizeof (struct vlist));
1737 newvl->next = *(varobj_table + index);
1738 newvl->var = var;
1739 *(varobj_table + index) = newvl;
1740
1741 /* If root, add varobj to root list */
1742 if (is_root_p (var))
1743 {
1744 /* Add to list of root variables */
1745 if (rootlist == NULL)
1746 var->root->next = NULL;
1747 else
1748 var->root->next = rootlist;
1749 rootlist = var->root;
1750 rootcount++;
1751 }
1752
1753 return 1; /* OK */
1754 }
1755
1756 /* Unistall the object VAR. */
1757 static void
1758 uninstall_variable (struct varobj *var)
1759 {
1760 struct vlist *cv;
1761 struct vlist *prev;
1762 struct varobj_root *cr;
1763 struct varobj_root *prer;
1764 const char *chp;
1765 unsigned int index = 0;
1766 unsigned int i = 1;
1767
1768 /* Remove varobj from hash table */
1769 for (chp = var->obj_name; *chp; chp++)
1770 {
1771 index = (index + (i++ * (unsigned int) *chp)) % VAROBJ_TABLE_SIZE;
1772 }
1773
1774 cv = *(varobj_table + index);
1775 prev = NULL;
1776 while ((cv != NULL) && (strcmp (cv->var->obj_name, var->obj_name) != 0))
1777 {
1778 prev = cv;
1779 cv = cv->next;
1780 }
1781
1782 if (varobjdebug)
1783 fprintf_unfiltered (gdb_stdlog, "Deleting %s\n", var->obj_name);
1784
1785 if (cv == NULL)
1786 {
1787 warning
1788 ("Assertion failed: Could not find variable object \"%s\" to delete",
1789 var->obj_name);
1790 return;
1791 }
1792
1793 if (prev == NULL)
1794 *(varobj_table + index) = cv->next;
1795 else
1796 prev->next = cv->next;
1797
1798 xfree (cv);
1799
1800 /* If root, remove varobj from root list */
1801 if (is_root_p (var))
1802 {
1803 /* Remove from list of root variables */
1804 if (rootlist == var->root)
1805 rootlist = var->root->next;
1806 else
1807 {
1808 prer = NULL;
1809 cr = rootlist;
1810 while ((cr != NULL) && (cr->rootvar != var))
1811 {
1812 prer = cr;
1813 cr = cr->next;
1814 }
1815 if (cr == NULL)
1816 {
1817 warning
1818 ("Assertion failed: Could not find varobj \"%s\" in root list",
1819 var->obj_name);
1820 return;
1821 }
1822 if (prer == NULL)
1823 rootlist = NULL;
1824 else
1825 prer->next = cr->next;
1826 }
1827 rootcount--;
1828 }
1829
1830 }
1831
1832 /* Create and install a child of the parent of the given name */
1833 static struct varobj *
1834 create_child (struct varobj *parent, int index, char *name)
1835 {
1836 return create_child_with_value (parent, index, name,
1837 value_of_child (parent, index));
1838 }
1839
1840 static struct varobj *
1841 create_child_with_value (struct varobj *parent, int index, const char *name,
1842 struct value *value)
1843 {
1844 struct varobj *child;
1845 char *childs_name;
1846
1847 child = new_variable ();
1848
1849 /* name is allocated by name_of_child */
1850 /* FIXME: xstrdup should not be here. */
1851 child->name = xstrdup (name);
1852 child->index = index;
1853 child->parent = parent;
1854 child->root = parent->root;
1855 childs_name = xstrprintf ("%s.%s", parent->obj_name, name);
1856 child->obj_name = childs_name;
1857 install_variable (child);
1858
1859 /* Compute the type of the child. Must do this before
1860 calling install_new_value. */
1861 if (value != NULL)
1862 /* If the child had no evaluation errors, var->value
1863 will be non-NULL and contain a valid type. */
1864 child->type = value_type (value);
1865 else
1866 /* Otherwise, we must compute the type. */
1867 child->type = (*child->root->lang->type_of_child) (child->parent,
1868 child->index);
1869 install_new_value (child, value, 1);
1870
1871 return child;
1872 }
1873 \f
1874
1875 /*
1876 * Miscellaneous utility functions.
1877 */
1878
1879 /* Allocate memory and initialize a new variable */
1880 static struct varobj *
1881 new_variable (void)
1882 {
1883 struct varobj *var;
1884
1885 var = (struct varobj *) xmalloc (sizeof (struct varobj));
1886 var->name = NULL;
1887 var->path_expr = NULL;
1888 var->obj_name = NULL;
1889 var->index = -1;
1890 var->type = NULL;
1891 var->value = NULL;
1892 var->num_children = -1;
1893 var->parent = NULL;
1894 var->children = NULL;
1895 var->format = 0;
1896 var->root = NULL;
1897 var->updated = 0;
1898 var->print_value = NULL;
1899 var->frozen = 0;
1900 var->not_fetched = 0;
1901 var->children_requested = 0;
1902 var->pretty_printer = 0;
1903
1904 return var;
1905 }
1906
1907 /* Allocate memory and initialize a new root variable */
1908 static struct varobj *
1909 new_root_variable (void)
1910 {
1911 struct varobj *var = new_variable ();
1912 var->root = (struct varobj_root *) xmalloc (sizeof (struct varobj_root));;
1913 var->root->lang = NULL;
1914 var->root->exp = NULL;
1915 var->root->valid_block = NULL;
1916 var->root->frame = null_frame_id;
1917 var->root->floating = 0;
1918 var->root->rootvar = NULL;
1919 var->root->is_valid = 1;
1920
1921 return var;
1922 }
1923
1924 /* Free any allocated memory associated with VAR. */
1925 static void
1926 free_variable (struct varobj *var)
1927 {
1928 #if HAVE_PYTHON
1929 if (var->pretty_printer)
1930 {
1931 struct cleanup *cleanup = varobj_ensure_python_env (var);
1932 Py_DECREF (var->pretty_printer);
1933 do_cleanups (cleanup);
1934 }
1935 #endif
1936
1937 value_free (var->value);
1938
1939 /* Free the expression if this is a root variable. */
1940 if (is_root_p (var))
1941 {
1942 xfree (var->root->exp);
1943 xfree (var->root);
1944 }
1945
1946 xfree (var->name);
1947 xfree (var->obj_name);
1948 xfree (var->print_value);
1949 xfree (var->path_expr);
1950 xfree (var);
1951 }
1952
1953 static void
1954 do_free_variable_cleanup (void *var)
1955 {
1956 free_variable (var);
1957 }
1958
1959 static struct cleanup *
1960 make_cleanup_free_variable (struct varobj *var)
1961 {
1962 return make_cleanup (do_free_variable_cleanup, var);
1963 }
1964
1965 /* This returns the type of the variable. It also skips past typedefs
1966 to return the real type of the variable.
1967
1968 NOTE: TYPE_TARGET_TYPE should NOT be used anywhere in this file
1969 except within get_target_type and get_type. */
1970 static struct type *
1971 get_type (struct varobj *var)
1972 {
1973 struct type *type;
1974 type = var->type;
1975
1976 if (type != NULL)
1977 type = check_typedef (type);
1978
1979 return type;
1980 }
1981
1982 /* Return the type of the value that's stored in VAR,
1983 or that would have being stored there if the
1984 value were accessible.
1985
1986 This differs from VAR->type in that VAR->type is always
1987 the true type of the expession in the source language.
1988 The return value of this function is the type we're
1989 actually storing in varobj, and using for displaying
1990 the values and for comparing previous and new values.
1991
1992 For example, top-level references are always stripped. */
1993 static struct type *
1994 get_value_type (struct varobj *var)
1995 {
1996 struct type *type;
1997
1998 if (var->value)
1999 type = value_type (var->value);
2000 else
2001 type = var->type;
2002
2003 type = check_typedef (type);
2004
2005 if (TYPE_CODE (type) == TYPE_CODE_REF)
2006 type = get_target_type (type);
2007
2008 type = check_typedef (type);
2009
2010 return type;
2011 }
2012
2013 /* This returns the target type (or NULL) of TYPE, also skipping
2014 past typedefs, just like get_type ().
2015
2016 NOTE: TYPE_TARGET_TYPE should NOT be used anywhere in this file
2017 except within get_target_type and get_type. */
2018 static struct type *
2019 get_target_type (struct type *type)
2020 {
2021 if (type != NULL)
2022 {
2023 type = TYPE_TARGET_TYPE (type);
2024 if (type != NULL)
2025 type = check_typedef (type);
2026 }
2027
2028 return type;
2029 }
2030
2031 /* What is the default display for this variable? We assume that
2032 everything is "natural". Any exceptions? */
2033 static enum varobj_display_formats
2034 variable_default_display (struct varobj *var)
2035 {
2036 return FORMAT_NATURAL;
2037 }
2038
2039 /* FIXME: The following should be generic for any pointer */
2040 static void
2041 cppush (struct cpstack **pstack, char *name)
2042 {
2043 struct cpstack *s;
2044
2045 s = (struct cpstack *) xmalloc (sizeof (struct cpstack));
2046 s->name = name;
2047 s->next = *pstack;
2048 *pstack = s;
2049 }
2050
2051 /* FIXME: The following should be generic for any pointer */
2052 static char *
2053 cppop (struct cpstack **pstack)
2054 {
2055 struct cpstack *s;
2056 char *v;
2057
2058 if ((*pstack)->name == NULL && (*pstack)->next == NULL)
2059 return NULL;
2060
2061 s = *pstack;
2062 v = s->name;
2063 *pstack = (*pstack)->next;
2064 xfree (s);
2065
2066 return v;
2067 }
2068 \f
2069 /*
2070 * Language-dependencies
2071 */
2072
2073 /* Common entry points */
2074
2075 /* Get the language of variable VAR. */
2076 static enum varobj_languages
2077 variable_language (struct varobj *var)
2078 {
2079 enum varobj_languages lang;
2080
2081 switch (var->root->exp->language_defn->la_language)
2082 {
2083 default:
2084 case language_c:
2085 lang = vlang_c;
2086 break;
2087 case language_cplus:
2088 lang = vlang_cplus;
2089 break;
2090 case language_java:
2091 lang = vlang_java;
2092 break;
2093 }
2094
2095 return lang;
2096 }
2097
2098 /* Return the number of children for a given variable.
2099 The result of this function is defined by the language
2100 implementation. The number of children returned by this function
2101 is the number of children that the user will see in the variable
2102 display. */
2103 static int
2104 number_of_children (struct varobj *var)
2105 {
2106 return (*var->root->lang->number_of_children) (var);;
2107 }
2108
2109 /* What is the expression for the root varobj VAR? Returns a malloc'd string. */
2110 static char *
2111 name_of_variable (struct varobj *var)
2112 {
2113 return (*var->root->lang->name_of_variable) (var);
2114 }
2115
2116 /* What is the name of the INDEX'th child of VAR? Returns a malloc'd string. */
2117 static char *
2118 name_of_child (struct varobj *var, int index)
2119 {
2120 return (*var->root->lang->name_of_child) (var, index);
2121 }
2122
2123 /* What is the ``struct value *'' of the root variable VAR?
2124 For floating variable object, evaluation can get us a value
2125 of different type from what is stored in varobj already. In
2126 that case:
2127 - *type_changed will be set to 1
2128 - old varobj will be freed, and new one will be
2129 created, with the same name.
2130 - *var_handle will be set to the new varobj
2131 Otherwise, *type_changed will be set to 0. */
2132 static struct value *
2133 value_of_root (struct varobj **var_handle, int *type_changed)
2134 {
2135 struct varobj *var;
2136
2137 if (var_handle == NULL)
2138 return NULL;
2139
2140 var = *var_handle;
2141
2142 /* This should really be an exception, since this should
2143 only get called with a root variable. */
2144
2145 if (!is_root_p (var))
2146 return NULL;
2147
2148 if (var->root->floating)
2149 {
2150 struct varobj *tmp_var;
2151 char *old_type, *new_type;
2152
2153 tmp_var = varobj_create (NULL, var->name, (CORE_ADDR) 0,
2154 USE_SELECTED_FRAME);
2155 if (tmp_var == NULL)
2156 {
2157 return NULL;
2158 }
2159 old_type = varobj_get_type (var);
2160 new_type = varobj_get_type (tmp_var);
2161 if (strcmp (old_type, new_type) == 0)
2162 {
2163 /* The expression presently stored inside var->root->exp
2164 remembers the locations of local variables relatively to
2165 the frame where the expression was created (in DWARF location
2166 button, for example). Naturally, those locations are not
2167 correct in other frames, so update the expression. */
2168
2169 struct expression *tmp_exp = var->root->exp;
2170 var->root->exp = tmp_var->root->exp;
2171 tmp_var->root->exp = tmp_exp;
2172
2173 varobj_delete (tmp_var, NULL, 0);
2174 *type_changed = 0;
2175 }
2176 else
2177 {
2178 tmp_var->obj_name = xstrdup (var->obj_name);
2179 varobj_delete (var, NULL, 0);
2180
2181 install_variable (tmp_var);
2182 *var_handle = tmp_var;
2183 var = *var_handle;
2184 *type_changed = 1;
2185 }
2186 xfree (old_type);
2187 xfree (new_type);
2188 }
2189 else
2190 {
2191 *type_changed = 0;
2192 }
2193
2194 return (*var->root->lang->value_of_root) (var_handle);
2195 }
2196
2197 /* What is the ``struct value *'' for the INDEX'th child of PARENT? */
2198 static struct value *
2199 value_of_child (struct varobj *parent, int index)
2200 {
2201 struct value *value;
2202
2203 value = (*parent->root->lang->value_of_child) (parent, index);
2204
2205 return value;
2206 }
2207
2208 /* GDB already has a command called "value_of_variable". Sigh. */
2209 static char *
2210 my_value_of_variable (struct varobj *var, enum varobj_display_formats format)
2211 {
2212 if (var->root->is_valid)
2213 return (*var->root->lang->value_of_variable) (var, format);
2214 else
2215 return NULL;
2216 }
2217
2218 static char *
2219 value_get_print_value (struct value *value, enum varobj_display_formats format,
2220 struct varobj *var)
2221 {
2222 long dummy;
2223 struct ui_file *stb;
2224 struct cleanup *old_chain;
2225 char *thevalue = NULL;
2226 struct value_print_options opts;
2227
2228 if (value == NULL)
2229 return NULL;
2230
2231 #if HAVE_PYTHON
2232 {
2233 struct cleanup *back_to = varobj_ensure_python_env (var);
2234 PyObject *value_formatter = var->pretty_printer;
2235
2236 if (value_formatter && PyObject_HasAttr (value_formatter,
2237 gdbpy_to_string_cst))
2238 {
2239 char *hint;
2240 struct value *replacement;
2241 int string_print = 0;
2242
2243 hint = gdbpy_get_display_hint (value_formatter);
2244 if (hint)
2245 {
2246 if (!strcmp (hint, "string"))
2247 string_print = 1;
2248 xfree (hint);
2249 }
2250
2251 thevalue = apply_varobj_pretty_printer (value_formatter,
2252 &replacement);
2253 if (thevalue && !string_print)
2254 {
2255 do_cleanups (back_to);
2256 return thevalue;
2257 }
2258 if (replacement)
2259 value = replacement;
2260 }
2261 do_cleanups (back_to);
2262 }
2263 #endif
2264
2265 stb = mem_fileopen ();
2266 old_chain = make_cleanup_ui_file_delete (stb);
2267
2268 get_formatted_print_options (&opts, format_code[(int) format]);
2269 opts.deref_ref = 0;
2270 opts.raw = 1;
2271 if (thevalue)
2272 {
2273 struct gdbarch *gdbarch = get_type_arch (value_type (value));
2274 make_cleanup (xfree, thevalue);
2275 LA_PRINT_STRING (stb, builtin_type (gdbarch)->builtin_char,
2276 (gdb_byte *) thevalue, strlen (thevalue),
2277 0, &opts);
2278 }
2279 else
2280 common_val_print (value, stb, 0, &opts, current_language);
2281 thevalue = ui_file_xstrdup (stb, &dummy);
2282
2283 do_cleanups (old_chain);
2284 return thevalue;
2285 }
2286
2287 int
2288 varobj_editable_p (struct varobj *var)
2289 {
2290 struct type *type;
2291 struct value *value;
2292
2293 if (!(var->root->is_valid && var->value && VALUE_LVAL (var->value)))
2294 return 0;
2295
2296 type = get_value_type (var);
2297
2298 switch (TYPE_CODE (type))
2299 {
2300 case TYPE_CODE_STRUCT:
2301 case TYPE_CODE_UNION:
2302 case TYPE_CODE_ARRAY:
2303 case TYPE_CODE_FUNC:
2304 case TYPE_CODE_METHOD:
2305 return 0;
2306 break;
2307
2308 default:
2309 return 1;
2310 break;
2311 }
2312 }
2313
2314 /* Return non-zero if changes in value of VAR
2315 must be detected and reported by -var-update.
2316 Return zero is -var-update should never report
2317 changes of such values. This makes sense for structures
2318 (since the changes in children values will be reported separately),
2319 or for artifical objects (like 'public' pseudo-field in C++).
2320
2321 Return value of 0 means that gdb need not call value_fetch_lazy
2322 for the value of this variable object. */
2323 static int
2324 varobj_value_is_changeable_p (struct varobj *var)
2325 {
2326 int r;
2327 struct type *type;
2328
2329 if (CPLUS_FAKE_CHILD (var))
2330 return 0;
2331
2332 type = get_value_type (var);
2333
2334 switch (TYPE_CODE (type))
2335 {
2336 case TYPE_CODE_STRUCT:
2337 case TYPE_CODE_UNION:
2338 case TYPE_CODE_ARRAY:
2339 r = 0;
2340 break;
2341
2342 default:
2343 r = 1;
2344 }
2345
2346 return r;
2347 }
2348
2349 /* Return 1 if that varobj is floating, that is is always evaluated in the
2350 selected frame, and not bound to thread/frame. Such variable objects
2351 are created using '@' as frame specifier to -var-create. */
2352 int
2353 varobj_floating_p (struct varobj *var)
2354 {
2355 return var->root->floating;
2356 }
2357
2358 /* Given the value and the type of a variable object,
2359 adjust the value and type to those necessary
2360 for getting children of the variable object.
2361 This includes dereferencing top-level references
2362 to all types and dereferencing pointers to
2363 structures.
2364
2365 Both TYPE and *TYPE should be non-null. VALUE
2366 can be null if we want to only translate type.
2367 *VALUE can be null as well -- if the parent
2368 value is not known.
2369
2370 If WAS_PTR is not NULL, set *WAS_PTR to 0 or 1
2371 depending on whether pointer was dereferenced
2372 in this function. */
2373 static void
2374 adjust_value_for_child_access (struct value **value,
2375 struct type **type,
2376 int *was_ptr)
2377 {
2378 gdb_assert (type && *type);
2379
2380 if (was_ptr)
2381 *was_ptr = 0;
2382
2383 *type = check_typedef (*type);
2384
2385 /* The type of value stored in varobj, that is passed
2386 to us, is already supposed to be
2387 reference-stripped. */
2388
2389 gdb_assert (TYPE_CODE (*type) != TYPE_CODE_REF);
2390
2391 /* Pointers to structures are treated just like
2392 structures when accessing children. Don't
2393 dererences pointers to other types. */
2394 if (TYPE_CODE (*type) == TYPE_CODE_PTR)
2395 {
2396 struct type *target_type = get_target_type (*type);
2397 if (TYPE_CODE (target_type) == TYPE_CODE_STRUCT
2398 || TYPE_CODE (target_type) == TYPE_CODE_UNION)
2399 {
2400 if (value && *value)
2401 {
2402 int success = gdb_value_ind (*value, value);
2403 if (!success)
2404 *value = NULL;
2405 }
2406 *type = target_type;
2407 if (was_ptr)
2408 *was_ptr = 1;
2409 }
2410 }
2411
2412 /* The 'get_target_type' function calls check_typedef on
2413 result, so we can immediately check type code. No
2414 need to call check_typedef here. */
2415 }
2416
2417 /* C */
2418 static int
2419 c_number_of_children (struct varobj *var)
2420 {
2421 struct type *type = get_value_type (var);
2422 int children = 0;
2423 struct type *target;
2424
2425 adjust_value_for_child_access (NULL, &type, NULL);
2426 target = get_target_type (type);
2427
2428 switch (TYPE_CODE (type))
2429 {
2430 case TYPE_CODE_ARRAY:
2431 if (TYPE_LENGTH (type) > 0 && TYPE_LENGTH (target) > 0
2432 && !TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (type))
2433 children = TYPE_LENGTH (type) / TYPE_LENGTH (target);
2434 else
2435 /* If we don't know how many elements there are, don't display
2436 any. */
2437 children = 0;
2438 break;
2439
2440 case TYPE_CODE_STRUCT:
2441 case TYPE_CODE_UNION:
2442 children = TYPE_NFIELDS (type);
2443 break;
2444
2445 case TYPE_CODE_PTR:
2446 /* The type here is a pointer to non-struct. Typically, pointers
2447 have one child, except for function ptrs, which have no children,
2448 and except for void*, as we don't know what to show.
2449
2450 We can show char* so we allow it to be dereferenced. If you decide
2451 to test for it, please mind that a little magic is necessary to
2452 properly identify it: char* has TYPE_CODE == TYPE_CODE_INT and
2453 TYPE_NAME == "char" */
2454 if (TYPE_CODE (target) == TYPE_CODE_FUNC
2455 || TYPE_CODE (target) == TYPE_CODE_VOID)
2456 children = 0;
2457 else
2458 children = 1;
2459 break;
2460
2461 default:
2462 /* Other types have no children */
2463 break;
2464 }
2465
2466 return children;
2467 }
2468
2469 static char *
2470 c_name_of_variable (struct varobj *parent)
2471 {
2472 return xstrdup (parent->name);
2473 }
2474
2475 /* Return the value of element TYPE_INDEX of a structure
2476 value VALUE. VALUE's type should be a structure,
2477 or union, or a typedef to struct/union.
2478
2479 Returns NULL if getting the value fails. Never throws. */
2480 static struct value *
2481 value_struct_element_index (struct value *value, int type_index)
2482 {
2483 struct value *result = NULL;
2484 volatile struct gdb_exception e;
2485
2486 struct type *type = value_type (value);
2487 type = check_typedef (type);
2488
2489 gdb_assert (TYPE_CODE (type) == TYPE_CODE_STRUCT
2490 || TYPE_CODE (type) == TYPE_CODE_UNION);
2491
2492 TRY_CATCH (e, RETURN_MASK_ERROR)
2493 {
2494 if (field_is_static (&TYPE_FIELD (type, type_index)))
2495 result = value_static_field (type, type_index);
2496 else
2497 result = value_primitive_field (value, 0, type_index, type);
2498 }
2499 if (e.reason < 0)
2500 {
2501 return NULL;
2502 }
2503 else
2504 {
2505 return result;
2506 }
2507 }
2508
2509 /* Obtain the information about child INDEX of the variable
2510 object PARENT.
2511 If CNAME is not null, sets *CNAME to the name of the child relative
2512 to the parent.
2513 If CVALUE is not null, sets *CVALUE to the value of the child.
2514 If CTYPE is not null, sets *CTYPE to the type of the child.
2515
2516 If any of CNAME, CVALUE, or CTYPE is not null, but the corresponding
2517 information cannot be determined, set *CNAME, *CVALUE, or *CTYPE
2518 to NULL. */
2519 static void
2520 c_describe_child (struct varobj *parent, int index,
2521 char **cname, struct value **cvalue, struct type **ctype,
2522 char **cfull_expression)
2523 {
2524 struct value *value = parent->value;
2525 struct type *type = get_value_type (parent);
2526 char *parent_expression = NULL;
2527 int was_ptr;
2528
2529 if (cname)
2530 *cname = NULL;
2531 if (cvalue)
2532 *cvalue = NULL;
2533 if (ctype)
2534 *ctype = NULL;
2535 if (cfull_expression)
2536 {
2537 *cfull_expression = NULL;
2538 parent_expression = varobj_get_path_expr (parent);
2539 }
2540 adjust_value_for_child_access (&value, &type, &was_ptr);
2541
2542 switch (TYPE_CODE (type))
2543 {
2544 case TYPE_CODE_ARRAY:
2545 if (cname)
2546 *cname = xstrprintf ("%d", index
2547 + TYPE_LOW_BOUND (TYPE_INDEX_TYPE (type)));
2548
2549 if (cvalue && value)
2550 {
2551 int real_index = index + TYPE_LOW_BOUND (TYPE_INDEX_TYPE (type));
2552 gdb_value_subscript (value, real_index, cvalue);
2553 }
2554
2555 if (ctype)
2556 *ctype = get_target_type (type);
2557
2558 if (cfull_expression)
2559 *cfull_expression = xstrprintf ("(%s)[%d]", parent_expression,
2560 index
2561 + TYPE_LOW_BOUND (TYPE_INDEX_TYPE (type)));
2562
2563
2564 break;
2565
2566 case TYPE_CODE_STRUCT:
2567 case TYPE_CODE_UNION:
2568 if (cname)
2569 *cname = xstrdup (TYPE_FIELD_NAME (type, index));
2570
2571 if (cvalue && value)
2572 {
2573 /* For C, varobj index is the same as type index. */
2574 *cvalue = value_struct_element_index (value, index);
2575 }
2576
2577 if (ctype)
2578 *ctype = TYPE_FIELD_TYPE (type, index);
2579
2580 if (cfull_expression)
2581 {
2582 char *join = was_ptr ? "->" : ".";
2583 *cfull_expression = xstrprintf ("(%s)%s%s", parent_expression, join,
2584 TYPE_FIELD_NAME (type, index));
2585 }
2586
2587 break;
2588
2589 case TYPE_CODE_PTR:
2590 if (cname)
2591 *cname = xstrprintf ("*%s", parent->name);
2592
2593 if (cvalue && value)
2594 {
2595 int success = gdb_value_ind (value, cvalue);
2596 if (!success)
2597 *cvalue = NULL;
2598 }
2599
2600 /* Don't use get_target_type because it calls
2601 check_typedef and here, we want to show the true
2602 declared type of the variable. */
2603 if (ctype)
2604 *ctype = TYPE_TARGET_TYPE (type);
2605
2606 if (cfull_expression)
2607 *cfull_expression = xstrprintf ("*(%s)", parent_expression);
2608
2609 break;
2610
2611 default:
2612 /* This should not happen */
2613 if (cname)
2614 *cname = xstrdup ("???");
2615 if (cfull_expression)
2616 *cfull_expression = xstrdup ("???");
2617 /* Don't set value and type, we don't know then. */
2618 }
2619 }
2620
2621 static char *
2622 c_name_of_child (struct varobj *parent, int index)
2623 {
2624 char *name;
2625 c_describe_child (parent, index, &name, NULL, NULL, NULL);
2626 return name;
2627 }
2628
2629 static char *
2630 c_path_expr_of_child (struct varobj *child)
2631 {
2632 c_describe_child (child->parent, child->index, NULL, NULL, NULL,
2633 &child->path_expr);
2634 return child->path_expr;
2635 }
2636
2637 /* If frame associated with VAR can be found, switch
2638 to it and return 1. Otherwise, return 0. */
2639 static int
2640 check_scope (struct varobj *var)
2641 {
2642 struct frame_info *fi;
2643 int scope;
2644
2645 fi = frame_find_by_id (var->root->frame);
2646 scope = fi != NULL;
2647
2648 if (fi)
2649 {
2650 CORE_ADDR pc = get_frame_pc (fi);
2651 if (pc < BLOCK_START (var->root->valid_block) ||
2652 pc >= BLOCK_END (var->root->valid_block))
2653 scope = 0;
2654 else
2655 select_frame (fi);
2656 }
2657 return scope;
2658 }
2659
2660 static struct value *
2661 c_value_of_root (struct varobj **var_handle)
2662 {
2663 struct value *new_val = NULL;
2664 struct varobj *var = *var_handle;
2665 struct frame_info *fi;
2666 int within_scope = 0;
2667 struct cleanup *back_to;
2668
2669 /* Only root variables can be updated... */
2670 if (!is_root_p (var))
2671 /* Not a root var */
2672 return NULL;
2673
2674 back_to = make_cleanup_restore_current_thread ();
2675
2676 /* Determine whether the variable is still around. */
2677 if (var->root->valid_block == NULL || var->root->floating)
2678 within_scope = 1;
2679 else if (var->root->thread_id == 0)
2680 {
2681 /* The program was single-threaded when the variable object was
2682 created. Technically, it's possible that the program became
2683 multi-threaded since then, but we don't support such
2684 scenario yet. */
2685 within_scope = check_scope (var);
2686 }
2687 else
2688 {
2689 ptid_t ptid = thread_id_to_pid (var->root->thread_id);
2690 if (in_thread_list (ptid))
2691 {
2692 switch_to_thread (ptid);
2693 within_scope = check_scope (var);
2694 }
2695 }
2696
2697 if (within_scope)
2698 {
2699 /* We need to catch errors here, because if evaluate
2700 expression fails we want to just return NULL. */
2701 gdb_evaluate_expression (var->root->exp, &new_val);
2702 return new_val;
2703 }
2704
2705 do_cleanups (back_to);
2706
2707 return NULL;
2708 }
2709
2710 static struct value *
2711 c_value_of_child (struct varobj *parent, int index)
2712 {
2713 struct value *value = NULL;
2714 c_describe_child (parent, index, NULL, &value, NULL, NULL);
2715
2716 return value;
2717 }
2718
2719 static struct type *
2720 c_type_of_child (struct varobj *parent, int index)
2721 {
2722 struct type *type = NULL;
2723 c_describe_child (parent, index, NULL, NULL, &type, NULL);
2724 return type;
2725 }
2726
2727 static char *
2728 c_value_of_variable (struct varobj *var, enum varobj_display_formats format)
2729 {
2730 /* BOGUS: if val_print sees a struct/class, or a reference to one,
2731 it will print out its children instead of "{...}". So we need to
2732 catch that case explicitly. */
2733 struct type *type = get_type (var);
2734
2735 /* If we have a custom formatter, return whatever string it has
2736 produced. */
2737 if (var->pretty_printer && var->print_value)
2738 return xstrdup (var->print_value);
2739
2740 /* Strip top-level references. */
2741 while (TYPE_CODE (type) == TYPE_CODE_REF)
2742 type = check_typedef (TYPE_TARGET_TYPE (type));
2743
2744 switch (TYPE_CODE (type))
2745 {
2746 case TYPE_CODE_STRUCT:
2747 case TYPE_CODE_UNION:
2748 return xstrdup ("{...}");
2749 /* break; */
2750
2751 case TYPE_CODE_ARRAY:
2752 {
2753 char *number;
2754 number = xstrprintf ("[%d]", var->num_children);
2755 return (number);
2756 }
2757 /* break; */
2758
2759 default:
2760 {
2761 if (var->value == NULL)
2762 {
2763 /* This can happen if we attempt to get the value of a struct
2764 member when the parent is an invalid pointer. This is an
2765 error condition, so we should tell the caller. */
2766 return NULL;
2767 }
2768 else
2769 {
2770 if (var->not_fetched && value_lazy (var->value))
2771 /* Frozen variable and no value yet. We don't
2772 implicitly fetch the value. MI response will
2773 use empty string for the value, which is OK. */
2774 return NULL;
2775
2776 gdb_assert (varobj_value_is_changeable_p (var));
2777 gdb_assert (!value_lazy (var->value));
2778
2779 /* If the specified format is the current one,
2780 we can reuse print_value */
2781 if (format == var->format)
2782 return xstrdup (var->print_value);
2783 else
2784 return value_get_print_value (var->value, format, var);
2785 }
2786 }
2787 }
2788 }
2789 \f
2790
2791 /* C++ */
2792
2793 static int
2794 cplus_number_of_children (struct varobj *var)
2795 {
2796 struct type *type;
2797 int children, dont_know;
2798
2799 dont_know = 1;
2800 children = 0;
2801
2802 if (!CPLUS_FAKE_CHILD (var))
2803 {
2804 type = get_value_type (var);
2805 adjust_value_for_child_access (NULL, &type, NULL);
2806
2807 if (((TYPE_CODE (type)) == TYPE_CODE_STRUCT) ||
2808 ((TYPE_CODE (type)) == TYPE_CODE_UNION))
2809 {
2810 int kids[3];
2811
2812 cplus_class_num_children (type, kids);
2813 if (kids[v_public] != 0)
2814 children++;
2815 if (kids[v_private] != 0)
2816 children++;
2817 if (kids[v_protected] != 0)
2818 children++;
2819
2820 /* Add any baseclasses */
2821 children += TYPE_N_BASECLASSES (type);
2822 dont_know = 0;
2823
2824 /* FIXME: save children in var */
2825 }
2826 }
2827 else
2828 {
2829 int kids[3];
2830
2831 type = get_value_type (var->parent);
2832 adjust_value_for_child_access (NULL, &type, NULL);
2833
2834 cplus_class_num_children (type, kids);
2835 if (strcmp (var->name, "public") == 0)
2836 children = kids[v_public];
2837 else if (strcmp (var->name, "private") == 0)
2838 children = kids[v_private];
2839 else
2840 children = kids[v_protected];
2841 dont_know = 0;
2842 }
2843
2844 if (dont_know)
2845 children = c_number_of_children (var);
2846
2847 return children;
2848 }
2849
2850 /* Compute # of public, private, and protected variables in this class.
2851 That means we need to descend into all baseclasses and find out
2852 how many are there, too. */
2853 static void
2854 cplus_class_num_children (struct type *type, int children[3])
2855 {
2856 int i;
2857
2858 children[v_public] = 0;
2859 children[v_private] = 0;
2860 children[v_protected] = 0;
2861
2862 for (i = TYPE_N_BASECLASSES (type); i < TYPE_NFIELDS (type); i++)
2863 {
2864 /* If we have a virtual table pointer, omit it. */
2865 if (TYPE_VPTR_BASETYPE (type) == type && TYPE_VPTR_FIELDNO (type) == i)
2866 continue;
2867
2868 if (TYPE_FIELD_PROTECTED (type, i))
2869 children[v_protected]++;
2870 else if (TYPE_FIELD_PRIVATE (type, i))
2871 children[v_private]++;
2872 else
2873 children[v_public]++;
2874 }
2875 }
2876
2877 static char *
2878 cplus_name_of_variable (struct varobj *parent)
2879 {
2880 return c_name_of_variable (parent);
2881 }
2882
2883 enum accessibility { private_field, protected_field, public_field };
2884
2885 /* Check if field INDEX of TYPE has the specified accessibility.
2886 Return 0 if so and 1 otherwise. */
2887 static int
2888 match_accessibility (struct type *type, int index, enum accessibility acc)
2889 {
2890 if (acc == private_field && TYPE_FIELD_PRIVATE (type, index))
2891 return 1;
2892 else if (acc == protected_field && TYPE_FIELD_PROTECTED (type, index))
2893 return 1;
2894 else if (acc == public_field && !TYPE_FIELD_PRIVATE (type, index)
2895 && !TYPE_FIELD_PROTECTED (type, index))
2896 return 1;
2897 else
2898 return 0;
2899 }
2900
2901 static void
2902 cplus_describe_child (struct varobj *parent, int index,
2903 char **cname, struct value **cvalue, struct type **ctype,
2904 char **cfull_expression)
2905 {
2906 char *name = NULL;
2907 struct value *value;
2908 struct type *type;
2909 int was_ptr;
2910 char *parent_expression = NULL;
2911
2912 if (cname)
2913 *cname = NULL;
2914 if (cvalue)
2915 *cvalue = NULL;
2916 if (ctype)
2917 *ctype = NULL;
2918 if (cfull_expression)
2919 *cfull_expression = NULL;
2920
2921 if (CPLUS_FAKE_CHILD (parent))
2922 {
2923 value = parent->parent->value;
2924 type = get_value_type (parent->parent);
2925 if (cfull_expression)
2926 parent_expression = varobj_get_path_expr (parent->parent);
2927 }
2928 else
2929 {
2930 value = parent->value;
2931 type = get_value_type (parent);
2932 if (cfull_expression)
2933 parent_expression = varobj_get_path_expr (parent);
2934 }
2935
2936 adjust_value_for_child_access (&value, &type, &was_ptr);
2937
2938 if (TYPE_CODE (type) == TYPE_CODE_STRUCT
2939 || TYPE_CODE (type) == TYPE_CODE_UNION)
2940 {
2941 char *join = was_ptr ? "->" : ".";
2942 if (CPLUS_FAKE_CHILD (parent))
2943 {
2944 /* The fields of the class type are ordered as they
2945 appear in the class. We are given an index for a
2946 particular access control type ("public","protected",
2947 or "private"). We must skip over fields that don't
2948 have the access control we are looking for to properly
2949 find the indexed field. */
2950 int type_index = TYPE_N_BASECLASSES (type);
2951 enum accessibility acc = public_field;
2952 if (strcmp (parent->name, "private") == 0)
2953 acc = private_field;
2954 else if (strcmp (parent->name, "protected") == 0)
2955 acc = protected_field;
2956
2957 while (index >= 0)
2958 {
2959 if (TYPE_VPTR_BASETYPE (type) == type
2960 && type_index == TYPE_VPTR_FIELDNO (type))
2961 ; /* ignore vptr */
2962 else if (match_accessibility (type, type_index, acc))
2963 --index;
2964 ++type_index;
2965 }
2966 --type_index;
2967
2968 if (cname)
2969 *cname = xstrdup (TYPE_FIELD_NAME (type, type_index));
2970
2971 if (cvalue && value)
2972 *cvalue = value_struct_element_index (value, type_index);
2973
2974 if (ctype)
2975 *ctype = TYPE_FIELD_TYPE (type, type_index);
2976
2977 if (cfull_expression)
2978 *cfull_expression = xstrprintf ("((%s)%s%s)", parent_expression,
2979 join,
2980 TYPE_FIELD_NAME (type, type_index));
2981 }
2982 else if (index < TYPE_N_BASECLASSES (type))
2983 {
2984 /* This is a baseclass. */
2985 if (cname)
2986 *cname = xstrdup (TYPE_FIELD_NAME (type, index));
2987
2988 if (cvalue && value)
2989 {
2990 *cvalue = value_cast (TYPE_FIELD_TYPE (type, index), value);
2991 release_value (*cvalue);
2992 }
2993
2994 if (ctype)
2995 {
2996 *ctype = TYPE_FIELD_TYPE (type, index);
2997 }
2998
2999 if (cfull_expression)
3000 {
3001 char *ptr = was_ptr ? "*" : "";
3002 /* Cast the parent to the base' type. Note that in gdb,
3003 expression like
3004 (Base1)d
3005 will create an lvalue, for all appearences, so we don't
3006 need to use more fancy:
3007 *(Base1*)(&d)
3008 construct. */
3009 *cfull_expression = xstrprintf ("(%s(%s%s) %s)",
3010 ptr,
3011 TYPE_FIELD_NAME (type, index),
3012 ptr,
3013 parent_expression);
3014 }
3015 }
3016 else
3017 {
3018 char *access = NULL;
3019 int children[3];
3020 cplus_class_num_children (type, children);
3021
3022 /* Everything beyond the baseclasses can
3023 only be "public", "private", or "protected"
3024
3025 The special "fake" children are always output by varobj in
3026 this order. So if INDEX == 2, it MUST be "protected". */
3027 index -= TYPE_N_BASECLASSES (type);
3028 switch (index)
3029 {
3030 case 0:
3031 if (children[v_public] > 0)
3032 access = "public";
3033 else if (children[v_private] > 0)
3034 access = "private";
3035 else
3036 access = "protected";
3037 break;
3038 case 1:
3039 if (children[v_public] > 0)
3040 {
3041 if (children[v_private] > 0)
3042 access = "private";
3043 else
3044 access = "protected";
3045 }
3046 else if (children[v_private] > 0)
3047 access = "protected";
3048 break;
3049 case 2:
3050 /* Must be protected */
3051 access = "protected";
3052 break;
3053 default:
3054 /* error! */
3055 break;
3056 }
3057
3058 gdb_assert (access);
3059 if (cname)
3060 *cname = xstrdup (access);
3061
3062 /* Value and type and full expression are null here. */
3063 }
3064 }
3065 else
3066 {
3067 c_describe_child (parent, index, cname, cvalue, ctype, cfull_expression);
3068 }
3069 }
3070
3071 static char *
3072 cplus_name_of_child (struct varobj *parent, int index)
3073 {
3074 char *name = NULL;
3075 cplus_describe_child (parent, index, &name, NULL, NULL, NULL);
3076 return name;
3077 }
3078
3079 static char *
3080 cplus_path_expr_of_child (struct varobj *child)
3081 {
3082 cplus_describe_child (child->parent, child->index, NULL, NULL, NULL,
3083 &child->path_expr);
3084 return child->path_expr;
3085 }
3086
3087 static struct value *
3088 cplus_value_of_root (struct varobj **var_handle)
3089 {
3090 return c_value_of_root (var_handle);
3091 }
3092
3093 static struct value *
3094 cplus_value_of_child (struct varobj *parent, int index)
3095 {
3096 struct value *value = NULL;
3097 cplus_describe_child (parent, index, NULL, &value, NULL, NULL);
3098 return value;
3099 }
3100
3101 static struct type *
3102 cplus_type_of_child (struct varobj *parent, int index)
3103 {
3104 struct type *type = NULL;
3105 cplus_describe_child (parent, index, NULL, NULL, &type, NULL);
3106 return type;
3107 }
3108
3109 static char *
3110 cplus_value_of_variable (struct varobj *var, enum varobj_display_formats format)
3111 {
3112
3113 /* If we have one of our special types, don't print out
3114 any value. */
3115 if (CPLUS_FAKE_CHILD (var))
3116 return xstrdup ("");
3117
3118 return c_value_of_variable (var, format);
3119 }
3120 \f
3121 /* Java */
3122
3123 static int
3124 java_number_of_children (struct varobj *var)
3125 {
3126 return cplus_number_of_children (var);
3127 }
3128
3129 static char *
3130 java_name_of_variable (struct varobj *parent)
3131 {
3132 char *p, *name;
3133
3134 name = cplus_name_of_variable (parent);
3135 /* If the name has "-" in it, it is because we
3136 needed to escape periods in the name... */
3137 p = name;
3138
3139 while (*p != '\000')
3140 {
3141 if (*p == '-')
3142 *p = '.';
3143 p++;
3144 }
3145
3146 return name;
3147 }
3148
3149 static char *
3150 java_name_of_child (struct varobj *parent, int index)
3151 {
3152 char *name, *p;
3153
3154 name = cplus_name_of_child (parent, index);
3155 /* Escape any periods in the name... */
3156 p = name;
3157
3158 while (*p != '\000')
3159 {
3160 if (*p == '.')
3161 *p = '-';
3162 p++;
3163 }
3164
3165 return name;
3166 }
3167
3168 static char *
3169 java_path_expr_of_child (struct varobj *child)
3170 {
3171 return NULL;
3172 }
3173
3174 static struct value *
3175 java_value_of_root (struct varobj **var_handle)
3176 {
3177 return cplus_value_of_root (var_handle);
3178 }
3179
3180 static struct value *
3181 java_value_of_child (struct varobj *parent, int index)
3182 {
3183 return cplus_value_of_child (parent, index);
3184 }
3185
3186 static struct type *
3187 java_type_of_child (struct varobj *parent, int index)
3188 {
3189 return cplus_type_of_child (parent, index);
3190 }
3191
3192 static char *
3193 java_value_of_variable (struct varobj *var, enum varobj_display_formats format)
3194 {
3195 return cplus_value_of_variable (var, format);
3196 }
3197 \f
3198 extern void _initialize_varobj (void);
3199 void
3200 _initialize_varobj (void)
3201 {
3202 int sizeof_table = sizeof (struct vlist *) * VAROBJ_TABLE_SIZE;
3203
3204 varobj_table = xmalloc (sizeof_table);
3205 memset (varobj_table, 0, sizeof_table);
3206
3207 add_setshow_zinteger_cmd ("debugvarobj", class_maintenance,
3208 &varobjdebug, _("\
3209 Set varobj debugging."), _("\
3210 Show varobj debugging."), _("\
3211 When non-zero, varobj debugging is enabled."),
3212 NULL,
3213 show_varobjdebug,
3214 &setlist, &showlist);
3215 }
3216
3217 /* Invalidate the varobjs that are tied to locals and re-create the ones that
3218 are defined on globals.
3219 Invalidated varobjs will be always printed in_scope="invalid". */
3220
3221 void
3222 varobj_invalidate (void)
3223 {
3224 struct varobj **all_rootvarobj;
3225 struct varobj **varp;
3226
3227 if (varobj_list (&all_rootvarobj) > 0)
3228 {
3229 varp = all_rootvarobj;
3230 while (*varp != NULL)
3231 {
3232 /* Floating varobjs are reparsed on each stop, so we don't care if
3233 the presently parsed expression refers to something that's gone.
3234 */
3235 if ((*varp)->root->floating)
3236 continue;
3237
3238 /* global var must be re-evaluated. */
3239 if ((*varp)->root->valid_block == NULL)
3240 {
3241 struct varobj *tmp_var;
3242
3243 /* Try to create a varobj with same expression. If we succeed
3244 replace the old varobj, otherwise invalidate it. */
3245 tmp_var = varobj_create (NULL, (*varp)->name, (CORE_ADDR) 0,
3246 USE_CURRENT_FRAME);
3247 if (tmp_var != NULL)
3248 {
3249 tmp_var->obj_name = xstrdup ((*varp)->obj_name);
3250 varobj_delete (*varp, NULL, 0);
3251 install_variable (tmp_var);
3252 }
3253 else
3254 (*varp)->root->is_valid = 0;
3255 }
3256 else /* locals must be invalidated. */
3257 (*varp)->root->is_valid = 0;
3258
3259 varp++;
3260 }
3261 }
3262 xfree (all_rootvarobj);
3263 return;
3264 }
This page took 0.095536 seconds and 4 git commands to generate.