diff options
author | Tom Tromey <tom@tromey.com> | 2020-04-24 15:35:01 -0600 |
---|---|---|
committer | Tom Tromey <tromey@adacore.com> | 2020-04-24 15:35:02 -0600 |
commit | e61108c92d4bc4021ab89671612308c01b18e15d (patch) | |
tree | 02aaf1bc391c6ae0754631220fa0e68e55720ca3 | |
parent | 8c87a4527f5102b124ad0128894b1195d80eef73 (diff) | |
download | gdb-e61108c92d4bc4021ab89671612308c01b18e15d.zip gdb-e61108c92d4bc4021ab89671612308c01b18e15d.tar.gz gdb-e61108c92d4bc4021ab89671612308c01b18e15d.tar.bz2 |
Add attribute::value_as_string method
The full DIE reader checks that an attribute has a "string" form in
some spots, but the partial DIE reader does not. This patch brings
the two readers in sync for one specific case, namely when examining
the linkage name. This avoids regressions in an existing DWARF test
case.
A full fix for this problem would be preferable. An accessor like
DW_STRING should always check the form. However, I haven't attempted
that in this series.
Also the fact that the partial and full readers can disagree like this
is a design flaw.
gdb/ChangeLog
2020-04-24 Tom Tromey <tom@tromey.com>
* dwarf2/read.c (partial_die_info::read) <case
DW_AT_linkage_name>: Use value_as_string.
(dwarf2_string_attr): Use value_as_string.
* dwarf2/attribute.h (struct attribute) <value_as_string>: Declare
method.
* dwarf2/attribute.c (attribute::value_as_string): New method.
-rw-r--r-- | gdb/ChangeLog | 9 | ||||
-rw-r--r-- | gdb/dwarf2/attribute.c | 18 | ||||
-rw-r--r-- | gdb/dwarf2/attribute.h | 4 | ||||
-rw-r--r-- | gdb/dwarf2/read.c | 15 |
4 files changed, 34 insertions, 12 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 6a8d82f..df43ffd 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,14 @@ 2020-04-24 Tom Tromey <tom@tromey.com> + * dwarf2/read.c (partial_die_info::read) <case + DW_AT_linkage_name>: Use value_as_string. + (dwarf2_string_attr): Use value_as_string. + * dwarf2/attribute.h (struct attribute) <value_as_string>: Declare + method. + * dwarf2/attribute.c (attribute::value_as_string): New method. + +2020-04-24 Tom Tromey <tom@tromey.com> + * symtab.c (general_symbol_info::natural_name) (general_symbol_info::demangled_name): Check for language_rust. diff --git a/gdb/dwarf2/attribute.c b/gdb/dwarf2/attribute.c index 9ceacf0..9f808aa 100644 --- a/gdb/dwarf2/attribute.c +++ b/gdb/dwarf2/attribute.c @@ -61,6 +61,24 @@ attribute::value_as_address () const /* See attribute.h. */ +const char * +attribute::value_as_string () const +{ + if (form == DW_FORM_strp || form == DW_FORM_line_strp + || form == DW_FORM_string + || form == DW_FORM_strx + || form == DW_FORM_strx1 + || form == DW_FORM_strx2 + || form == DW_FORM_strx3 + || form == DW_FORM_strx4 + || form == DW_FORM_GNU_str_index + || form == DW_FORM_GNU_strp_alt) + return DW_STRING (this); + return nullptr; +} + +/* See attribute.h. */ + bool attribute::form_is_block () const { diff --git a/gdb/dwarf2/attribute.h b/gdb/dwarf2/attribute.h index 69b3351..a9cabd6 100644 --- a/gdb/dwarf2/attribute.h +++ b/gdb/dwarf2/attribute.h @@ -46,6 +46,10 @@ struct attribute attribute's form into account. */ CORE_ADDR value_as_address () const; + /* If the attribute has a string form, return the string value; + otherwise return NULL. */ + const char *value_as_string () const; + /* Return non-zero if ATTR's value is a section offset --- classes lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise. You may use DW_UNSND (attr) to retrieve such offsets. diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index a221394..5663d7d 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -18300,7 +18300,7 @@ partial_die_info::read (const struct die_reader_specs *reader, /* Note that both forms of linkage name might appear. We assume they will be the same, and we only store the last one we see. */ - linkage_name = DW_STRING (&attr); + linkage_name = attr.value_as_string (); /* rustc emits invalid values for DW_AT_linkage_name. Ignore these. See https://github.com/rust-lang/rust/issues/32925. */ if (cu->language == language_rust && linkage_name != NULL @@ -19485,17 +19485,8 @@ dwarf2_string_attr (struct die_info *die, unsigned int name, struct dwarf2_cu *c if (attr != NULL) { - if (attr->form == DW_FORM_strp || attr->form == DW_FORM_line_strp - || attr->form == DW_FORM_string - || attr->form == DW_FORM_strx - || attr->form == DW_FORM_strx1 - || attr->form == DW_FORM_strx2 - || attr->form == DW_FORM_strx3 - || attr->form == DW_FORM_strx4 - || attr->form == DW_FORM_GNU_str_index - || attr->form == DW_FORM_GNU_strp_alt) - str = DW_STRING (attr); - else + str = attr->value_as_string (); + if (str == nullptr) complaint (_("string type expected for attribute %s for " "DIE at %s in module %s"), dwarf_attr_name (name), sect_offset_str (die->sect_off), |