From 1f9413e87880280ac2d98ef30597e7708271cca8 Mon Sep 17 00:00:00 2001 From: Eli Bendersky Date: Sun, 25 Dec 2011 05:38:46 +0200 Subject: [PATCH] another example --- MANIFEST.in | 1 + examples/elf_relocations.py | 2 -- examples/elf_show_debug_sections.py | 35 +++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 examples/elf_show_debug_sections.py 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) + -- 2.30.2