aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2020-09-29 18:49:08 -0600
committerTom Tromey <tom@tromey.com>2020-09-29 20:29:07 -0600
commitbf23a26804608145c316c7516b1aceecc055a888 (patch)
treebe20da9ed4760c0ba74a3da2a6a32a5bd1d3be39
parent7a5f294dbd11a64f5231f0fecdb163e3c7ecfaf8 (diff)
downloadgdb-bf23a26804608145c316c7516b1aceecc055a888.zip
gdb-bf23a26804608145c316c7516b1aceecc055a888.tar.gz
gdb-bf23a26804608145c316c7516b1aceecc055a888.tar.bz2
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 <tom@tromey.com> * 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.
-rw-r--r--gdb/ChangeLog7
-rw-r--r--gdb/dwarf2/read.c41
2 files changed, 26 insertions, 22 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 5418288..6fa5fff 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,12 @@
2020-09-29 Tom Tromey <tom@tromey.com>
+ * 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 <tom@tromey.com>
+
* dwarf2/read.c (skip_one_die): Update.
(read_full_die_1): Change how reprocessing is done.
(partial_die_info::read): Update.
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 0ce07df..fe9522c 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: