1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 21:07:35 +00:00

LibDebug: Propagate errors throughout DWARF parsing

Splitting this into a separate commit was an afterthought, so this does
not yet feature any fallible operations.
This commit is contained in:
Tim Schumacher 2023-01-22 00:32:08 +01:00 committed by Andreas Kling
parent e235c42e4d
commit e62269650a
17 changed files with 243 additions and 204 deletions

View file

@ -15,10 +15,10 @@ namespace Debug::Dwarf {
DIE::DIE(CompilationUnit const& unit, u32 offset, Optional<u32> parent_offset)
: m_compilation_unit(unit)
{
rehydrate_from(offset, parent_offset);
rehydrate_from(offset, parent_offset).release_value_but_fixme_should_propagate_errors();
}
void DIE::rehydrate_from(u32 offset, Optional<u32> parent_offset)
ErrorOr<void> DIE::rehydrate_from(u32 offset, Optional<u32> parent_offset)
{
m_offset = offset;
@ -39,14 +39,15 @@ void DIE::rehydrate_from(u32 offset, Optional<u32> parent_offset)
// We iterate the attributes data only to calculate this DIE's size
for (auto& attribute_spec : abbreviation_info->attribute_specifications) {
m_compilation_unit.dwarf_info().get_attribute_value(attribute_spec.form, attribute_spec.value, stream, &m_compilation_unit);
TRY(m_compilation_unit.dwarf_info().get_attribute_value(attribute_spec.form, attribute_spec.value, stream, &m_compilation_unit));
}
}
m_size = stream.offset() - m_offset;
m_parent_offset = parent_offset;
return {};
}
Optional<AttributeValue> DIE::get_attribute(Attribute const& attribute) const
ErrorOr<Optional<AttributeValue>> DIE::get_attribute(Attribute const& attribute) const
{
InputMemoryStream stream { m_compilation_unit.dwarf_info().debug_info_data() };
stream.discard_or_error(m_data_offset);
@ -55,42 +56,45 @@ Optional<AttributeValue> DIE::get_attribute(Attribute const& attribute) const
VERIFY(abbreviation_info);
for (auto const& attribute_spec : abbreviation_info->attribute_specifications) {
auto value = m_compilation_unit.dwarf_info().get_attribute_value(attribute_spec.form, attribute_spec.value, stream, &m_compilation_unit);
auto value = TRY(m_compilation_unit.dwarf_info().get_attribute_value(attribute_spec.form, attribute_spec.value, stream, &m_compilation_unit));
if (attribute_spec.attribute == attribute) {
return value;
}
}
return {};
return Optional<AttributeValue> {};
}
void DIE::for_each_child(Function<void(DIE const& child)> callback) const
ErrorOr<void> DIE::for_each_child(Function<ErrorOr<void>(DIE const& child)> callback) const
{
if (!m_has_children)
return;
return {};
auto current_child = DIE(m_compilation_unit, m_offset + m_size, m_offset);
while (true) {
callback(current_child);
TRY(callback(current_child));
if (current_child.is_null())
break;
if (!current_child.has_children()) {
current_child.rehydrate_from(current_child.offset() + current_child.size(), m_offset);
TRY(current_child.rehydrate_from(current_child.offset() + current_child.size(), m_offset));
continue;
}
auto sibling = current_child.get_attribute(Attribute::Sibling);
auto sibling = TRY(current_child.get_attribute(Attribute::Sibling));
u32 sibling_offset = 0;
if (sibling.has_value()) {
sibling_offset = sibling.value().as_unsigned();
} else {
// NOTE: According to the spec, the compiler doesn't have to supply the sibling information.
// When it doesn't, we have to recursively iterate the current child's children to find where they end
current_child.for_each_child([&](DIE const& sub_child) {
TRY(current_child.for_each_child([&](DIE const& sub_child) -> ErrorOr<void> {
sibling_offset = sub_child.offset() + sub_child.size();
});
return {};
}));
}
current_child.rehydrate_from(sibling_offset, m_offset);
TRY(current_child.rehydrate_from(sibling_offset, m_offset));
}
return {};
}
}