From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [PATCH 09/20] Remove DW_SND
Date: Sat, 28 Mar 2020 13:21:57 -0600 [thread overview]
Message-ID: <20200328192208.11324-10-tom@tromey.com> (raw)
In-Reply-To: <20200328192208.11324-1-tom@tromey.com>
This removes DW_SND in favor of accessors on struct attribute.
These accessors check that the form is appropriate.
gdb/ChangeLog
2020-03-28 Tom Tromey <tom@tromey.com>
* dwarf2/read.c (get_alignment, read_array_order)
(read_attribute_value, dwarf2_const_value_attr)
(dump_die_shallow, dwarf2_fetch_constant_bytes): Update.
* dwarf2/attribute.h (struct attribute) <get_signed, set_signed>:
New methods.
(DW_SND): Remove.
---
gdb/ChangeLog | 9 +++++++++
gdb/dwarf2/attribute.h | 16 +++++++++++++++-
gdb/dwarf2/read.c | 20 ++++++++++++--------
3 files changed, 36 insertions(+), 9 deletions(-)
diff --git a/gdb/dwarf2/attribute.h b/gdb/dwarf2/attribute.h
index 8a7aab84eb2..a08c5a13e44 100644
--- a/gdb/dwarf2/attribute.h
+++ b/gdb/dwarf2/attribute.h
@@ -65,6 +65,14 @@ struct attribute
return u.signature;
}
+ /* Return the signed value. The attribute must have the appropriate
+ form. */
+ LONGEST get_signed () const
+ {
+ gdb_assert (form == DW_FORM_sdata || form == DW_FORM_implicit_const);
+ return u.snd;
+ }
+
/* 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.
@@ -154,6 +162,13 @@ struct attribute
u.signature = signature;
}
+ /* Set this attribute to a signed integer. */
+ void set_signed (LONGEST snd)
+ {
+ gdb_assert (form == DW_FORM_sdata || form == DW_FORM_implicit_const);
+ u.snd = snd;
+ }
+
ENUM_BITFIELD(dwarf_attribute) name : 16;
ENUM_BITFIELD(dwarf_form) form : 15;
@@ -178,7 +193,6 @@ struct attribute
/* Get at parts of an attribute structure. */
#define DW_UNSND(attr) ((attr)->u.unsnd)
-#define DW_SND(attr) ((attr)->u.snd)
#define DW_ADDR(attr) ((attr)->u.addr)
#endif /* GDB_DWARF2_ATTRIBUTE_H */
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index cecdc41a0eb..6eecf051c84 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -14812,7 +14812,7 @@ get_alignment (struct dwarf2_cu *cu, struct die_info *die)
ULONGEST align;
if (attr->form == DW_FORM_sdata)
{
- LONGEST val = DW_SND (attr);
+ LONGEST val = attr->get_signed ();
if (val < 0)
{
complaint (_("DW_AT_alignment value must not be negative"
@@ -15764,7 +15764,11 @@ read_array_order (struct die_info *die, struct dwarf2_cu *cu)
attr = dwarf2_attr (die, DW_AT_ordering, cu);
if (attr != nullptr)
- return (enum dwarf_array_dim_ordering) DW_SND (attr);
+ {
+ LONGEST val = attr->constant_value (-1);
+ if (val == DW_ORD_row_major || val == DW_ORD_col_major)
+ return (enum dwarf_array_dim_ordering) val;
+ }
/* GNU F77 is a special case, as at 08/2004 array type info is the
opposite order to the dwarf2 specification, but data is still
@@ -18474,7 +18478,7 @@ read_attribute_value (const struct die_reader_specs *reader,
DW_UNSND (attr) = 1;
break;
case DW_FORM_sdata:
- DW_SND (attr) = read_signed_leb128 (abfd, info_ptr, &bytes_read);
+ attr->set_signed (read_signed_leb128 (abfd, info_ptr, &bytes_read));
info_ptr += bytes_read;
break;
case DW_FORM_udata:
@@ -18523,7 +18527,7 @@ read_attribute_value (const struct die_reader_specs *reader,
info_ptr, need_reprocess);
break;
case DW_FORM_implicit_const:
- DW_SND (attr) = implicit_const;
+ attr->set_signed (implicit_const);
break;
case DW_FORM_addrx:
case DW_FORM_GNU_addr_index:
@@ -20508,7 +20512,7 @@ dwarf2_const_value_attr (const struct attribute *attr, struct type *type,
case DW_FORM_sdata:
case DW_FORM_implicit_const:
- *value = DW_SND (attr);
+ *value = attr->get_signed ();
break;
case DW_FORM_udata:
@@ -21373,7 +21377,6 @@ dump_die_shallow (struct ui_file *f, int indent, struct die_info *die)
case DW_FORM_data4:
case DW_FORM_data8:
case DW_FORM_udata:
- case DW_FORM_sdata:
fprintf_unfiltered (f, "constant: %s",
pulongest (DW_UNSND (&die->attrs[i])));
break;
@@ -21411,9 +21414,10 @@ dump_die_shallow (struct ui_file *f, int indent, struct die_info *die)
fprintf_unfiltered (f,
"unexpected attribute form: DW_FORM_indirect");
break;
+ case DW_FORM_sdata:
case DW_FORM_implicit_const:
fprintf_unfiltered (f, "constant: %s",
- plongest (DW_SND (&die->attrs[i])));
+ plongest (die->attrs[i].get_signed ()));
break;
default:
fprintf_unfiltered (f, "unsupported attribute form: %d.",
@@ -21839,7 +21843,7 @@ dwarf2_fetch_constant_bytes (sect_offset sect_off,
case DW_FORM_implicit_const:
type = die_type (die, cu);
result = write_constant_as_bytes (obstack, byte_order,
- type, DW_SND (attr), len);
+ type, attr->get_signed (), len);
break;
case DW_FORM_udata:
--
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 ` Tom Tromey [this message]
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 ` [PATCH 16/20] Change is_valid_DW_AT_defaulted to a method on attribute Tom Tromey
2020-03-30 16:00 ` 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-10-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