[PATCH 17/20] Change die_info methods to check the attribute's form

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

This changes two die_info methods to check the form of the attribute
before using it.

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

* dwarf2/die.h (struct die_info) <addr_base, ranges_base>: Check
the attribute's form.
---
gdb/ChangeLog | 5 +++++
gdb/dwarf2/die.h | 14 ++++++++------
2 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/gdb/dwarf2/die.h b/gdb/dwarf2/die.h
index 5522ebdf311..37f83a45a50 100644
--- a/gdb/dwarf2/die.h
+++ b/gdb/dwarf2/die.h
@@ -39,11 +39,12 @@ struct die_info
gdb::optional<ULONGEST> addr_base ()
{
for (unsigned i = 0; i < num_attrs; ++i)
- if (attrs[i].name == DW_AT_addr_base
- || attrs[i].name == DW_AT_GNU_addr_base)
+ if ((attrs[i].name == DW_AT_addr_base
+ || attrs[i].name == DW_AT_GNU_addr_base)
+ && attrs[i].form_is_unsigned ())
{
/* If both exist, just use the first one. */
- return DW_UNSND (&attrs[i]);
+ return attrs[i].get_unsigned ();
}
return gdb::optional<ULONGEST> ();
}
@@ -54,11 +55,12 @@ struct die_info
ULONGEST ranges_base ()
{
for (unsigned i = 0; i < num_attrs; ++i)
- if (attrs[i].name == DW_AT_rnglists_base
- || attrs[i].name == DW_AT_GNU_ranges_base)
+ if ((attrs[i].name == DW_AT_rnglists_base
+ || attrs[i].name == DW_AT_GNU_ranges_base)
+ && attrs[i].form_is_unsigned ())
{
/* If both exist, just use the first one. */
- return DW_UNSND (&attrs[i]);
+ return attrs[i].get_unsigned ();
}
return 0;
}
--
2.17.2