From: Roland McGrath Date: Fri, 25 Sep 2009 21:52:21 +0000 (-0700) Subject: Fix range_list/location_attr iterators to actually start at the right offset. X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=a1d2a7175846fdf951e5bc75fb346343641c7c0f;p=thirdparty%2Felfutils.git Fix range_list/location_attr iterators to actually start at the right offset. --- diff --git a/libdw/ChangeLog b/libdw/ChangeLog index fea9ebd7c..c6a576c7a 100644 --- a/libdw/ChangeLog +++ b/libdw/ChangeLog @@ -1,3 +1,11 @@ +2009-09-25 Roland McGrath + + * 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 * c++/dwarf-knowledge.cc (expected_value_space): DW_AT_const_value can diff --git a/libdw/c++/dwarf b/libdw/c++/dwarf index 0760942d5..05c4af4e1 100644 --- a/libdw/c++/dwarf +++ b/libdw/c++/dwarf @@ -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 diff --git a/libdw/c++/values.cc b/libdw/c++/values.cc index 66fffc128..1c84ad4c1 100644 --- a/libdw/c++/values.cc +++ b/libdw/c++/values.cc @@ -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 ();