c-varobj.c revision 1.9
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 24static 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 37bool 38varobj_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 64static void 65adjust_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 133static bool 134c_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 181static int 182c_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->bounds ()->high.kind () != PROP_UNDEFINED)) 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 232static std::string 233c_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 244static struct value * 245value_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 281static void 282c_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 + type->bounds ()->low.const_val (), 310 10, 1, 0, 0); 311 312 if (cvalue && value) 313 { 314 int real_index 315 = index + type->bounds ()->low.const_val (); 316 317 try 318 { 319 *cvalue = value_subscript (value, real_index); 320 } 321 catch (const gdb_exception_error &except) 322 { 323 } 324 } 325 326 if (ctype) 327 *ctype = get_target_type (type); 328 329 if (cfull_expression) 330 *cfull_expression = string_printf 331 ("(%s)[%s]", parent_expression.c_str (), 332 int_string (index + type->bounds ()->low.const_val (), 333 10, 1, 0, 0)); 334 335 break; 336 337 case TYPE_CODE_STRUCT: 338 case TYPE_CODE_UNION: 339 { 340 const char *field_name; 341 342 /* If the type is anonymous and the field has no name, 343 set an appropriate name. */ 344 field_name = TYPE_FIELD_NAME (type, index); 345 if (field_name == NULL || *field_name == '\0') 346 { 347 if (cname) 348 { 349 if (type->field (index).type ()->code () 350 == TYPE_CODE_STRUCT) 351 *cname = ANONYMOUS_STRUCT_NAME; 352 else 353 *cname = ANONYMOUS_UNION_NAME; 354 } 355 356 if (cfull_expression) 357 *cfull_expression = ""; 358 } 359 else 360 { 361 if (cname) 362 *cname = field_name; 363 364 if (cfull_expression) 365 { 366 const char *join = was_ptr ? "->" : "."; 367 368 *cfull_expression = string_printf ("(%s)%s%s", 369 parent_expression.c_str (), 370 join, field_name); 371 } 372 } 373 374 if (cvalue && value) 375 { 376 /* For C, varobj index is the same as type index. */ 377 *cvalue = value_struct_element_index (value, index); 378 } 379 380 if (ctype) 381 *ctype = type->field (index).type (); 382 } 383 break; 384 385 case TYPE_CODE_PTR: 386 if (cname) 387 *cname = string_printf ("*%s", parent->name.c_str ()); 388 389 if (cvalue && value) 390 { 391 try 392 { 393 *cvalue = value_ind (value); 394 } 395 396 catch (const gdb_exception_error &except) 397 { 398 *cvalue = NULL; 399 } 400 } 401 402 /* Don't use get_target_type because it calls 403 check_typedef and here, we want to show the true 404 declared type of the variable. */ 405 if (ctype) 406 *ctype = TYPE_TARGET_TYPE (type); 407 408 if (cfull_expression) 409 *cfull_expression = string_printf ("*(%s)", parent_expression.c_str ()); 410 break; 411 412 default: 413 /* This should not happen. */ 414 if (cname) 415 *cname = "???"; 416 if (cfull_expression) 417 *cfull_expression = "???"; 418 /* Don't set value and type, we don't know then. */ 419 } 420} 421 422static std::string 423c_name_of_child (const struct varobj *parent, int index) 424{ 425 std::string name; 426 427 c_describe_child (parent, index, &name, NULL, NULL, NULL); 428 return name; 429} 430 431static std::string 432c_path_expr_of_child (const struct varobj *child) 433{ 434 std::string path_expr; 435 436 c_describe_child (child->parent, child->index, NULL, NULL, NULL, 437 &path_expr); 438 return path_expr; 439} 440 441static struct value * 442c_value_of_child (const struct varobj *parent, int index) 443{ 444 struct value *value = NULL; 445 446 c_describe_child (parent, index, NULL, &value, NULL, NULL); 447 return value; 448} 449 450static struct type * 451c_type_of_child (const struct varobj *parent, int index) 452{ 453 struct type *type = NULL; 454 455 c_describe_child (parent, index, NULL, NULL, &type, NULL); 456 return type; 457} 458 459/* This returns the type of the variable. It also skips past typedefs 460 to return the real type of the variable. */ 461 462static struct type * 463get_type (const struct varobj *var) 464{ 465 struct type *type; 466 467 type = var->type; 468 if (type != NULL) 469 type = check_typedef (type); 470 471 return type; 472} 473 474static std::string 475c_value_of_variable (const struct varobj *var, 476 enum varobj_display_formats format) 477{ 478 /* BOGUS: if val_print sees a struct/class, or a reference to one, 479 it will print out its children instead of "{...}". So we need to 480 catch that case explicitly. */ 481 struct type *type = get_type (var); 482 483 /* Strip top-level references. */ 484 while (TYPE_IS_REFERENCE (type)) 485 type = check_typedef (TYPE_TARGET_TYPE (type)); 486 487 switch (type->code ()) 488 { 489 case TYPE_CODE_STRUCT: 490 case TYPE_CODE_UNION: 491 return "{...}"; 492 /* break; */ 493 494 case TYPE_CODE_ARRAY: 495 return string_printf ("[%d]", var->num_children); 496 /* break; */ 497 498 default: 499 { 500 if (var->value == NULL) 501 { 502 /* This can happen if we attempt to get the value of a struct 503 member when the parent is an invalid pointer. This is an 504 error condition, so we should tell the caller. */ 505 return std::string (); 506 } 507 else 508 { 509 if (var->not_fetched && value_lazy (var->value.get ())) 510 /* Frozen variable and no value yet. We don't 511 implicitly fetch the value. MI response will 512 use empty string for the value, which is OK. */ 513 return std::string (); 514 515 gdb_assert (varobj_value_is_changeable_p (var)); 516 gdb_assert (!value_lazy (var->value.get ())); 517 518 /* If the specified format is the current one, 519 we can reuse print_value. */ 520 if (format == var->format) 521 return var->print_value; 522 else 523 return varobj_value_get_print_value (var->value.get (), format, 524 var); 525 } 526 } 527 } 528} 529 530 531/* varobj operations for c. */ 532 533const struct lang_varobj_ops c_varobj_ops = 534{ 535 c_number_of_children, 536 c_name_of_variable, 537 c_name_of_child, 538 c_path_expr_of_child, 539 c_value_of_child, 540 c_type_of_child, 541 c_value_of_variable, 542 varobj_default_value_is_changeable_p, 543 NULL, /* value_has_mutated */ 544 c_is_path_expr_parent /* is_path_expr_parent */ 545}; 546 547/* A little convenience enum for dealing with C++. */ 548enum vsections 549{ 550 v_public = 0, v_private, v_protected 551}; 552 553/* C++ */ 554 555static int 556cplus_number_of_children (const struct varobj *var) 557{ 558 struct value *value = NULL; 559 struct type *type; 560 int children, dont_know; 561 int lookup_actual_type = 0; 562 struct value_print_options opts; 563 564 dont_know = 1; 565 children = 0; 566 567 get_user_print_options (&opts); 568 569 if (!CPLUS_FAKE_CHILD (var)) 570 { 571 type = varobj_get_value_type (var); 572 573 /* It is necessary to access a real type (via RTTI). */ 574 if (opts.objectprint) 575 { 576 value = var->value.get (); 577 lookup_actual_type = (TYPE_IS_REFERENCE (var->type) 578 || var->type->code () == TYPE_CODE_PTR); 579 } 580 adjust_value_for_child_access (&value, &type, NULL, lookup_actual_type); 581 582 if (((type->code ()) == TYPE_CODE_STRUCT) 583 || ((type->code ()) == TYPE_CODE_UNION)) 584 { 585 int kids[3]; 586 587 cplus_class_num_children (type, kids); 588 if (kids[v_public] != 0) 589 children++; 590 if (kids[v_private] != 0) 591 children++; 592 if (kids[v_protected] != 0) 593 children++; 594 595 /* Add any baseclasses. */ 596 children += TYPE_N_BASECLASSES (type); 597 dont_know = 0; 598 599 /* FIXME: save children in var. */ 600 } 601 } 602 else 603 { 604 int kids[3]; 605 606 type = varobj_get_value_type (var->parent); 607 608 /* It is necessary to access a real type (via RTTI). */ 609 if (opts.objectprint) 610 { 611 const struct varobj *parent = var->parent; 612 613 value = parent->value.get (); 614 lookup_actual_type = (TYPE_IS_REFERENCE (parent->type) 615 || parent->type->code () == TYPE_CODE_PTR); 616 } 617 adjust_value_for_child_access (&value, &type, NULL, lookup_actual_type); 618 619 cplus_class_num_children (type, kids); 620 if (var->name == "public") 621 children = kids[v_public]; 622 else if (var->name == "private") 623 children = kids[v_private]; 624 else 625 children = kids[v_protected]; 626 dont_know = 0; 627 } 628 629 if (dont_know) 630 children = c_number_of_children (var); 631 632 return children; 633} 634 635/* Compute # of public, private, and protected variables in this class. 636 That means we need to descend into all baseclasses and find out 637 how many are there, too. */ 638 639static void 640cplus_class_num_children (struct type *type, int children[3]) 641{ 642 int i, vptr_fieldno; 643 struct type *basetype = NULL; 644 645 children[v_public] = 0; 646 children[v_private] = 0; 647 children[v_protected] = 0; 648 649 vptr_fieldno = get_vptr_fieldno (type, &basetype); 650 for (i = TYPE_N_BASECLASSES (type); i < type->num_fields (); i++) 651 { 652 /* If we have a virtual table pointer, omit it. Even if virtual 653 table pointers are not specifically marked in the debug info, 654 they should be artificial. */ 655 if ((type == basetype && i == vptr_fieldno) 656 || TYPE_FIELD_ARTIFICIAL (type, i)) 657 continue; 658 659 if (TYPE_FIELD_PROTECTED (type, i)) 660 children[v_protected]++; 661 else if (TYPE_FIELD_PRIVATE (type, i)) 662 children[v_private]++; 663 else 664 children[v_public]++; 665 } 666} 667 668static std::string 669cplus_name_of_variable (const struct varobj *parent) 670{ 671 return c_name_of_variable (parent); 672} 673 674enum accessibility { private_field, protected_field, public_field }; 675 676/* Check if field INDEX of TYPE has the specified accessibility. 677 Return 0 if so and 1 otherwise. */ 678 679static int 680match_accessibility (struct type *type, int index, enum accessibility acc) 681{ 682 if (acc == private_field && TYPE_FIELD_PRIVATE (type, index)) 683 return 1; 684 else if (acc == protected_field && TYPE_FIELD_PROTECTED (type, index)) 685 return 1; 686 else if (acc == public_field && !TYPE_FIELD_PRIVATE (type, index) 687 && !TYPE_FIELD_PROTECTED (type, index)) 688 return 1; 689 else 690 return 0; 691} 692 693static void 694cplus_describe_child (const struct varobj *parent, int index, 695 std::string *cname, struct value **cvalue, struct type **ctype, 696 std::string *cfull_expression) 697{ 698 struct value *value; 699 struct type *type; 700 int was_ptr; 701 int lookup_actual_type = 0; 702 const char *parent_expression = NULL; 703 const struct varobj *var; 704 struct value_print_options opts; 705 706 if (cname) 707 *cname = std::string (); 708 if (cvalue) 709 *cvalue = NULL; 710 if (ctype) 711 *ctype = NULL; 712 if (cfull_expression) 713 *cfull_expression = std::string (); 714 715 get_user_print_options (&opts); 716 717 var = (CPLUS_FAKE_CHILD (parent)) ? parent->parent : parent; 718 if (opts.objectprint) 719 lookup_actual_type = (TYPE_IS_REFERENCE (var->type) 720 || var->type->code () == TYPE_CODE_PTR); 721 value = var->value.get (); 722 type = varobj_get_value_type (var); 723 if (cfull_expression) 724 parent_expression 725 = varobj_get_path_expr (varobj_get_path_expr_parent (var)); 726 727 adjust_value_for_child_access (&value, &type, &was_ptr, lookup_actual_type); 728 729 if (type->code () == TYPE_CODE_STRUCT 730 || type->code () == TYPE_CODE_UNION) 731 { 732 const char *join = was_ptr ? "->" : "."; 733 734 if (CPLUS_FAKE_CHILD (parent)) 735 { 736 /* The fields of the class type are ordered as they 737 appear in the class. We are given an index for a 738 particular access control type ("public","protected", 739 or "private"). We must skip over fields that don't 740 have the access control we are looking for to properly 741 find the indexed field. */ 742 int type_index = TYPE_N_BASECLASSES (type); 743 enum accessibility acc = public_field; 744 int vptr_fieldno; 745 struct type *basetype = NULL; 746 const char *field_name; 747 748 vptr_fieldno = get_vptr_fieldno (type, &basetype); 749 if (parent->name == "private") 750 acc = private_field; 751 else if (parent->name == "protected") 752 acc = protected_field; 753 754 while (index >= 0) 755 { 756 if ((type == basetype && type_index == vptr_fieldno) 757 || TYPE_FIELD_ARTIFICIAL (type, type_index)) 758 ; /* ignore vptr */ 759 else if (match_accessibility (type, type_index, acc)) 760 --index; 761 ++type_index; 762 } 763 --type_index; 764 765 /* If the type is anonymous and the field has no name, 766 set an appropriate name. */ 767 field_name = TYPE_FIELD_NAME (type, type_index); 768 if (field_name == NULL || *field_name == '\0') 769 { 770 if (cname) 771 { 772 if (type->field (type_index).type ()->code () 773 == TYPE_CODE_STRUCT) 774 *cname = ANONYMOUS_STRUCT_NAME; 775 else if (type->field (type_index).type ()->code () 776 == TYPE_CODE_UNION) 777 *cname = ANONYMOUS_UNION_NAME; 778 } 779 780 if (cfull_expression) 781 *cfull_expression = std::string (); 782 } 783 else 784 { 785 if (cname) 786 *cname = TYPE_FIELD_NAME (type, type_index); 787 788 if (cfull_expression) 789 *cfull_expression 790 = string_printf ("((%s)%s%s)", parent_expression, join, 791 field_name); 792 } 793 794 if (cvalue && value) 795 *cvalue = value_struct_element_index (value, type_index); 796 797 if (ctype) 798 *ctype = type->field (type_index).type (); 799 } 800 else if (index < TYPE_N_BASECLASSES (type)) 801 { 802 /* This is a baseclass. */ 803 if (cname) 804 *cname = TYPE_FIELD_NAME (type, index); 805 806 if (cvalue && value) 807 *cvalue = value_cast (type->field (index).type (), value); 808 809 if (ctype) 810 { 811 *ctype = type->field (index).type (); 812 } 813 814 if (cfull_expression) 815 { 816 const char *ptr = was_ptr ? "*" : ""; 817 818 /* Cast the parent to the base' type. Note that in gdb, 819 expression like 820 (Base1)d 821 will create an lvalue, for all appearences, so we don't 822 need to use more fancy: 823 *(Base1*)(&d) 824 construct. 825 826 When we are in the scope of the base class or of one 827 of its children, the type field name will be interpreted 828 as a constructor, if it exists. Therefore, we must 829 indicate that the name is a class name by using the 830 'class' keyword. See PR mi/11912 */ 831 *cfull_expression = string_printf ("(%s(class %s%s) %s)", 832 ptr, 833 TYPE_FIELD_NAME (type, index), 834 ptr, 835 parent_expression); 836 } 837 } 838 else 839 { 840 const char *access = NULL; 841 int children[3]; 842 843 cplus_class_num_children (type, children); 844 845 /* Everything beyond the baseclasses can 846 only be "public", "private", or "protected" 847 848 The special "fake" children are always output by varobj in 849 this order. So if INDEX == 2, it MUST be "protected". */ 850 index -= TYPE_N_BASECLASSES (type); 851 switch (index) 852 { 853 case 0: 854 if (children[v_public] > 0) 855 access = "public"; 856 else if (children[v_private] > 0) 857 access = "private"; 858 else 859 access = "protected"; 860 break; 861 case 1: 862 if (children[v_public] > 0) 863 { 864 if (children[v_private] > 0) 865 access = "private"; 866 else 867 access = "protected"; 868 } 869 else if (children[v_private] > 0) 870 access = "protected"; 871 break; 872 case 2: 873 /* Must be protected. */ 874 access = "protected"; 875 break; 876 default: 877 /* error! */ 878 break; 879 } 880 881 gdb_assert (access); 882 if (cname) 883 *cname = access; 884 885 /* Value and type and full expression are null here. */ 886 } 887 } 888 else 889 { 890 c_describe_child (parent, index, cname, cvalue, ctype, cfull_expression); 891 } 892} 893 894static std::string 895cplus_name_of_child (const struct varobj *parent, int index) 896{ 897 std::string name; 898 899 cplus_describe_child (parent, index, &name, NULL, NULL, NULL); 900 return name; 901} 902 903static std::string 904cplus_path_expr_of_child (const struct varobj *child) 905{ 906 std::string path_expr; 907 908 cplus_describe_child (child->parent, child->index, NULL, NULL, NULL, 909 &path_expr); 910 return path_expr; 911} 912 913static struct value * 914cplus_value_of_child (const struct varobj *parent, int index) 915{ 916 struct value *value = NULL; 917 918 cplus_describe_child (parent, index, NULL, &value, NULL, NULL); 919 return value; 920} 921 922static struct type * 923cplus_type_of_child (const struct varobj *parent, int index) 924{ 925 struct type *type = NULL; 926 927 cplus_describe_child (parent, index, NULL, NULL, &type, NULL); 928 return type; 929} 930 931static std::string 932cplus_value_of_variable (const struct varobj *var, 933 enum varobj_display_formats format) 934{ 935 936 /* If we have one of our special types, don't print out 937 any value. */ 938 if (CPLUS_FAKE_CHILD (var)) 939 return std::string (); 940 941 return c_value_of_variable (var, format); 942} 943 944 945/* varobj operations for c++. */ 946 947const struct lang_varobj_ops cplus_varobj_ops = 948{ 949 cplus_number_of_children, 950 cplus_name_of_variable, 951 cplus_name_of_child, 952 cplus_path_expr_of_child, 953 cplus_value_of_child, 954 cplus_type_of_child, 955 cplus_value_of_variable, 956 varobj_default_value_is_changeable_p, 957 NULL, /* value_has_mutated */ 958 c_is_path_expr_parent /* is_path_expr_parent */ 959}; 960 961 962