more preparations for full DIE parsing:
- DWARFStructs got a new target_addr field that reflects the size of address fields in a CU
- DWARFInfo now gives access to the symbol table
- fixed stream parsing bugs that happened because the stream was not being preserved during parsing while issuing calls to other APIs that also move the stream
diff --git a/elftools/common/utils.py b/elftools/common/utils.py
index a36b3ec..5358072 100644
--- a/elftools/common/utils.py
+++ b/elftools/common/utils.py
@@ -41,3 +41,18 @@
if not cond:
raise exception_type(msg)
+
+from contextlib import contextmanager
+
+@contextmanager
+def preserve_stream_pos(stream):
+ """ Usage:
+
+ # stream has some position FOO (return value of stream.tell())
+ with preserve_stream_pos(stream):
+ # do stuff that manipulates the stream
+ # stream still has position FOO
+ """
+ saved_pos = stream.tell()
+ yield
+ stream.seek(saved_pos)