1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 16:18:12 +00:00

LibDebug: Move get_attribute_value to the DwarfInfo class

This commit is contained in:
Gunnar Beutner 2021-04-28 20:12:21 +02:00 committed by Andreas Kling
parent d9ee2c6a89
commit ea6fdad88b
5 changed files with 189 additions and 187 deletions

View file

@ -33,162 +33,13 @@ DIE::DIE(const CompilationUnit& unit, u32 offset)
// We iterate the attributes data only to calculate this DIE's size
for (auto& attribute_spec : abbreviation_info.value().attribute_specifications) {
get_attribute_value(attribute_spec.form, stream);
m_compilation_unit.dwarf_info().get_attribute_value(attribute_spec.form, stream, &m_compilation_unit);
}
}
m_size = stream.offset() - m_offset;
}
DIE::AttributeValue DIE::get_attribute_value(AttributeDataForm form,
InputMemoryStream& debug_info_stream) const
{
AttributeValue value;
auto assign_raw_bytes_value = [&](size_t length) {
value.data.as_raw_bytes.length = length;
value.data.as_raw_bytes.bytes = reinterpret_cast<const u8*>(m_compilation_unit.dwarf_info().debug_info_data().data()
+ debug_info_stream.offset());
debug_info_stream.discard_or_error(length);
};
switch (form) {
case AttributeDataForm::StringPointer: {
u32 offset;
debug_info_stream >> offset;
VERIFY(!debug_info_stream.has_any_error());
value.type = AttributeValue::Type::String;
auto strings_data = m_compilation_unit.dwarf_info().debug_strings_data();
value.data.as_string = reinterpret_cast<const char*>(strings_data.data() + offset);
break;
}
case AttributeDataForm::Data1: {
u8 data;
debug_info_stream >> data;
VERIFY(!debug_info_stream.has_any_error());
value.type = AttributeValue::Type::UnsignedNumber;
value.data.as_u32 = data;
break;
}
case AttributeDataForm::Data2: {
u16 data;
debug_info_stream >> data;
VERIFY(!debug_info_stream.has_any_error());
value.type = AttributeValue::Type::UnsignedNumber;
value.data.as_u32 = data;
break;
}
case AttributeDataForm::Addr: {
u32 address;
debug_info_stream >> address;
VERIFY(!debug_info_stream.has_any_error());
value.type = AttributeValue::Type::UnsignedNumber;
value.data.as_u32 = address;
break;
}
case AttributeDataForm::SData: {
ssize_t data;
debug_info_stream.read_LEB128_signed(data);
VERIFY(!debug_info_stream.has_any_error());
value.type = AttributeValue::Type::SignedNumber;
value.data.as_i32 = data;
break;
}
case AttributeDataForm::SecOffset: {
u32 data;
debug_info_stream >> data;
VERIFY(!debug_info_stream.has_any_error());
value.type = AttributeValue::Type::SecOffset;
value.data.as_u32 = data;
break;
}
case AttributeDataForm::Data4: {
u32 data;
debug_info_stream >> data;
VERIFY(!debug_info_stream.has_any_error());
value.type = AttributeValue::Type::UnsignedNumber;
value.data.as_u32 = data;
break;
}
case AttributeDataForm::Data8: {
u64 data;
debug_info_stream >> data;
VERIFY(!debug_info_stream.has_any_error());
value.type = AttributeValue::Type::LongUnsignedNumber;
value.data.as_u64 = data;
break;
}
case AttributeDataForm::Ref4: {
u32 data;
debug_info_stream >> data;
VERIFY(!debug_info_stream.has_any_error());
value.type = AttributeValue::Type::DieReference;
value.data.as_u32 = data + m_compilation_unit.offset();
break;
}
case AttributeDataForm::FlagPresent: {
value.type = AttributeValue::Type::Boolean;
value.data.as_bool = true;
break;
}
case AttributeDataForm::ExprLoc: {
size_t length;
debug_info_stream.read_LEB128_unsigned(length);
VERIFY(!debug_info_stream.has_any_error());
value.type = AttributeValue::Type::DwarfExpression;
assign_raw_bytes_value(length);
break;
}
case AttributeDataForm::String: {
String str;
u32 str_offset = debug_info_stream.offset();
debug_info_stream >> str;
VERIFY(!debug_info_stream.has_any_error());
value.type = AttributeValue::Type::String;
value.data.as_string = reinterpret_cast<const char*>(str_offset + m_compilation_unit.dwarf_info().debug_info_data().data());
break;
}
case AttributeDataForm::Block1: {
value.type = AttributeValue::Type::RawBytes;
u8 length;
debug_info_stream >> length;
VERIFY(!debug_info_stream.has_any_error());
assign_raw_bytes_value(length);
break;
}
case AttributeDataForm::Block2: {
value.type = AttributeValue::Type::RawBytes;
u16 length;
debug_info_stream >> length;
VERIFY(!debug_info_stream.has_any_error());
assign_raw_bytes_value(length);
break;
}
case AttributeDataForm::Block4: {
value.type = AttributeValue::Type::RawBytes;
u32 length;
debug_info_stream >> length;
VERIFY(!debug_info_stream.has_any_error());
assign_raw_bytes_value(length);
break;
}
case AttributeDataForm::Block: {
value.type = AttributeValue::Type::RawBytes;
size_t length;
debug_info_stream.read_LEB128_unsigned(length);
VERIFY(!debug_info_stream.has_any_error());
assign_raw_bytes_value(length);
break;
}
default:
dbgln("Unimplemented AttributeDataForm: {}", (u32)form);
VERIFY_NOT_REACHED();
}
return value;
}
Optional<DIE::AttributeValue> DIE::get_attribute(const Attribute& attribute) const
Optional<AttributeValue> DIE::get_attribute(const Attribute& attribute) const
{
InputMemoryStream stream { m_compilation_unit.dwarf_info().debug_info_data() };
stream.discard_or_error(m_data_offset);
@ -197,7 +48,7 @@ Optional<DIE::AttributeValue> DIE::get_attribute(const Attribute& attribute) con
VERIFY(abbreviation_info.has_value());
for (const auto& attribute_spec : abbreviation_info.value().attribute_specifications) {
auto value = get_attribute_value(attribute_spec.form, stream);
auto value = m_compilation_unit.dwarf_info().get_attribute_value(attribute_spec.form, stream, &m_compilation_unit);
if (attribute_spec.attribute == attribute) {
return value;
}