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 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] = ['.', '..']
16 from elftools
.elf
.elffile
import ELFFile
19 def process_file(filename
):
20 print('In file:', filename
)
21 with
open(filename
, 'rb') as f
:
24 for section
in elffile
.iter_sections():
25 if section
.name
.startswith('.debug'):
26 print(' ' + section
.name
)
29 if __name__
== '__main__':
30 if sys
.argv
[1] == '--test':
31 for filename
in sys
.argv
[2:]:
32 process_file(filename
)