[PATCH 18/20] Add attribute::virtuality method

Tom Tromey
2020-03-28T19:22:14Z

This adds a new attribute::virtuality method and changes the DWARF
reader to use it. This also ensures that the attibute's form will now
be respected.

2020-03-28 Tom Tromey <tom@tromey.com>

* dwarf2/read.c (dwarf2_add_field, dwarf2_add_member_fn): Update.
* dwarf2/attribute.h (struct attribute) <virtuality>: New method.
* dwarf2/attribute.c (attribute::virtuality): New method.
---
gdb/ChangeLog | 6 ++++++
gdb/dwarf2/attribute.c | 21 +++++++++++++++++++++
gdb/dwarf2/attribute.h | 5 +++++
gdb/dwarf2/read.c | 4 ++--
4 files changed, 34 insertions(+), 2 deletions(-)

diff --git a/gdb/dwarf2/attribute.c b/gdb/dwarf2/attribute.c
index ee5e6321bde..7f428279757 100644
--- a/gdb/dwarf2/attribute.c
+++ b/gdb/dwarf2/attribute.c
@@ -240,3 +240,24 @@ attribute::defaulted () const
plongest (value));
return DW_DEFAULTED_no;
}
+
+/* See attribute.h. */
+
+dwarf_virtuality_attribute
+attribute::virtuality () const
+{
+ LONGEST value = constant_value (-1);
+
+ switch (value)
+ {
+ case DW_VIRTUALITY_none:
+ case DW_VIRTUALITY_virtual:
+ case DW_VIRTUALITY_pure_virtual:
+ return (dwarf_virtuality_attribute) value;
+ }
+
+ if (form_is_constant ())
+ complaint (_("unrecognized DW_AT_virtuality value (%s)"),
+ plongest (value));
+ return DW_VIRTUALITY_none;
+}
diff --git a/gdb/dwarf2/attribute.h b/gdb/dwarf2/attribute.h
index dce93b154a8..7c0ce1615cf 100644
--- a/gdb/dwarf2/attribute.h
+++ b/gdb/dwarf2/attribute.h
@@ -237,6 +237,11 @@ struct attribute
returned. */
dwarf_defaulted_attribute defaulted () const;

+ /* Return the attribute's value as a dwarf_virtuality_attribute
+ constant according to DWARF spec. An unrecognized value will
+ issue a complaint and return DW_VIRTUALITY_none. */
+ dwarf_virtuality_attribute virtuality () const;
+

ENUM_BITFIELD(dwarf_attribute) name : 15;

diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index ec4e6e2e3b4..66a508c95ea 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -14107,7 +14107,7 @@ dwarf2_add_field (struct field_info *fip, struct die_info *die,

attr = dwarf2_attr (die, DW_AT_virtuality, cu);
if (attr != nullptr)
- new_field->virtuality = DW_UNSND (attr);
+ new_field->virtuality = attr->virtuality ();
else
new_field->virtuality = DW_VIRTUALITY_none;

@@ -14661,7 +14661,7 @@ dwarf2_add_member_fn (struct field_info *fip, struct die_info *die,
else
{
attr = dwarf2_attr (die, DW_AT_virtuality, cu);
- if (attr && DW_UNSND (attr))
+ if (attr != nullptr && attr->virtuality () != DW_VIRTUALITY_none)
{
/* GCC does this, as of 2008-08-25; PR debug/37237. */
complaint (_("Member function \"%s\" (offset %s) is virtual "
--
2.17.2