gdb: remove TYPE_HIGH_BOUND and TYPE_LOW_BOUND
[binutils-gdb.git] / gdb / c-varobj.c
1 /* varobj support for C and C++.
2
3 Copyright (C) 1999-2020 Free Software Foundation, Inc.
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
17
18 #include "defs.h"
19 #include "value.h"
20 #include "varobj.h"
21 #include "gdbthread.h"
22 #include "valprint.h"
23
24 static void cplus_class_num_children (struct type *type, int children[3]);
25
26 /* The names of varobjs representing anonymous structs or unions. */
27 #define ANONYMOUS_STRUCT_NAME _("<anonymous struct>")
28 #define ANONYMOUS_UNION_NAME _("<anonymous union>")
29
30 /* Does CHILD represent a child with no name? This happens when
31 the child is an anonymous struct or union and it has no field name
32 in its parent variable.
33
34 This has already been determined by *_describe_child. The easiest
35 thing to do is to compare the child's name with ANONYMOUS_*_NAME. */
36
37 bool
38 varobj_is_anonymous_child (const struct varobj *child)
39 {
40 return (child->name == ANONYMOUS_STRUCT_NAME
41 || child->name == ANONYMOUS_UNION_NAME);
42 }
43
44 /* Given the value and the type of a variable object,
45 adjust the value and type to those necessary
46 for getting children of the variable object.
47 This includes dereferencing top-level references
48 to all types and dereferencing pointers to
49 structures.
50
51 If LOOKUP_ACTUAL_TYPE is set the enclosing type of the
52 value will be fetched and if it differs from static type
53 the value will be casted to it.
54
55 Both TYPE and *TYPE should be non-null. VALUE
56 can be null if we want to only translate type.
57 *VALUE can be null as well -- if the parent
58 value is not known.
59
60 If WAS_PTR is not NULL, set *WAS_PTR to 0 or 1
61 depending on whether pointer was dereferenced
62 in this function. */
63
64 static void
65 adjust_value_for_child_access (struct value **value,
66 struct type **type,
67 int *was_ptr,
68 int lookup_actual_type)
69 {
70 gdb_assert (type && *type);
71
72 if (was_ptr)
73 *was_ptr = 0;
74
75 *type = check_typedef (*type);
76
77 /* The type of value stored in varobj, that is passed
78 to us, is already supposed to be
79 reference-stripped. */
80
81 gdb_assert (!TYPE_IS_REFERENCE (*type));
82
83 /* Pointers to structures are treated just like
84 structures when accessing children. Don't
85 dereference pointers to other types. */
86 if ((*type)->code () == TYPE_CODE_PTR)
87 {
88 struct type *target_type = get_target_type (*type);
89 if (target_type->code () == TYPE_CODE_STRUCT
90 || target_type->code () == TYPE_CODE_UNION)
91 {
92 if (value && *value)
93 {
94
95 try
96 {
97 *value = value_ind (*value);
98 }
99
100 catch (const gdb_exception_error &except)
101 {
102 *value = NULL;
103 }
104 }
105 *type = target_type;
106 if (was_ptr)
107 *was_ptr = 1;
108 }
109 }
110
111 /* The 'get_target_type' function calls check_typedef on
112 result, so we can immediately check type code. No
113 need to call check_typedef here. */
114
115 /* Access a real type of the value (if necessary and possible). */
116 if (value && *value && lookup_actual_type)
117 {
118 struct type *enclosing_type;
119 int real_type_found = 0;
120
121 enclosing_type = value_actual_type (*value, 1, &real_type_found);
122 if (real_type_found)
123 {
124 *type = enclosing_type;
125 *value = value_cast (enclosing_type, *value);
126 }
127 }
128 }
129
130 /* Is VAR a path expression parent, i.e., can it be used to construct
131 a valid path expression? */
132
133 static bool
134 c_is_path_expr_parent (const struct varobj *var)
135 {
136 struct type *type;
137
138 /* "Fake" children are not path_expr parents. */
139 if (CPLUS_FAKE_CHILD (var))
140 return false;
141
142 type = varobj_get_gdb_type (var);
143
144 /* Anonymous unions and structs are also not path_expr parents. */
145 if ((type->code () == TYPE_CODE_STRUCT
146 || type->code () == TYPE_CODE_UNION)
147 && type->name () == NULL)
148 {
149 const struct varobj *parent = var->parent;
150
151 while (parent != NULL && CPLUS_FAKE_CHILD (parent))
152 parent = parent->parent;
153
154 if (parent != NULL)
155 {
156 struct type *parent_type;
157 int was_ptr;
158
159 parent_type = varobj_get_value_type (parent);
160 adjust_value_for_child_access (NULL, &parent_type, &was_ptr, 0);
161
162 if (parent_type->code () == TYPE_CODE_STRUCT
163 || parent_type->code () == TYPE_CODE_UNION)
164 {
165 const char *field_name;
166
167 gdb_assert (var->index < parent_type->num_fields ());
168 field_name = TYPE_FIELD_NAME (parent_type, var->index);
169 return !(field_name == NULL || *field_name == '\0');
170 }
171 }
172
173 return false;
174 }
175
176 return true;
177 }
178
179 /* C */
180
181 static int
182 c_number_of_children (const struct varobj *var)
183 {
184 struct type *type = varobj_get_value_type (var);
185 int children = 0;
186 struct type *target;
187
188 adjust_value_for_child_access (NULL, &type, NULL, 0);
189 target = get_target_type (type);
190
191 switch (type->code ())
192 {
193 case TYPE_CODE_ARRAY:
194 if (TYPE_LENGTH (type) > 0 && TYPE_LENGTH (target) > 0
195 && !TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (type))
196 children = TYPE_LENGTH (type) / TYPE_LENGTH (target);
197 else
198 /* If we don't know how many elements there are, don't display
199 any. */
200 children = 0;
201 break;
202
203 case TYPE_CODE_STRUCT:
204 case TYPE_CODE_UNION:
205 children = type->num_fields ();
206 break;
207
208 case TYPE_CODE_PTR:
209 /* The type here is a pointer to non-struct. Typically, pointers
210 have one child, except for function ptrs, which have no children,
211 and except for void*, as we don't know what to show.
212
213 We can show char* so we allow it to be dereferenced. If you decide
214 to test for it, please mind that a little magic is necessary to
215 properly identify it: char* has TYPE_CODE == TYPE_CODE_INT and
216 TYPE_NAME == "char". */
217 if (target->code () == TYPE_CODE_FUNC
218 || target->code () == TYPE_CODE_VOID)
219 children = 0;
220 else
221 children = 1;
222 break;
223
224 default:
225 /* Other types have no children. */
226 break;
227 }
228
229 return children;
230 }
231
232 static std::string
233 c_name_of_variable (const struct varobj *parent)
234 {
235 return parent->name;
236 }
237
238 /* Return the value of element TYPE_INDEX of a structure
239 value VALUE. VALUE's type should be a structure,
240 or union, or a typedef to struct/union.
241
242 Returns NULL if getting the value fails. Never throws. */
243
244 static struct value *
245 value_struct_element_index (struct value *value, int type_index)
246 {
247 struct value *result = NULL;
248 struct type *type = value_type (value);
249
250 type = check_typedef (type);
251
252 gdb_assert (type->code () == TYPE_CODE_STRUCT
253 || type->code () == TYPE_CODE_UNION);
254
255 try
256 {
257 if (field_is_static (&type->field (type_index)))
258 result = value_static_field (type, type_index);
259 else
260 result = value_primitive_field (value, 0, type_index, type);
261 }
262 catch (const gdb_exception_error &e)
263 {
264 return NULL;
265 }
266
267 return result;
268 }
269
270 /* Obtain the information about child INDEX of the variable
271 object PARENT.
272 If CNAME is not null, sets *CNAME to the name of the child relative
273 to the parent.
274 If CVALUE is not null, sets *CVALUE to the value of the child.
275 If CTYPE is not null, sets *CTYPE to the type of the child.
276
277 If any of CNAME, CVALUE, or CTYPE is not null, but the corresponding
278 information cannot be determined, set *CNAME, *CVALUE, or *CTYPE
279 to empty. */
280
281 static void
282 c_describe_child (const struct varobj *parent, int index,
283 std::string *cname, struct value **cvalue,
284 struct type **ctype, std::string *cfull_expression)
285 {
286 struct value *value = parent->value.get ();
287 struct type *type = varobj_get_value_type (parent);
288 std::string parent_expression;
289 int was_ptr;
290
291 if (cname)
292 *cname = std::string ();
293 if (cvalue)
294 *cvalue = NULL;
295 if (ctype)
296 *ctype = NULL;
297 if (cfull_expression)
298 {
299 *cfull_expression = std::string ();
300 parent_expression
301 = varobj_get_path_expr (varobj_get_path_expr_parent (parent));
302 }
303 adjust_value_for_child_access (&value, &type, &was_ptr, 0);
304
305 switch (type->code ())
306 {
307 case TYPE_CODE_ARRAY:
308 if (cname)
309 *cname = int_string (index
310 + type->index_type ()->bounds ()->low.const_val (),
311 10, 1, 0, 0);
312
313 if (cvalue && value)
314 {
315 int real_index
316 = index + type->index_type ()->bounds ()->low.const_val ();
317
318 try
319 {
320 *cvalue = value_subscript (value, real_index);
321 }
322 catch (const gdb_exception_error &except)
323 {
324 }
325 }
326
327 if (ctype)
328 *ctype = get_target_type (type);
329
330 if (cfull_expression)
331 *cfull_expression = string_printf
332 ("(%s)[%s]", parent_expression.c_str (),
333 int_string (index + type->index_type ()->bounds ()->low.const_val (),
334 10, 1, 0, 0));
335
336 break;
337
338 case TYPE_CODE_STRUCT:
339 case TYPE_CODE_UNION:
340 {
341 const char *field_name;
342
343 /* If the type is anonymous and the field has no name,
344 set an appropriate name. */
345 field_name = TYPE_FIELD_NAME (type, index);
346 if (field_name == NULL || *field_name == '\0')
347 {
348 if (cname)
349 {
350 if (type->field (index).type ()->code ()
351 == TYPE_CODE_STRUCT)
352 *cname = ANONYMOUS_STRUCT_NAME;
353 else
354 *cname = ANONYMOUS_UNION_NAME;
355 }
356
357 if (cfull_expression)
358 *cfull_expression = "";
359 }
360 else
361 {
362 if (cname)
363 *cname = field_name;
364
365 if (cfull_expression)
366 {
367 const char *join = was_ptr ? "->" : ".";
368
369 *cfull_expression = string_printf ("(%s)%s%s",
370 parent_expression.c_str (),
371 join, field_name);
372 }
373 }
374
375 if (cvalue && value)
376 {
377 /* For C, varobj index is the same as type index. */
378 *cvalue = value_struct_element_index (value, index);
379 }
380
381 if (ctype)
382 *ctype = type->field (index).type ();
383 }
384 break;
385
386 case TYPE_CODE_PTR:
387 if (cname)
388 *cname = string_printf ("*%s", parent->name.c_str ());
389
390 if (cvalue && value)
391 {
392 try
393 {
394 *cvalue = value_ind (value);
395 }
396
397 catch (const gdb_exception_error &except)
398 {
399 *cvalue = NULL;
400 }
401 }
402
403 /* Don't use get_target_type because it calls
404 check_typedef and here, we want to show the true
405 declared type of the variable. */
406 if (ctype)
407 *ctype = TYPE_TARGET_TYPE (type);
408
409 if (cfull_expression)
410 *cfull_expression = string_printf ("*(%s)", parent_expression.c_str ());
411 break;
412
413 default:
414 /* This should not happen. */
415 if (cname)
416 *cname = "???";
417 if (cfull_expression)
418 *cfull_expression = "???";
419 /* Don't set value and type, we don't know then. */
420 }
421 }
422
423 static std::string
424 c_name_of_child (const struct varobj *parent, int index)
425 {
426 std::string name;
427
428 c_describe_child (parent, index, &name, NULL, NULL, NULL);
429 return name;
430 }
431
432 static std::string
433 c_path_expr_of_child (const struct varobj *child)
434 {
435 std::string path_expr;
436
437 c_describe_child (child->parent, child->index, NULL, NULL, NULL,
438 &path_expr);
439 return path_expr;
440 }
441
442 static struct value *
443 c_value_of_child (const struct varobj *parent, int index)
444 {
445 struct value *value = NULL;
446
447 c_describe_child (parent, index, NULL, &value, NULL, NULL);
448 return value;
449 }
450
451 static struct type *
452 c_type_of_child (const struct varobj *parent, int index)
453 {
454 struct type *type = NULL;
455
456 c_describe_child (parent, index, NULL, NULL, &type, NULL);
457 return type;
458 }
459
460 /* This returns the type of the variable. It also skips past typedefs
461 to return the real type of the variable. */
462
463 static struct type *
464 get_type (const struct varobj *var)
465 {
466 struct type *type;
467
468 type = var->type;
469 if (type != NULL)
470 type = check_typedef (type);
471
472 return type;
473 }
474
475 static std::string
476 c_value_of_variable (const struct varobj *var,
477 enum varobj_display_formats format)
478 {
479 /* BOGUS: if val_print sees a struct/class, or a reference to one,
480 it will print out its children instead of "{...}". So we need to
481 catch that case explicitly. */
482 struct type *type = get_type (var);
483
484 /* Strip top-level references. */
485 while (TYPE_IS_REFERENCE (type))
486 type = check_typedef (TYPE_TARGET_TYPE (type));
487
488 switch (type->code ())
489 {
490 case TYPE_CODE_STRUCT:
491 case TYPE_CODE_UNION:
492 return "{...}";
493 /* break; */
494
495 case TYPE_CODE_ARRAY:
496 return string_printf ("[%d]", var->num_children);
497 /* break; */
498
499 default:
500 {
501 if (var->value == NULL)
502 {
503 /* This can happen if we attempt to get the value of a struct
504 member when the parent is an invalid pointer. This is an
505 error condition, so we should tell the caller. */
506 return std::string ();
507 }
508 else
509 {
510 if (var->not_fetched && value_lazy (var->value.get ()))
511 /* Frozen variable and no value yet. We don't
512 implicitly fetch the value. MI response will
513 use empty string for the value, which is OK. */
514 return std::string ();
515
516 gdb_assert (varobj_value_is_changeable_p (var));
517 gdb_assert (!value_lazy (var->value.get ()));
518
519 /* If the specified format is the current one,
520 we can reuse print_value. */
521 if (format == var->format)
522 return var->print_value;
523 else
524 return varobj_value_get_print_value (var->value.get (), format,
525 var);
526 }
527 }
528 }
529 }
530 \f
531
532 /* varobj operations for c. */
533
534 const struct lang_varobj_ops c_varobj_ops =
535 {
536 c_number_of_children,
537 c_name_of_variable,
538 c_name_of_child,
539 c_path_expr_of_child,
540 c_value_of_child,
541 c_type_of_child,
542 c_value_of_variable,
543 varobj_default_value_is_changeable_p,
544 NULL, /* value_has_mutated */
545 c_is_path_expr_parent /* is_path_expr_parent */
546 };
547
548 /* A little convenience enum for dealing with C++. */
549 enum vsections
550 {
551 v_public = 0, v_private, v_protected
552 };
553
554 /* C++ */
555
556 static int
557 cplus_number_of_children (const struct varobj *var)
558 {
559 struct value *value = NULL;
560 struct type *type;
561 int children, dont_know;
562 int lookup_actual_type = 0;
563 struct value_print_options opts;
564
565 dont_know = 1;
566 children = 0;
567
568 get_user_print_options (&opts);
569
570 if (!CPLUS_FAKE_CHILD (var))
571 {
572 type = varobj_get_value_type (var);
573
574 /* It is necessary to access a real type (via RTTI). */
575 if (opts.objectprint)
576 {
577 value = var->value.get ();
578 lookup_actual_type = (TYPE_IS_REFERENCE (var->type)
579 || var->type->code () == TYPE_CODE_PTR);
580 }
581 adjust_value_for_child_access (&value, &type, NULL, lookup_actual_type);
582
583 if (((type->code ()) == TYPE_CODE_STRUCT)
584 || ((type->code ()) == TYPE_CODE_UNION))
585 {
586 int kids[3];
587
588 cplus_class_num_children (type, kids);
589 if (kids[v_public] != 0)
590 children++;
591 if (kids[v_private] != 0)
592 children++;
593 if (kids[v_protected] != 0)
594 children++;
595
596 /* Add any baseclasses. */
597 children += TYPE_N_BASECLASSES (type);
598 dont_know = 0;
599
600 /* FIXME: save children in var. */
601 }
602 }
603 else
604 {
605 int kids[3];
606
607 type = varobj_get_value_type (var->parent);
608
609 /* It is necessary to access a real type (via RTTI). */
610 if (opts.objectprint)
611 {
612 const struct varobj *parent = var->parent;
613
614 value = parent->value.get ();
615 lookup_actual_type = (TYPE_IS_REFERENCE (parent->type)
616 || parent->type->code () == TYPE_CODE_PTR);
617 }
618 adjust_value_for_child_access (&value, &type, NULL, lookup_actual_type);
619
620 cplus_class_num_children (type, kids);
621 if (var->name == "public")
622 children = kids[v_public];
623 else if (var->name == "private")
624 children = kids[v_private];
625 else
626 children = kids[v_protected];
627 dont_know = 0;
628 }
629
630 if (dont_know)
631 children = c_number_of_children (var);
632
633 return children;
634 }
635
636 /* Compute # of public, private, and protected variables in this class.
637 That means we need to descend into all baseclasses and find out
638 how many are there, too. */
639
640 static void
641 cplus_class_num_children (struct type *type, int children[3])
642 {
643 int i, vptr_fieldno;
644 struct type *basetype = NULL;
645
646 children[v_public] = 0;
647 children[v_private] = 0;
648 children[v_protected] = 0;
649
650 vptr_fieldno = get_vptr_fieldno (type, &basetype);
651 for (i = TYPE_N_BASECLASSES (type); i < type->num_fields (); i++)
652 {
653 /* If we have a virtual table pointer, omit it. Even if virtual
654 table pointers are not specifically marked in the debug info,
655 they should be artificial. */
656 if ((type == basetype && i == vptr_fieldno)
657 || TYPE_FIELD_ARTIFICIAL (type, i))
658 continue;
659
660 if (TYPE_FIELD_PROTECTED (type, i))
661 children[v_protected]++;
662 else if (TYPE_FIELD_PRIVATE (type, i))
663 children[v_private]++;
664 else
665 children[v_public]++;
666 }
667 }
668
669 static std::string
670 cplus_name_of_variable (const struct varobj *parent)
671 {
672 return c_name_of_variable (parent);
673 }
674
675 enum accessibility { private_field, protected_field, public_field };
676
677 /* Check if field INDEX of TYPE has the specified accessibility.
678 Return 0 if so and 1 otherwise. */
679
680 static int
681 match_accessibility (struct type *type, int index, enum accessibility acc)
682 {
683 if (acc == private_field && TYPE_FIELD_PRIVATE (type, index))
684 return 1;
685 else if (acc == protected_field && TYPE_FIELD_PROTECTED (type, index))
686 return 1;
687 else if (acc == public_field && !TYPE_FIELD_PRIVATE (type, index)
688 && !TYPE_FIELD_PROTECTED (type, index))
689 return 1;
690 else
691 return 0;
692 }
693
694 static void
695 cplus_describe_child (const struct varobj *parent, int index,
696 std::string *cname, struct value **cvalue, struct type **ctype,
697 std::string *cfull_expression)
698 {
699 struct value *value;
700 struct type *type;
701 int was_ptr;
702 int lookup_actual_type = 0;
703 const char *parent_expression = NULL;
704 const struct varobj *var;
705 struct value_print_options opts;
706
707 if (cname)
708 *cname = std::string ();
709 if (cvalue)
710 *cvalue = NULL;
711 if (ctype)
712 *ctype = NULL;
713 if (cfull_expression)
714 *cfull_expression = std::string ();
715
716 get_user_print_options (&opts);
717
718 var = (CPLUS_FAKE_CHILD (parent)) ? parent->parent : parent;
719 if (opts.objectprint)
720 lookup_actual_type = (TYPE_IS_REFERENCE (var->type)
721 || var->type->code () == TYPE_CODE_PTR);
722 value = var->value.get ();
723 type = varobj_get_value_type (var);
724 if (cfull_expression)
725 parent_expression
726 = varobj_get_path_expr (varobj_get_path_expr_parent (var));
727
728 adjust_value_for_child_access (&value, &type, &was_ptr, lookup_actual_type);
729
730 if (type->code () == TYPE_CODE_STRUCT
731 || type->code () == TYPE_CODE_UNION)
732 {
733 const char *join = was_ptr ? "->" : ".";
734
735 if (CPLUS_FAKE_CHILD (parent))
736 {
737 /* The fields of the class type are ordered as they
738 appear in the class. We are given an index for a
739 particular access control type ("public","protected",
740 or "private"). We must skip over fields that don't
741 have the access control we are looking for to properly
742 find the indexed field. */
743 int type_index = TYPE_N_BASECLASSES (type);
744 enum accessibility acc = public_field;
745 int vptr_fieldno;
746 struct type *basetype = NULL;
747 const char *field_name;
748
749 vptr_fieldno = get_vptr_fieldno (type, &basetype);
750 if (parent->name == "private")
751 acc = private_field;
752 else if (parent->name == "protected")
753 acc = protected_field;
754
755 while (index >= 0)
756 {
757 if ((type == basetype && type_index == vptr_fieldno)
758 || TYPE_FIELD_ARTIFICIAL (type, type_index))
759 ; /* ignore vptr */
760 else if (match_accessibility (type, type_index, acc))
761 --index;
762 ++type_index;
763 }
764 --type_index;
765
766 /* If the type is anonymous and the field has no name,
767 set an appropriate name. */
768 field_name = TYPE_FIELD_NAME (type, type_index);
769 if (field_name == NULL || *field_name == '\0')
770 {
771 if (cname)
772 {
773 if (type->field (type_index).type ()->code ()
774 == TYPE_CODE_STRUCT)
775 *cname = ANONYMOUS_STRUCT_NAME;
776 else if (type->field (type_index).type ()->code ()
777 == TYPE_CODE_UNION)
778 *cname = ANONYMOUS_UNION_NAME;
779 }
780
781 if (cfull_expression)
782 *cfull_expression = std::string ();
783 }
784 else
785 {
786 if (cname)
787 *cname = TYPE_FIELD_NAME (type, type_index);
788
789 if (cfull_expression)
790 *cfull_expression
791 = string_printf ("((%s)%s%s)", parent_expression, join,
792 field_name);
793 }
794
795 if (cvalue && value)
796 *cvalue = value_struct_element_index (value, type_index);
797
798 if (ctype)
799 *ctype = type->field (type_index).type ();
800 }
801 else if (index < TYPE_N_BASECLASSES (type))
802 {
803 /* This is a baseclass. */
804 if (cname)
805 *cname = TYPE_FIELD_NAME (type, index);
806
807 if (cvalue && value)
808 *cvalue = value_cast (type->field (index).type (), value);
809
810 if (ctype)
811 {
812 *ctype = type->field (index).type ();
813 }
814
815 if (cfull_expression)
816 {
817 const char *ptr = was_ptr ? "*" : "";
818
819 /* Cast the parent to the base' type. Note that in gdb,
820 expression like
821 (Base1)d
822 will create an lvalue, for all appearences, so we don't
823 need to use more fancy:
824 *(Base1*)(&d)
825 construct.
826
827 When we are in the scope of the base class or of one
828 of its children, the type field name will be interpreted
829 as a constructor, if it exists. Therefore, we must
830 indicate that the name is a class name by using the
831 'class' keyword. See PR mi/11912 */
832 *cfull_expression = string_printf ("(%s(class %s%s) %s)",
833 ptr,
834 TYPE_FIELD_NAME (type, index),
835 ptr,
836 parent_expression);
837 }
838 }
839 else
840 {
841 const char *access = NULL;
842 int children[3];
843
844 cplus_class_num_children (type, children);
845
846 /* Everything beyond the baseclasses can
847 only be "public", "private", or "protected"
848
849 The special "fake" children are always output by varobj in
850 this order. So if INDEX == 2, it MUST be "protected". */
851 index -= TYPE_N_BASECLASSES (type);
852 switch (index)
853 {
854 case 0:
855 if (children[v_public] > 0)
856 access = "public";
857 else if (children[v_private] > 0)
858 access = "private";
859 else
860 access = "protected";
861 break;
862 case 1:
863 if (children[v_public] > 0)
864 {
865 if (children[v_private] > 0)
866 access = "private";
867 else
868 access = "protected";
869 }
870 else if (children[v_private] > 0)
871 access = "protected";
872 break;
873 case 2:
874 /* Must be protected. */
875 access = "protected";
876 break;
877 default:
878 /* error! */
879 break;
880 }
881
882 gdb_assert (access);
883 if (cname)
884 *cname = access;
885
886 /* Value and type and full expression are null here. */
887 }
888 }
889 else
890 {
891 c_describe_child (parent, index, cname, cvalue, ctype, cfull_expression);
892 }
893 }
894
895 static std::string
896 cplus_name_of_child (const struct varobj *parent, int index)
897 {
898 std::string name;
899
900 cplus_describe_child (parent, index, &name, NULL, NULL, NULL);
901 return name;
902 }
903
904 static std::string
905 cplus_path_expr_of_child (const struct varobj *child)
906 {
907 std::string path_expr;
908
909 cplus_describe_child (child->parent, child->index, NULL, NULL, NULL,
910 &path_expr);
911 return path_expr;
912 }
913
914 static struct value *
915 cplus_value_of_child (const struct varobj *parent, int index)
916 {
917 struct value *value = NULL;
918
919 cplus_describe_child (parent, index, NULL, &value, NULL, NULL);
920 return value;
921 }
922
923 static struct type *
924 cplus_type_of_child (const struct varobj *parent, int index)
925 {
926 struct type *type = NULL;
927
928 cplus_describe_child (parent, index, NULL, NULL, &type, NULL);
929 return type;
930 }
931
932 static std::string
933 cplus_value_of_variable (const struct varobj *var,
934 enum varobj_display_formats format)
935 {
936
937 /* If we have one of our special types, don't print out
938 any value. */
939 if (CPLUS_FAKE_CHILD (var))
940 return std::string ();
941
942 return c_value_of_variable (var, format);
943 }
944 \f
945
946 /* varobj operations for c++. */
947
948 const struct lang_varobj_ops cplus_varobj_ops =
949 {
950 cplus_number_of_children,
951 cplus_name_of_variable,
952 cplus_name_of_child,
953 cplus_path_expr_of_child,
954 cplus_value_of_child,
955 cplus_type_of_child,
956 cplus_value_of_variable,
957 varobj_default_value_is_changeable_p,
958 NULL, /* value_has_mutated */
959 c_is_path_expr_parent /* is_path_expr_parent */
960 };
961
962 \f