]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
Test dwarf_edit refs
authorRoland McGrath <roland@redhat.com>
Thu, 2 Jul 2009 11:12:58 +0000 (04:12 -0700)
committerRoland McGrath <roland@redhat.com>
Thu, 2 Jul 2009 11:17:27 +0000 (04:17 -0700)
tests/dwarf_edit.cc
tests/print-die.hh
tests/run-dwarf_edit.sh

index 5510be1ceed2130af8e9f4813d35610eee006136..674605334839d1bde813611e7d3069ca5869b309 100644 (file)
@@ -47,12 +47,19 @@ main (int argc, char **argv)
 
   cu.attributes ()[DW_AT_name].source_file () = "source-file.c";
 
-  dwarf_edit::debug_info_entry &ent = cu.add_entry (DW_TAG_subprogram);
+  dwarf_edit::debug_info_entry::pointer bt = cu.add_entry (DW_TAG_base_type);
+  bt->attributes ()[DW_AT_name].identifier () = "int";
+
+  dwarf_edit::debug_info_entry &ent = *cu.add_entry (DW_TAG_subprogram);
 
   ent.attributes ()[DW_AT_name].identifier () = "foo";
 
   ent.attributes ()[DW_AT_description] = ent.attributes ()[DW_AT_name];
 
+  ent.attributes ()[DW_AT_external].flag ();
+
+  ent.attributes ()[DW_AT_type].reference () = bt;
+
   print_file ("consed", f, depth);
 
   return 0;
index 91d70c9979c06304ee367b5db23797654e09bfc2..3f4cd9d238a2fcc8b23ebe05321bddcf6482cc3f 100644 (file)
@@ -29,6 +29,7 @@
 #include <libintl.h>
 #include <ostream>
 #include <iomanip>
+#include <tr1/unordered_map>
 
 static bool print_offset;
 
@@ -61,10 +62,34 @@ print_die_main (int &argc, char **&argv, unsigned int &depth)
     }
 }
 
+typedef tr1::unordered_map< ::Dwarf_Off, int> refs_map;
+
+static void
+finish_refs_map (refs_map &refs)
+{
+  int id = 0;
+  for (refs_map::iterator it = refs.begin (); it != refs.end (); ++it)
+    it->second = ++id;
+}
+
+template<typename file>
+static void
+prewalk_die (const typename file::debug_info_entry &die, refs_map &refs)
+{
+  for (typename file::debug_info_entry::children_type::const_iterator i
+        = die.children ().begin (); i != die.children ().end (); ++i)
+    prewalk_die<file> (*i, refs);
+
+  for (typename file::debug_info_entry::attributes_type::const_iterator i
+        = die.attributes ().begin (); i != die.attributes ().end (); ++i)
+    if ((*i).second.what_space () == dwarf::VS_reference)
+      refs[(*i).second.reference ()->identity ()];
+}
+
 template<typename file>
 static void
 print_die (const typename file::debug_info_entry &die,
-          unsigned int indent, unsigned int limit)
+          unsigned int indent, unsigned int limit, refs_map &refs)
 {
   string prefix (indent, ' ');
   const string tag = dwarf::tags::name (die.tag ());
@@ -72,10 +97,22 @@ print_die (const typename file::debug_info_entry &die,
   cout << prefix << "<" << tag;
   if (print_offset)
     cout << " offset=[" << die.offset () << "]";
+  else
+    {
+      refs_map::const_iterator it = refs.find (die.identity ());
+      if (it != refs.end ())
+       cout << " ref=\"" << hex << it->second << "\"";
+    }
 
   for (typename file::debug_info_entry::attributes_type::const_iterator i
         = die.attributes ().begin (); i != die.attributes ().end (); ++i)
-    cout << " " << to_string (*i);
+    {
+      if (!print_offset && (*i).second.what_space () == dwarf::VS_reference)
+       cout << " " << dwarf::attributes::name ((*i).first) << "=\"#"
+            << hex << refs[(*i).second.reference ()->identity ()] << "\"";
+      else
+       cout << " " << to_string (*i);
+    }
 
   if (die.has_children ())
     {
@@ -89,7 +126,7 @@ print_die (const typename file::debug_info_entry &die,
 
       for (typename file::debug_info_entry::children_type::const_iterator i
             = die.children ().begin (); i != die.children ().end (); ++i)
-       print_die<file> (*i, indent + 1, limit);
+       print_die<file> (*i, indent + 1, limit, refs);
 
       cout << prefix << "</" << tag << ">\n";
     }
@@ -101,8 +138,18 @@ template<typename file>
 static void
 print_cu (const typename file::compile_unit &cu, const unsigned int limit)
 {
-  print_die<file> (static_cast<const typename file::debug_info_entry &> (cu),
-                  1, limit);
+  const typename file::debug_info_entry &die = cu;
+  // static_cast<const typename file::debug_info_entry &> (cu),
+
+  refs_map refs;
+
+  if (!print_offset)
+    {
+      prewalk_die<file> (die, refs);
+      finish_refs_map (refs);
+    }
+
+  print_die<file> (die, 1, limit, refs);
 }
 
 template<typename file>
index a7b0baf6e07f20f0d73bd334695d867bf05dbc5c..2ae53209c96327e50414bec9ed2b0c8f4f630ab7 100755 (executable)
@@ -28,7 +28,8 @@
 testrun_compare ./dwarf_edit <<\EOF
 consed:
  <compile_unit name="source-file.c">
-  <subprogram name="foo" description="foo"/>
+  <base_type ref="0x1" name="int"/>
+  <subprogram name="foo" external=1 type="#0x1" description="foo"/>
  </compile_unit>
 EOF