Keep raw note descriptors in ELF note sections as raw bytes (#372)
[pyelftools.git] / z.py
diff --git a/z.py b/z.py
index e5f26b7c627e0ef126686ce53597f33db9bb08c2..18f7d35b844d2585e3905c8e21ca03e95d4952d3 100644 (file)
--- a/z.py
+++ b/z.py
@@ -1,6 +1,14 @@
+#-------------------------------------------------------------------------------
+# elftools
+#
+# Eli Bendersky (eliben@gmail.com)
+# This code is in the public domain
+#-------------------------------------------------------------------------------
+
 # Just a script for playing around with pyelftools during testing
 # please ignore it!
 #
+from __future__ import print_function
 
 import sys, pprint
 from elftools.elf.structs import ELFStructs
@@ -13,6 +21,18 @@ from elftools.elf.relocation import *
 stream = open('test/testfiles/exe_simple64.elf', 'rb')
 
 efile = ELFFile(stream)
-print 'elfclass', efile.elfclass
-print '===> %s sections!' % efile.num_sections() 
-print efile.header
+print('elfclass', efile.elfclass)
+print('===> %s sections!' % efile.num_sections())
+print(efile.header)
+
+dinfo = efile.get_dwarf_info()
+from elftools.dwarf.locationlists import LocationLists
+from elftools.dwarf.descriptions import describe_DWARF_expr
+llists = LocationLists(dinfo.debug_loc_sec.stream, dinfo.structs)
+for loclist in llists.iter_location_lists():
+    print('----> loclist!')
+    for li in loclist:
+        print(li)
+        print(describe_DWARF_expr(li.loc_expr, dinfo.structs))
+
+