]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
Add dwarf::aranges for linear map of .debug_aranges sets.
authorRoland McGrath <roland@redhat.com>
Tue, 27 Jan 2009 08:48:29 +0000 (00:48 -0800)
committerRoland McGrath <roland@redhat.com>
Tue, 27 Jan 2009 08:48:29 +0000 (00:48 -0800)
libdw/c++/dwarf
libdw/c++/values.cc

index e7b36ad2efb15a5b1434ffdae21fee40ddd4d77e..e118f49a594281e37d015a0dff4fbb41ac5d6c61 100644 (file)
@@ -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<std::pair< ::Dwarf_Addr, ::Dwarf_Addr> >
+    {
+    private:
+      typedef std::set<std::pair< ::Dwarf_Addr, ::Dwarf_Addr> > _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<const _base &> (other)) {}
+
+      std::string to_string () const;
+    };
+
+  private:
+    struct arange_less
+      : public std::binary_function<compile_unit, compile_unit, bool>
+    {
+      inline bool operator() (const compile_unit &a, const compile_unit &b)
+       const
+      {
+       return a.offset () < b.offset ();
+      }
+    };
+
+  public:
+    typedef std::map<compile_unit, arange_list, arange_less> aranges_map;
+
+    aranges_map aranges () const;
   };
 
   inline class dwarf::debug_info_entry::raw_children
index c0a0cbd1345835a753d9a7d3f4b3d52fdc016f7f..5f9c646f6f19a1000f66295b8f04f8e9c94a2d0e 100644 (file)
@@ -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;
+}