Fix for mixed version loclists, tests (#521)
[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.elf.elffile import ELFFile
17
18
19 def process_file(filename):
20 print('In file:', filename)
21 with open(filename, 'rb') as f:
22 elffile = ELFFile(f)
23
24 for section in elffile.iter_sections():
25 if section.name.startswith('.debug'):
26 print(' ' + section.name)
27
28
29 if __name__ == '__main__':
30 if sys.argv[1] == '--test':
31 for filename in sys.argv[2:]:
32 process_file(filename)