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