From 2ec8d037fce48d2541ec0398bbc3ab2d9a9dc766 Mon Sep 17 00:00:00 2001 From: Eli Bendersky Date: Tue, 27 Oct 2020 06:29:22 -0700 Subject: [PATCH] Add a bit more details to dwarf_pubnames_types example Fix reference output and make test emit both outputs when they differ --- examples/dwarf_pubnames_types.py | 28 ++++++++++++------- .../reference_output/dwarf_pubnames_types.out | 12 ++++++++ test/run_examples_test.py | 2 +- 3 files changed, 31 insertions(+), 11 deletions(-) diff --git a/examples/dwarf_pubnames_types.py b/examples/dwarf_pubnames_types.py index a747874..d9daaff 100644 --- a/examples/dwarf_pubnames_types.py +++ b/examples/dwarf_pubnames_types.py @@ -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]) diff --git a/examples/reference_output/dwarf_pubnames_types.out b/examples/reference_output/dwarf_pubnames_types.out index 3ed3d26..b8f4040 100644 --- a/examples/reference_output/dwarf_pubnames_types.out +++ b/examples/reference_output/dwarf_pubnames_types.out @@ -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 diff --git a/test/run_examples_test.py b/test/run_examples_test.py index 4a2843f..c5268f3 100755 --- a/test/run_examples_test.py +++ b/test/run_examples_test.py @@ -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 -- 2.30.2