*** 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
4 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 2 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, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 Boston, MA 02110-1301, USA. */
20
21 #include "defs.h"
22 #include "exceptions.h"
23 #include "value.h"
24 #include "expression.h"
25 #include "frame.h"
26 #include "language.h"
27 #include "wrapper.h"
28 #include "gdbcmd.h"
29 #include "block.h"
30
31 #include "gdb_assert.h"
32 #include "gdb_string.h"
33
34 #include "varobj.h"
35 #include "vec.h"
36
37 /* Non-zero if we want to see trace of varobj level stuff. */
38
39 int varobjdebug = 0;
40 static void
41 show_varobjdebug (struct ui_file *file, int from_tty,
42 struct cmd_list_element *c, const char *value)
43 {
44 fprintf_filtered (file, _("Varobj debugging is %s.\n"), value);
45 }
46
47 /* String representations of gdb's format codes */
48 char *varobj_format_string[] =
49 { "natural", "binary", "decimal", "hexadecimal", "octal" };
50
51 /* String representations of gdb's known languages */
52 char *varobj_language_string[] = { "unknown", "C", "C++", "Java" };
53
54 /* Data structures */
55
56 /* Every root variable has one of these structures saved in its
57 varobj. Members which must be free'd are noted. */
58 struct varobj_root
59 {
60
61 /* Alloc'd expression for this parent. */
62 struct expression *exp;
63
64 /* Block for which this expression is valid */
65 struct block *valid_block;
66
67 /* The frame for this expression */
68 struct frame_id frame;
69
70 /* If 1, "update" always recomputes the frame & valid block
71 using the currently selected frame. */
72 int use_selected_frame;
73
74 /* Language info for this variable and its children */
75 struct language_specific *lang;
76
77 /* The varobj for this root node. */
78 struct varobj *rootvar;
79
80 /* Next root variable */
81 struct varobj_root *next;
82 };
83
84 typedef struct varobj *varobj_p;
85
86 DEF_VEC_P (varobj_p);
87
88 /* Every variable in the system has a structure of this type defined
89 for it. This structure holds all information necessary to manipulate
90 a particular object variable. Members which must be freed are noted. */
91 struct varobj
92 {
93
94 /* Alloc'd name of the variable for this object.. If this variable is a
95 child, then this name will be the child's source name.
96 (bar, not foo.bar) */
97 /* NOTE: This is the "expression" */
98 char *name;
99
100 /* The alloc'd name for this variable's object. This is here for
101 convenience when constructing this object's children. */
102 char *obj_name;
103
104 /* Index of this variable in its parent or -1 */
105 int index;
106
107 /* The type of this variable. This may NEVER be NULL. */
108 struct type *type;
109
110 /* The value of this expression or subexpression. A NULL value
111 indicates there was an error getting this value.
112 Invariant: if varobj_value_is_changeable_p (this) is non-zero,
113 the value is either NULL, or not lazy. */
114 struct value *value;
115
116 /* The number of (immediate) children this variable has */
117 int num_children;
118
119 /* If this object is a child, this points to its immediate parent. */
120 struct varobj *parent;
121
122 /* Children of this object. */
123 VEC (varobj_p) *children;
124
125 /* Description of the root variable. Points to root variable for children. */
126 struct varobj_root *root;
127
128 /* The format of the output for this object */
129 enum varobj_display_formats format;
130
131 /* Was this variable updated via a varobj_set_value operation */
132 int updated;
133
134 /* Last print value. */
135 char *print_value;
136 };
137
138 struct cpstack
139 {
140 char *name;
141 struct cpstack *next;
142 };
143
144 /* A list of varobjs */
145
146 struct vlist
147 {
148 struct varobj *var;
149 struct vlist *next;
150 };
151
152 /* Private function prototypes */
153
154 /* Helper functions for the above subcommands. */
155
156 static int delete_variable (struct cpstack **, struct varobj *, int);
157
158 static void delete_variable_1 (struct cpstack **, int *,
159 struct varobj *, int, int);
160
161 static int install_variable (struct varobj *);
162
163 static void uninstall_variable (struct varobj *);
164
165 static struct varobj *create_child (struct varobj *, int, char *);
166
167 /* Utility routines */
168
169 static struct varobj *new_variable (void);
170
171 static struct varobj *new_root_variable (void);
172
173 static void free_variable (struct varobj *var);
174
175 static struct cleanup *make_cleanup_free_variable (struct varobj *var);
176
177 static struct type *get_type (struct varobj *var);
178
179 static struct type *get_type_deref (struct varobj *var);
180
181 static struct type *get_target_type (struct type *);
182
183 static enum varobj_display_formats variable_default_display (struct varobj *);
184
185 static void cppush (struct cpstack **pstack, char *name);
186
187 static char *cppop (struct cpstack **pstack);
188
189 static int install_new_value (struct varobj *var, struct value *value,
190 int initial);
191
192 /* Language-specific routines. */
193
194 static enum varobj_languages variable_language (struct varobj *var);
195
196 static int number_of_children (struct varobj *);
197
198 static char *name_of_variable (struct varobj *);
199
200 static char *name_of_child (struct varobj *, int);
201
202 static struct value *value_of_root (struct varobj **var_handle, int *);
203
204 static struct value *value_of_child (struct varobj *parent, int index);
205
206 static int variable_editable (struct varobj *var);
207
208 static char *my_value_of_variable (struct varobj *var);
209
210 static char *value_get_print_value (struct value *value,
211 enum varobj_display_formats format);
212
213 static int varobj_value_is_changeable_p (struct varobj *var);
214
215 static int is_root_p (struct varobj *var);
216
217 /* C implementation */
218
219 static int c_number_of_children (struct varobj *var);
220
221 static char *c_name_of_variable (struct varobj *parent);
222
223 static char *c_name_of_child (struct varobj *parent, int index);
224
225 static struct value *c_value_of_root (struct varobj **var_handle);
226
227 static struct value *c_value_of_child (struct varobj *parent, int index);
228
229 static struct type *c_type_of_child (struct varobj *parent, int index);
230
231 static int c_variable_editable (struct varobj *var);
232
233 static char *c_value_of_variable (struct varobj *var);
234
235 /* C++ implementation */
236
237 static int cplus_number_of_children (struct varobj *var);
238
239 static void cplus_class_num_children (struct type *type, int children[3]);
240
241 static char *cplus_name_of_variable (struct varobj *parent);
242
243 static char *cplus_name_of_child (struct varobj *parent, int index);
244
245 static struct value *cplus_value_of_root (struct varobj **var_handle);
246
247 static struct value *cplus_value_of_child (struct varobj *parent, int index);
248
249 static struct type *cplus_type_of_child (struct varobj *parent, int index);
250
251 static int cplus_variable_editable (struct varobj *var);
252
253 static char *cplus_value_of_variable (struct varobj *var);
254
255 /* Java implementation */
256
257 static int java_number_of_children (struct varobj *var);
258
259 static char *java_name_of_variable (struct varobj *parent);
260
261 static char *java_name_of_child (struct varobj *parent, int index);
262
263 static struct value *java_value_of_root (struct varobj **var_handle);
264
265 static struct value *java_value_of_child (struct varobj *parent, int index);
266
267 static struct type *java_type_of_child (struct varobj *parent, int index);
268
269 static int java_variable_editable (struct varobj *var);
270
271 static char *java_value_of_variable (struct varobj *var);
272
273 /* The language specific vector */
274
275 struct language_specific
276 {
277
278 /* The language of this variable */
279 enum varobj_languages language;
280
281 /* The number of children of PARENT. */
282 int (*number_of_children) (struct varobj * parent);
283
284 /* The name (expression) of a root varobj. */
285 char *(*name_of_variable) (struct varobj * parent);
286
287 /* The name of the INDEX'th child of PARENT. */
288 char *(*name_of_child) (struct varobj * parent, int index);
289
290 /* The ``struct value *'' of the root variable ROOT. */
291 struct value *(*value_of_root) (struct varobj ** root_handle);
292
293 /* The ``struct value *'' of the INDEX'th child of PARENT. */
294 struct value *(*value_of_child) (struct varobj * parent, int index);
295
296 /* The type of the INDEX'th child of PARENT. */
297 struct type *(*type_of_child) (struct varobj * parent, int index);
298
299 /* Is VAR editable? */
300 int (*variable_editable) (struct varobj * var);
301
302 /* The current value of VAR. */
303 char *(*value_of_variable) (struct varobj * var);
304 };
305
306 /* Array of known source language routines. */
307 static struct language_specific languages[vlang_end] = {
308 /* Unknown (try treating as C */
309 {
310 vlang_unknown,
311 c_number_of_children,
312 c_name_of_variable,
313 c_name_of_child,
314 c_value_of_root,
315 c_value_of_child,
316 c_type_of_child,
317 c_variable_editable,
318 c_value_of_variable}
319 ,
320 /* C */
321 {
322 vlang_c,
323 c_number_of_children,
324 c_name_of_variable,
325 c_name_of_child,
326 c_value_of_root,
327 c_value_of_child,
328 c_type_of_child,
329 c_variable_editable,
330 c_value_of_variable}
331 ,
332 /* C++ */
333 {
334 vlang_cplus,
335 cplus_number_of_children,
336 cplus_name_of_variable,
337 cplus_name_of_child,
338 cplus_value_of_root,
339 cplus_value_of_child,
340 cplus_type_of_child,
341 cplus_variable_editable,
342 cplus_value_of_variable}
343 ,
344 /* Java */
345 {
346 vlang_java,
347 java_number_of_children,
348 java_name_of_variable,
349 java_name_of_child,
350 java_value_of_root,
351 java_value_of_child,
352 java_type_of_child,
353 java_variable_editable,
354 java_value_of_variable}
355 };
356
357 /* A little convenience enum for dealing with C++/Java */
358 enum vsections
359 {
360 v_public = 0, v_private, v_protected
361 };
362
363 /* Private data */
364
365 /* Mappings of varobj_display_formats enums to gdb's format codes */
366 static int format_code[] = { 0, 't', 'd', 'x', 'o' };
367
368 /* Header of the list of root variable objects */
369 static struct varobj_root *rootlist;
370 static int rootcount = 0; /* number of root varobjs in the list */
371
372 /* Prime number indicating the number of buckets in the hash table */
373 /* A prime large enough to avoid too many colisions */
374 #define VAROBJ_TABLE_SIZE 227
375
376 /* Pointer to the varobj hash table (built at run time) */
377 static struct vlist **varobj_table;
378
379 /* Is the variable X one of our "fake" children? */
380 #define CPLUS_FAKE_CHILD(x) \
381 ((x) != NULL && (x)->type == NULL && (x)->value == NULL)
382 \f
383
384 /* API Implementation */
385 static int
386 is_root_p (struct varobj *var)
387 {
388 return (var->root->rootvar == var);
389 }
390
391 /* Creates a varobj (not its children) */
392
393 /* Return the full FRAME which corresponds to the given CORE_ADDR
394 or NULL if no FRAME on the chain corresponds to CORE_ADDR. */
395
396 static struct frame_info *
397 find_frame_addr_in_frame_chain (CORE_ADDR frame_addr)
398 {
399 struct frame_info *frame = NULL;
400
401 if (frame_addr == (CORE_ADDR) 0)
402 return NULL;
403
404 while (1)
405 {
406 frame = get_prev_frame (frame);
407 if (frame == NULL)
408 return NULL;
409 if (get_frame_base_address (frame) == frame_addr)
410 return frame;
411 }
412 }
413
414 struct varobj *
415 varobj_create (char *objname,
416 char *expression, CORE_ADDR frame, enum varobj_type type)
417 {
418 struct varobj *var;
419 struct frame_info *fi;
420 struct frame_info *old_fi = NULL;
421 struct block *block;
422 struct cleanup *old_chain;
423
424 /* Fill out a varobj structure for the (root) variable being constructed. */
425 var = new_root_variable ();
426 old_chain = make_cleanup_free_variable (var);
427
428 if (expression != NULL)
429 {
430 char *p;
431 enum varobj_languages lang;
432 struct value *value;
433
434 /* Parse and evaluate the expression, filling in as much
435 of the variable's data as possible */
436
437 /* Allow creator to specify context of variable */
438 if ((type == USE_CURRENT_FRAME) || (type == USE_SELECTED_FRAME))
439 fi = deprecated_selected_frame;
440 else
441 /* FIXME: cagney/2002-11-23: This code should be doing a
442 lookup using the frame ID and not just the frame's
443 ``address''. This, of course, means an interface change.
444 However, with out that interface change ISAs, such as the
445 ia64 with its two stacks, won't work. Similar goes for the
446 case where there is a frameless function. */
447 fi = find_frame_addr_in_frame_chain (frame);
448
449 /* frame = -2 means always use selected frame */
450 if (type == USE_SELECTED_FRAME)
451 var->root->use_selected_frame = 1;
452
453 block = NULL;
454 if (fi != NULL)
455 block = get_frame_block (fi, 0);
456
457 p = expression;
458 innermost_block = NULL;
459 /* Wrap the call to parse expression, so we can
460 return a sensible error. */
461 if (!gdb_parse_exp_1 (&p, block, 0, &var->root->exp))
462 {
463 return NULL;
464 }
465
466 /* Don't allow variables to be created for types. */
467 if (var->root->exp->elts[0].opcode == OP_TYPE)
468 {
469 do_cleanups (old_chain);
470 fprintf_unfiltered (gdb_stderr, "Attempt to use a type name"
471 " as an expression.\n");
472 return NULL;
473 }
474
475 var->format = variable_default_display (var);
476 var->root->valid_block = innermost_block;
477 var->name = savestring (expression, strlen (expression));
478
479 /* When the frame is different from the current frame,
480 we must select the appropriate frame before parsing
481 the expression, otherwise the value will not be current.
482 Since select_frame is so benign, just call it for all cases. */
483 if (fi != NULL)
484 {
485 var->root->frame = get_frame_id (fi);
486 old_fi = deprecated_selected_frame;
487 select_frame (fi);
488 }
489
490 /* We definitively need to catch errors here.
491 If evaluate_expression succeeds we got the value we wanted.
492 But if it fails, we still go on with a call to evaluate_type() */
493 if (!gdb_evaluate_expression (var->root->exp, &value))
494 /* Error getting the value. Try to at least get the
495 right type. */
496 value = evaluate_type (var->root->exp);
497
498 var->type = value_type (value);
499 install_new_value (var, value, 1 /* Initial assignment */);
500
501 /* Set language info */
502 lang = variable_language (var);
503 var->root->lang = &languages[lang];
504
505 /* Set ourselves as our root */
506 var->root->rootvar = var;
507
508 /* Reset the selected frame */
509 if (fi != NULL)
510 select_frame (old_fi);
511 }
512
513 /* If the variable object name is null, that means this
514 is a temporary variable, so don't install it. */
515
516 if ((var != NULL) && (objname != NULL))
517 {
518 var->obj_name = savestring (objname, strlen (objname));
519
520 /* If a varobj name is duplicated, the install will fail so
521 we must clenup */
522 if (!install_variable (var))
523 {
524 do_cleanups (old_chain);
525 return NULL;
526 }
527 }
528
529 discard_cleanups (old_chain);
530 return var;
531 }
532
533 /* Generates an unique name that can be used for a varobj */
534
535 char *
536 varobj_gen_name (void)
537 {
538 static int id = 0;
539 char *obj_name;
540
541 /* generate a name for this object */
542 id++;
543 obj_name = xstrprintf ("var%d", id);
544
545 return obj_name;
546 }
547
548 /* Given an "objname", returns the pointer to the corresponding varobj
549 or NULL if not found */
550
551 struct varobj *
552 varobj_get_handle (char *objname)
553 {
554 struct vlist *cv;
555 const char *chp;
556 unsigned int index = 0;
557 unsigned int i = 1;
558
559 for (chp = objname; *chp; chp++)
560 {
561 index = (index + (i++ * (unsigned int) *chp)) % VAROBJ_TABLE_SIZE;
562 }
563
564 cv = *(varobj_table + index);
565 while ((cv != NULL) && (strcmp (cv->var->obj_name, objname) != 0))
566 cv = cv->next;
567
568 if (cv == NULL)
569 error (_("Variable object not found"));
570
571 return cv->var;
572 }
573
574 /* Given the handle, return the name of the object */
575
576 char *
577 varobj_get_objname (struct varobj *var)
578 {
579 return var->obj_name;
580 }
581
582 /* Given the handle, return the expression represented by the object */
583
584 char *
585 varobj_get_expression (struct varobj *var)
586 {
587 return name_of_variable (var);
588 }
589
590 /* Deletes a varobj and all its children if only_children == 0,
591 otherwise deletes only the children; returns a malloc'ed list of all the
592 (malloc'ed) names of the variables that have been deleted (NULL terminated) */
593
594 int
595 varobj_delete (struct varobj *var, char ***dellist, int only_children)
596 {
597 int delcount;
598 int mycount;
599 struct cpstack *result = NULL;
600 char **cp;
601
602 /* Initialize a stack for temporary results */
603 cppush (&result, NULL);
604
605 if (only_children)
606 /* Delete only the variable children */
607 delcount = delete_variable (&result, var, 1 /* only the children */ );
608 else
609 /* Delete the variable and all its children */
610 delcount = delete_variable (&result, var, 0 /* parent+children */ );
611
612 /* We may have been asked to return a list of what has been deleted */
613 if (dellist != NULL)
614 {
615 *dellist = xmalloc ((delcount + 1) * sizeof (char *));
616
617 cp = *dellist;
618 mycount = delcount;
619 *cp = cppop (&result);
620 while ((*cp != NULL) && (mycount > 0))
621 {
622 mycount--;
623 cp++;
624 *cp = cppop (&result);
625 }
626
627 if (mycount || (*cp != NULL))
628 warning (_("varobj_delete: assertion failed - mycount(=%d) <> 0"),
629 mycount);
630 }
631
632 return delcount;
633 }
634
635 /* Set/Get variable object display format */
636
637 enum varobj_display_formats
638 varobj_set_display_format (struct varobj *var,
639 enum varobj_display_formats format)
640 {
641 switch (format)
642 {
643 case FORMAT_NATURAL:
644 case FORMAT_BINARY:
645 case FORMAT_DECIMAL:
646 case FORMAT_HEXADECIMAL:
647 case FORMAT_OCTAL:
648 var->format = format;
649 break;
650
651 default:
652 var->format = variable_default_display (var);
653 }
654
655 return var->format;
656 }
657
658 enum varobj_display_formats
659 varobj_get_display_format (struct varobj *var)
660 {
661 return var->format;
662 }
663
664 int
665 varobj_get_num_children (struct varobj *var)
666 {
667 if (var->num_children == -1)
668 var->num_children = number_of_children (var);
669
670 return var->num_children;
671 }
672
673 /* Creates a list of the immediate children of a variable object;
674 the return code is the number of such children or -1 on error */
675
676 int
677 varobj_list_children (struct varobj *var, struct varobj ***childlist)
678 {
679 struct varobj *child;
680 char *name;
681 int i;
682
683 /* sanity check: have we been passed a pointer? */
684 if (childlist == NULL)
685 return -1;
686
687 *childlist = NULL;
688
689 if (var->num_children == -1)
690 var->num_children = number_of_children (var);
691
692 /* If that failed, give up. */
693 if (var->num_children == -1)
694 return -1;
695
696 /* If we're called when the list of children is not yet initialized,
697 allocate enough elements in it. */
698 while (VEC_length (varobj_p, var->children) < var->num_children)
699 VEC_safe_push (varobj_p, var->children, NULL);
700
701 /* List of children */
702 *childlist = xmalloc ((var->num_children + 1) * sizeof (struct varobj *));
703
704 for (i = 0; i < var->num_children; i++)
705 {
706 varobj_p existing;
707
708 /* Mark as the end in case we bail out */
709 *((*childlist) + i) = NULL;
710
711 existing = VEC_index (varobj_p, var->children, i);
712
713 if (existing == NULL)
714 {
715 /* Either it's the first call to varobj_list_children for
716 this variable object, and the child was never created,
717 or it was explicitly deleted by the client. */
718 name = name_of_child (var, i);
719 existing = create_child (var, i, name);
720 VEC_replace (varobj_p, var->children, i, existing);
721 }
722
723 *((*childlist) + i) = existing;
724 }
725
726 /* End of list is marked by a NULL pointer */
727 *((*childlist) + i) = NULL;
728
729 return var->num_children;
730 }
731
732 /* Obtain the type of an object Variable as a string similar to the one gdb
733 prints on the console */
734
735 char *
736 varobj_get_type (struct varobj *var)
737 {
738 struct value *val;
739 struct cleanup *old_chain;
740 struct ui_file *stb;
741 char *thetype;
742 long length;
743
744 /* For the "fake" variables, do not return a type. (It's type is
745 NULL, too.) */
746 if (CPLUS_FAKE_CHILD (var))
747 return NULL;
748
749 stb = mem_fileopen ();
750 old_chain = make_cleanup_ui_file_delete (stb);
751
752 /* To print the type, we simply create a zero ``struct value *'' and
753 cast it to our type. We then typeprint this variable. */
754 val = value_zero (var->type, not_lval);
755 type_print (value_type (val), "", stb, -1);
756
757 thetype = ui_file_xstrdup (stb, &length);
758 do_cleanups (old_chain);
759 return thetype;
760 }
761
762 /* Obtain the type of an object variable. */
763
764 struct type *
765 varobj_get_gdb_type (struct varobj *var)
766 {
767 return var->type;
768 }
769
770 enum varobj_languages
771 varobj_get_language (struct varobj *var)
772 {
773 return variable_language (var);
774 }
775
776 int
777 varobj_get_attributes (struct varobj *var)
778 {
779 int attributes = 0;
780
781 if (variable_editable (var))
782 /* FIXME: define masks for attributes */
783 attributes |= 0x00000001; /* Editable */
784
785 return attributes;
786 }
787
788 char *
789 varobj_get_value (struct varobj *var)
790 {
791 return my_value_of_variable (var);
792 }
793
794 /* Set the value of an object variable (if it is editable) to the
795 value of the given expression */
796 /* Note: Invokes functions that can call error() */
797
798 int
799 varobj_set_value (struct varobj *var, char *expression)
800 {
801 struct value *val;
802 int offset = 0;
803 int error = 0;
804
805 /* The argument "expression" contains the variable's new value.
806 We need to first construct a legal expression for this -- ugh! */
807 /* Does this cover all the bases? */
808 struct expression *exp;
809 struct value *value;
810 int saved_input_radix = input_radix;
811
812 if (var->value != NULL && variable_editable (var))
813 {
814 char *s = expression;
815 int i;
816
817 input_radix = 10; /* ALWAYS reset to decimal temporarily */
818 exp = parse_exp_1 (&s, 0, 0);
819 if (!gdb_evaluate_expression (exp, &value))
820 {
821 /* We cannot proceed without a valid expression. */
822 xfree (exp);
823 return 0;
824 }
825
826 /* All types that are editable must also be changeable. */
827 gdb_assert (varobj_value_is_changeable_p (var));
828
829 /* The value of a changeable variable object must not be lazy. */
830 gdb_assert (!value_lazy (var->value));
831
832 /* Need to coerce the input. We want to check if the
833 value of the variable object will be different
834 after assignment, and the first thing value_assign
835 does is coerce the input.
836 For example, if we are assigning an array to a pointer variable we
837 should compare the pointer with the the array's address, not with the
838 array's content. */
839 value = coerce_array (value);
840
841 /* The new value may be lazy. gdb_value_assign, or
842 rather value_contents, will take care of this.
843 If fetching of the new value will fail, gdb_value_assign
844 with catch the exception. */
845 if (!gdb_value_assign (var->value, value, &val))
846 return 0;
847
848 /* If the value has changed, record it, so that next -var-update can
849 report this change. If a variable had a value of '1', we've set it
850 to '333' and then set again to '1', when -var-update will report this
851 variable as changed -- because the first assignment has set the
852 'updated' flag. There's no need to optimize that, because return value
853 of -var-update should be considered an approximation. */
854 var->updated = install_new_value (var, val, 0 /* Compare values. */);
855 input_radix = saved_input_radix;
856 return 1;
857 }
858
859 return 0;
860 }
861
862 /* Returns a malloc'ed list with all root variable objects */
863 int
864 varobj_list (struct varobj ***varlist)
865 {
866 struct varobj **cv;
867 struct varobj_root *croot;
868 int mycount = rootcount;
869
870 /* Alloc (rootcount + 1) entries for the result */
871 *varlist = xmalloc ((rootcount + 1) * sizeof (struct varobj *));
872
873 cv = *varlist;
874 croot = rootlist;
875 while ((croot != NULL) && (mycount > 0))
876 {
877 *cv = croot->rootvar;
878 mycount--;
879 cv++;
880 croot = croot->next;
881 }
882 /* Mark the end of the list */
883 *cv = NULL;
884
885 if (mycount || (croot != NULL))
886 warning
887 ("varobj_list: assertion failed - wrong tally of root vars (%d:%d)",
888 rootcount, mycount);
889
890 return rootcount;
891 }
892
893 /* Assign a new value to a variable object. If INITIAL is non-zero,
894 this is the first assignement after the variable object was just
895 created, or changed type. In that case, just assign the value
896 and return 0.
897 Otherwise, assign the value and if type_changeable returns non-zero,
898 find if the new value is different from the current value.
899 Return 1 if so, and 0 if the values are equal.
900
901 The VALUE parameter should not be released -- the function will
902 take care of releasing it when needed. */
903 static int
904 install_new_value (struct varobj *var, struct value *value, int initial)
905 {
906 int changeable;
907 int need_to_fetch;
908 int changed = 0;
909
910 /* We need to know the varobj's type to decide if the value should
911 be fetched or not. C++ fake children (public/protected/private) don't have
912 a type. */
913 gdb_assert (var->type || CPLUS_FAKE_CHILD (var));
914 changeable = varobj_value_is_changeable_p (var);
915 need_to_fetch = changeable;
916
917 /* We are not interested in the address of references, and given
918 that in C++ a reference is not rebindable, it cannot
919 meaningfully change. So, get hold of the real value. */
920 if (value)
921 {
922 value = coerce_ref (value);
923 release_value (value);
924 }
925
926 if (var->type && TYPE_CODE (var->type) == TYPE_CODE_UNION)
927 /* For unions, we need to fetch the value implicitly because
928 of implementation of union member fetch. When gdb
929 creates a value for a field and the value of the enclosing
930 structure is not lazy, it immediately copies the necessary
931 bytes from the enclosing values. If the enclosing value is
932 lazy, the call to value_fetch_lazy on the field will read
933 the data from memory. For unions, that means we'll read the
934 same memory more than once, which is not desirable. So
935 fetch now. */
936 need_to_fetch = 1;
937
938 /* The new value might be lazy. If the type is changeable,
939 that is we'll be comparing values of this type, fetch the
940 value now. Otherwise, on the next update the old value
941 will be lazy, which means we've lost that old value. */
942 if (need_to_fetch && value && value_lazy (value))
943 {
944 if (!gdb_value_fetch_lazy (value))
945 {
946 /* Set the value to NULL, so that for the next -var-update,
947 we don't try to compare the new value with this value,
948 that we couldn't even read. */
949 value = NULL;
950 }
951 }
952
953 /* If the type is changeable, compare the old and the new values.
954 If this is the initial assignment, we don't have any old value
955 to compare with. */
956 if (initial)
957 var->print_value = value_get_print_value (value, var->format);
958 else if (changeable)
959 {
960 /* If the value of the varobj was changed by -var-set-value, then the
961 value in the varobj and in the target is the same. However, that value
962 is different from the value that the varobj had after the previous
963 -var-update. So need to the varobj as changed. */
964 if (var->updated)
965 {
966 xfree (var->print_value);
967 var->print_value = value_get_print_value (value, var->format);
968 changed = 1;
969 }
970 else
971 {
972 /* Try to compare the values. That requires that both
973 values are non-lazy. */
974
975 /* Quick comparison of NULL values. */
976 if (var->value == NULL && value == NULL)
977 /* Equal. */
978 ;
979 else if (var->value == NULL || value == NULL)
980 {
981 xfree (var->print_value);
982 var->print_value = value_get_print_value (value, var->format);
983 changed = 1;
984 }
985 else
986 {
987 char *print_value;
988 gdb_assert (!value_lazy (var->value));
989 gdb_assert (!value_lazy (value));
990 print_value = value_get_print_value (value, var->format);
991
992 gdb_assert (var->print_value != NULL && print_value != NULL);
993 if (strcmp (var->print_value, print_value) != 0)
994 {
995 xfree (var->print_value);
996 var->print_value = print_value;
997 changed = 1;
998 }
999 else
1000 xfree (print_value);
1001 }
1002 }
1003 }
1004
1005 /* We must always keep the new value, since children depend on it. */
1006 if (var->value != NULL)
1007 value_free (var->value);
1008 var->value = value;
1009 var->updated = 0;
1010
1011 gdb_assert (!var->value || value_type (var->value));
1012
1013 return changed;
1014 }
1015
1016 /* Update the values for a variable and its children. This is a
1017 two-pronged attack. First, re-parse the value for the root's
1018 expression to see if it's changed. Then go all the way
1019 through its children, reconstructing them and noting if they've
1020 changed.
1021 Return value:
1022 -1 if there was an error updating the varobj
1023 -2 if the type changed
1024 Otherwise it is the number of children + parent changed
1025
1026 Only root variables can be updated...
1027
1028 NOTE: This function may delete the caller's varobj. If it
1029 returns -2, then it has done this and VARP will be modified
1030 to point to the new varobj. */
1031
1032 int
1033 varobj_update (struct varobj **varp, struct varobj ***changelist)
1034 {
1035 int changed = 0;
1036 int error = 0;
1037 int type_changed;
1038 int i;
1039 int vleft;
1040 struct varobj *v;
1041 struct varobj **cv;
1042 struct varobj **templist = NULL;
1043 struct value *new;
1044 VEC (varobj_p) *stack = NULL;
1045 VEC (varobj_p) *result = NULL;
1046 struct frame_id old_fid;
1047 struct frame_info *fi;
1048
1049 /* sanity check: have we been passed a pointer? */
1050 if (changelist == NULL)
1051 return -1;
1052
1053 /* Only root variables can be updated... */
1054 if (!is_root_p (*varp))
1055 /* Not a root var */
1056 return -1;
1057
1058 /* Save the selected stack frame, since we will need to change it
1059 in order to evaluate expressions. */
1060 old_fid = get_frame_id (deprecated_selected_frame);
1061
1062 /* Update the root variable. value_of_root can return NULL
1063 if the variable is no longer around, i.e. we stepped out of
1064 the frame in which a local existed. We are letting the
1065 value_of_root variable dispose of the varobj if the type
1066 has changed. */
1067 type_changed = 1;
1068 new = value_of_root (varp, &type_changed);
1069
1070 /* Restore selected frame */
1071 fi = frame_find_by_id (old_fid);
1072 if (fi)
1073 select_frame (fi);
1074
1075 /* If this is a "use_selected_frame" varobj, and its type has changed,
1076 them note that it's changed. */
1077 if (type_changed)
1078 VEC_safe_push (varobj_p, result, *varp);
1079
1080 if (install_new_value ((*varp), new, type_changed))
1081 {
1082 /* If type_changed is 1, install_new_value will never return
1083 non-zero, so we'll never report the same variable twice. */
1084 gdb_assert (!type_changed);
1085 VEC_safe_push (varobj_p, result, *varp);
1086 }
1087
1088 if (new == NULL)
1089 {
1090 /* This means the varobj itself is out of scope.
1091 Report it. */
1092 VEC_free (varobj_p, result);
1093 return -1;
1094 }
1095
1096 VEC_safe_push (varobj_p, stack, *varp);
1097
1098 /* Walk through the children, reconstructing them all. */
1099 while (!VEC_empty (varobj_p, stack))
1100 {
1101 v = VEC_pop (varobj_p, stack);
1102
1103 /* Push any children. Use reverse order so that the first
1104 child is popped from the work stack first, and so
1105 will be added to result first. This does not
1106 affect correctness, just "nicer". */
1107 for (i = VEC_length (varobj_p, v->children)-1; i >= 0; --i)
1108 {
1109 varobj_p c = VEC_index (varobj_p, v->children, i);
1110 /* Child may be NULL if explicitly deleted by -var-delete. */
1111 if (c != NULL)
1112 VEC_safe_push (varobj_p, stack, c);
1113 }
1114
1115 /* Update this variable, unless it's a root, which is already
1116 updated. */
1117 if (v != *varp)
1118 {
1119 new = value_of_child (v->parent, v->index);
1120 if (install_new_value (v, new, 0 /* type not changed */))
1121 {
1122 /* Note that it's changed */
1123 VEC_safe_push (varobj_p, result, v);
1124 v->updated = 0;
1125 }
1126 }
1127 }
1128
1129 /* Alloc (changed + 1) list entries */
1130 changed = VEC_length (varobj_p, result);
1131 *changelist = xmalloc ((changed + 1) * sizeof (struct varobj *));
1132 cv = *changelist;
1133
1134 for (i = 0; i < changed; ++i)
1135 {
1136 *cv = VEC_index (varobj_p, result, i);
1137 gdb_assert (*cv != NULL);
1138 ++cv;
1139 }
1140 *cv = 0;
1141
1142 if (type_changed)
1143 return -2;
1144 else
1145 return changed;
1146 }
1147 \f
1148
1149 /* Helper functions */
1150
1151 /*
1152 * Variable object construction/destruction
1153 */
1154
1155 static int
1156 delete_variable (struct cpstack **resultp, struct varobj *var,
1157 int only_children_p)
1158 {
1159 int delcount = 0;
1160
1161 delete_variable_1 (resultp, &delcount, var,
1162 only_children_p, 1 /* remove_from_parent_p */ );
1163
1164 return delcount;
1165 }
1166
1167 /* Delete the variable object VAR and its children */
1168 /* IMPORTANT NOTE: If we delete a variable which is a child
1169 and the parent is not removed we dump core. It must be always
1170 initially called with remove_from_parent_p set */
1171 static void
1172 delete_variable_1 (struct cpstack **resultp, int *delcountp,
1173 struct varobj *var, int only_children_p,
1174 int remove_from_parent_p)
1175 {
1176 int i;
1177
1178 /* Delete any children of this variable, too. */
1179 for (i = 0; i < VEC_length (varobj_p, var->children); ++i)
1180 {
1181 varobj_p child = VEC_index (varobj_p, var->children, i);
1182 if (!remove_from_parent_p)
1183 child->parent = NULL;
1184 delete_variable_1 (resultp, delcountp, child, 0, only_children_p);
1185 }
1186 VEC_free (varobj_p, var->children);
1187
1188 /* if we were called to delete only the children we are done here */
1189 if (only_children_p)
1190 return;
1191
1192 /* Otherwise, add it to the list of deleted ones and proceed to do so */
1193 /* If the name is null, this is a temporary variable, that has not
1194 yet been installed, don't report it, it belongs to the caller... */
1195 if (var->obj_name != NULL)
1196 {
1197 cppush (resultp, xstrdup (var->obj_name));
1198 *delcountp = *delcountp + 1;
1199 }
1200
1201 /* If this variable has a parent, remove it from its parent's list */
1202 /* OPTIMIZATION: if the parent of this variable is also being deleted,
1203 (as indicated by remove_from_parent_p) we don't bother doing an
1204 expensive list search to find the element to remove when we are
1205 discarding the list afterwards */
1206 if ((remove_from_parent_p) && (var->parent != NULL))
1207 {
1208 VEC_replace (varobj_p, var->parent->children, var->index, NULL);
1209 }
1210
1211 if (var->obj_name != NULL)
1212 uninstall_variable (var);
1213
1214 /* Free memory associated with this variable */
1215 free_variable (var);
1216 }
1217
1218 /* Install the given variable VAR with the object name VAR->OBJ_NAME. */
1219 static int
1220 install_variable (struct varobj *var)
1221 {
1222 struct vlist *cv;
1223 struct vlist *newvl;
1224 const char *chp;
1225 unsigned int index = 0;
1226 unsigned int i = 1;
1227
1228 for (chp = var->obj_name; *chp; chp++)
1229 {
1230 index = (index + (i++ * (unsigned int) *chp)) % VAROBJ_TABLE_SIZE;
1231 }
1232
1233 cv = *(varobj_table + index);
1234 while ((cv != NULL) && (strcmp (cv->var->obj_name, var->obj_name) != 0))
1235 cv = cv->next;
1236
1237 if (cv != NULL)
1238 error (_("Duplicate variable object name"));
1239
1240 /* Add varobj to hash table */
1241 newvl = xmalloc (sizeof (struct vlist));
1242 newvl->next = *(varobj_table + index);
1243 newvl->var = var;
1244 *(varobj_table + index) = newvl;
1245
1246 /* If root, add varobj to root list */
1247 if (is_root_p (var))
1248 {
1249 /* Add to list of root variables */
1250 if (rootlist == NULL)
1251 var->root->next = NULL;
1252 else
1253 var->root->next = rootlist;
1254 rootlist = var->root;
1255 rootcount++;
1256 }
1257
1258 return 1; /* OK */
1259 }
1260
1261 /* Unistall the object VAR. */
1262 static void
1263 uninstall_variable (struct varobj *var)
1264 {
1265 struct vlist *cv;
1266 struct vlist *prev;
1267 struct varobj_root *cr;
1268 struct varobj_root *prer;
1269 const char *chp;
1270 unsigned int index = 0;
1271 unsigned int i = 1;
1272
1273 /* Remove varobj from hash table */
1274 for (chp = var->obj_name; *chp; chp++)
1275 {
1276 index = (index + (i++ * (unsigned int) *chp)) % VAROBJ_TABLE_SIZE;
1277 }
1278
1279 cv = *(varobj_table + index);
1280 prev = NULL;
1281 while ((cv != NULL) && (strcmp (cv->var->obj_name, var->obj_name) != 0))
1282 {
1283 prev = cv;
1284 cv = cv->next;
1285 }
1286
1287 if (varobjdebug)
1288 fprintf_unfiltered (gdb_stdlog, "Deleting %s\n", var->obj_name);
1289
1290 if (cv == NULL)
1291 {
1292 warning
1293 ("Assertion failed: Could not find variable object \"%s\" to delete",
1294 var->obj_name);
1295 return;
1296 }
1297
1298 if (prev == NULL)
1299 *(varobj_table + index) = cv->next;
1300 else
1301 prev->next = cv->next;
1302
1303 xfree (cv);
1304
1305 /* If root, remove varobj from root list */
1306 if (is_root_p (var))
1307 {
1308 /* Remove from list of root variables */
1309 if (rootlist == var->root)
1310 rootlist = var->root->next;
1311 else
1312 {
1313 prer = NULL;
1314 cr = rootlist;
1315 while ((cr != NULL) && (cr->rootvar != var))
1316 {
1317 prer = cr;
1318 cr = cr->next;
1319 }
1320 if (cr == NULL)
1321 {
1322 warning
1323 ("Assertion failed: Could not find varobj \"%s\" in root list",
1324 var->obj_name);
1325 return;
1326 }
1327 if (prer == NULL)
1328 rootlist = NULL;
1329 else
1330 prer->next = cr->next;
1331 }
1332 rootcount--;
1333 }
1334
1335 }
1336
1337 /* Create and install a child of the parent of the given name */
1338 static struct varobj *
1339 create_child (struct varobj *parent, int index, char *name)
1340 {
1341 struct varobj *child;
1342 char *childs_name;
1343 struct value *value;
1344
1345 child = new_variable ();
1346
1347 /* name is allocated by name_of_child */
1348 child->name = name;
1349 child->index = index;
1350 value = value_of_child (parent, index);
1351 child->parent = parent;
1352 child->root = parent->root;
1353 childs_name = xstrprintf ("%s.%s", parent->obj_name, name);
1354 child->obj_name = childs_name;
1355 install_variable (child);
1356
1357 /* Compute the type of the child. Must do this before
1358 calling install_new_value. */
1359 if (value != NULL)
1360 /* If the child had no evaluation errors, var->value
1361 will be non-NULL and contain a valid type. */
1362 child->type = value_type (value);
1363 else
1364 /* Otherwise, we must compute the type. */
1365 child->type = (*child->root->lang->type_of_child) (child->parent,
1366 child->index);
1367 install_new_value (child, value, 1);
1368
1369 return child;
1370 }
1371 \f
1372
1373 /*
1374 * Miscellaneous utility functions.
1375 */
1376
1377 /* Allocate memory and initialize a new variable */
1378 static struct varobj *
1379 new_variable (void)
1380 {
1381 struct varobj *var;
1382
1383 var = (struct varobj *) xmalloc (sizeof (struct varobj));
1384 var->name = NULL;
1385 var->obj_name = NULL;
1386 var->index = -1;
1387 var->type = NULL;
1388 var->value = NULL;
1389 var->num_children = -1;
1390 var->parent = NULL;
1391 var->children = NULL;
1392 var->format = 0;
1393 var->root = NULL;
1394 var->updated = 0;
1395 var->print_value = NULL;
1396
1397 return var;
1398 }
1399
1400 /* Allocate memory and initialize a new root variable */
1401 static struct varobj *
1402 new_root_variable (void)
1403 {
1404 struct varobj *var = new_variable ();
1405 var->root = (struct varobj_root *) xmalloc (sizeof (struct varobj_root));;
1406 var->root->lang = NULL;
1407 var->root->exp = NULL;
1408 var->root->valid_block = NULL;
1409 var->root->frame = null_frame_id;
1410 var->root->use_selected_frame = 0;
1411 var->root->rootvar = NULL;
1412
1413 return var;
1414 }
1415
1416 /* Free any allocated memory associated with VAR. */
1417 static void
1418 free_variable (struct varobj *var)
1419 {
1420 /* Free the expression if this is a root variable. */
1421 if (is_root_p (var))
1422 {
1423 free_current_contents (&var->root->exp);
1424 xfree (var->root);
1425 }
1426
1427 xfree (var->name);
1428 xfree (var->obj_name);
1429 xfree (var->print_value);
1430 xfree (var);
1431 }
1432
1433 static void
1434 do_free_variable_cleanup (void *var)
1435 {
1436 free_variable (var);
1437 }
1438
1439 static struct cleanup *
1440 make_cleanup_free_variable (struct varobj *var)
1441 {
1442 return make_cleanup (do_free_variable_cleanup, var);
1443 }
1444
1445 /* This returns the type of the variable. It also skips past typedefs
1446 to return the real type of the variable.
1447
1448 NOTE: TYPE_TARGET_TYPE should NOT be used anywhere in this file
1449 except within get_target_type and get_type. */
1450 static struct type *
1451 get_type (struct varobj *var)
1452 {
1453 struct type *type;
1454 type = var->type;
1455
1456 if (type != NULL)
1457 type = check_typedef (type);
1458
1459 return type;
1460 }
1461
1462 /* This returns the type of the variable, dereferencing references, pointers
1463 and references to pointers, too. */
1464 static struct type *
1465 get_type_deref (struct varobj *var)
1466 {
1467 struct type *type;
1468
1469 type = get_type (var);
1470
1471 if (type)
1472 {
1473 if (TYPE_CODE (type) == TYPE_CODE_REF)
1474 type = get_target_type (type);
1475 if (TYPE_CODE (type) == TYPE_CODE_PTR)
1476 type = get_target_type (type);
1477 }
1478
1479 return type;
1480 }
1481
1482 /* This returns the target type (or NULL) of TYPE, also skipping
1483 past typedefs, just like get_type ().
1484
1485 NOTE: TYPE_TARGET_TYPE should NOT be used anywhere in this file
1486 except within get_target_type and get_type. */
1487 static struct type *
1488 get_target_type (struct type *type)
1489 {
1490 if (type != NULL)
1491 {
1492 type = TYPE_TARGET_TYPE (type);
1493 if (type != NULL)
1494 type = check_typedef (type);
1495 }
1496
1497 return type;
1498 }
1499
1500 /* What is the default display for this variable? We assume that
1501 everything is "natural". Any exceptions? */
1502 static enum varobj_display_formats
1503 variable_default_display (struct varobj *var)
1504 {
1505 return FORMAT_NATURAL;
1506 }
1507
1508 /* FIXME: The following should be generic for any pointer */
1509 static void
1510 cppush (struct cpstack **pstack, char *name)
1511 {
1512 struct cpstack *s;
1513
1514 s = (struct cpstack *) xmalloc (sizeof (struct cpstack));
1515 s->name = name;
1516 s->next = *pstack;
1517 *pstack = s;
1518 }
1519
1520 /* FIXME: The following should be generic for any pointer */
1521 static char *
1522 cppop (struct cpstack **pstack)
1523 {
1524 struct cpstack *s;
1525 char *v;
1526
1527 if ((*pstack)->name == NULL && (*pstack)->next == NULL)
1528 return NULL;
1529
1530 s = *pstack;
1531 v = s->name;
1532 *pstack = (*pstack)->next;
1533 xfree (s);
1534
1535 return v;
1536 }
1537 \f
1538 /*
1539 * Language-dependencies
1540 */
1541
1542 /* Common entry points */
1543
1544 /* Get the language of variable VAR. */
1545 static enum varobj_languages
1546 variable_language (struct varobj *var)
1547 {
1548 enum varobj_languages lang;
1549
1550 switch (var->root->exp->language_defn->la_language)
1551 {
1552 default:
1553 case language_c:
1554 lang = vlang_c;
1555 break;
1556 case language_cplus:
1557 lang = vlang_cplus;
1558 break;
1559 case language_java:
1560 lang = vlang_java;
1561 break;
1562 }
1563
1564 return lang;
1565 }
1566
1567 /* Return the number of children for a given variable.
1568 The result of this function is defined by the language
1569 implementation. The number of children returned by this function
1570 is the number of children that the user will see in the variable
1571 display. */
1572 static int
1573 number_of_children (struct varobj *var)
1574 {
1575 return (*var->root->lang->number_of_children) (var);;
1576 }
1577
1578 /* What is the expression for the root varobj VAR? Returns a malloc'd string. */
1579 static char *
1580 name_of_variable (struct varobj *var)
1581 {
1582 return (*var->root->lang->name_of_variable) (var);
1583 }
1584
1585 /* What is the name of the INDEX'th child of VAR? Returns a malloc'd string. */
1586 static char *
1587 name_of_child (struct varobj *var, int index)
1588 {
1589 return (*var->root->lang->name_of_child) (var, index);
1590 }
1591
1592 /* What is the ``struct value *'' of the root variable VAR?
1593 TYPE_CHANGED controls what to do if the type of a
1594 use_selected_frame = 1 variable changes. On input,
1595 TYPE_CHANGED = 1 means discard the old varobj, and replace
1596 it with this one. TYPE_CHANGED = 0 means leave it around.
1597 NB: In both cases, var_handle will point to the new varobj,
1598 so if you use TYPE_CHANGED = 0, you will have to stash the
1599 old varobj pointer away somewhere before calling this.
1600 On return, TYPE_CHANGED will be 1 if the type has changed, and
1601 0 otherwise. */
1602 static struct value *
1603 value_of_root (struct varobj **var_handle, int *type_changed)
1604 {
1605 struct varobj *var;
1606
1607 if (var_handle == NULL)
1608 return NULL;
1609
1610 var = *var_handle;
1611
1612 /* This should really be an exception, since this should
1613 only get called with a root variable. */
1614
1615 if (!is_root_p (var))
1616 return NULL;
1617
1618 if (var->root->use_selected_frame)
1619 {
1620 struct varobj *tmp_var;
1621 char *old_type, *new_type;
1622 old_type = varobj_get_type (var);
1623 tmp_var = varobj_create (NULL, var->name, (CORE_ADDR) 0,
1624 USE_SELECTED_FRAME);
1625 if (tmp_var == NULL)
1626 {
1627 return NULL;
1628 }
1629 new_type = varobj_get_type (tmp_var);
1630 if (strcmp (old_type, new_type) == 0)
1631 {
1632 varobj_delete (tmp_var, NULL, 0);
1633 *type_changed = 0;
1634 }
1635 else
1636 {
1637 if (*type_changed)
1638 {
1639 tmp_var->obj_name =
1640 savestring (var->obj_name, strlen (var->obj_name));
1641 varobj_delete (var, NULL, 0);
1642 }
1643 else
1644 {
1645 tmp_var->obj_name = varobj_gen_name ();
1646 }
1647 install_variable (tmp_var);
1648 *var_handle = tmp_var;
1649 var = *var_handle;
1650 *type_changed = 1;
1651 }
1652 }
1653 else
1654 {
1655 *type_changed = 0;
1656 }
1657
1658 return (*var->root->lang->value_of_root) (var_handle);
1659 }
1660
1661 /* What is the ``struct value *'' for the INDEX'th child of PARENT? */
1662 static struct value *
1663 value_of_child (struct varobj *parent, int index)
1664 {
1665 struct value *value;
1666
1667 value = (*parent->root->lang->value_of_child) (parent, index);
1668
1669 return value;
1670 }
1671
1672 /* Is this variable editable? Use the variable's type to make
1673 this determination. */
1674 static int
1675 variable_editable (struct varobj *var)
1676 {
1677 return (*var->root->lang->variable_editable) (var);
1678 }
1679
1680 /* GDB already has a command called "value_of_variable". Sigh. */
1681 static char *
1682 my_value_of_variable (struct varobj *var)
1683 {
1684 return (*var->root->lang->value_of_variable) (var);
1685 }
1686
1687 static char *
1688 value_get_print_value (struct value *value, enum varobj_display_formats format)
1689 {
1690 long dummy;
1691 struct ui_file *stb;
1692 struct cleanup *old_chain;
1693 char *thevalue;
1694
1695 if (value == NULL)
1696 return NULL;
1697
1698 stb = mem_fileopen ();
1699 old_chain = make_cleanup_ui_file_delete (stb);
1700
1701 common_val_print (value, stb, format_code[(int) format], 1, 0, 0);
1702 thevalue = ui_file_xstrdup (stb, &dummy);
1703
1704 do_cleanups (old_chain);
1705 return thevalue;
1706 }
1707
1708 /* Return non-zero if changes in value of VAR
1709 must be detected and reported by -var-update.
1710 Return zero is -var-update should never report
1711 changes of such values. This makes sense for structures
1712 (since the changes in children values will be reported separately),
1713 or for artifical objects (like 'public' pseudo-field in C++).
1714
1715 Return value of 0 means that gdb need not call value_fetch_lazy
1716 for the value of this variable object. */
1717 static int
1718 varobj_value_is_changeable_p (struct varobj *var)
1719 {
1720 int r;
1721 struct type *type;
1722
1723 if (CPLUS_FAKE_CHILD (var))
1724 return 0;
1725
1726 type = get_type (var);
1727
1728 switch (TYPE_CODE (type))
1729 {
1730 case TYPE_CODE_STRUCT:
1731 case TYPE_CODE_UNION:
1732 case TYPE_CODE_ARRAY:
1733 r = 0;
1734 break;
1735
1736 default:
1737 r = 1;
1738 }
1739
1740 return r;
1741 }
1742
1743 /* C */
1744 static int
1745 c_number_of_children (struct varobj *var)
1746 {
1747 struct type *type;
1748 struct type *target;
1749 int children;
1750
1751 type = get_type (var);
1752 target = get_target_type (type);
1753 children = 0;
1754
1755 switch (TYPE_CODE (type))
1756 {
1757 case TYPE_CODE_ARRAY:
1758 if (TYPE_LENGTH (type) > 0 && TYPE_LENGTH (target) > 0
1759 && TYPE_ARRAY_UPPER_BOUND_TYPE (type) != BOUND_CANNOT_BE_DETERMINED)
1760 children = TYPE_LENGTH (type) / TYPE_LENGTH (target);
1761 else
1762 /* If we don't know how many elements there are, don't display
1763 any. */
1764 children = 0;
1765 break;
1766
1767 case TYPE_CODE_STRUCT:
1768 case TYPE_CODE_UNION:
1769 children = TYPE_NFIELDS (type);
1770 break;
1771
1772 case TYPE_CODE_PTR:
1773 /* This is where things get complicated. All pointers have one child.
1774 Except, of course, for struct and union ptr, which we automagically
1775 dereference for the user, and function ptrs which have no children.
1776 We also don't dereference void* as we don't know what to show.
1777 We can show char* so we allow it to be dereferenced. If you decide
1778 to test for it, please mind that a little magic is necessary to
1779 properly identify it: char* has TYPE_CODE == TYPE_CODE_INT and
1780 TYPE_NAME == "char" */
1781
1782 switch (TYPE_CODE (target))
1783 {
1784 case TYPE_CODE_STRUCT:
1785 case TYPE_CODE_UNION:
1786 children = TYPE_NFIELDS (target);
1787 break;
1788
1789 case TYPE_CODE_FUNC:
1790 case TYPE_CODE_VOID:
1791 children = 0;
1792 break;
1793
1794 default:
1795 children = 1;
1796 }
1797 break;
1798
1799 default:
1800 /* Other types have no children */
1801 break;
1802 }
1803
1804 return children;
1805 }
1806
1807 static char *
1808 c_name_of_variable (struct varobj *parent)
1809 {
1810 return savestring (parent->name, strlen (parent->name));
1811 }
1812
1813 /* Return the value of element TYPE_INDEX of a structure
1814 value VALUE. VALUE's type should be a structure,
1815 or union, or a typedef to struct/union.
1816
1817 Returns NULL if getting the value fails. Never throws. */
1818 static struct value *
1819 value_struct_element_index (struct value *value, int type_index)
1820 {
1821 struct value *result = NULL;
1822 volatile struct gdb_exception e;
1823
1824 struct type *type = value_type (value);
1825 type = check_typedef (type);
1826
1827 gdb_assert (TYPE_CODE (type) == TYPE_CODE_STRUCT
1828 || TYPE_CODE (type) == TYPE_CODE_UNION);
1829
1830 TRY_CATCH (e, RETURN_MASK_ERROR)
1831 {
1832 if (TYPE_FIELD_STATIC (type, type_index))
1833 result = value_static_field (type, type_index);
1834 else
1835 result = value_primitive_field (value, 0, type_index, type);
1836 }
1837 if (e.reason < 0)
1838 {
1839 return NULL;
1840 }
1841 else
1842 {
1843 return result;
1844 }
1845 }
1846
1847 /* Obtain the information about child INDEX of the variable
1848 object PARENT.
1849 If CNAME is not null, sets *CNAME to the name of the child relative
1850 to the parent.
1851 If CVALUE is not null, sets *CVALUE to the value of the child.
1852 If CTYPE is not null, sets *CTYPE to the type of the child.
1853
1854 If any of CNAME, CVALUE, or CTYPE is not null, but the corresponding
1855 information cannot be determined, set *CNAME, *CVALUE, or *CTYPE
1856 to NULL. */
1857 static void
1858 c_describe_child (struct varobj *parent, int index,
1859 char **cname, struct value **cvalue, struct type **ctype)
1860 {
1861 struct value *value = parent->value;
1862 struct type *type = get_type (parent);
1863
1864 if (cname)
1865 *cname = NULL;
1866 if (cvalue)
1867 *cvalue = NULL;
1868 if (ctype)
1869 *ctype = NULL;
1870
1871 /* Pointers to structures are treated just like
1872 structures when accessing children. */
1873 if (TYPE_CODE (type) == TYPE_CODE_PTR)
1874 {
1875 struct type *target_type = get_target_type (type);
1876 if (TYPE_CODE (target_type) == TYPE_CODE_STRUCT
1877 || TYPE_CODE (target_type) == TYPE_CODE_UNION)
1878 {
1879 if (value)
1880 gdb_value_ind (value, &value);
1881 type = target_type;
1882 }
1883 }
1884
1885 switch (TYPE_CODE (type))
1886 {
1887 case TYPE_CODE_ARRAY:
1888 if (cname)
1889 *cname = xstrprintf ("%d", index
1890 + TYPE_LOW_BOUND (TYPE_INDEX_TYPE (type)));
1891
1892 if (cvalue && value)
1893 {
1894 int real_index = index + TYPE_LOW_BOUND (TYPE_INDEX_TYPE (type));
1895 struct value *indval =
1896 value_from_longest (builtin_type_int, (LONGEST) real_index);
1897 gdb_value_subscript (value, indval, cvalue);
1898 }
1899
1900 if (ctype)
1901 *ctype = get_target_type (type);
1902
1903 break;
1904
1905 case TYPE_CODE_STRUCT:
1906 case TYPE_CODE_UNION:
1907 if (cname)
1908 {
1909 char *string = TYPE_FIELD_NAME (type, index);
1910 *cname = savestring (string, strlen (string));
1911 }
1912
1913 if (cvalue && value)
1914 {
1915 /* For C, varobj index is the same as type index. */
1916 *cvalue = value_struct_element_index (value, index);
1917 }
1918
1919 if (ctype)
1920 *ctype = TYPE_FIELD_TYPE (type, index);
1921
1922 break;
1923
1924 case TYPE_CODE_PTR:
1925 if (cname)
1926 *cname = xstrprintf ("*%s", parent->name);
1927
1928 if (cvalue && value)
1929 gdb_value_ind (value, cvalue);
1930
1931 if (ctype)
1932 *ctype = get_target_type (type);
1933
1934 break;
1935
1936 default:
1937 /* This should not happen */
1938 if (cname)
1939 *cname = xstrdup ("???");
1940 /* Don't set value and type, we don't know then. */
1941 }
1942 }
1943
1944 static char *
1945 c_name_of_child (struct varobj *parent, int index)
1946 {
1947 char *name;
1948 c_describe_child (parent, index, &name, NULL, NULL);
1949 return name;
1950 }
1951
1952 static struct value *
1953 c_value_of_root (struct varobj **var_handle)
1954 {
1955 struct value *new_val = NULL;
1956 struct varobj *var = *var_handle;
1957 struct frame_info *fi;
1958 int within_scope;
1959
1960 /* Only root variables can be updated... */
1961 if (!is_root_p (var))
1962 /* Not a root var */
1963 return NULL;
1964
1965
1966 /* Determine whether the variable is still around. */
1967 if (var->root->valid_block == NULL || var->root->use_selected_frame)
1968 within_scope = 1;
1969 else
1970 {
1971 fi = frame_find_by_id (var->root->frame);
1972 within_scope = fi != NULL;
1973 /* FIXME: select_frame could fail */
1974 if (fi)
1975 {
1976 CORE_ADDR pc = get_frame_pc (fi);
1977 if (pc < BLOCK_START (var->root->valid_block) ||
1978 pc >= BLOCK_END (var->root->valid_block))
1979 within_scope = 0;
1980 else
1981 select_frame (fi);
1982 }
1983 }
1984
1985 if (within_scope)
1986 {
1987 /* We need to catch errors here, because if evaluate
1988 expression fails we just want to make val->error = 1 and
1989 go on */
1990 if (gdb_evaluate_expression (var->root->exp, &new_val))
1991 {
1992 release_value (new_val);
1993 }
1994
1995 return new_val;
1996 }
1997
1998 return NULL;
1999 }
2000
2001 static struct value *
2002 c_value_of_child (struct varobj *parent, int index)
2003 {
2004 struct value *value = NULL;
2005 c_describe_child (parent, index, NULL, &value, NULL);
2006 if (value != NULL)
2007 release_value (value);
2008
2009 return value;
2010 }
2011
2012 static struct type *
2013 c_type_of_child (struct varobj *parent, int index)
2014 {
2015 struct type *type = NULL;
2016 c_describe_child (parent, index, NULL, NULL, &type);
2017 return type;
2018 }
2019
2020 static int
2021 c_variable_editable (struct varobj *var)
2022 {
2023 switch (TYPE_CODE (get_type (var)))
2024 {
2025 case TYPE_CODE_STRUCT:
2026 case TYPE_CODE_UNION:
2027 case TYPE_CODE_ARRAY:
2028 case TYPE_CODE_FUNC:
2029 case TYPE_CODE_METHOD:
2030 return 0;
2031 break;
2032
2033 default:
2034 return 1;
2035 break;
2036 }
2037 }
2038
2039 static char *
2040 c_value_of_variable (struct varobj *var)
2041 {
2042 /* BOGUS: if val_print sees a struct/class, or a reference to one,
2043 it will print out its children instead of "{...}". So we need to
2044 catch that case explicitly. */
2045 struct type *type = get_type (var);
2046
2047 /* Strip top-level references. */
2048 while (TYPE_CODE (type) == TYPE_CODE_REF)
2049 type = check_typedef (TYPE_TARGET_TYPE (type));
2050
2051 switch (TYPE_CODE (type))
2052 {
2053 case TYPE_CODE_STRUCT:
2054 case TYPE_CODE_UNION:
2055 return xstrdup ("{...}");
2056 /* break; */
2057
2058 case TYPE_CODE_ARRAY:
2059 {
2060 char *number;
2061 number = xstrprintf ("[%d]", var->num_children);
2062 return (number);
2063 }
2064 /* break; */
2065
2066 default:
2067 {
2068 if (var->value == NULL)
2069 {
2070 /* This can happen if we attempt to get the value of a struct
2071 member when the parent is an invalid pointer. This is an
2072 error condition, so we should tell the caller. */
2073 return NULL;
2074 }
2075 else
2076 {
2077 gdb_assert (varobj_value_is_changeable_p (var));
2078 gdb_assert (!value_lazy (var->value));
2079 return value_get_print_value (var->value, var->format);
2080 }
2081 }
2082 }
2083 }
2084 \f
2085
2086 /* C++ */
2087
2088 static int
2089 cplus_number_of_children (struct varobj *var)
2090 {
2091 struct type *type;
2092 int children, dont_know;
2093
2094 dont_know = 1;
2095 children = 0;
2096
2097 if (!CPLUS_FAKE_CHILD (var))
2098 {
2099 type = get_type_deref (var);
2100
2101 if (((TYPE_CODE (type)) == TYPE_CODE_STRUCT) ||
2102 ((TYPE_CODE (type)) == TYPE_CODE_UNION))
2103 {
2104 int kids[3];
2105
2106 cplus_class_num_children (type, kids);
2107 if (kids[v_public] != 0)
2108 children++;
2109 if (kids[v_private] != 0)
2110 children++;
2111 if (kids[v_protected] != 0)
2112 children++;
2113
2114 /* Add any baseclasses */
2115 children += TYPE_N_BASECLASSES (type);
2116 dont_know = 0;
2117
2118 /* FIXME: save children in var */
2119 }
2120 }
2121 else
2122 {
2123 int kids[3];
2124
2125 type = get_type_deref (var->parent);
2126
2127 cplus_class_num_children (type, kids);
2128 if (strcmp (var->name, "public") == 0)
2129 children = kids[v_public];
2130 else if (strcmp (var->name, "private") == 0)
2131 children = kids[v_private];
2132 else
2133 children = kids[v_protected];
2134 dont_know = 0;
2135 }
2136
2137 if (dont_know)
2138 children = c_number_of_children (var);
2139
2140 return children;
2141 }
2142
2143 /* Compute # of public, private, and protected variables in this class.
2144 That means we need to descend into all baseclasses and find out
2145 how many are there, too. */
2146 static void
2147 cplus_class_num_children (struct type *type, int children[3])
2148 {
2149 int i;
2150
2151 children[v_public] = 0;
2152 children[v_private] = 0;
2153 children[v_protected] = 0;
2154
2155 for (i = TYPE_N_BASECLASSES (type); i < TYPE_NFIELDS (type); i++)
2156 {
2157 /* If we have a virtual table pointer, omit it. */
2158 if (TYPE_VPTR_BASETYPE (type) == type && TYPE_VPTR_FIELDNO (type) == i)
2159 continue;
2160
2161 if (TYPE_FIELD_PROTECTED (type, i))
2162 children[v_protected]++;
2163 else if (TYPE_FIELD_PRIVATE (type, i))
2164 children[v_private]++;
2165 else
2166 children[v_public]++;
2167 }
2168 }
2169
2170 static char *
2171 cplus_name_of_variable (struct varobj *parent)
2172 {
2173 return c_name_of_variable (parent);
2174 }
2175
2176 static char *
2177 cplus_name_of_child (struct varobj *parent, int index)
2178 {
2179 char *name;
2180 struct type *type;
2181
2182 if (CPLUS_FAKE_CHILD (parent))
2183 {
2184 /* Looking for children of public, private, or protected. */
2185 type = get_type_deref (parent->parent);
2186 }
2187 else
2188 type = get_type_deref (parent);
2189
2190 name = NULL;
2191 switch (TYPE_CODE (type))
2192 {
2193 case TYPE_CODE_STRUCT:
2194 case TYPE_CODE_UNION:
2195 if (CPLUS_FAKE_CHILD (parent))
2196 {
2197 /* The fields of the class type are ordered as they
2198 appear in the class. We are given an index for a
2199 particular access control type ("public","protected",
2200 or "private"). We must skip over fields that don't
2201 have the access control we are looking for to properly
2202 find the indexed field. */
2203 int type_index = TYPE_N_BASECLASSES (type);
2204 if (strcmp (parent->name, "private") == 0)
2205 {
2206 while (index >= 0)
2207 {
2208 if (TYPE_VPTR_BASETYPE (type) == type
2209 && type_index == TYPE_VPTR_FIELDNO (type))
2210 ; /* ignore vptr */
2211 else if (TYPE_FIELD_PRIVATE (type, type_index))
2212 --index;
2213 ++type_index;
2214 }
2215 --type_index;
2216 }
2217 else if (strcmp (parent->name, "protected") == 0)
2218 {
2219 while (index >= 0)
2220 {
2221 if (TYPE_VPTR_BASETYPE (type) == type
2222 && type_index == TYPE_VPTR_FIELDNO (type))
2223 ; /* ignore vptr */
2224 else if (TYPE_FIELD_PROTECTED (type, type_index))
2225 --index;
2226 ++type_index;
2227 }
2228 --type_index;
2229 }
2230 else
2231 {
2232 while (index >= 0)
2233 {
2234 if (TYPE_VPTR_BASETYPE (type) == type
2235 && type_index == TYPE_VPTR_FIELDNO (type))
2236 ; /* ignore vptr */
2237 else if (!TYPE_FIELD_PRIVATE (type, type_index) &&
2238 !TYPE_FIELD_PROTECTED (type, type_index))
2239 --index;
2240 ++type_index;
2241 }
2242 --type_index;
2243 }
2244
2245 name = TYPE_FIELD_NAME (type, type_index);
2246 }
2247 else if (index < TYPE_N_BASECLASSES (type))
2248 /* We are looking up the name of a base class */
2249 name = TYPE_FIELD_NAME (type, index);
2250 else
2251 {
2252 int children[3];
2253 cplus_class_num_children(type, children);
2254
2255 /* Everything beyond the baseclasses can
2256 only be "public", "private", or "protected"
2257
2258 The special "fake" children are always output by varobj in
2259 this order. So if INDEX == 2, it MUST be "protected". */
2260 index -= TYPE_N_BASECLASSES (type);
2261 switch (index)
2262 {
2263 case 0:
2264 if (children[v_public] > 0)
2265 name = "public";
2266 else if (children[v_private] > 0)
2267 name = "private";
2268 else
2269 name = "protected";
2270 break;
2271 case 1:
2272 if (children[v_public] > 0)
2273 {
2274 if (children[v_private] > 0)
2275 name = "private";
2276 else
2277 name = "protected";
2278 }
2279 else if (children[v_private] > 0)
2280 name = "protected";
2281 break;
2282 case 2:
2283 /* Must be protected */
2284 name = "protected";
2285 break;
2286 default:
2287 /* error! */
2288 break;
2289 }
2290 }
2291 break;
2292
2293 default:
2294 break;
2295 }
2296
2297 if (name == NULL)
2298 return c_name_of_child (parent, index);
2299 else
2300 {
2301 if (name != NULL)
2302 name = savestring (name, strlen (name));
2303 }
2304
2305 return name;
2306 }
2307
2308 static struct value *
2309 cplus_value_of_root (struct varobj **var_handle)
2310 {
2311 return c_value_of_root (var_handle);
2312 }
2313
2314 static struct value *
2315 cplus_value_of_child (struct varobj *parent, int index)
2316 {
2317 struct type *type;
2318 struct value *value;
2319
2320 if (CPLUS_FAKE_CHILD (parent))
2321 type = get_type_deref (parent->parent);
2322 else
2323 type = get_type_deref (parent);
2324
2325 value = NULL;
2326
2327 if (((TYPE_CODE (type)) == TYPE_CODE_STRUCT) ||
2328 ((TYPE_CODE (type)) == TYPE_CODE_UNION))
2329 {
2330 if (CPLUS_FAKE_CHILD (parent))
2331 {
2332 char *name;
2333 struct value *temp = parent->parent->value;
2334
2335 if (temp == NULL)
2336 return NULL;
2337
2338 name = name_of_child (parent, index);
2339 gdb_value_struct_elt (NULL, &value, &temp, NULL, name, NULL,
2340 "cplus_structure");
2341 if (value != NULL)
2342 release_value (value);
2343
2344 xfree (name);
2345 }
2346 else if (index >= TYPE_N_BASECLASSES (type))
2347 {
2348 /* public, private, or protected */
2349 return NULL;
2350 }
2351 else
2352 {
2353 /* Baseclass */
2354 if (parent->value != NULL)
2355 {
2356 struct value *temp = NULL;
2357
2358 /* No special processing for references is needed --
2359 value_cast below handles references. */
2360 if (TYPE_CODE (value_type (parent->value)) == TYPE_CODE_PTR)
2361 {
2362 if (!gdb_value_ind (parent->value, &temp))
2363 return NULL;
2364 }
2365 else
2366 temp = parent->value;
2367
2368 if (temp != NULL)
2369 {
2370 value = value_cast (TYPE_FIELD_TYPE (type, index), temp);
2371 release_value (value);
2372 }
2373 else
2374 {
2375 /* We failed to evaluate the parent's value, so don't even
2376 bother trying to evaluate this child. */
2377 return NULL;
2378 }
2379 }
2380 }
2381 }
2382
2383 if (value == NULL)
2384 return c_value_of_child (parent, index);
2385
2386 return value;
2387 }
2388
2389 static struct type *
2390 cplus_type_of_child (struct varobj *parent, int index)
2391 {
2392 struct type *type, *t;
2393
2394 if (CPLUS_FAKE_CHILD (parent))
2395 {
2396 /* Looking for the type of a child of public, private, or protected. */
2397 t = get_type_deref (parent->parent);
2398 }
2399 else
2400 t = get_type_deref (parent);
2401
2402 type = NULL;
2403 switch (TYPE_CODE (t))
2404 {
2405 case TYPE_CODE_STRUCT:
2406 case TYPE_CODE_UNION:
2407 if (CPLUS_FAKE_CHILD (parent))
2408 {
2409 char *name = cplus_name_of_child (parent, index);
2410 type = lookup_struct_elt_type (t, name, 0);
2411 xfree (name);
2412 }
2413 else if (index < TYPE_N_BASECLASSES (t))
2414 type = TYPE_FIELD_TYPE (t, index);
2415 else
2416 {
2417 /* special */
2418 return NULL;
2419 }
2420 break;
2421
2422 default:
2423 break;
2424 }
2425
2426 if (type == NULL)
2427 return c_type_of_child (parent, index);
2428
2429 return type;
2430 }
2431
2432 static int
2433 cplus_variable_editable (struct varobj *var)
2434 {
2435 if (CPLUS_FAKE_CHILD (var))
2436 return 0;
2437
2438 return c_variable_editable (var);
2439 }
2440
2441 static char *
2442 cplus_value_of_variable (struct varobj *var)
2443 {
2444
2445 /* If we have one of our special types, don't print out
2446 any value. */
2447 if (CPLUS_FAKE_CHILD (var))
2448 return xstrdup ("");
2449
2450 return c_value_of_variable (var);
2451 }
2452 \f
2453 /* Java */
2454
2455 static int
2456 java_number_of_children (struct varobj *var)
2457 {
2458 return cplus_number_of_children (var);
2459 }
2460
2461 static char *
2462 java_name_of_variable (struct varobj *parent)
2463 {
2464 char *p, *name;
2465
2466 name = cplus_name_of_variable (parent);
2467 /* If the name has "-" in it, it is because we
2468 needed to escape periods in the name... */
2469 p = name;
2470
2471 while (*p != '\000')
2472 {
2473 if (*p == '-')
2474 *p = '.';
2475 p++;
2476 }
2477
2478 return name;
2479 }
2480
2481 static char *
2482 java_name_of_child (struct varobj *parent, int index)
2483 {
2484 char *name, *p;
2485
2486 name = cplus_name_of_child (parent, index);
2487 /* Escape any periods in the name... */
2488 p = name;
2489
2490 while (*p != '\000')
2491 {
2492 if (*p == '.')
2493 *p = '-';
2494 p++;
2495 }
2496
2497 return name;
2498 }
2499
2500 static struct value *
2501 java_value_of_root (struct varobj **var_handle)
2502 {
2503 return cplus_value_of_root (var_handle);
2504 }
2505
2506 static struct value *
2507 java_value_of_child (struct varobj *parent, int index)
2508 {
2509 return cplus_value_of_child (parent, index);
2510 }
2511
2512 static struct type *
2513 java_type_of_child (struct varobj *parent, int index)
2514 {
2515 return cplus_type_of_child (parent, index);
2516 }
2517
2518 static int
2519 java_variable_editable (struct varobj *var)
2520 {
2521 return cplus_variable_editable (var);
2522 }
2523
2524 static char *
2525 java_value_of_variable (struct varobj *var)
2526 {
2527 return cplus_value_of_variable (var);
2528 }
2529 \f
2530 extern void _initialize_varobj (void);
2531 void
2532 _initialize_varobj (void)
2533 {
2534 int sizeof_table = sizeof (struct vlist *) * VAROBJ_TABLE_SIZE;
2535
2536 varobj_table = xmalloc (sizeof_table);
2537 memset (varobj_table, 0, sizeof_table);
2538
2539 add_setshow_zinteger_cmd ("debugvarobj", class_maintenance,
2540 &varobjdebug, _("\
2541 Set varobj debugging."), _("\
2542 Show varobj debugging."), _("\
2543 When non-zero, varobj debugging is enabled."),
2544 NULL,
2545 show_varobjdebug,
2546 &setlist, &showlist);
2547 }
This page took 0.08566 seconds and 4 git commands to generate.