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 ...')
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])
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