Remove unused import
[pyelftools.git] / examples / elf_show_debug_sections.py
1 #-------------------------------------------------------------------------------
2 # elftools example: elf_show_debug_sections.py
3 #
4 # Show the names of all .debug_* sections in ELF files.
5 #
6 # Eli Bendersky (eliben@gmail.com)
7 # This code is in the public domain
8 #-------------------------------------------------------------------------------
9 from __future__ import print_function
10 import sys
11
12 # If pyelftools is not installed, the example can also run from the root or
13 # examples/ dir of the source distribution.
14 sys.path[0:0] = ['.', '..']
15
16 from elftools.common.py3compat import bytes2str
17 from elftools.elf.elffile import ELFFile
18
19
20 def process_file(filename):
21 print('In file:', filename)
22 with open(filename, 'rb') as f:
23 elffile = ELFFile(f)
24
25 for section in elffile.iter_sections():
26 # Section names are bytes objects
27 if section.name.startswith(b'.debug'):
28 print(' ' + bytes2str(section.name))
29
30
31 if __name__ == '__main__':
32 for filename in sys.argv[1:]:
33 process_file(filename)
34