From: Eli Bendersky Date: Sun, 25 Dec 2011 03:38:46 +0000 (+0200) Subject: another example X-Git-Tag: v0.10~9 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=1f9413e87880280ac2d98ef30597e7708271cca8;p=pyelftools.git another example --- diff --git a/MANIFEST.in b/MANIFEST.in index e09a955..6a6d19d 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -5,6 +5,7 @@ recursive-include test *.py *.elf include README include LICENSE include CHANGES +include tox.ini diff --git a/examples/elf_relocations.py b/examples/elf_relocations.py index e142e18..53bbac4 100644 --- a/examples/elf_relocations.py +++ b/examples/elf_relocations.py @@ -50,5 +50,3 @@ if __name__ == '__main__': for filename in sys.argv[1:]: process_file(filename) - - diff --git a/examples/elf_show_debug_sections.py b/examples/elf_show_debug_sections.py new file mode 100644 index 0000000..3b2c806 --- /dev/null +++ b/examples/elf_show_debug_sections.py @@ -0,0 +1,35 @@ +#------------------------------------------------------------------------------- +# elftools example: elf_show_debug_sections.py +# +# Show the names of all .debug_* sections in ELF files. +# +# Eli Bendersky (eliben@gmail.com) +# This code is in the public domain +#------------------------------------------------------------------------------- +from __future__ import print_function +import sys + +# If elftools is not installed, maybe we're running from the root or examples +# dir of the source distribution +try: + import elftools +except ImportError: + sys.path.extend(['.', '..']) + +from elftools.elf.elffile import ELFFile + + +def process_file(filename): + print('In file:', filename) + with open(filename) as f: + elffile = ELFFile(f) + + for section in elffile.iter_sections(): + if section.name.startswith('.debug'): + print(' ' + section.name) + + +if __name__ == '__main__': + for filename in sys.argv[1:]: + process_file(filename) +