[20/22] Rewrite new die_info methods

Message ID 20200322184523.28959-21-tom@tromey.com
State New
Headers show
Series
  • More splitting of dwarf2/read.c
Related show

Commit Message

Tom Tromey March 22, 2020, 6:45 p.m.
This rewrites the two new die_info to iterate over attributes rather
than to do two separate searches.

gdb/ChangeLog
2020-03-22  Tom Tromey  <tom@tromey.com>

	* dwarf2/die.h (struct die_info) <addr_base, ranges_base>:
	Rewrite.
---
 gdb/ChangeLog    |  5 +++++
 gdb/dwarf2/die.h | 30 ++++++++++++++++--------------
 2 files changed, 21 insertions(+), 14 deletions(-)

-- 
2.17.2

Patch

diff --git a/gdb/dwarf2/die.h b/gdb/dwarf2/die.h
index 5673ae261ac..5522ebdf311 100644
--- a/gdb/dwarf2/die.h
+++ b/gdb/dwarf2/die.h
@@ -38,13 +38,14 @@  struct die_info
      DW_AT_addr_base.  */
   gdb::optional<ULONGEST> addr_base ()
   {
-    struct attribute *attr;
-    attr = attr (DW_AT_addr_base);
-    if (attr == nullptr)
-      attr = attr (DW_AT_GNU_addr_base);
-    if (attr == nullptr)
-      return gdb::optional<ULONGEST> ();
-    return DW_UNSND (attr);
+    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 both exist, just use the first one.  */
+	  return DW_UNSND (&attrs[i]);
+	}
+    return gdb::optional<ULONGEST> ();
   }
 
   /* Return range lists base of the compile unit, which, if exists, is
@@ -52,13 +53,14 @@  struct die_info
      DW_AT_GNU_ranges_base.  */
   ULONGEST ranges_base ()
   {
-    struct attribute *attr;
-    attr = attr (DW_AT_rnglists_base);
-    if (attr == nullptr)
-      attr = attr (DW_AT_GNU_ranges_base);
-    if (attr == nullptr)
-      return 0;
-    return DW_UNSND (attr);
+    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 both exist, just use the first one.  */
+	  return DW_UNSND (&attrs[i]);
+	}
+    return 0;
   }