another example
authorEli Bendersky <eliben@gmail.com>
Sun, 25 Dec 2011 03:38:46 +0000 (05:38 +0200)
committerEli Bendersky <eliben@gmail.com>
Sun, 25 Dec 2011 03:38:46 +0000 (05:38 +0200)
MANIFEST.in
examples/elf_relocations.py
examples/elf_show_debug_sections.py [new file with mode: 0644]

index e09a955ca18929e7b8ec325fba547f337061e692..6a6d19d88e6e7117e778697f7604dffab857ad89 100644 (file)
@@ -5,6 +5,7 @@ recursive-include test *.py *.elf
 include README\r
 include LICENSE\r
 include CHANGES\r
+include tox.ini\r
 \r
 \r
 \r
index e142e188134964da7a5ed5d610058f7e186f5b71..53bbac49d39f084c2c58073a21e7e1335ec7e865 100644 (file)
@@ -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 (file)
index 0000000..3b2c806
--- /dev/null
@@ -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)
+