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
.common
.py3compat
import bytes2str
17 from elftools
.elf
.elffile
import ELFFile
20 def process_file(filename
):
21 print('In file:', filename
)
22 with
open(filename
, 'rb') as f
:
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
))
31 if __name__
== '__main__':
32 for filename
in sys
.argv
[1:]:
33 process_file(filename
)