]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
Fix range_list/location_attr iterators to actually start at the right offset.
authorRoland McGrath <roland@redhat.com>
Fri, 25 Sep 2009 21:52:21 +0000 (14:52 -0700)
committerRoland McGrath <roland@redhat.com>
Fri, 25 Sep 2009 21:52:21 +0000 (14:52 -0700)
libdw/ChangeLog
libdw/c++/dwarf
libdw/c++/values.cc

index fea9ebd7c00a7a99aae91d1e14f6cb506b647d2f..c6a576c7a93ff48aea94c3c056512a91712aa518 100644 (file)
@@ -1,3 +1,11 @@
+2009-09-25  Roland McGrath  <roland@redhat.com>
+
+       * c++/values.cc (dwarf::range_list::const_iterator::const_iterator):
+       For begin case, actually get the offset from the attribute!
+       (dwarf::location_attr::begin): Likewise.
+       * c++/dwarf (dwarf::range_list, dwarf::location_attr): Fix iterator
+       initializers accordingly.
+
 2009-09-21  Roland McGrath  <roland@redhat.com>
 
        * c++/dwarf-knowledge.cc (expected_value_space): DW_AT_const_value can
index 0760942d510870e7ac9e59fb4e4ba49bc4b5d6e0..05c4af4e1602f4bc2d5f7bb06b5ca8fd9454c9d5 100644 (file)
@@ -1323,7 +1323,7 @@ namespace elfutils
        ::Dwarf_CU *_m_cu;
        ptrdiff_t _m_offset;
 
-       const_iterator (Dwarf_Attribute *, ptrdiff_t);
+       const_iterator (Dwarf_Attribute *, ptrdiff_t offset);
 
       public:
        // Default constructor: only valid for operator=.
@@ -1496,8 +1496,9 @@ namespace elfutils
 
        void advance ();
 
-       inline const_iterator (Dwarf_Attribute *attr, ptrdiff_t offset)
-         : range_list::const_iterator (attr, offset), _m_block ()
+       // For end iterator.
+       inline explicit const_iterator (Dwarf_Attribute *attr)
+         : dwarf::range_list::const_iterator (attr, 1), _m_block ()
        {}
 
       public:
@@ -1548,7 +1549,7 @@ namespace elfutils
       const_iterator begin () const;
       inline const_iterator end () const
       {
-       return const_iterator (_m_attr.thisattr (), 1);
+       return const_iterator (_m_attr.thisattr ());
       }
 
       inline bool empty () const
index 66fffc1283a5ab28525cc576aa5795bcbd8cac51..1c84ad4c124c2b128c0a6f1452b62d93788a8692 100644 (file)
@@ -379,6 +379,12 @@ dwarf::range_list::const_iterator::const_iterator (Dwarf_Attribute *attr,
                                                   ptrdiff_t offset)
   : _m_base (-1), _m_begin (0), _m_end (0), _m_cu (attr->cu), _m_offset (offset)
 {
+  if (_m_offset == 0)
+    {
+      Dwarf_Word ofs;
+      xif (attr, dwarf_formudata (attr, &ofs) < 0); // XXX __libdw_formptr
+      _m_offset = ofs;
+    }
 }
 
 static bool
@@ -574,12 +580,24 @@ dwarf::location_attr::const_iterator::advance ()
 dwarf::location_attr::const_iterator
 dwarf::location_attr::begin () const
 {
-  const_iterator i (_m_attr.thisattr (), 0);
+  const_iterator i (_m_attr.thisattr ());
   if (is_list ())
-    i.advance ();
+    {
+      // XXX __libdw_formptr
+      Dwarf_Word offset;
+      xif (_m_attr.thisattr (),
+          dwarf_formudata (_m_attr.thisattr (), &offset) < 0);
+      i._m_offset = offset;
+      i.advance ();
+    }
   else
-    xif (_m_attr.thisattr (),
-        dwarf_formblock (_m_attr.thisattr (), &i._m_block) < 0);
+    {
+      xif (_m_attr.thisattr (),
+          dwarf_formblock (_m_attr.thisattr (), &i._m_block) < 0);
+      i._m_base = 0;
+      i._m_end = -1;
+      i._m_offset = 0;
+    }
 
   return i;
 }
@@ -591,8 +609,12 @@ dwarf::location_attr::const_iterator::operator++ ()
     throw std::runtime_error ("incrementing end iterator");
 
   if (_m_offset == 0)
-    // Singleton, now at end.
-    _m_offset = 1;
+    {
+      // Singleton, now at end.
+      _m_offset = 1;
+      _m_block.data = NULL;
+      _m_block.length = 0;
+    }
   else
     // Advance to next list entry.
     advance ();