From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [PATCH 16/20] Change is_valid_DW_AT_defaulted to a method on attribute
Date: Sat, 28 Mar 2020 13:22:04 -0600 [thread overview]
Message-ID: <20200328192208.11324-17-tom@tromey.com> (raw)
In-Reply-To: <20200328192208.11324-1-tom@tromey.com>
This changes is_valid_DW_AT_defaulted to be a method on struct attribute.
Now it correctly respects the form of the attribute.
2020-03-28 Tom Tromey <tom@tromey.com>
* dwarf2/read.c (is_valid_DW_AT_defaulted): Move to attribute.c.
(dwarf2_add_member_fn): Update.
* dwarf2/attribute.h (struct attribute) <defaulted>: Declare.
* dwarf2/attribute.c (attribute::defaulted): New method, from
is_valid_DW_AT_defaulted.
---
gdb/ChangeLog | 8 ++++++++
gdb/dwarf2/attribute.c | 21 +++++++++++++++++++++
gdb/dwarf2/attribute.h | 8 ++++++++
gdb/dwarf2/read.c | 23 ++---------------------
4 files changed, 39 insertions(+), 21 deletions(-)
diff --git a/gdb/dwarf2/attribute.c b/gdb/dwarf2/attribute.c
index 94bedf6dbd3..ee5e6321bde 100644
--- a/gdb/dwarf2/attribute.c
+++ b/gdb/dwarf2/attribute.c
@@ -219,3 +219,24 @@ attribute::form_is_reprocessed () const
|| form == DW_FORM_addrx
|| form == DW_FORM_GNU_addr_index);
}
+
+/* See attribute.h. */
+
+dwarf_defaulted_attribute
+attribute::defaulted () const
+{
+ LONGEST value = constant_value (-1);
+
+ switch (value)
+ {
+ case DW_DEFAULTED_no:
+ case DW_DEFAULTED_in_class:
+ case DW_DEFAULTED_out_of_class:
+ return (dwarf_defaulted_attribute) value;
+ }
+
+ if (form_is_constant ())
+ complaint (_("unrecognized DW_AT_defaulted value (%s)"),
+ plongest (value));
+ return DW_DEFAULTED_no;
+}
diff --git a/gdb/dwarf2/attribute.h b/gdb/dwarf2/attribute.h
index 546156283b3..dce93b154a8 100644
--- a/gdb/dwarf2/attribute.h
+++ b/gdb/dwarf2/attribute.h
@@ -29,6 +29,7 @@
#include "dwarf2.h"
#include "gdbtypes.h"
+#include "gdbsupport/gdb_optional.h"
/* Blocks are a bunch of untyped bytes. */
struct dwarf_block
@@ -229,6 +230,13 @@ struct attribute
return requires_reprocessing;
}
+ /* Return the value as one of the recognized enum
+ dwarf_defaulted_attribute constants according to DWARF5 spec,
+ Table 7.24. If the value is incorrect, or if this attribute has
+ the wrong form, then a complaint is issued and DW_DEFAULTED_no is
+ returned. */
+ dwarf_defaulted_attribute defaulted () const;
+
ENUM_BITFIELD(dwarf_attribute) name : 15;
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index abeb0e1a4e9..ec4e6e2e3b4 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -14479,25 +14479,6 @@ dwarf2_is_constructor (struct die_info *die, struct dwarf2_cu *cu)
&& (type_name[len] == '\0' || type_name[len] == '<'));
}
-/* Check if the given VALUE is a recognized enum
- dwarf_defaulted_attribute constant according to DWARF5 spec,
- Table 7.24. */
-
-static bool
-is_valid_DW_AT_defaulted (ULONGEST value)
-{
- switch (value)
- {
- case DW_DEFAULTED_no:
- case DW_DEFAULTED_in_class:
- case DW_DEFAULTED_out_of_class:
- return true;
- }
-
- complaint (_("unrecognized DW_AT_defaulted value (%s)"), pulongest (value));
- return false;
-}
-
/* Add a member function to the proper fieldlist. */
static void
@@ -14607,8 +14588,8 @@ dwarf2_add_member_fn (struct field_info *fip, struct die_info *die,
/* Check for defaulted methods. */
attr = dwarf2_attr (die, DW_AT_defaulted, cu);
- if (attr != nullptr && is_valid_DW_AT_defaulted (DW_UNSND (attr)))
- fnp->defaulted = (enum dwarf_defaulted_attribute) DW_UNSND (attr);
+ if (attr != nullptr)
+ fnp->defaulted = attr->defaulted ();
/* Check for deleted methods. */
attr = dwarf2_attr (die, DW_AT_deleted, cu);
--
2.17.2
next prev parent reply other threads:[~2020-03-28 19:22 UTC|newest]
Thread overview: 47+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-28 19:21 [PATCH 00/20] Make DWARF attribute references safe Tom Tromey
2020-03-28 19:21 ` [PATCH 01/20] Add attribute::value_as_string method Tom Tromey
2020-03-28 19:21 ` [PATCH 02/20] Rename struct attribute accessors Tom Tromey
2020-03-30 8:58 ` Aktemur, Tankut Baris
2020-03-30 23:39 ` Tom Tromey
2020-03-30 14:45 ` Simon Marchi
2020-03-30 23:39 ` Tom Tromey
2020-03-28 19:21 ` [PATCH 03/20] Avoid using DW_* macros in dwarf2/attribute.c Tom Tromey
2020-03-28 19:21 ` [PATCH 04/20] Change some uses of DW_STRING to string method Tom Tromey
2020-03-30 14:56 ` Simon Marchi
2020-03-30 23:53 ` Tom Tromey
2020-03-28 19:21 ` [PATCH 05/20] Remove some uses of DW_STRING_IS_CANONICAL Tom Tromey
2020-03-30 15:02 ` Simon Marchi
2020-03-31 0:01 ` Tom Tromey
2020-03-28 19:21 ` [PATCH 06/20] Remove DW_STRING and DW_STRING_IS_CANONICAL Tom Tromey
2020-03-30 15:10 ` Simon Marchi
2020-03-31 0:23 ` Tom Tromey
2020-03-28 19:21 ` [PATCH 07/20] Remove DW_BLOCK Tom Tromey
2020-03-30 15:13 ` Simon Marchi
2020-03-28 19:21 ` [PATCH 08/20] Remove DW_SIGNATURE Tom Tromey
2020-03-28 19:21 ` [PATCH 09/20] Remove DW_SND Tom Tromey
2020-03-28 19:21 ` [PATCH 10/20] Use setter for attribute's unsigned value Tom Tromey
2020-03-28 19:21 ` [PATCH 11/20] Add reprocessing flag to struct attribute Tom Tromey
2020-03-30 15:32 ` Simon Marchi
2020-04-04 14:02 ` Tom Tromey
2020-03-28 19:22 ` [PATCH 12/20] Remove DW_ADDR Tom Tromey
2020-03-30 15:40 ` Simon Marchi
2020-04-04 14:05 ` Tom Tromey
2020-03-28 19:22 ` [PATCH 13/20] Change how reprocessing is done Tom Tromey
2020-03-30 15:46 ` Simon Marchi
2020-04-04 14:14 ` Tom Tromey
2020-03-28 19:22 ` [PATCH 14/20] Change how accessibility is handled in dwarf2/read.c Tom Tromey
2020-03-30 15:50 ` Simon Marchi
2020-03-28 19:22 ` [PATCH 15/20] Add attribute::get_unsigned method Tom Tromey
2020-03-30 15:57 ` Simon Marchi
2020-04-04 14:17 ` Tom Tromey
2020-03-28 19:22 ` Tom Tromey [this message]
2020-03-30 16:00 ` [PATCH 16/20] Change is_valid_DW_AT_defaulted to a method on attribute Simon Marchi
2020-04-04 14:23 ` Tom Tromey
2020-03-28 19:22 ` [PATCH 17/20] Change die_info methods to check the attribute's form Tom Tromey
2020-03-30 16:02 ` Simon Marchi
2020-03-30 19:04 ` Tom Tromey
2020-03-30 20:18 ` Simon Marchi
2020-03-30 20:26 ` Tom Tromey
2020-03-28 19:22 ` [PATCH 18/20] Add attribute::virtuality method Tom Tromey
2020-03-28 19:22 ` [PATCH 19/20] Add attribute::boolean method Tom Tromey
2020-03-28 19:22 ` [PATCH 20/20] Remove DW_UNSND Tom Tromey
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200328192208.11324-17-tom@tromey.com \
--to=tom@tromey.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox