From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 66207 invoked by alias); 25 Jun 2017 18:52:18 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 66198 invoked by uid 89); 25 Jun 2017 18:52:17 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.4 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_SORBS_SPAM,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 25 Jun 2017 18:52:16 +0000 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A2FF987649 for ; Sun, 25 Jun 2017 18:52:14 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com A2FF987649 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=keiths@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com A2FF987649 Received: from valrhona.Home (ovpn04.gateway.prod.ext.phx2.redhat.com [10.5.9.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 75B9417106 for ; Sun, 25 Jun 2017 18:52:14 +0000 (UTC) From: Keith Seitz To: gdb-patches@sourceware.org Subject: [PATCH] Record/output access specifiers for class typedefs Date: Sun, 25 Jun 2017 18:52:00 -0000 Message-Id: <1498416734-14498-1-git-send-email-keiths@redhat.com> X-IsSubscribed: yes X-SW-Source: 2017-06/txt/msg00692.txt.bz2 We do not currently record/output accessibility for typedefs defined in a class: (gdb) list 71 struct typedef_struct { 72 public: 73 typedef int public_int; 74 public_int a; 75 protected: 76 typedef int protected_int; 77 protected_int b; 78 private: 79 typedef int private_int; 80 private_int c; 81 protected: 82 typedef float protected_float; 83 protected_float d; 84 private: 85 typedef float private_float; 86 private_float e; 87 public: 88 typedef float public_float; 89 public_float f; 90 }; (gdb) ptype typedef_struct type = struct typedef_struct { public: public_int a; protected: public_int b; private: public_int c; protected: protected_float d; private: protected_float e; public: protected_float f; typedef int public_int; typedef int protected_int; typedef int private_int; typedef float protected_float; typedef float private_float; typedef float public_float; } This patch modifies the DWARF reader to record accessibility when reading in typedef DIEs. gdb/ChangeLog: yyyy-mm-dd Keith Seitz * c-typeprint.c (c_type_print_base): Output access specifiers for any class-defined typedefs. * dwarf2read.c (dwarf2_add_typedef): Record DW_AT_accessibility. * gdbtypes.h (struct typedef_field) : New fields. (TYPE_TYPEDEF_FIELD_PUBLIC,TYPE_TYPEDEF_FIELD_PROTECTED) (TYPE_TYPEDEF_FIELD_PRIVATE): New macros. gdb/testsuite/ChangeLog: yyyy-mm-dd Keith Seitz * gdb.cp/classes.cc (struct typedef_struct): New struct. (typedef_s): New variable. * gdb.cp/classes.exp (ptype_class_objects): Add test for typedef_struct. --- gdb/c-typeprint.c | 29 +++++++++++++++++++++++++++++ gdb/dwarf2read.c | 23 +++++++++++++++++++++++ gdb/gdbtypes.h | 18 ++++++++++++++++++ gdb/testsuite/gdb.cp/classes.cc | 22 ++++++++++++++++++++++ gdb/testsuite/gdb.cp/classes.exp | 17 +++++++++++++++++ 5 files changed, 109 insertions(+) diff --git a/gdb/c-typeprint.c b/gdb/c-typeprint.c index 9e197f5..b38d3b4 100644 --- a/gdb/c-typeprint.c +++ b/gdb/c-typeprint.c @@ -1319,6 +1319,35 @@ c_type_print_base (struct type *type, struct ui_file *stream, gdb_assert (TYPE_CODE (target) == TYPE_CODE_TYPEDEF); target = TYPE_TARGET_TYPE (target); + if (TYPE_TYPEDEF_FIELD_PROTECTED (type, i)) + { + if (section_type != s_protected) + { + section_type = s_protected; + fprintfi_filtered (level + 2, stream, + "protected:\n"); + } + } + else if (TYPE_TYPEDEF_FIELD_PRIVATE (type, i)) + { + if (section_type != s_private) + { + section_type = s_private; + fprintfi_filtered (level + 2, stream, + "private:\n"); + } + } + else + { + gdb_assert (TYPE_TYPEDEF_FIELD_PUBLIC (type, i)); + if (section_type != s_public) + { + section_type = s_public; + fprintfi_filtered (level + 2, stream, + "public:\n"); + } + } + print_spaces_filtered (level + 4, stream); fprintf_filtered (stream, "typedef "); diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c index 2369d4b..922e81d 100644 --- a/gdb/dwarf2read.c +++ b/gdb/dwarf2read.c @@ -12987,6 +12987,29 @@ dwarf2_add_typedef (struct field_info *fip, struct die_info *die, fp->type = read_type_die (die, cu); + /* Save accessibility. */ + struct attribute *attr = dwarf2_attr (die, DW_AT_accessibility, cu); + enum dwarf_access_attribute accessibility; + + 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: + fp->is_public = 1; + 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++; diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h index 6f896db..4efaab2 100644 --- a/gdb/gdbtypes.h +++ b/gdb/gdbtypes.h @@ -884,6 +884,18 @@ struct typedef_field /* * Type this typedef named NAME represents. */ struct type *type; + + /* * True if this field was declared public, false otherwise. */ + unsigned int is_public : 1; + + /* * True if this field was declared protected, false otherwise. */ + unsigned int is_protected : 1; + + /* * True if this field was declared private, false otherwise. */ + unsigned int is_private : 1; + + /* * Unused. */ + unsigned int dummy : 13; }; /* * C++ language-specific information for TYPE_CODE_STRUCT and @@ -1429,6 +1441,12 @@ extern void set_type_vptr_basetype (struct type *, struct type *); TYPE_TYPEDEF_FIELD (thistype, n).type #define TYPE_TYPEDEF_FIELD_COUNT(thistype) \ TYPE_CPLUS_SPECIFIC (thistype)->typedef_field_count +#define TYPE_TYPEDEF_FIELD_PUBLIC(thistype, n) \ + TYPE_TYPEDEF_FIELD (thistype, n).is_public +#define TYPE_TYPEDEF_FIELD_PROTECTED(thistype, n) \ + TYPE_TYPEDEF_FIELD (thistype, n).is_protected +#define TYPE_TYPEDEF_FIELD_PRIVATE(thistype, n) \ + TYPE_TYPEDEF_FIELD (thistype, n).is_private #define TYPE_IS_OPAQUE(thistype) \ (((TYPE_CODE (thistype) == TYPE_CODE_STRUCT) \ diff --git a/gdb/testsuite/gdb.cp/classes.cc b/gdb/testsuite/gdb.cp/classes.cc index 2a81473..1aa9f84 100644 --- a/gdb/testsuite/gdb.cp/classes.cc +++ b/gdb/testsuite/gdb.cp/classes.cc @@ -68,6 +68,27 @@ struct mixed_protection_struct { int i; }; +struct typedef_struct { +public: + typedef int public_int; + public_int a; +protected: + typedef int protected_int; + protected_int b; +private: + typedef int private_int; + private_int c; +protected: + typedef float protected_float; + protected_float d; +private: + typedef float private_float; + private_float e; +public: + typedef float public_float; + public_float f; +}; + class public_class { public: int a; @@ -624,3 +645,4 @@ protected_class protected_c; default_private_class default_private_c; explicit_private_class explicit_private_c; mixed_protection_class mixed_protection_c; +typedef_struct typedef_s; diff --git a/gdb/testsuite/gdb.cp/classes.exp b/gdb/testsuite/gdb.cp/classes.exp index 256fa68..eda2327 100644 --- a/gdb/testsuite/gdb.cp/classes.exp +++ b/gdb/testsuite/gdb.cp/classes.exp @@ -84,6 +84,23 @@ proc test_ptype_class_objects {} { { field protected "int i;" } } + cp_test_ptype_class \ + "struct typedef_struct" "" "struct" "typedef_struct" \ + { + { field public "typedef_struct::public_int a;" } + { field protected "typedef_struct::protected_int b;" } + { field private "typedef_struct::private_int c;" } + { field protected "typedef_struct::protected_float d;" } + { field private "typedef_struct::private_float e;" } + { field public "typedef_struct::public_float f;" } + { typedef public "typedef int public_int;" } + { typedef protected "typedef int protected_int;" } + { typedef private "typedef int private_int;" } + { typedef protected "typedef float protected_float;" } + { typedef private "typedef float private_float;" } + { typedef public "typedef float public_float;" } + } + # All that again with "class" instead of "struct". # gdb does not care about the difference anyways. -- 2.1.0