class StreamOffset(Construct):
"""
- Captures the current stream offset
+ Captures the current stream offset
Parameters:
* name - the name of the value
def _build(self, obj, stream, context):
context[self.name] = stream.tell()
def _sizeof(self, context):
- return 0
+ return 0
with open(filename, 'wb') as file:
data = stream.read(section.size)
file.write(data)
- stream.seek(pos, os.SEEK_SET)
+ stream.seek(pos, os.SEEK_SET)
#------------------------- PRIVATE -------------------------
add('DW_OP_entry_value', parse_nestedexpr())
add('DW_OP_const_type', parse_typedblob())
add('DW_OP_regval_type', parse_arg_struct2(structs.Dwarf_uleb128(''),
- structs.Dwarf_uleb128('')))
+ structs.Dwarf_uleb128('')))
add('DW_OP_deref_type', parse_arg_struct2(structs.Dwarf_uint8(''),
- structs.Dwarf_uleb128('')))
+ structs.Dwarf_uleb128('')))
add('DW_OP_implicit_pointer', parse_arg_struct2(structs.Dwarf_offset(''),
- structs.Dwarf_sleb128('')))
- add('DW_OP_convert', parse_arg_struct(structs.Dwarf_uleb128('')))
+ structs.Dwarf_sleb128('')))
+ add('DW_OP_convert', parse_arg_struct(structs.Dwarf_uleb128('')))
add('DW_OP_GNU_entry_value', parse_nestedexpr())
add('DW_OP_GNU_const_type', parse_typedblob())
add('DW_OP_GNU_regval_type', parse_arg_struct2(structs.Dwarf_uleb128(''),
DW_LLE_default_location = 0x05,
DW_LLE_base_address = 0x06,
DW_LLE_start_end = 0x07,
- DW_LLE_start_length = 0x08
+ DW_LLE_start_length = 0x08
)
ENUM_DW_RLE = dict(
Starting with DWARF5, it may also contain LocationViewPair, but only
if scanning the section, never when requested for a DIE attribute.
- The default location entries are returned as LocationEntry with
+ The default location entries are returned as LocationEntry with
begin_offset == end_offset == -1
Version determines whether the executable contains a debug_loc
"""
# The location lists section was never meant for sequential access.
# Location lists are referenced by DIE attributes by offset or by index.
-
+
# As of DWARFv5, it may contain, in addition to proper location lists,
#location list view pairs, which are referenced by the nonstandard DW_AT_GNU_locviews
# attribute. A set of locview pairs (which is a couple of ULEB128 values) may preceed
- # a location list; the former is referenced by the DW_AT_GNU_locviews attribute, the
+ # a location list; the former is referenced by the DW_AT_GNU_locviews attribute, the
# latter - by DW_AT_location (in the same DIE). Binutils' readelf dumps those.
# There is a view pair for each location-type entry in the list.
#
stream.seek(0, os.SEEK_END)
endpos = stream.tell()
- stream.seek(0, os.SEEK_SET)
+ stream.seek(0, os.SEEK_SET)
if self.version >= 5:
# Need to provide support for DW_AT_GNU_locviews. They are interspersed in
cu_end_offset = offset_past_len + unit_length
# Unit_length includes the header but doesn't include the length
-
+
while stream.tell() < cu_end_offset:
# Skip the gap to the next object
next_offset = all_offsets[offset_index]
return LocationEntry(off, len, entry.start_address, entry.end_address, entry.loc_expr, True)
elif type == 'DW_LLE_default_location': # No test for this either, and this is new in the API
return LocationEntry(off, len, -1, -1, entry.loc_expr, True)
- elif type in ('DW_LLE_base_addressx', 'DW_LLE_startx_endx', 'DW_LLE_startx_length'):
+ elif type in ('DW_LLE_base_addressx', 'DW_LLE_startx_endx', 'DW_LLE_startx_length'):
# We don't have sample binaries for those LLEs. Their proper parsing would
# require knowing the CU context (so that indices can be resolved to code offsets)
raise NotImplementedError("Location list entry type %s is not supported yet" % (type,))
return self.location_lists.get_location_list_at_offset(
attr.value, die)
# We don't yet know if the DIE context will be needed.
- # We might get it without a full tree traversal using
+ # We might get it without a full tree traversal using
# attr.offset as a key, but we assume a good DWARF5
# aware consumer would pass a DIE along.
else:
for mask, desc in _DESCR_NOTE_GNU_PROPERTY_X86_ISA_1_FLAGS:
if value & mask:
descs.append(desc)
- return 'x86 ISA needed: ' + ', '.join(descs)
+ return 'x86 ISA needed: ' + ', '.join(descs)
def describe_note_gnu_properties(properties):
descriptions = []
self._emitline('%s:' % cu_filename)
else:
self._emitline('CU: %s:' % cu_filename)
-
+
self._emitline('File name Line number Starting address Stmt')
# GNU readelf has a View column that we don't try to replicate
# The autotest has logic in place to ignore that
self._emitline(" %08x v%015x v%015x location view pair" % (entry.entry_offset, entry.begin, entry.end))
else:
if in_views:
- in_views = False
+ in_views = False
self._emitline("")
-
+
# Need the CU for this loclist, but the map is keyed by the offset
# of the first entry in the loclist. Got to skip the views first.
if cu is None:
cu = cu_map.get(entry.entry_offset, False)
if not cu:
- raise ValueError("Location list can't be tracked to a CU")
+ raise ValueError("Location list can't be tracked to a CU")
if isinstance(entry, LocationEntry):
if base_ip is None and not entry.is_absolute:
- base_ip = _get_cu_base(cu)
+ base_ip = _get_cu_base(cu)
begin_offset = (0 if entry.is_absolute else base_ip) + entry.begin_offset
end_offset = (0 if entry.is_absolute else base_ip) + entry.end_offset
self._emitline('Contents of the %s section:\n' % (di.debug_rnglists_sec or di.debug_ranges_sec).name)
self._emitline(' Offset Begin End')
-
+
for range_list in range_lists:
# Weird discrepancy in binutils: for DWARFv5 it outputs entry offset,
# for DWARF<=4 list offset.
else:
raise NotImplementedError("Unknown object in a range list")
last = range_list[-1]
- self._emitline(' %08x <End of list>' % (last.entry_offset + last.entry_length if ver5 else first.entry_offset))
+ self._emitline(' %08x <End of list>' % (last.entry_offset + last.entry_length if ver5 else first.entry_offset))
def _display_arch_specific_arm(self):
""" Display the ARM architecture-specific info contained in the file.
# Position of the View column in the output file, if parsing readelf..decodedline
# output, and the GNU readelf output contains the View column. Otherwise stays -1.
- view_col_position = -1
+ view_col_position = -1
for i in range(len(lines1)):
if lines1[i].endswith('debug_line section:'):
# .debug_line or .zdebug_line
# readelf spelling error for GNU property notes
lines1[i] = lines1[i].replace('procesor-specific type', 'processor-specific type')
-
+
# The view column position may change from CU to CU:
if view_col_position >= 0 and lines1[i].startswith('cu:'):
- view_col_position = -1
-
+ view_col_position = -1
+
# Check if readelf..decodedline output line contains the view column
if flag_in_debug_line_section and lines1[i].startswith('file name') and view_col_position < 0:
view_col_position = lines1[i].find("view")
# lit0
# skip 3
# lit4
- # minus
- # deref
+ # minus
+ # deref
lst = p.parse_expr([0x97,0x6,0x12,0x28,0x4,0x0,0x30,0x2F,0x3,0x0,0x34,0x1C,0x6])
self.assertEqual(len(lst), 9)
self.assertEqual(lst, [