From: Roland McGrath Date: Tue, 27 Jan 2009 08:48:29 +0000 (-0800) Subject: Add dwarf::aranges for linear map of .debug_aranges sets. X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=acef182424f60967462d6abad8582fae7c2cbe02;p=thirdparty%2Felfutils.git Add dwarf::aranges for linear map of .debug_aranges sets. --- diff --git a/libdw/c++/dwarf b/libdw/c++/dwarf index e7b36ad2e..e118f49a5 100644 --- a/libdw/c++/dwarf +++ b/libdw/c++/dwarf @@ -1342,7 +1342,7 @@ namespace elfutils public: inline const_iterator (const const_iterator &i) : _m_die (i._m_die), _m_base (i._m_base), - _m_begin (i._m_begin), _m_end (i._m_begin), + _m_begin (i._m_begin), _m_end (i._m_end), _m_offset (i._m_offset) {} inline value_type operator* () const @@ -1611,6 +1611,41 @@ namespace elfutils { return !(*this == other); } + + class arange_list + : public std::set > + { + private: + typedef std::set > _base; + + public: + typedef _base::key_type key_type; + typedef _base::value_type value_type; + typedef _base::iterator iterator; + typedef _base::const_iterator const_iterator; + + arange_list () {} + arange_list (const arange_list &other) + : _base (static_cast (other)) {} + + std::string to_string () const; + }; + + private: + struct arange_less + : public std::binary_function + { + inline bool operator() (const compile_unit &a, const compile_unit &b) + const + { + return a.offset () < b.offset (); + } + }; + + public: + typedef std::map aranges_map; + + aranges_map aranges () const; }; inline class dwarf::debug_info_entry::raw_children diff --git a/libdw/c++/values.cc b/libdw/c++/values.cc index c0a0cbd13..5f9c646f6 100644 --- a/libdw/c++/values.cc +++ b/libdw/c++/values.cc @@ -143,7 +143,8 @@ static string hex_string (Dwarf_Word value, const char *before = "", const char *after = "") { std::ostringstream os; - os.setf(std::ios::hex, std::ios::basefield); + os.setf (std::ios::hex, std::ios::basefield); + os.setf (std::ios::showbase); os << before << value << after; return os.str (); } @@ -523,14 +524,15 @@ string __libdw_ranges_to_string (const container &c) { std::ostringstream os; - os.setf(std::ios::hex, std::ios::basefield); + os.setf (std::ios::hex, std::ios::basefield); + os.setf (std::ios::showbase); os << "<"; bool first = true; for (typename container::const_iterator i = c.begin (); i != c.end (); ++i) { - typename container::value_type range = *i; + const typename container::value_type range = *i; if (!first) os << ","; os << range.first << "-" << range.second; @@ -553,3 +555,28 @@ dwarf::ranges::to_string () const { return __libdw_ranges_to_string (*this); } + +string +dwarf::arange_list::to_string () const +{ + return __libdw_ranges_to_string (*this); +} + +dwarf::aranges_map +dwarf::aranges () const +{ + Dwarf_Aranges *these; + xif (dwarf_getaranges (_m_dw, &these, NULL) < 0); + + if (these == NULL) + return aranges_map (); + + aranges_map result; + for (const Dwarf_Aranges_s::Dwarf_Arange_s *r = &these->info[0]; + r < &these->info[these->naranges]; + ++r) + result[compile_unit (debug_info_entry (_m_dw, r->offset))].insert + (arange_list::value_type (r->addr, r->addr + r->length)); + + return result; +}