@@ -59,6 +59,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
{
@@ -45,6 +45,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.
@@ -18031,7 +18031,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
@@ -19200,17 +19200,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),