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