From c191a6875b118fce30e7dc4d9e4bd20eff850270 Mon Sep 17 00:00:00 2001 From: Keith Seitz Date: Mon, 16 Oct 2017 17:19:29 -0700 Subject: Record and output access specifiers for nested typedefs We currently do not record access information for typedefs defined inside classes. Consider: struct foo { typedef int PUBLIC; private: typedef int PRIVATE; PRIVATE b; }; (gdb) ptype foo type = struct foo { private: PRIVATE b; typedef int PRIVATE; typedef int PUBLIC; } This patch fixes this: (gdb) ptype foo type = struct foo { private: PRIVATE b; typedef int PRIVATE; public: typedef int PUBLIC; } gdb/ChangeLog: * c-typeprint.c (enum access_specifier): Moved here from c_type_print_base. (output_access_specifier): New function. (c_type_print_base): Consider typedefs when assessing whether access labels are needed. Use output_access_specifier as needed. Output access specifier for typedefs, if needed. * dwarf2read.c (dwarf2_add_typedef): Record DW_AT_accessibility. * gdbtypes.h (struct typedef_field) : New fields. (TYPE_TYPEDEF_FIELD_PROTECTED, TYPE_TYPEDEF_FIELD_PRIVATE): New accessor macros. gdb/testsuite/ChangeLog: * gdb.cp/classes.cc (class_with_typedefs, class_with_public_typedef) (class_with_protected_typedef, class_with_private_typedef) (struct_with_public_typedef, struct_with_protected_typedef) (struct_with_private_typedef): New classes/structs. * gdb.cp/classes.exp (test_ptype_class_objects): Add tests for typedefs and access specifiers. --- gdb/dwarf2read.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'gdb/dwarf2read.c') diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c index af4bb648a0c..f27d9b96afe 100644 --- a/gdb/dwarf2read.c +++ b/gdb/dwarf2read.c @@ -13112,6 +13112,28 @@ dwarf2_add_typedef (struct field_info *fip, struct die_info *die, fp->type = read_type_die (die, cu); + /* Save accessibility. */ + enum dwarf_access_attribute accessibility; + struct attribute *attr = dwarf2_attr (die, DW_AT_accessibility, cu); + if (attr != NULL) + accessibility = (enum dwarf_access_attribute) DW_UNSND (attr); + else + accessibility = dwarf2_default_access_attribute (die, cu); + switch (accessibility) + { + case DW_ACCESS_public: + /* The assumed value if neither private nor protected. */ + break; + case DW_ACCESS_private: + fp->is_private = 1; + break; + case DW_ACCESS_protected: + fp->is_protected = 1; + break; + default: + gdb_assert_not_reached ("unexpected accessibility attribute"); + } + new_field->next = fip->typedef_field_list; fip->typedef_field_list = new_field; fip->typedef_field_list_count++; -- cgit v1.2.1