1 #-------------------------------------------------------------------------------
2 # elftools example: elf_show_debug_sections.py
4 # Show the names of all .debug_* sections in ELF files.
6 # Eli Bendersky (eliben@gmail.com)
7 # This code is in the public domain
8 #-------------------------------------------------------------------------------
9 from __future__ import print_function
12 # If elftools is not installed, maybe we're running from the root or examples
13 # dir of the source distribution
17 sys.path.extend(['.', '..'])
19 from elftools.common.py3compat import bytes2str
20 from elftools.elf.elffile import ELFFile
23 def process_file(filename):
24 print('In file:', filename)
25 with open(filename, 'rb') as f:
28 for section in elffile.iter_sections():
29 # Section names are bytes objects
30 if section.name.startswith(b'.debug'):
31 print(' ' + bytes2str(section.name))
34 if __name__ == '__main__':
35 for filename in sys.argv[1:]:
36 process_file(filename)