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