mirror of
https://github.com/RGBCube/serenity
synced 2025-06-01 09:58:14 +00:00
LibDebug: Store 64-bit numbers in AttributeValue
This helps us avoid weird truncation issues and fixes a bug on Clang builds where truncation while reading caused the DIE offsets following large LEB128 numbers to be incorrect. This removes the need for the separate `LongUnsignedNumber` type.
This commit is contained in:
parent
efd1aea969
commit
7396e4aedc
6 changed files with 32 additions and 31 deletions
|
@ -15,7 +15,6 @@ struct AttributeValue {
|
|||
enum class Type : u8 {
|
||||
UnsignedNumber,
|
||||
SignedNumber,
|
||||
LongUnsignedNumber,
|
||||
String,
|
||||
DieReference, // Reference to another DIE in the same compilation unit
|
||||
Boolean,
|
||||
|
@ -26,9 +25,8 @@ struct AttributeValue {
|
|||
|
||||
union {
|
||||
FlatPtr as_addr;
|
||||
u32 as_u32;
|
||||
i32 as_i32;
|
||||
u64 as_u64;
|
||||
u64 as_unsigned;
|
||||
i64 as_signed;
|
||||
const char* as_string; // points to bytes in the memory mapped elf image
|
||||
bool as_bool;
|
||||
struct {
|
||||
|
|
|
@ -75,7 +75,7 @@ void DIE::for_each_child(Function<void(DIE const& child)> callback) const
|
|||
auto sibling = current_child->get_attribute(Attribute::Sibling);
|
||||
u32 sibling_offset = 0;
|
||||
if (sibling.has_value()) {
|
||||
sibling_offset = sibling.value().data.as_u32;
|
||||
sibling_offset = sibling.value().data.as_unsigned;
|
||||
}
|
||||
|
||||
if (!sibling.has_value()) {
|
||||
|
|
|
@ -90,7 +90,7 @@ AttributeValue DwarfInfo::get_attribute_value(AttributeDataForm form, ssize_t im
|
|||
debug_info_stream >> data;
|
||||
VERIFY(!debug_info_stream.has_any_error());
|
||||
value.type = AttributeValue::Type::UnsignedNumber;
|
||||
value.data.as_u32 = data;
|
||||
value.data.as_unsigned = data;
|
||||
break;
|
||||
}
|
||||
case AttributeDataForm::Data2: {
|
||||
|
@ -98,7 +98,7 @@ AttributeValue DwarfInfo::get_attribute_value(AttributeDataForm form, ssize_t im
|
|||
debug_info_stream >> data;
|
||||
VERIFY(!debug_info_stream.has_any_error());
|
||||
value.type = AttributeValue::Type::UnsignedNumber;
|
||||
value.data.as_u32 = data;
|
||||
value.data.as_signed = data;
|
||||
break;
|
||||
}
|
||||
case AttributeDataForm::Addr: {
|
||||
|
@ -110,19 +110,19 @@ AttributeValue DwarfInfo::get_attribute_value(AttributeDataForm form, ssize_t im
|
|||
break;
|
||||
}
|
||||
case AttributeDataForm::SData: {
|
||||
ssize_t data;
|
||||
i64 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;
|
||||
value.data.as_signed = data;
|
||||
break;
|
||||
}
|
||||
case AttributeDataForm::UData: {
|
||||
size_t data;
|
||||
u64 data;
|
||||
debug_info_stream.read_LEB128_unsigned(data);
|
||||
VERIFY(!debug_info_stream.has_any_error());
|
||||
value.type = AttributeValue::Type::UnsignedNumber;
|
||||
value.data.as_u32 = data;
|
||||
value.data.as_unsigned = data;
|
||||
break;
|
||||
}
|
||||
case AttributeDataForm::SecOffset: {
|
||||
|
@ -130,7 +130,7 @@ AttributeValue DwarfInfo::get_attribute_value(AttributeDataForm form, ssize_t im
|
|||
debug_info_stream >> data;
|
||||
VERIFY(!debug_info_stream.has_any_error());
|
||||
value.type = AttributeValue::Type::SecOffset;
|
||||
value.data.as_u32 = data;
|
||||
value.data.as_unsigned = data;
|
||||
break;
|
||||
}
|
||||
case AttributeDataForm::Data4: {
|
||||
|
@ -138,15 +138,15 @@ AttributeValue DwarfInfo::get_attribute_value(AttributeDataForm form, ssize_t im
|
|||
debug_info_stream >> data;
|
||||
VERIFY(!debug_info_stream.has_any_error());
|
||||
value.type = AttributeValue::Type::UnsignedNumber;
|
||||
value.data.as_u32 = data;
|
||||
value.data.as_unsigned = 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;
|
||||
value.type = AttributeValue::Type::UnsignedNumber;
|
||||
value.data.as_unsigned = data;
|
||||
break;
|
||||
}
|
||||
case AttributeDataForm::Ref4: {
|
||||
|
@ -155,7 +155,7 @@ AttributeValue DwarfInfo::get_attribute_value(AttributeDataForm form, ssize_t im
|
|||
VERIFY(!debug_info_stream.has_any_error());
|
||||
value.type = AttributeValue::Type::DieReference;
|
||||
VERIFY(unit);
|
||||
value.data.as_u32 = data + unit->offset();
|
||||
value.data.as_unsigned = data + unit->offset();
|
||||
break;
|
||||
}
|
||||
case AttributeDataForm::FlagPresent: {
|
||||
|
@ -225,7 +225,7 @@ AttributeValue DwarfInfo::get_attribute_value(AttributeDataForm form, ssize_t im
|
|||
case AttributeDataForm::ImplicitConst: {
|
||||
/* Value is part of the abbreviation record. */
|
||||
value.type = AttributeValue::Type::SignedNumber;
|
||||
value.data.as_i32 = implicit_const_value;
|
||||
value.data.as_signed = implicit_const_value;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
@ -250,7 +250,7 @@ void DwarfInfo::build_cached_dies() const
|
|||
if (!start.has_value() || !end.has_value())
|
||||
return {};
|
||||
|
||||
VERIFY(start->type == Dwarf::AttributeValue::Type::UnsignedNumber);
|
||||
VERIFY(start->form == Dwarf::AttributeDataForm::Addr);
|
||||
|
||||
// DW_AT_high_pc attribute can have different meanings depending on the attribute form.
|
||||
// (Dwarf version 5, section 2.17.2).
|
||||
|
@ -259,9 +259,9 @@ void DwarfInfo::build_cached_dies() const
|
|||
if (end->form == Dwarf::AttributeDataForm::Addr)
|
||||
range_end = end->data.as_addr;
|
||||
else
|
||||
range_end = start->data.as_u32 + end->data.as_u32;
|
||||
range_end = start->data.as_unsigned + end->data.as_unsigned;
|
||||
|
||||
return { DIERange { start.value().data.as_u32, range_end } };
|
||||
return { DIERange { (FlatPtr)start.value().data.as_addr, range_end } };
|
||||
};
|
||||
|
||||
// If we simply use a lambda, type deduction fails because it's used recursively.
|
||||
|
|
|
@ -63,7 +63,7 @@ void LineProgram::parse_path_entries(Function<void(PathEntry& entry)> callback,
|
|||
entry.path = value.data.as_string;
|
||||
break;
|
||||
case ContentType::DirectoryIndex:
|
||||
entry.directory_index = value.data.as_u32;
|
||||
entry.directory_index = value.data.as_unsigned;
|
||||
break;
|
||||
default:
|
||||
dbgln_if(DWARF_DEBUG, "Unhandled path list attribute: {}", (int)format_description.type);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue