LocationList location_list( simgrid::mc::ObjectInformation& info, Dwarf_Attribute& attr) { LocationList locations; std::ptrdiff_t offset = 0; while (1) { Dwarf_Addr base, start, end; Dwarf_Op *ops; std::size_t len; offset = dwarf_getlocations( &attr, offset, &base, &start, &end, &ops, &len); if (offset == 0) break; else if (offset == -1) xbt_die("Error while loading location list"); std::uint64_t base_address = (std::uint64_t) info.base_address(); LocationListEntry::range_type range; if (start == 0) // If start == 0, this is not a location list: range = { 0, UINT64_MAX }; else range = { base_address + start, base_address + end }; locations.push_back({ DwarfExpression(ops, ops+len), range }); } return locations; }
QVariant DwarfDie::attributeLocal(Dwarf_Half attributeType) const { Dwarf_Attribute attr; auto res = dwarf_attr(m_die, attributeType, &attr, nullptr); if (res != DW_DLV_OK) return {}; Dwarf_Half formType; res = dwarf_whatform(attr, &formType, nullptr); if (res != DW_DLV_OK) return {}; QVariant value; switch (formType) { case DW_FORM_data1: case DW_FORM_data2: case DW_FORM_data4: case DW_FORM_data8: case DW_FORM_udata: { Dwarf_Unsigned n; res = dwarf_formudata(attr, &n, nullptr); value = n; break; } case DW_FORM_sdata: { Dwarf_Signed n; res = dwarf_formsdata(attr, &n, nullptr); value = n; break; } case DW_FORM_string: case DW_FORM_strp: { char *str; res = dwarf_formstring(attr, &str, nullptr); value = QByteArray(str); break; } case DW_FORM_flag: case DW_FORM_flag_present: { Dwarf_Bool b; res = dwarf_formflag(attr, &b, nullptr); value = b ? true : false; break; } case DW_FORM_ref1: case DW_FORM_ref2: case DW_FORM_ref4: case DW_FORM_ref8: { Dwarf_Off offset; res = dwarf_global_formref(attr, &offset, nullptr); value = QVariant::fromValue(dwarfInfo()->dieAtOffset(offset)); break; } case DW_FORM_sec_offset: { Dwarf_Off offset; res = dwarf_global_formref(attr, &offset, nullptr); value = offset; break; } case DW_FORM_addr: { Dwarf_Addr addr; res = dwarf_formaddr(attr, &addr, nullptr); value = addr; break; } case DW_FORM_exprloc: { Dwarf_Unsigned len; Dwarf_Ptr block; res = dwarf_formexprloc(attr, &len, &block, nullptr); value = QVariant::fromValue(DwarfExpression(block, len, dwarfInfo()->elfFile()->addressSize())); break; } default: { const char* formName; res = dwarf_get_FORM_name(formType, &formName); if (res != DW_DLV_OK) return {}; value = QStringLiteral("TODO: ") + QString::fromLocal8Bit(formName); break; } } // post-process some well-known types switch (attributeType) { case DW_AT_decl_file: case DW_AT_call_file: { const auto fileIndex = value.value<Dwarf_Unsigned>(); // index 0 means not present, TODO handle that value = compilationUnit()->sourceFileForIndex(fileIndex -1); break; } case DW_AT_ranges: value = QVariant::fromValue(DwarfRanges(this, value.toLongLong())); break; case DW_AT_accessibility: stringifyEnum(value, &dwarf_get_ACCESS_name); break; case DW_AT_language: stringifyEnum(value, &dwarf_get_LANG_name); break; case DW_AT_virtuality: value = QVariant::fromValue(static_cast<DwarfVirtuality>(value.toInt())); break; case DW_AT_visibility: stringifyEnum(value, &dwarf_get_VIS_name); break; case DW_AT_identifier_case: stringifyEnum(value, &dwarf_get_ID_name); break; case DW_AT_inline: stringifyEnum(value, &dwarf_get_INL_name); break; case DW_AT_encoding: stringifyEnum(value, &dwarf_get_ATE_name); break; case DW_AT_ordering: stringifyEnum(value, &dwarf_get_ORD_name); break; case DW_AT_calling_convention: stringifyEnum(value, &dwarf_get_CC_name); break; case DW_AT_discr_list: stringifyEnum(value, &dwarf_get_DSC_name); break; default: break; } return value; }