return struct.parse_stream(stream)
except ConstructError as e:
raise ELFParseError(e.message)
-
+
def parse_cstring_from_stream(stream, stream_pos=None):
""" Parse a C-string from the given stream. The string is returned without
@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
+ # 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
from collections import namedtuple
import os
+from ..common.exceptions import DWARFError
from ..common.py3compat import OrderedDict, bytes2str, iteritems
from ..common.utils import struct_parse, preserve_stream_pos
+from .enums import DW_FORM_raw2name
# AttributeValue - describes an attribute value in the DIE:
elif form == 'DW_FORM_flag':
value = not raw_value == 0
elif form == 'DW_FORM_indirect':
- form = raw_value
+ try:
+ form = DW_FORM_raw2name[raw_value]
+ except KeyError as err:
+ raise DWARFError(
+ 'Found DW_FORM_indirect with unknown raw_value=' +
+ str(raw_value))
+
raw_value = struct_parse(
self.cu.structs.Dwarf_dw_form[form], self.stream)
# Let's hope this doesn't get too deep :-)
# This code is in the public domain
#-------------------------------------------------------------------------------
from ..construct import Pass
+from ..common.py3compat import iteritems
ENUM_DW_TAG = dict(
_default_ = Pass,
)
+# Inverse mapping for ENUM_DW_FORM
+DW_FORM_raw2name = dict((v, k) for k, v in iteritems(ENUM_DW_FORM))
+