Пример #1
0
DIERef::DIERef(const DWARFFormValue &form_value)
    : cu_offset(DW_INVALID_OFFSET), die_offset(DW_INVALID_OFFSET) {
  if (form_value.IsValid()) {
    const DWARFUnit *dwarf_cu = form_value.GetCompileUnit();
    if (dwarf_cu) {
      if (dwarf_cu->GetBaseObjOffset() != DW_INVALID_OFFSET)
        cu_offset = dwarf_cu->GetBaseObjOffset();
      else
        cu_offset = dwarf_cu->GetOffset();
    }
    die_offset = form_value.Reference();
  }
}
Пример #2
0
int
DWARFFormValue::Compare (const DWARFFormValue& a_value, const DWARFFormValue& b_value, const DWARFCompileUnit* a_cu, const DWARFCompileUnit* b_cu, const DWARFDataExtractor* debug_str_data_ptr)
{
    dw_form_t a_form = a_value.Form();
    dw_form_t b_form = b_value.Form();
    if (a_form < b_form)
        return -1;
    if (a_form > b_form)
        return 1;
    switch (a_form)
    {
    case DW_FORM_addr:
    case DW_FORM_flag:
    case DW_FORM_data1:
    case DW_FORM_data2:
    case DW_FORM_data4:
    case DW_FORM_data8:
    case DW_FORM_udata:
    case DW_FORM_ref_addr:
    case DW_FORM_sec_offset:
    case DW_FORM_flag_present:
    case DW_FORM_ref_sig8:
        {
            uint64_t a = a_value.Unsigned();
            uint64_t b = b_value.Unsigned();
            if (a < b)
                return -1;
            if (a > b)
                return 1;
            return 0;
        }

    case DW_FORM_sdata:
        {
            int64_t a = a_value.Signed();
            int64_t b = b_value.Signed();
            if (a < b)
                return -1;
            if (a > b)
                return 1;
            return 0;
        }

    case DW_FORM_string:
    case DW_FORM_strp:
        {
            const char *a_string = a_value.AsCString(debug_str_data_ptr);
            const char *b_string = b_value.AsCString(debug_str_data_ptr);
            if (a_string == b_string)
                return 0;
            else if (a_string && b_string)
                return strcmp(a_string, b_string);
            else if (a_string == NULL)
                return -1;  // A string is NULL, and B is valid
            else
                return 1;   // A string valid, and B is NULL
        }


    case DW_FORM_block:
    case DW_FORM_block1:
    case DW_FORM_block2:
    case DW_FORM_block4:
    case DW_FORM_exprloc:
        {
            uint64_t a_len = a_value.Unsigned();
            uint64_t b_len = b_value.Unsigned();
            if (a_len < b_len)
                return -1;
            if (a_len > b_len)
                return 1;
            // The block lengths are the same
            return memcmp(a_value.BlockData(), b_value.BlockData(), a_value.Unsigned());
        }
        break;

    case DW_FORM_ref1:
    case DW_FORM_ref2:
    case DW_FORM_ref4:
    case DW_FORM_ref8:
    case DW_FORM_ref_udata:
        {
            uint64_t a = a_value.Reference(a_cu);
            uint64_t b = b_value.Reference(b_cu);
            if (a < b)
                return -1;
            if (a > b)
                return 1;
            return 0;
        }

    case DW_FORM_indirect:
        assert(!"This shouldn't happen after the form has been extracted...");
        break;

    default:
        assert(!"Unhandled DW_FORM");
        break;
    }
    return -1;
}