Add a bit more details to dwarf_pubnames_types example
authorEli Bendersky <eliben@gmail.com>
Tue, 27 Oct 2020 13:29:22 +0000 (06:29 -0700)
committerEli Bendersky <eliben@gmail.com>
Tue, 27 Oct 2020 13:29:22 +0000 (06:29 -0700)
Fix reference output and make test emit both outputs when they differ

examples/dwarf_pubnames_types.py
examples/reference_output/dwarf_pubnames_types.out
test/run_examples_test.py

index a747874d93cc48c1c95c057ea51702dbdbcc552e..d9daaff493e934ed2e1a54a3bd5c7de79182f344 100644 (file)
@@ -69,24 +69,19 @@ def process_file(filename):
         else:
             print('%d entries found in .debug_pubtypes' % len(pubtypes))
 
-            # try getting information on a global type.
-            sym_name = 'char'
-            # note: using the .get() API (pubtypes[key] will also work).
-            entry = pubtypes.get(sym_name)
-            if entry is None:
-                print('ERROR: No pubtype entry for %s' % sym_name)
-            else:
-                print('%s: cu_ofs %d, die_ofs %d' %
-                        (sym_name, entry.cu_ofs, entry.die_ofs))
+            for name, entry in pubtypes.items():
+                print('%s: cu_ofs = %d, die_ofs = %d' %
+                        (name, entry.cu_ofs, entry.die_ofs))
 
                 # get the actual CU/DIE that has this information.
-                print('Fetching the actual die for %s ...' % sym_name)
+                print('Fetching the actual die for %s ...' % name)
                 for cu in dwarfinfo.iter_CUs():
                     if cu.cu_offset == entry.cu_ofs:
                         for die in cu.iter_DIEs():
                             if die.offset == entry.die_ofs:
                                 print('Die Name: %s' %
                                         bytes2str(die.attributes['DW_AT_name'].value))
+                                die_info_rec(die)
 
             # dump all entries in .debug_pubtypes section.
             print('Dumping .debug_pubtypes table ...')
@@ -97,6 +92,19 @@ def process_file(filename):
                 print('%50s%8d%8d' % (name, entry.cu_ofs, entry.die_ofs))
             print('-' * 66)
 
+
+def die_info_rec(die, indent_level='    '):
+    """ A recursive function for showing information about a DIE and its
+        children.
+    """
+    print(indent_level + 'DIE tag=%s, attrs=' % die.tag)
+    for name, val in die.attributes.items():
+        print(indent_level + '  %s = %s' % (name, val))
+    child_indent = indent_level + '  '
+    for child in die.iter_children():
+        die_info_rec(child, child_indent)
+
+
 if __name__ == '__main__':
     if sys.argv[1] == '--test':
         process_file(sys.argv[2])
index 3ed3d2688a9aff03897d5d1290672ea8b03443b2..b8f4040d9fa24a007d3efff01c39938a6c8ef125 100644 (file)
@@ -1,9 +1,21 @@
 Processing file: ./examples/sample_exe64.elf
 5 entries found in .debug_pubnames
 Trying pubnames example ...
+_IO_stdin_used: cu_ofs = 119, die_ofs = 230
+Fetching the actual die for _IO_stdin_used ...
+Die Name: _IO_stdin_used
 main: cu_ofs = 258, die_ofs = 303
 Fetching the actual die for main ...
 Die Name: main
+glob: cu_ofs = 258, die_ofs = 395
+Fetching the actual die for glob ...
+Die Name: glob
+__libc_csu_fini: cu_ofs = 418, die_ofs = 495
+Fetching the actual die for __libc_csu_fini ...
+Die Name: __libc_csu_fini
+__libc_csu_init: cu_ofs = 418, die_ofs = 523
+Fetching the actual die for __libc_csu_init ...
+Die Name: __libc_csu_init
 Dumping .debug_pubnames table ...
 ------------------------------------------------------------------
                                             Symbol  CU_OFS DIE_OFS
index 4a2843f1443a59d9e33d605657db31cc2200000d..c5268f3492c95d8cf704e8a43426d82d625d7cf0 100755 (executable)
@@ -63,7 +63,7 @@ def run_example_and_compare(example_path):
         return True
     else:
         testlog.info('.......FAIL comparison')
-        dump_output_to_temp_files(testlog, example_out)
+        dump_output_to_temp_files(testlog, example_out, ref_str)
         return False