mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 03:57:43 +00:00
LibDebug: Move get_attribute_value to the DwarfInfo class
This commit is contained in:
parent
d9ee2c6a89
commit
ea6fdad88b
5 changed files with 189 additions and 187 deletions
|
@ -48,4 +48,154 @@ void DwarfInfo::populate_compilation_units()
|
|||
}
|
||||
}
|
||||
|
||||
AttributeValue DwarfInfo::get_attribute_value(AttributeDataForm form,
|
||||
InputMemoryStream& debug_info_stream, const CompilationUnit* unit) 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*>(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 = 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;
|
||||
VERIFY(unit);
|
||||
value.data.as_u32 = data + 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 + 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue