aboutsummaryrefslogtreecommitdiff
path: root/gdb/dwarf2/attribute.c
diff options
context:
space:
mode:
authorTom Tromey <tromey@adacore.com>2025-02-06 09:32:48 -0700
committerTom Tromey <tromey@adacore.com>2025-03-18 12:40:58 -0600
commite0a55ad42257771a6bed89130d45d0a24d417759 (patch)
treeb32ebe1a19796bafbdf650d0168a19da792d4cf5 /gdb/dwarf2/attribute.c
parente4d946a97a67fe692b13e64b541b0e8ddb39e2e9 (diff)
downloadbinutils-e0a55ad42257771a6bed89130d45d0a24d417759.zip
binutils-e0a55ad42257771a6bed89130d45d0a24d417759.tar.gz
binutils-e0a55ad42257771a6bed89130d45d0a24d417759.tar.bz2
Introduce and use attribute::unsigned_constant
This introduces a new 'unsigned_constant' method on attribute. This method can be used to get the value as an unsigned number. Unsigned scalar forms are handled, and signed scalar forms are handled as well provided that the value is non-negative. Several spots in the reader that expect small DWARF-defined constants are updated to use this new method. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32680 Approved-By: Simon Marchi <simon.marchi@efficios.com>
Diffstat (limited to 'gdb/dwarf2/attribute.c')
-rw-r--r--gdb/dwarf2/attribute.c71
1 files changed, 49 insertions, 22 deletions
diff --git a/gdb/dwarf2/attribute.c b/gdb/dwarf2/attribute.c
index 3eb32b6..49c0bc0 100644
--- a/gdb/dwarf2/attribute.c
+++ b/gdb/dwarf2/attribute.c
@@ -164,6 +164,27 @@ attribute::constant_value (int default_value) const
/* See attribute.h. */
+std::optional<ULONGEST>
+attribute::unsigned_constant () const
+{
+ if (form_is_strictly_signed ())
+ {
+ if (u.snd >= 0)
+ return u.snd;
+ complaint (_("Attribute value is not unsigned (%s)"),
+ dwarf_form_name (form));
+ }
+ else if (form_is_constant ())
+ return u.unsnd;
+
+ /* For DW_FORM_data16 see attribute::form_is_constant. */
+ complaint (_("Attribute value is not a constant (%s)"),
+ dwarf_form_name (form));
+ return {};
+}
+
+/* See attribute.h. */
+
bool
attribute::form_is_unsigned () const
{
@@ -216,21 +237,24 @@ attribute::form_requires_reprocessing () const
dwarf_defaulted_attribute
attribute::defaulted () const
{
- LONGEST value = constant_value (-1);
+ std::optional<ULONGEST> value = unsigned_constant ();
- switch (value)
+ if (value.has_value ())
{
- case DW_DEFAULTED_no:
- case DW_DEFAULTED_in_class:
- case DW_DEFAULTED_out_of_class:
- return (dwarf_defaulted_attribute) value;
+ switch (*value)
+ {
+ case DW_DEFAULTED_no:
+ case DW_DEFAULTED_in_class:
+ case DW_DEFAULTED_out_of_class:
+ return (dwarf_defaulted_attribute) *value;
+
+ default:
+ complaint (_("unrecognized DW_AT_defaulted value (%s)"),
+ plongest (*value));
+ break;
+ }
}
- /* 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_defaulted value (%s)"),
- plongest (value));
return DW_DEFAULTED_no;
}
@@ -239,21 +263,24 @@ attribute::defaulted () const
dwarf_virtuality_attribute
attribute::as_virtuality () const
{
- LONGEST value = constant_value (-1);
+ std::optional<ULONGEST> value = unsigned_constant ();
- switch (value)
+ if (value.has_value ())
{
- case DW_VIRTUALITY_none:
- case DW_VIRTUALITY_virtual:
- case DW_VIRTUALITY_pure_virtual:
- return (dwarf_virtuality_attribute) value;
+ switch (*value)
+ {
+ case DW_VIRTUALITY_none:
+ case DW_VIRTUALITY_virtual:
+ case DW_VIRTUALITY_pure_virtual:
+ return (dwarf_virtuality_attribute) *value;
+
+ default:
+ complaint (_("unrecognized DW_AT_virtuality value (%s)"),
+ plongest (*value));
+ break;
+ }
}
- /* 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;
}