Rewrite new die_info methods
authorTom Tromey <tom@tromey.com>
Thu, 26 Mar 2020 15:28:08 +0000 (09:28 -0600)
committerTom Tromey <tom@tromey.com>
Thu, 26 Mar 2020 15:28:26 +0000 (09:28 -0600)
This rewrites the two new die_info methods to iterate over attributes
rather than to do two separate searches.

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

* dwarf2/die.h (struct die_info) <addr_base, ranges_base>:
Rewrite.

gdb/ChangeLog
gdb/dwarf2/die.h

index b8190a1381ed789194b16984c3bc4c1fa00e024f..670f7f6c25b0df630d9ef6e02778bb4077151e35 100644 (file)
@@ -1,3 +1,8 @@
+2020-03-26  Tom Tromey  <tom@tromey.com>
+
+       * dwarf2/die.h (struct die_info) <addr_base, ranges_base>:
+       Rewrite.
+
 2020-03-26  Tom Tromey  <tom@tromey.com>
 
        * dwarf2/die.h (struct die_info) <addr_base, ranges_base>: New
index c3586645bd60eb37031ebea4e6c7ef7826702ea8..5522ebdf3114f013b70184811c930db8d90be194 100644 (file)
@@ -38,12 +38,14 @@ struct die_info
      DW_AT_addr_base.  */
   gdb::optional<ULONGEST> addr_base ()
   {
-    struct attribute *attr = this->attr (DW_AT_addr_base);
-    if (attr == nullptr)
-      attr = this->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
@@ -51,12 +53,14 @@ struct die_info
      DW_AT_GNU_ranges_base.  */
   ULONGEST ranges_base ()
   {
-    struct attribute *attr = this->attr (DW_AT_rnglists_base);
-    if (attr == nullptr)
-      attr = this->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;
   }
 
 
This page took 0.028409 seconds and 4 git commands to generate.