Ejemplo n.º 1
0
    def __eval_offset(self):
        bitoffset = get_attr_val(self.die, 'DW_AT_data_bit_offset')
        if bitoffset is not None:
            # Bit offset is given directly
            return bitoffset

        location = get_attr_val(self.die, 'DW_AT_data_member_location')
        if location is None:
            # no offset attribute exists -- the member is located at the beginning of its parent
            return 0
        elif isinstance(location, (int, long)):
            # the attribute is a number -- this is the offset in bytes
            return location * 8
        elif isinstance(location, list):
            # the attribute is an expression
            dwxpr = location
            if dwxpr[0] == dwarf_expr.DW_OP_name2opcode['DW_OP_plus_uconst']:
                # Right now we only support location descriptions in the form [DW_OP_plus_uconst, <ULEB128>].
                # This is the only form GCC and clang produce.
                return LEB.decode(BytesIO(bytearray(dwxpr[1:]))) * 8
            else:
                opcode = dwarf_expr.DW_OP_opcode2name.get(
                    dwxpr[0], '<unknown>')
                raise NotImplementedError(
                    'Unsupported opcode in data member location %s (%02x)' %
                    (opcode, dwxpr[0]))

        assert False, 'Unreachable code.'
Ejemplo n.º 2
0
    def __eval_offset(self):
        bitoffset = get_attr_val(self.die, 'DW_AT_data_bit_offset')
        if bitoffset is not None:
            # Bit offset is given directly
            return bitoffset

        location = get_attr_val(self.die, 'DW_AT_data_member_location')
        if location is None:
            # no offset attribute exists -- the member is located at the beginning of its parent
            return 0
        elif isinstance(location, (int, long)):
            # the attribute is a number -- this is the offset in bytes
            return location * 8
        elif isinstance(location, list):
            # the attribute is an expression
            dwxpr = location
            if dwxpr[0] == dwarf_expr.DW_OP_name2opcode['DW_OP_plus_uconst']:
                # Right now we only support location descriptions in the form [DW_OP_plus_uconst, <ULEB128>].
                # This is the only form GCC and clang produce.
                return LEB.decode(BytesIO(bytearray(dwxpr[1:]))) * 8
            else:
                opcode = dwarf_expr.DW_OP_opcode2name.get(dwxpr[0], '<unknown>')
                raise NotImplementedError('Unsupported opcode in data member location %s (%02x)' % (opcode, dwxpr[0]))

        assert False, 'Unreachable code.'
Ejemplo n.º 3
0
def decode_offset(member_location):
    '''Convert dwarf expression in DW_AT_data_member_location to offset from structure start.'''
    if member_location is None:
        # the attribute does not exist -- the member is located at the beginning of its parent
        return 0
    elif isinstance(member_location, int):
        # the attribute is a number -- this is the offset
        return member_location
    elif isinstance(member_location, list):
        # the attribute is an expression
        dwxpr = member_location
        if dwxpr[0] == dwarf_expr.DW_OP_name2opcode['DW_OP_plus_uconst']:
            # Right now we only support location descriptions in the form [DW_OP_plus_uconst, <ULEB128>].
            # This is the only form GCC and clang produce.
            return LEB.decode(BytesIO(bytearray(dwxpr[1:])))
        else:
            opcode = dwarf_expr.DW_OP_opcode2name.get(dwxpr[0], '<unknown>')
            raise NotImplementedError('Unsupported opcode in data member location %s (%02x)' % (opcode, dwxpr[0]))
Ejemplo n.º 4
0
def decode_offset(member_location):
    '''Convert dwarf expression in DW_AT_data_member_location to offset from structure start.'''
    if member_location is None:
        # the attribute does not exist -- the member is located at the beginning of its parent
        return 0
    elif isinstance(member_location, int):
        # the attribute is a number -- this is the offset
        return member_location
    elif isinstance(member_location, list):
        # the attribute is an expression
        dwxpr = member_location
        if dwxpr[0] == dwarf_expr.DW_OP_name2opcode['DW_OP_plus_uconst']:
            # Right now we only support location descriptions in the form [DW_OP_plus_uconst, <ULEB128>].
            # This is the only form GCC and clang produce.
            return LEB.decode(BytesIO(bytearray(dwxpr[1:])))
        else:
            opcode = dwarf_expr.DW_OP_opcode2name.get(dwxpr[0], '<unknown>')
            raise NotImplementedError(
                'Unsupported opcode in data member location %s (%02x)' %
                (opcode, dwxpr[0]))
Ejemplo n.º 5
0
 def regx(self):
     regnum = LEB.decode(self.expression)
     return 'get_reg(%i)' % regnum
Ejemplo n.º 6
0
 def bregx(self):
     '''The DW_OP_bregx operation has two operands: a register which is specified by an unsigned LEB128 number, 
     followed by a signed LEB128 offset.'''
     regnum = LEB.decode(self.expression)
     return self.bregN(regnum)
Ejemplo n.º 7
0
 def constu(self):
     '''The single operand of the DW_OP_constu operation provides an unsigned LEB128 integer constant.'''
     val = LEB.decode(self.expression)
     self.push('%#x' % val)
Ejemplo n.º 8
0
 def regx(self):
     regnum = LEB.decode(self.expression)
     return 'get_reg(%i)' % regnum
Ejemplo n.º 9
0
 def bregx(self):
     '''The DW_OP_bregx operation has two operands: a register which is specified by an unsigned LEB128 number, 
     followed by a signed LEB128 offset.'''
     regnum = LEB.decode(self.expression)
     return self.bregN(regnum)
Ejemplo n.º 10
0
 def constu(self):
     '''The single operand of the DW_OP_constu operation provides an unsigned LEB128 integer constant.'''
     val = LEB.decode(self.expression)
     self.push('%#x' % val)