]> Git Repo - binutils.git/blob - gdb/varobj.c
f97c09090530d459ac720e863d92fa6cb22cb941
[binutils.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_value_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))
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   /* We need to know the varobj's type to decide if the value should
913      be fetched or not.  C++ fake children (public/protected/private) don't have
914      a type. */
915   gdb_assert (var->type || CPLUS_FAKE_CHILD (var));
916   changeable = varobj_value_is_changeable_p (var);
917   need_to_fetch = changeable;
918
919   /* We are not interested in the address of references, and given
920      that in C++ a reference is not rebindable, it cannot
921      meaningfully change.  So, get hold of the real value.  */
922   if (value)
923     {
924       value = coerce_ref (value);
925       release_value (value);
926     }
927
928   if (var->type && TYPE_CODE (var->type) == TYPE_CODE_UNION)
929     /* For unions, we need to fetch the value implicitly because
930        of implementation of union member fetch.  When gdb
931        creates a value for a field and the value of the enclosing
932        structure is not lazy,  it immediately copies the necessary
933        bytes from the enclosing values.  If the enclosing value is
934        lazy, the call to value_fetch_lazy on the field will read
935        the data from memory.  For unions, that means we'll read the
936        same memory more than once, which is not desirable.  So
937        fetch now.  */
938     need_to_fetch = 1;
939
940   /* The new value might be lazy.  If the type is changeable,
941      that is we'll be comparing values of this type, fetch the
942      value now.  Otherwise, on the next update the old value
943      will be lazy, which means we've lost that old value.  */
944   if (need_to_fetch && value && value_lazy (value))
945     {
946       if (!gdb_value_fetch_lazy (value))
947         {
948           /* Set the value to NULL, so that for the next -var-update,
949              we don't try to compare the new value with this value,
950              that we couldn't even read.  */
951           value = NULL;
952         }
953     }
954
955   /* If the type is changeable, compare the old and the new values.
956      If this is the initial assignment, we don't have any old value
957      to compare with.  */
958   if (initial)
959     var->print_value = value_get_print_value (value, var->format);
960   else if (changeable)
961     {
962       /* If the value of the varobj was changed by -var-set-value, then the 
963          value in the varobj and in the target is the same.  However, that value
964          is different from the value that the varobj had after the previous
965          -var-update. So need to the varobj as changed.  */
966       if (var->updated)
967         {
968           xfree (var->print_value);
969           var->print_value = value_get_print_value (value, var->format);
970           changed = 1;
971         }
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             {
983               xfree (var->print_value);
984               var->print_value = value_get_print_value (value, var->format);
985               changed = 1;
986             }
987           else
988             {
989               char *print_value;
990               gdb_assert (!value_lazy (var->value));
991               gdb_assert (!value_lazy (value));
992               print_value = value_get_print_value (value, var->format);
993
994               gdb_assert (var->print_value != NULL && print_value != NULL);
995               if (strcmp (var->print_value, print_value) != 0)
996                 {
997                   xfree (var->print_value);
998                   var->print_value = print_value;
999                   changed = 1;
1000                 }
1001               else
1002                 xfree (print_value);
1003             }
1004         }
1005     }
1006
1007   /* We must always keep the new value, since children depend on it.  */
1008   if (var->value != NULL)
1009     value_free (var->value);
1010   var->value = value;
1011   var->updated = 0;
1012
1013   gdb_assert (!var->value || value_type (var->value));
1014
1015   return changed;
1016 }
1017
1018 /* Update the values for a variable and its children.  This is a
1019    two-pronged attack.  First, re-parse the value for the root's
1020    expression to see if it's changed.  Then go all the way
1021    through its children, reconstructing them and noting if they've
1022    changed.
1023    Return value:
1024     -1 if there was an error updating the varobj
1025     -2 if the type changed
1026     Otherwise it is the number of children + parent changed
1027
1028    Only root variables can be updated... 
1029
1030    NOTE: This function may delete the caller's varobj. If it
1031    returns -2, then it has done this and VARP will be modified
1032    to point to the new varobj. */
1033
1034 int
1035 varobj_update (struct varobj **varp, struct varobj ***changelist)
1036 {
1037   int changed = 0;
1038   int error = 0;
1039   int type_changed;
1040   int i;
1041   int vleft;
1042   struct varobj *v;
1043   struct varobj **cv;
1044   struct varobj **templist = NULL;
1045   struct value *new;
1046   VEC (varobj_p) *stack = NULL;
1047   VEC (varobj_p) *result = NULL;
1048   struct frame_id old_fid;
1049   struct frame_info *fi;
1050
1051   /* sanity check: have we been passed a pointer? */
1052   if (changelist == NULL)
1053     return -1;
1054
1055   /*  Only root variables can be updated... */
1056   if (!is_root_p (*varp))
1057     /* Not a root var */
1058     return -1;
1059
1060   /* Save the selected stack frame, since we will need to change it
1061      in order to evaluate expressions. */
1062   old_fid = get_frame_id (deprecated_selected_frame);
1063
1064   /* Update the root variable. value_of_root can return NULL
1065      if the variable is no longer around, i.e. we stepped out of
1066      the frame in which a local existed. We are letting the 
1067      value_of_root variable dispose of the varobj if the type
1068      has changed. */
1069   type_changed = 1;
1070   new = value_of_root (varp, &type_changed);
1071
1072   /* Restore selected frame */
1073   fi = frame_find_by_id (old_fid);
1074   if (fi)
1075     select_frame (fi);
1076
1077   /* If this is a "use_selected_frame" varobj, and its type has changed,
1078      them note that it's changed. */
1079   if (type_changed)
1080     VEC_safe_push (varobj_p, result, *varp);
1081
1082   if (install_new_value ((*varp), new, type_changed))
1083     {
1084       /* If type_changed is 1, install_new_value will never return
1085          non-zero, so we'll never report the same variable twice.  */
1086       gdb_assert (!type_changed);
1087       VEC_safe_push (varobj_p, result, *varp);
1088     }
1089
1090   if (new == NULL)
1091     {
1092       /* This means the varobj itself is out of scope.
1093          Report it.  */
1094       VEC_free (varobj_p, result);
1095       return -1;
1096     }
1097
1098   VEC_safe_push (varobj_p, stack, *varp);
1099
1100   /* Walk through the children, reconstructing them all. */
1101   while (!VEC_empty (varobj_p, stack))
1102     {
1103       v = VEC_pop (varobj_p, stack);
1104
1105       /* Push any children.  Use reverse order so that the first
1106          child is popped from the work stack first, and so
1107          will be added to result first.  This does not
1108          affect correctness, just "nicer".  */
1109       for (i = VEC_length (varobj_p, v->children)-1; i >= 0; --i)
1110         {
1111           varobj_p c = VEC_index (varobj_p, v->children, i);
1112           /* Child may be NULL if explicitly deleted by -var-delete.  */
1113           if (c != NULL)
1114             VEC_safe_push (varobj_p, stack, c);
1115         }
1116
1117       /* Update this variable, unless it's a root, which is already
1118          updated.  */
1119       if (v != *varp)
1120         {         
1121           new = value_of_child (v->parent, v->index);
1122           if (install_new_value (v, new, 0 /* type not changed */))
1123             {
1124               /* Note that it's changed */
1125               VEC_safe_push (varobj_p, result, v);
1126               v->updated = 0;
1127             }
1128         }
1129     }
1130
1131   /* Alloc (changed + 1) list entries */
1132   changed = VEC_length (varobj_p, result);
1133   *changelist = xmalloc ((changed + 1) * sizeof (struct varobj *));
1134   cv = *changelist;
1135
1136   for (i = 0; i < changed; ++i)
1137     {
1138       *cv = VEC_index (varobj_p, result, i);
1139       gdb_assert (*cv != NULL);
1140       ++cv;
1141     }
1142   *cv = 0;
1143
1144   if (type_changed)
1145     return -2;
1146   else
1147     return changed;
1148 }
1149 \f
1150
1151 /* Helper functions */
1152
1153 /*
1154  * Variable object construction/destruction
1155  */
1156
1157 static int
1158 delete_variable (struct cpstack **resultp, struct varobj *var,
1159                  int only_children_p)
1160 {
1161   int delcount = 0;
1162
1163   delete_variable_1 (resultp, &delcount, var,
1164                      only_children_p, 1 /* remove_from_parent_p */ );
1165
1166   return delcount;
1167 }
1168
1169 /* Delete the variable object VAR and its children */
1170 /* IMPORTANT NOTE: If we delete a variable which is a child
1171    and the parent is not removed we dump core.  It must be always
1172    initially called with remove_from_parent_p set */
1173 static void
1174 delete_variable_1 (struct cpstack **resultp, int *delcountp,
1175                    struct varobj *var, int only_children_p,
1176                    int remove_from_parent_p)
1177 {
1178   int i;
1179
1180   /* Delete any children of this variable, too. */
1181   for (i = 0; i < VEC_length (varobj_p, var->children); ++i)
1182     {   
1183       varobj_p child = VEC_index (varobj_p, var->children, i);
1184       if (!remove_from_parent_p)
1185         child->parent = NULL;
1186       delete_variable_1 (resultp, delcountp, child, 0, only_children_p);
1187     }
1188   VEC_free (varobj_p, var->children);
1189
1190   /* if we were called to delete only the children we are done here */
1191   if (only_children_p)
1192     return;
1193
1194   /* Otherwise, add it to the list of deleted ones and proceed to do so */
1195   /* If the name is null, this is a temporary variable, that has not
1196      yet been installed, don't report it, it belongs to the caller... */
1197   if (var->obj_name != NULL)
1198     {
1199       cppush (resultp, xstrdup (var->obj_name));
1200       *delcountp = *delcountp + 1;
1201     }
1202
1203   /* If this variable has a parent, remove it from its parent's list */
1204   /* OPTIMIZATION: if the parent of this variable is also being deleted, 
1205      (as indicated by remove_from_parent_p) we don't bother doing an
1206      expensive list search to find the element to remove when we are
1207      discarding the list afterwards */
1208   if ((remove_from_parent_p) && (var->parent != NULL))
1209     {
1210       VEC_replace (varobj_p, var->parent->children, var->index, NULL);
1211     }
1212
1213   if (var->obj_name != NULL)
1214     uninstall_variable (var);
1215
1216   /* Free memory associated with this variable */
1217   free_variable (var);
1218 }
1219
1220 /* Install the given variable VAR with the object name VAR->OBJ_NAME. */
1221 static int
1222 install_variable (struct varobj *var)
1223 {
1224   struct vlist *cv;
1225   struct vlist *newvl;
1226   const char *chp;
1227   unsigned int index = 0;
1228   unsigned int i = 1;
1229
1230   for (chp = var->obj_name; *chp; chp++)
1231     {
1232       index = (index + (i++ * (unsigned int) *chp)) % VAROBJ_TABLE_SIZE;
1233     }
1234
1235   cv = *(varobj_table + index);
1236   while ((cv != NULL) && (strcmp (cv->var->obj_name, var->obj_name) != 0))
1237     cv = cv->next;
1238
1239   if (cv != NULL)
1240     error (_("Duplicate variable object name"));
1241
1242   /* Add varobj to hash table */
1243   newvl = xmalloc (sizeof (struct vlist));
1244   newvl->next = *(varobj_table + index);
1245   newvl->var = var;
1246   *(varobj_table + index) = newvl;
1247
1248   /* If root, add varobj to root list */
1249   if (is_root_p (var))
1250     {
1251       /* Add to list of root variables */
1252       if (rootlist == NULL)
1253         var->root->next = NULL;
1254       else
1255         var->root->next = rootlist;
1256       rootlist = var->root;
1257       rootcount++;
1258     }
1259
1260   return 1;                     /* OK */
1261 }
1262
1263 /* Unistall the object VAR. */
1264 static void
1265 uninstall_variable (struct varobj *var)
1266 {
1267   struct vlist *cv;
1268   struct vlist *prev;
1269   struct varobj_root *cr;
1270   struct varobj_root *prer;
1271   const char *chp;
1272   unsigned int index = 0;
1273   unsigned int i = 1;
1274
1275   /* Remove varobj from hash table */
1276   for (chp = var->obj_name; *chp; chp++)
1277     {
1278       index = (index + (i++ * (unsigned int) *chp)) % VAROBJ_TABLE_SIZE;
1279     }
1280
1281   cv = *(varobj_table + index);
1282   prev = NULL;
1283   while ((cv != NULL) && (strcmp (cv->var->obj_name, var->obj_name) != 0))
1284     {
1285       prev = cv;
1286       cv = cv->next;
1287     }
1288
1289   if (varobjdebug)
1290     fprintf_unfiltered (gdb_stdlog, "Deleting %s\n", var->obj_name);
1291
1292   if (cv == NULL)
1293     {
1294       warning
1295         ("Assertion failed: Could not find variable object \"%s\" to delete",
1296          var->obj_name);
1297       return;
1298     }
1299
1300   if (prev == NULL)
1301     *(varobj_table + index) = cv->next;
1302   else
1303     prev->next = cv->next;
1304
1305   xfree (cv);
1306
1307   /* If root, remove varobj from root list */
1308   if (is_root_p (var))
1309     {
1310       /* Remove from list of root variables */
1311       if (rootlist == var->root)
1312         rootlist = var->root->next;
1313       else
1314         {
1315           prer = NULL;
1316           cr = rootlist;
1317           while ((cr != NULL) && (cr->rootvar != var))
1318             {
1319               prer = cr;
1320               cr = cr->next;
1321             }
1322           if (cr == NULL)
1323             {
1324               warning
1325                 ("Assertion failed: Could not find varobj \"%s\" in root list",
1326                  var->obj_name);
1327               return;
1328             }
1329           if (prer == NULL)
1330             rootlist = NULL;
1331           else
1332             prer->next = cr->next;
1333         }
1334       rootcount--;
1335     }
1336
1337 }
1338
1339 /* Create and install a child of the parent of the given name */
1340 static struct varobj *
1341 create_child (struct varobj *parent, int index, char *name)
1342 {
1343   struct varobj *child;
1344   char *childs_name;
1345   struct value *value;
1346
1347   child = new_variable ();
1348
1349   /* name is allocated by name_of_child */
1350   child->name = name;
1351   child->index = index;
1352   value = value_of_child (parent, index);
1353   child->parent = parent;
1354   child->root = parent->root;
1355   childs_name = xstrprintf ("%s.%s", parent->obj_name, name);
1356   child->obj_name = childs_name;
1357   install_variable (child);
1358
1359   /* Compute the type of the child.  Must do this before
1360      calling install_new_value.  */
1361   if (value != NULL)
1362     /* If the child had no evaluation errors, var->value
1363        will be non-NULL and contain a valid type. */
1364     child->type = value_type (value);
1365   else
1366     /* Otherwise, we must compute the type. */
1367     child->type = (*child->root->lang->type_of_child) (child->parent, 
1368                                                        child->index);
1369   install_new_value (child, value, 1);
1370
1371   return child;
1372 }
1373 \f
1374
1375 /*
1376  * Miscellaneous utility functions.
1377  */
1378
1379 /* Allocate memory and initialize a new variable */
1380 static struct varobj *
1381 new_variable (void)
1382 {
1383   struct varobj *var;
1384
1385   var = (struct varobj *) xmalloc (sizeof (struct varobj));
1386   var->name = NULL;
1387   var->obj_name = NULL;
1388   var->index = -1;
1389   var->type = NULL;
1390   var->value = NULL;
1391   var->num_children = -1;
1392   var->parent = NULL;
1393   var->children = NULL;
1394   var->format = 0;
1395   var->root = NULL;
1396   var->updated = 0;
1397   var->print_value = NULL;
1398
1399   return var;
1400 }
1401
1402 /* Allocate memory and initialize a new root variable */
1403 static struct varobj *
1404 new_root_variable (void)
1405 {
1406   struct varobj *var = new_variable ();
1407   var->root = (struct varobj_root *) xmalloc (sizeof (struct varobj_root));;
1408   var->root->lang = NULL;
1409   var->root->exp = NULL;
1410   var->root->valid_block = NULL;
1411   var->root->frame = null_frame_id;
1412   var->root->use_selected_frame = 0;
1413   var->root->rootvar = NULL;
1414
1415   return var;
1416 }
1417
1418 /* Free any allocated memory associated with VAR. */
1419 static void
1420 free_variable (struct varobj *var)
1421 {
1422   /* Free the expression if this is a root variable. */
1423   if (is_root_p (var))
1424     {
1425       free_current_contents (&var->root->exp);
1426       xfree (var->root);
1427     }
1428
1429   xfree (var->name);
1430   xfree (var->obj_name);
1431   xfree (var->print_value);
1432   xfree (var);
1433 }
1434
1435 static void
1436 do_free_variable_cleanup (void *var)
1437 {
1438   free_variable (var);
1439 }
1440
1441 static struct cleanup *
1442 make_cleanup_free_variable (struct varobj *var)
1443 {
1444   return make_cleanup (do_free_variable_cleanup, var);
1445 }
1446
1447 /* This returns the type of the variable. It also skips past typedefs
1448    to return the real type of the variable.
1449
1450    NOTE: TYPE_TARGET_TYPE should NOT be used anywhere in this file
1451    except within get_target_type and get_type. */
1452 static struct type *
1453 get_type (struct varobj *var)
1454 {
1455   struct type *type;
1456   type = var->type;
1457
1458   if (type != NULL)
1459     type = check_typedef (type);
1460
1461   return type;
1462 }
1463
1464 /* Return the type of the value that's stored in VAR,
1465    or that would have being stored there if the
1466    value were accessible.  
1467
1468    This differs from VAR->type in that VAR->type is always
1469    the true type of the expession in the source language.
1470    The return value of this function is the type we're
1471    actually storing in varobj, and using for displaying
1472    the values and for comparing previous and new values.
1473
1474    For example, top-level references are always stripped.  */
1475 static struct type *
1476 get_value_type (struct varobj *var)
1477 {
1478   struct type *type;
1479
1480   if (var->value)
1481     type = value_type (var->value);
1482   else
1483     type = var->type;
1484
1485   type = check_typedef (type);
1486
1487   if (TYPE_CODE (type) == TYPE_CODE_REF)
1488     type = get_target_type (type);
1489
1490   type = check_typedef (type);
1491
1492   return type;
1493 }
1494
1495 /* This returns the type of the variable, dereferencing references, pointers
1496    and references to pointers, too. */
1497 static struct type *
1498 get_type_deref (struct varobj *var)
1499 {
1500   struct type *type;
1501
1502   type = get_type (var);
1503
1504   if (type)
1505     {
1506       if (TYPE_CODE (type) == TYPE_CODE_REF)
1507         type = get_target_type (type);
1508       if (TYPE_CODE (type) == TYPE_CODE_PTR)
1509         type = get_target_type (type);
1510     }
1511
1512   return type;
1513 }
1514
1515 /* This returns the target type (or NULL) of TYPE, also skipping
1516    past typedefs, just like get_type ().
1517
1518    NOTE: TYPE_TARGET_TYPE should NOT be used anywhere in this file
1519    except within get_target_type and get_type. */
1520 static struct type *
1521 get_target_type (struct type *type)
1522 {
1523   if (type != NULL)
1524     {
1525       type = TYPE_TARGET_TYPE (type);
1526       if (type != NULL)
1527         type = check_typedef (type);
1528     }
1529
1530   return type;
1531 }
1532
1533 /* What is the default display for this variable? We assume that
1534    everything is "natural". Any exceptions? */
1535 static enum varobj_display_formats
1536 variable_default_display (struct varobj *var)
1537 {
1538   return FORMAT_NATURAL;
1539 }
1540
1541 /* FIXME: The following should be generic for any pointer */
1542 static void
1543 cppush (struct cpstack **pstack, char *name)
1544 {
1545   struct cpstack *s;
1546
1547   s = (struct cpstack *) xmalloc (sizeof (struct cpstack));
1548   s->name = name;
1549   s->next = *pstack;
1550   *pstack = s;
1551 }
1552
1553 /* FIXME: The following should be generic for any pointer */
1554 static char *
1555 cppop (struct cpstack **pstack)
1556 {
1557   struct cpstack *s;
1558   char *v;
1559
1560   if ((*pstack)->name == NULL && (*pstack)->next == NULL)
1561     return NULL;
1562
1563   s = *pstack;
1564   v = s->name;
1565   *pstack = (*pstack)->next;
1566   xfree (s);
1567
1568   return v;
1569 }
1570 \f
1571 /*
1572  * Language-dependencies
1573  */
1574
1575 /* Common entry points */
1576
1577 /* Get the language of variable VAR. */
1578 static enum varobj_languages
1579 variable_language (struct varobj *var)
1580 {
1581   enum varobj_languages lang;
1582
1583   switch (var->root->exp->language_defn->la_language)
1584     {
1585     default:
1586     case language_c:
1587       lang = vlang_c;
1588       break;
1589     case language_cplus:
1590       lang = vlang_cplus;
1591       break;
1592     case language_java:
1593       lang = vlang_java;
1594       break;
1595     }
1596
1597   return lang;
1598 }
1599
1600 /* Return the number of children for a given variable.
1601    The result of this function is defined by the language
1602    implementation. The number of children returned by this function
1603    is the number of children that the user will see in the variable
1604    display. */
1605 static int
1606 number_of_children (struct varobj *var)
1607 {
1608   return (*var->root->lang->number_of_children) (var);;
1609 }
1610
1611 /* What is the expression for the root varobj VAR? Returns a malloc'd string. */
1612 static char *
1613 name_of_variable (struct varobj *var)
1614 {
1615   return (*var->root->lang->name_of_variable) (var);
1616 }
1617
1618 /* What is the name of the INDEX'th child of VAR? Returns a malloc'd string. */
1619 static char *
1620 name_of_child (struct varobj *var, int index)
1621 {
1622   return (*var->root->lang->name_of_child) (var, index);
1623 }
1624
1625 /* What is the ``struct value *'' of the root variable VAR? 
1626    TYPE_CHANGED controls what to do if the type of a
1627    use_selected_frame = 1 variable changes.  On input,
1628    TYPE_CHANGED = 1 means discard the old varobj, and replace
1629    it with this one.  TYPE_CHANGED = 0 means leave it around.
1630    NB: In both cases, var_handle will point to the new varobj,
1631    so if you use TYPE_CHANGED = 0, you will have to stash the
1632    old varobj pointer away somewhere before calling this.
1633    On return, TYPE_CHANGED will be 1 if the type has changed, and 
1634    0 otherwise. */
1635 static struct value *
1636 value_of_root (struct varobj **var_handle, int *type_changed)
1637 {
1638   struct varobj *var;
1639
1640   if (var_handle == NULL)
1641     return NULL;
1642
1643   var = *var_handle;
1644
1645   /* This should really be an exception, since this should
1646      only get called with a root variable. */
1647
1648   if (!is_root_p (var))
1649     return NULL;
1650
1651   if (var->root->use_selected_frame)
1652     {
1653       struct varobj *tmp_var;
1654       char *old_type, *new_type;
1655       old_type = varobj_get_type (var);
1656       tmp_var = varobj_create (NULL, var->name, (CORE_ADDR) 0,
1657                                USE_SELECTED_FRAME);
1658       if (tmp_var == NULL)
1659         {
1660           return NULL;
1661         }
1662       new_type = varobj_get_type (tmp_var);
1663       if (strcmp (old_type, new_type) == 0)
1664         {
1665           varobj_delete (tmp_var, NULL, 0);
1666           *type_changed = 0;
1667         }
1668       else
1669         {
1670           if (*type_changed)
1671             {
1672               tmp_var->obj_name =
1673                 savestring (var->obj_name, strlen (var->obj_name));
1674               varobj_delete (var, NULL, 0);
1675             }
1676           else
1677             {
1678               tmp_var->obj_name = varobj_gen_name ();
1679             }
1680           install_variable (tmp_var);
1681           *var_handle = tmp_var;
1682           var = *var_handle;
1683           *type_changed = 1;
1684         }
1685     }
1686   else
1687     {
1688       *type_changed = 0;
1689     }
1690
1691   return (*var->root->lang->value_of_root) (var_handle);
1692 }
1693
1694 /* What is the ``struct value *'' for the INDEX'th child of PARENT? */
1695 static struct value *
1696 value_of_child (struct varobj *parent, int index)
1697 {
1698   struct value *value;
1699
1700   value = (*parent->root->lang->value_of_child) (parent, index);
1701
1702   return value;
1703 }
1704
1705 /* Is this variable editable? Use the variable's type to make
1706    this determination. */
1707 static int
1708 variable_editable (struct varobj *var)
1709 {
1710   return (*var->root->lang->variable_editable) (var);
1711 }
1712
1713 /* GDB already has a command called "value_of_variable". Sigh. */
1714 static char *
1715 my_value_of_variable (struct varobj *var)
1716 {
1717   return (*var->root->lang->value_of_variable) (var);
1718 }
1719
1720 static char *
1721 value_get_print_value (struct value *value, enum varobj_display_formats format)
1722 {
1723   long dummy;
1724   struct ui_file *stb;
1725   struct cleanup *old_chain;
1726   char *thevalue;
1727
1728   if (value == NULL)
1729     return NULL;
1730
1731   stb = mem_fileopen ();
1732   old_chain = make_cleanup_ui_file_delete (stb);
1733
1734   common_val_print (value, stb, format_code[(int) format], 1, 0, 0);
1735   thevalue = ui_file_xstrdup (stb, &dummy);
1736
1737   do_cleanups (old_chain);
1738   return thevalue;
1739 }
1740
1741 /* Return non-zero if changes in value of VAR
1742    must be detected and reported by -var-update.
1743    Return zero is -var-update should never report
1744    changes of such values.  This makes sense for structures
1745    (since the changes in children values will be reported separately),
1746    or for artifical objects (like 'public' pseudo-field in C++).
1747
1748    Return value of 0 means that gdb need not call value_fetch_lazy
1749    for the value of this variable object.  */
1750 static int
1751 varobj_value_is_changeable_p (struct varobj *var)
1752 {
1753   int r;
1754   struct type *type;
1755
1756   if (CPLUS_FAKE_CHILD (var))
1757     return 0;
1758
1759   type = get_value_type (var);
1760
1761   switch (TYPE_CODE (type))
1762     {
1763     case TYPE_CODE_STRUCT:
1764     case TYPE_CODE_UNION:
1765     case TYPE_CODE_ARRAY:
1766       r = 0;
1767       break;
1768
1769     default:
1770       r = 1;
1771     }
1772
1773   return r;
1774 }
1775
1776 /* C */
1777 static int
1778 c_number_of_children (struct varobj *var)
1779 {
1780   struct type *type;
1781   struct type *target;
1782   int children;
1783
1784   type = get_type (var);
1785   target = get_target_type (type);
1786   children = 0;
1787
1788   switch (TYPE_CODE (type))
1789     {
1790     case TYPE_CODE_ARRAY:
1791       if (TYPE_LENGTH (type) > 0 && TYPE_LENGTH (target) > 0
1792           && TYPE_ARRAY_UPPER_BOUND_TYPE (type) != BOUND_CANNOT_BE_DETERMINED)
1793         children = TYPE_LENGTH (type) / TYPE_LENGTH (target);
1794       else
1795         /* If we don't know how many elements there are, don't display
1796            any.  */
1797         children = 0;
1798       break;
1799
1800     case TYPE_CODE_STRUCT:
1801     case TYPE_CODE_UNION:
1802       children = TYPE_NFIELDS (type);
1803       break;
1804
1805     case TYPE_CODE_PTR:
1806       /* This is where things get complicated. All pointers have one child.
1807          Except, of course, for struct and union ptr, which we automagically
1808          dereference for the user, and function ptrs which have no children.
1809          We also don't dereference void* as we don't know what to show.
1810          We can show char* so we allow it to be dereferenced.  If you decide
1811          to test for it, please mind that a little magic is necessary to
1812          properly identify it: char* has TYPE_CODE == TYPE_CODE_INT and 
1813          TYPE_NAME == "char" */
1814
1815       switch (TYPE_CODE (target))
1816         {
1817         case TYPE_CODE_STRUCT:
1818         case TYPE_CODE_UNION:
1819           children = TYPE_NFIELDS (target);
1820           break;
1821
1822         case TYPE_CODE_FUNC:
1823         case TYPE_CODE_VOID:
1824           children = 0;
1825           break;
1826
1827         default:
1828           children = 1;
1829         }
1830       break;
1831
1832     default:
1833       /* Other types have no children */
1834       break;
1835     }
1836
1837   return children;
1838 }
1839
1840 static char *
1841 c_name_of_variable (struct varobj *parent)
1842 {
1843   return savestring (parent->name, strlen (parent->name));
1844 }
1845
1846 /* Return the value of element TYPE_INDEX of a structure
1847    value VALUE.  VALUE's type should be a structure,
1848    or union, or a typedef to struct/union.  
1849
1850    Returns NULL if getting the value fails.  Never throws.  */
1851 static struct value *
1852 value_struct_element_index (struct value *value, int type_index)
1853 {
1854   struct value *result = NULL;
1855   volatile struct gdb_exception e;
1856
1857   struct type *type = value_type (value);
1858   type = check_typedef (type);
1859
1860   gdb_assert (TYPE_CODE (type) == TYPE_CODE_STRUCT
1861               || TYPE_CODE (type) == TYPE_CODE_UNION);
1862
1863   TRY_CATCH (e, RETURN_MASK_ERROR)
1864     {
1865       if (TYPE_FIELD_STATIC (type, type_index))
1866         result = value_static_field (type, type_index);
1867       else
1868         result = value_primitive_field (value, 0, type_index, type);
1869     }
1870   if (e.reason < 0)
1871     {
1872       return NULL;
1873     }
1874   else
1875     {
1876       return result;
1877     }
1878 }
1879
1880 /* Obtain the information about child INDEX of the variable
1881    object PARENT.  
1882    If CNAME is not null, sets *CNAME to the name of the child relative
1883    to the parent.
1884    If CVALUE is not null, sets *CVALUE to the value of the child.
1885    If CTYPE is not null, sets *CTYPE to the type of the child.
1886
1887    If any of CNAME, CVALUE, or CTYPE is not null, but the corresponding
1888    information cannot be determined, set *CNAME, *CVALUE, or *CTYPE
1889    to NULL.  */
1890 static void 
1891 c_describe_child (struct varobj *parent, int index,
1892                   char **cname, struct value **cvalue, struct type **ctype)
1893 {
1894   struct value *value = parent->value;
1895   struct type *type = get_type (parent);
1896
1897   if (cname)
1898     *cname = NULL;
1899   if (cvalue)
1900     *cvalue = NULL;
1901   if (ctype)
1902     *ctype = NULL;
1903
1904   /* Pointers to structures are treated just like
1905      structures when accessing children.  */
1906   if (TYPE_CODE (type) == TYPE_CODE_PTR)
1907     {
1908       struct type *target_type = get_target_type (type);
1909       if (TYPE_CODE (target_type) == TYPE_CODE_STRUCT
1910           || TYPE_CODE (target_type) == TYPE_CODE_UNION)
1911         {
1912           if (value)
1913             gdb_value_ind (value, &value);        
1914           type = target_type;
1915         }
1916     }
1917       
1918   switch (TYPE_CODE (type))
1919     {
1920     case TYPE_CODE_ARRAY:
1921       if (cname)
1922         *cname = xstrprintf ("%d", index
1923                              + TYPE_LOW_BOUND (TYPE_INDEX_TYPE (type)));
1924
1925       if (cvalue && value)
1926         {
1927           int real_index = index + TYPE_LOW_BOUND (TYPE_INDEX_TYPE (type));
1928           struct value *indval = 
1929             value_from_longest (builtin_type_int, (LONGEST) real_index);
1930           gdb_value_subscript (value, indval, cvalue);
1931         }
1932
1933       if (ctype)
1934         *ctype = get_target_type (type);
1935
1936       break;
1937
1938     case TYPE_CODE_STRUCT:
1939     case TYPE_CODE_UNION:
1940       if (cname)
1941         {
1942           char *string = TYPE_FIELD_NAME (type, index);
1943           *cname = savestring (string, strlen (string));
1944         }
1945
1946       if (cvalue && value)
1947         {
1948           /* For C, varobj index is the same as type index.  */
1949           *cvalue = value_struct_element_index (value, index);
1950         }
1951
1952       if (ctype)
1953         *ctype = TYPE_FIELD_TYPE (type, index);
1954
1955       break;
1956
1957     case TYPE_CODE_PTR:
1958       if (cname)
1959         *cname = xstrprintf ("*%s", parent->name);
1960
1961       if (cvalue && value)
1962         gdb_value_ind (value, cvalue);
1963
1964       if (ctype)
1965         *ctype = get_target_type (type);
1966       
1967       break;
1968
1969     default:
1970       /* This should not happen */
1971       if (cname)
1972         *cname = xstrdup ("???");
1973       /* Don't set value and type, we don't know then. */
1974     }
1975 }
1976
1977 static char *
1978 c_name_of_child (struct varobj *parent, int index)
1979 {
1980   char *name;
1981   c_describe_child (parent, index, &name, NULL, NULL);
1982   return name;
1983 }
1984
1985 static struct value *
1986 c_value_of_root (struct varobj **var_handle)
1987 {
1988   struct value *new_val = NULL;
1989   struct varobj *var = *var_handle;
1990   struct frame_info *fi;
1991   int within_scope;
1992
1993   /*  Only root variables can be updated... */
1994   if (!is_root_p (var))
1995     /* Not a root var */
1996     return NULL;
1997
1998
1999   /* Determine whether the variable is still around. */
2000   if (var->root->valid_block == NULL || var->root->use_selected_frame)
2001     within_scope = 1;
2002   else
2003     {
2004       fi = frame_find_by_id (var->root->frame);
2005       within_scope = fi != NULL;
2006       /* FIXME: select_frame could fail */
2007       if (fi)
2008         {
2009           CORE_ADDR pc = get_frame_pc (fi);
2010           if (pc <  BLOCK_START (var->root->valid_block) ||
2011               pc >= BLOCK_END (var->root->valid_block))
2012             within_scope = 0;
2013           else
2014             select_frame (fi);
2015         }         
2016     }
2017
2018   if (within_scope)
2019     {
2020       /* We need to catch errors here, because if evaluate
2021          expression fails we just want to make val->error = 1 and
2022          go on */
2023       if (gdb_evaluate_expression (var->root->exp, &new_val))
2024         {
2025           release_value (new_val);
2026         }
2027
2028       return new_val;
2029     }
2030
2031   return NULL;
2032 }
2033
2034 static struct value *
2035 c_value_of_child (struct varobj *parent, int index)
2036 {
2037   struct value *value = NULL;
2038   c_describe_child (parent, index, NULL, &value, NULL);
2039   if (value != NULL)
2040     release_value (value);
2041
2042   return value;
2043 }
2044
2045 static struct type *
2046 c_type_of_child (struct varobj *parent, int index)
2047 {
2048   struct type *type = NULL;
2049   c_describe_child (parent, index, NULL, NULL, &type);
2050   return type;
2051 }
2052
2053 static int
2054 c_variable_editable (struct varobj *var)
2055 {
2056   switch (TYPE_CODE (get_value_type (var)))
2057     {
2058     case TYPE_CODE_STRUCT:
2059     case TYPE_CODE_UNION:
2060     case TYPE_CODE_ARRAY:
2061     case TYPE_CODE_FUNC:
2062     case TYPE_CODE_METHOD:
2063       return 0;
2064       break;
2065
2066     default:
2067       return 1;
2068       break;
2069     }
2070 }
2071
2072 static char *
2073 c_value_of_variable (struct varobj *var)
2074 {
2075   /* BOGUS: if val_print sees a struct/class, or a reference to one,
2076      it will print out its children instead of "{...}".  So we need to
2077      catch that case explicitly.  */
2078   struct type *type = get_type (var);
2079
2080   /* Strip top-level references. */
2081   while (TYPE_CODE (type) == TYPE_CODE_REF)
2082     type = check_typedef (TYPE_TARGET_TYPE (type));
2083
2084   switch (TYPE_CODE (type))
2085     {
2086     case TYPE_CODE_STRUCT:
2087     case TYPE_CODE_UNION:
2088       return xstrdup ("{...}");
2089       /* break; */
2090
2091     case TYPE_CODE_ARRAY:
2092       {
2093         char *number;
2094         number = xstrprintf ("[%d]", var->num_children);
2095         return (number);
2096       }
2097       /* break; */
2098
2099     default:
2100       {
2101         if (var->value == NULL)
2102           {
2103             /* This can happen if we attempt to get the value of a struct
2104                member when the parent is an invalid pointer. This is an
2105                error condition, so we should tell the caller. */
2106             return NULL;
2107           }
2108         else
2109           {
2110             gdb_assert (varobj_value_is_changeable_p (var));
2111             gdb_assert (!value_lazy (var->value));
2112             return value_get_print_value (var->value, var->format);
2113           }
2114       }
2115     }
2116 }
2117 \f
2118
2119 /* C++ */
2120
2121 static int
2122 cplus_number_of_children (struct varobj *var)
2123 {
2124   struct type *type;
2125   int children, dont_know;
2126
2127   dont_know = 1;
2128   children = 0;
2129
2130   if (!CPLUS_FAKE_CHILD (var))
2131     {
2132       type = get_type_deref (var);
2133
2134       if (((TYPE_CODE (type)) == TYPE_CODE_STRUCT) ||
2135           ((TYPE_CODE (type)) == TYPE_CODE_UNION))
2136         {
2137           int kids[3];
2138
2139           cplus_class_num_children (type, kids);
2140           if (kids[v_public] != 0)
2141             children++;
2142           if (kids[v_private] != 0)
2143             children++;
2144           if (kids[v_protected] != 0)
2145             children++;
2146
2147           /* Add any baseclasses */
2148           children += TYPE_N_BASECLASSES (type);
2149           dont_know = 0;
2150
2151           /* FIXME: save children in var */
2152         }
2153     }
2154   else
2155     {
2156       int kids[3];
2157
2158       type = get_type_deref (var->parent);
2159
2160       cplus_class_num_children (type, kids);
2161       if (strcmp (var->name, "public") == 0)
2162         children = kids[v_public];
2163       else if (strcmp (var->name, "private") == 0)
2164         children = kids[v_private];
2165       else
2166         children = kids[v_protected];
2167       dont_know = 0;
2168     }
2169
2170   if (dont_know)
2171     children = c_number_of_children (var);
2172
2173   return children;
2174 }
2175
2176 /* Compute # of public, private, and protected variables in this class.
2177    That means we need to descend into all baseclasses and find out
2178    how many are there, too. */
2179 static void
2180 cplus_class_num_children (struct type *type, int children[3])
2181 {
2182   int i;
2183
2184   children[v_public] = 0;
2185   children[v_private] = 0;
2186   children[v_protected] = 0;
2187
2188   for (i = TYPE_N_BASECLASSES (type); i < TYPE_NFIELDS (type); i++)
2189     {
2190       /* If we have a virtual table pointer, omit it. */
2191       if (TYPE_VPTR_BASETYPE (type) == type && TYPE_VPTR_FIELDNO (type) == i)
2192         continue;
2193
2194       if (TYPE_FIELD_PROTECTED (type, i))
2195         children[v_protected]++;
2196       else if (TYPE_FIELD_PRIVATE (type, i))
2197         children[v_private]++;
2198       else
2199         children[v_public]++;
2200     }
2201 }
2202
2203 static char *
2204 cplus_name_of_variable (struct varobj *parent)
2205 {
2206   return c_name_of_variable (parent);
2207 }
2208
2209 static char *
2210 cplus_name_of_child (struct varobj *parent, int index)
2211 {
2212   char *name;
2213   struct type *type;
2214
2215   if (CPLUS_FAKE_CHILD (parent))
2216     {
2217       /* Looking for children of public, private, or protected. */
2218       type = get_type_deref (parent->parent);
2219     }
2220   else
2221     type = get_type_deref (parent);
2222
2223   name = NULL;
2224   switch (TYPE_CODE (type))
2225     {
2226     case TYPE_CODE_STRUCT:
2227     case TYPE_CODE_UNION:
2228       if (CPLUS_FAKE_CHILD (parent))
2229         {
2230           /* The fields of the class type are ordered as they
2231              appear in the class.  We are given an index for a
2232              particular access control type ("public","protected",
2233              or "private").  We must skip over fields that don't
2234              have the access control we are looking for to properly
2235              find the indexed field. */
2236           int type_index = TYPE_N_BASECLASSES (type);
2237           if (strcmp (parent->name, "private") == 0)
2238             {
2239               while (index >= 0)
2240                 {
2241                   if (TYPE_VPTR_BASETYPE (type) == type
2242                       && type_index == TYPE_VPTR_FIELDNO (type))
2243                     ; /* ignore vptr */
2244                   else if (TYPE_FIELD_PRIVATE (type, type_index))
2245                     --index;
2246                   ++type_index;
2247                 }
2248               --type_index;
2249             }
2250           else if (strcmp (parent->name, "protected") == 0)
2251             {
2252               while (index >= 0)
2253                 {
2254                   if (TYPE_VPTR_BASETYPE (type) == type
2255                       && type_index == TYPE_VPTR_FIELDNO (type))
2256                     ; /* ignore vptr */
2257                   else if (TYPE_FIELD_PROTECTED (type, type_index))
2258                     --index;
2259                   ++type_index;
2260                 }
2261               --type_index;
2262             }
2263           else
2264             {
2265               while (index >= 0)
2266                 {
2267                   if (TYPE_VPTR_BASETYPE (type) == type
2268                       && type_index == TYPE_VPTR_FIELDNO (type))
2269                     ; /* ignore vptr */
2270                   else if (!TYPE_FIELD_PRIVATE (type, type_index) &&
2271                       !TYPE_FIELD_PROTECTED (type, type_index))
2272                     --index;
2273                   ++type_index;
2274                 }
2275               --type_index;
2276             }
2277
2278           name = TYPE_FIELD_NAME (type, type_index);
2279         }
2280       else if (index < TYPE_N_BASECLASSES (type))
2281         /* We are looking up the name of a base class */
2282         name = TYPE_FIELD_NAME (type, index);
2283       else
2284         {
2285           int children[3];
2286           cplus_class_num_children(type, children);
2287
2288           /* Everything beyond the baseclasses can
2289              only be "public", "private", or "protected"
2290
2291              The special "fake" children are always output by varobj in
2292              this order. So if INDEX == 2, it MUST be "protected". */
2293           index -= TYPE_N_BASECLASSES (type);
2294           switch (index)
2295             {
2296             case 0:
2297               if (children[v_public] > 0)
2298                 name = "public";
2299               else if (children[v_private] > 0)
2300                 name = "private";
2301               else 
2302                 name = "protected";
2303               break;
2304             case 1:
2305               if (children[v_public] > 0)
2306                 {
2307                   if (children[v_private] > 0)
2308                     name = "private";
2309                   else
2310                     name = "protected";
2311                 }
2312               else if (children[v_private] > 0)
2313                 name = "protected";
2314               break;
2315             case 2:
2316               /* Must be protected */
2317               name = "protected";
2318               break;
2319             default:
2320               /* error! */
2321               break;
2322             }
2323         }
2324       break;
2325
2326     default:
2327       break;
2328     }
2329
2330   if (name == NULL)
2331     return c_name_of_child (parent, index);
2332   else
2333     {
2334       if (name != NULL)
2335         name = savestring (name, strlen (name));
2336     }
2337
2338   return name;
2339 }
2340
2341 static struct value *
2342 cplus_value_of_root (struct varobj **var_handle)
2343 {
2344   return c_value_of_root (var_handle);
2345 }
2346
2347 static struct value *
2348 cplus_value_of_child (struct varobj *parent, int index)
2349 {
2350   struct type *type;
2351   struct value *value;
2352
2353   if (CPLUS_FAKE_CHILD (parent))
2354     type = get_type_deref (parent->parent);
2355   else
2356     type = get_type_deref (parent);
2357
2358   value = NULL;
2359
2360   if (((TYPE_CODE (type)) == TYPE_CODE_STRUCT) ||
2361       ((TYPE_CODE (type)) == TYPE_CODE_UNION))
2362     {
2363       if (CPLUS_FAKE_CHILD (parent))
2364         {
2365           char *name;
2366           struct value *temp = parent->parent->value;
2367
2368           if (temp == NULL)
2369             return NULL;
2370
2371           name = name_of_child (parent, index);
2372           gdb_value_struct_elt (NULL, &value, &temp, NULL, name, NULL,
2373                                 "cplus_structure");
2374           if (value != NULL)
2375             release_value (value);
2376
2377           xfree (name);
2378         }
2379       else if (index >= TYPE_N_BASECLASSES (type))
2380         {
2381           /* public, private, or protected */
2382           return NULL;
2383         }
2384       else
2385         {
2386           /* Baseclass */
2387           if (parent->value != NULL)
2388             {
2389               struct value *temp = NULL;
2390
2391               /* No special processing for references is needed --
2392                  value_cast below handles references.  */
2393               if (TYPE_CODE (value_type (parent->value)) == TYPE_CODE_PTR)
2394                 {
2395                   if (!gdb_value_ind (parent->value, &temp))
2396                     return NULL;
2397                 }
2398               else
2399                 temp = parent->value;
2400
2401               if (temp != NULL)
2402                 {
2403                   value = value_cast (TYPE_FIELD_TYPE (type, index), temp);
2404                   release_value (value);
2405                 }
2406               else
2407                 {
2408                   /* We failed to evaluate the parent's value, so don't even
2409                      bother trying to evaluate this child. */
2410                   return NULL;
2411                 }
2412             }
2413         }
2414     }
2415
2416   if (value == NULL)
2417     return c_value_of_child (parent, index);
2418
2419   return value;
2420 }
2421
2422 static struct type *
2423 cplus_type_of_child (struct varobj *parent, int index)
2424 {
2425   struct type *type, *t;
2426
2427   if (CPLUS_FAKE_CHILD (parent))
2428     {
2429       /* Looking for the type of a child of public, private, or protected. */
2430       t = get_type_deref (parent->parent);
2431     }
2432   else
2433     t = get_type_deref (parent);
2434
2435   type = NULL;
2436   switch (TYPE_CODE (t))
2437     {
2438     case TYPE_CODE_STRUCT:
2439     case TYPE_CODE_UNION:
2440       if (CPLUS_FAKE_CHILD (parent))
2441         {
2442           char *name = cplus_name_of_child (parent, index);
2443           type = lookup_struct_elt_type (t, name, 0);
2444           xfree (name);
2445         }
2446       else if (index < TYPE_N_BASECLASSES (t))
2447         type = TYPE_FIELD_TYPE (t, index);
2448       else
2449         {
2450           /* special */
2451           return NULL;
2452         }
2453       break;
2454
2455     default:
2456       break;
2457     }
2458
2459   if (type == NULL)
2460     return c_type_of_child (parent, index);
2461
2462   return type;
2463 }
2464
2465 static int
2466 cplus_variable_editable (struct varobj *var)
2467 {
2468   if (CPLUS_FAKE_CHILD (var))
2469     return 0;
2470
2471   return c_variable_editable (var);
2472 }
2473
2474 static char *
2475 cplus_value_of_variable (struct varobj *var)
2476 {
2477
2478   /* If we have one of our special types, don't print out
2479      any value. */
2480   if (CPLUS_FAKE_CHILD (var))
2481     return xstrdup ("");
2482
2483   return c_value_of_variable (var);
2484 }
2485 \f
2486 /* Java */
2487
2488 static int
2489 java_number_of_children (struct varobj *var)
2490 {
2491   return cplus_number_of_children (var);
2492 }
2493
2494 static char *
2495 java_name_of_variable (struct varobj *parent)
2496 {
2497   char *p, *name;
2498
2499   name = cplus_name_of_variable (parent);
2500   /* If  the name has "-" in it, it is because we
2501      needed to escape periods in the name... */
2502   p = name;
2503
2504   while (*p != '\000')
2505     {
2506       if (*p == '-')
2507         *p = '.';
2508       p++;
2509     }
2510
2511   return name;
2512 }
2513
2514 static char *
2515 java_name_of_child (struct varobj *parent, int index)
2516 {
2517   char *name, *p;
2518
2519   name = cplus_name_of_child (parent, index);
2520   /* Escape any periods in the name... */
2521   p = name;
2522
2523   while (*p != '\000')
2524     {
2525       if (*p == '.')
2526         *p = '-';
2527       p++;
2528     }
2529
2530   return name;
2531 }
2532
2533 static struct value *
2534 java_value_of_root (struct varobj **var_handle)
2535 {
2536   return cplus_value_of_root (var_handle);
2537 }
2538
2539 static struct value *
2540 java_value_of_child (struct varobj *parent, int index)
2541 {
2542   return cplus_value_of_child (parent, index);
2543 }
2544
2545 static struct type *
2546 java_type_of_child (struct varobj *parent, int index)
2547 {
2548   return cplus_type_of_child (parent, index);
2549 }
2550
2551 static int
2552 java_variable_editable (struct varobj *var)
2553 {
2554   return cplus_variable_editable (var);
2555 }
2556
2557 static char *
2558 java_value_of_variable (struct varobj *var)
2559 {
2560   return cplus_value_of_variable (var);
2561 }
2562 \f
2563 extern void _initialize_varobj (void);
2564 void
2565 _initialize_varobj (void)
2566 {
2567   int sizeof_table = sizeof (struct vlist *) * VAROBJ_TABLE_SIZE;
2568
2569   varobj_table = xmalloc (sizeof_table);
2570   memset (varobj_table, 0, sizeof_table);
2571
2572   add_setshow_zinteger_cmd ("debugvarobj", class_maintenance,
2573                             &varobjdebug, _("\
2574 Set varobj debugging."), _("\
2575 Show varobj debugging."), _("\
2576 When non-zero, varobj debugging is enabled."),
2577                             NULL,
2578                             show_varobjdebug,
2579                             &setlist, &showlist);
2580 }
This page took 0.154932 seconds and 2 git commands to generate.