[binutils-gdb] Add attribute::as_virtuality method

Tom Tromey tromey@sourceware.org
Wed Sep 30 02:37:32 GMT 2020


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=23dca5c3d77252ad8000d749b4457f7e286b8367

commit 23dca5c3d77252ad8000d749b4457f7e286b8367
Author: Tom Tromey <tom@tromey.com>
Date:   Tue Sep 29 18:49:08 2020 -0600

    Add attribute::as_virtuality method
    
    This adds a new attribute::as_virtuality method and changes the DWARF
    reader to use it.  This also ensures that the attibute's form will now
    be respected.
    
    gdb/ChangeLog
    2020-09-29  Tom Tromey  <tom@tromey.com>
    
            * dwarf2/read.c (dwarf2_add_field, dwarf2_add_member_fn): Update.
            * dwarf2/attribute.h (struct attribute) <as_virtuality>: New
            method.
            * dwarf2/attribute.c (attribute::as_virtuality): New method.

Diff:
---
 gdb/ChangeLog          |  7 +++++++
 gdb/dwarf2/attribute.c | 23 +++++++++++++++++++++++
 gdb/dwarf2/attribute.h |  5 +++++
 gdb/dwarf2/read.c      |  4 ++--
 4 files changed, 37 insertions(+), 2 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 02f686ea43e..f21e549849a 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,10 @@
+2020-09-29  Tom Tromey  <tom@tromey.com>
+
+	* dwarf2/read.c (dwarf2_add_field, dwarf2_add_member_fn): Update.
+	* dwarf2/attribute.h (struct attribute) <as_virtuality>: New
+	method.
+	* dwarf2/attribute.c (attribute::as_virtuality): New method.
+
 2020-09-29  Tom Tromey  <tom@tromey.com>
 
 	* dwarf2/die.h (struct die_info) <addr_base, ranges_base>: Check
diff --git a/gdb/dwarf2/attribute.c b/gdb/dwarf2/attribute.c
index 1e5613963c1..95c5fe427f0 100644
--- a/gdb/dwarf2/attribute.c
+++ b/gdb/dwarf2/attribute.c
@@ -222,3 +222,26 @@ attribute::defaulted () const
 	       plongest (value));
   return DW_DEFAULTED_no;
 }
+
+/* See attribute.h.  */
+
+dwarf_virtuality_attribute
+attribute::as_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 the form was not constant, we already complained in
+     constant_value, so there's no need to complain again.  */
+  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 0e29f80d321..8890fdba88e 100644
--- a/gdb/dwarf2/attribute.h
+++ b/gdb/dwarf2/attribute.h
@@ -258,6 +258,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 as_virtuality () const;
+
   ENUM_BITFIELD(dwarf_attribute) name : 15;
 
   /* A boolean that is used for forms that require reprocessing.  A
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 86a7918a4de..6653aee1497 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -15021,7 +15021,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->as_virtuality ();
   else
     new_field->virtuality = DW_VIRTUALITY_none;
 
@@ -15722,7 +15722,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->as_virtuality () != DW_VIRTUALITY_none)
 	{
 	  /* GCC does this, as of 2008-08-25; PR debug/37237.  */
 	  complaint (_("Member function \"%s\" (offset %s) is virtual "


More information about the Gdb-cvs mailing list