From: Tom Tromey Date: Wed, 30 Sep 2020 00:49:08 +0000 (-0600) Subject: Change how accessibility is handled in dwarf2/read.c X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=bf23a26804608145c316c7516b1aceecc055a888;p=binutils-gdb.git Change how accessibility is handled in dwarf2/read.c dwarf2/read.c uses dwarf2_default_access_attribute to check for the default access attribute. This patch simplifies the code by moving more of the access processing into this function, changing its name to reflect the difference. This also ensures that the attribute's form is respected, by changing to code to use the constant_value method. gdb/ChangeLog 2020-09-29 Tom Tromey * dwarf2/read.c (dwarf2_access_attribute): Rename from dwarf2_default_access_attribute. Look up attribute. (dwarf2_add_field, dwarf2_add_type_defn, dwarf2_add_member_fn): Update. --- diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 5418288e277..6fa5fffb1cc 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,10 @@ +2020-09-29 Tom Tromey + + * dwarf2/read.c (dwarf2_access_attribute): Rename from + dwarf2_default_access_attribute. Look up attribute. + (dwarf2_add_field, dwarf2_add_type_defn, dwarf2_add_member_fn): + Update. + 2020-09-29 Tom Tromey * dwarf2/read.c (skip_one_die): Update. diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 0ce07dfa9a9..fe9522c87e0 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -14864,12 +14864,25 @@ producer_is_codewarrior (struct dwarf2_cu *cu) return cu->producer_is_codewarrior; } -/* Return the default accessibility type if it is not overridden by - DW_AT_accessibility. */ +/* Return the accessibility of DIE, as given by DW_AT_accessibility. + If that attribute is not available, return the appropriate + default. */ static enum dwarf_access_attribute -dwarf2_default_access_attribute (struct die_info *die, struct dwarf2_cu *cu) +dwarf2_access_attribute (struct die_info *die, struct dwarf2_cu *cu) { + attribute *attr = dwarf2_attr (die, DW_AT_accessibility, cu); + if (attr != nullptr) + { + LONGEST value = attr->constant_value (-1); + if (value == DW_ACCESS_public + || value == DW_ACCESS_protected + || value == DW_ACCESS_private) + return (dwarf_access_attribute) value; + complaint (_("Unhandled DW_AT_accessibility value (%s)"), + plongest (value)); + } + if (cu->header.version < 3 || producer_is_gxx_lt_4_6 (cu)) { /* The default DWARF 2 accessibility for members is public, the default @@ -15002,11 +15015,7 @@ dwarf2_add_field (struct field_info *fip, struct die_info *die, new_field->offset = die->sect_off; - attr = dwarf2_attr (die, DW_AT_accessibility, cu); - if (attr != nullptr) - new_field->accessibility = DW_UNSND (attr); - else - new_field->accessibility = dwarf2_default_access_attribute (die, cu); + new_field->accessibility = dwarf2_access_attribute (die, cu); if (new_field->accessibility != DW_ACCESS_public) fip->non_public_fields = true; @@ -15193,12 +15202,7 @@ dwarf2_add_type_defn (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); + dwarf_access_attribute accessibility = dwarf2_access_attribute (die, cu); switch (accessibility) { case DW_ACCESS_public: @@ -15210,8 +15214,6 @@ dwarf2_add_type_defn (struct field_info *fip, struct die_info *die, case DW_ACCESS_protected: fp.is_protected = 1; break; - default: - complaint (_("Unhandled DW_AT_accessibility value (%x)"), accessibility); } if (die->tag == DW_TAG_typedef) @@ -15568,7 +15570,6 @@ dwarf2_add_member_fn (struct field_info *fip, struct die_info *die, struct fn_field *fnp; const char *fieldname; struct type *this_type; - enum dwarf_access_attribute accessibility; if (cu->language == language_ada) error (_("unexpected member function in Ada type")); @@ -15647,11 +15648,7 @@ dwarf2_add_member_fn (struct field_info *fip, struct die_info *die, is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */ /* Get accessibility. */ - attr = dwarf2_attr (die, DW_AT_accessibility, cu); - if (attr != nullptr) - accessibility = (enum dwarf_access_attribute) DW_UNSND (attr); - else - accessibility = dwarf2_default_access_attribute (die, cu); + dwarf_access_attribute accessibility = dwarf2_access_attribute (die, cu); switch (accessibility) { case DW_ACCESS_private: