mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 07:17:35 +00:00
LibDebug: Store optional parent_offset in Dwarf::DIE objects
In the current implementation, only DIE objects that are created via DIE::for_each_child() will have parent offsets. DIE objects that are created with CompilationUnit::get_die_at_offset() do not currently store a parent offset. We may improve this in the future, but this is enough for what we currently need.
This commit is contained in:
parent
84609aecc1
commit
a5f69efa5c
2 changed files with 9 additions and 6 deletions
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2020, Itamar S. <itamar8910@gmail.com>
|
* Copyright (c) 2020-2021, Itamar S. <itamar8910@gmail.com>
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
@ -12,7 +12,7 @@
|
||||||
|
|
||||||
namespace Debug::Dwarf {
|
namespace Debug::Dwarf {
|
||||||
|
|
||||||
DIE::DIE(const CompilationUnit& unit, u32 offset)
|
DIE::DIE(const CompilationUnit& unit, u32 offset, Optional<u32> parent_offset)
|
||||||
: m_compilation_unit(unit)
|
: m_compilation_unit(unit)
|
||||||
, m_offset(offset)
|
, m_offset(offset)
|
||||||
{
|
{
|
||||||
|
@ -37,6 +37,7 @@ DIE::DIE(const CompilationUnit& unit, u32 offset)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m_size = stream.offset() - m_offset;
|
m_size = stream.offset() - m_offset;
|
||||||
|
m_parent_offset = parent_offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<AttributeValue> DIE::get_attribute(const Attribute& attribute) const
|
Optional<AttributeValue> DIE::get_attribute(const Attribute& attribute) const
|
||||||
|
@ -61,13 +62,13 @@ void DIE::for_each_child(Function<void(const DIE& child)> callback) const
|
||||||
if (!m_has_children)
|
if (!m_has_children)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
NonnullOwnPtr<DIE> current_child = make<DIE>(m_compilation_unit, m_offset + m_size);
|
NonnullOwnPtr<DIE> current_child = make<DIE>(m_compilation_unit, m_offset + m_size, m_offset);
|
||||||
while (true) {
|
while (true) {
|
||||||
callback(*current_child);
|
callback(*current_child);
|
||||||
if (current_child->is_null())
|
if (current_child->is_null())
|
||||||
break;
|
break;
|
||||||
if (!current_child->has_children()) {
|
if (!current_child->has_children()) {
|
||||||
current_child = make<DIE>(m_compilation_unit, current_child->offset() + current_child->size());
|
current_child = make<DIE>(m_compilation_unit, current_child->offset() + current_child->size(), m_offset);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,7 +85,7 @@ void DIE::for_each_child(Function<void(const DIE& child)> callback) const
|
||||||
sibling_offset = sub_child.offset() + sub_child.size();
|
sibling_offset = sub_child.offset() + sub_child.size();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
current_child = make<DIE>(m_compilation_unit, sibling_offset);
|
current_child = make<DIE>(m_compilation_unit, sibling_offset, m_offset);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2020, Itamar S. <itamar8910@gmail.com>
|
* Copyright (c) 2020-2021, Itamar S. <itamar8910@gmail.com>
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
@ -33,6 +33,7 @@ public:
|
||||||
|
|
||||||
bool is_null() const { return m_tag == EntryTag::None; }
|
bool is_null() const { return m_tag == EntryTag::None; }
|
||||||
const CompilationUnit& compilation_unit() const { return m_compilation_unit; }
|
const CompilationUnit& compilation_unit() const { return m_compilation_unit; }
|
||||||
|
Optional<u32> parent_offset() const { return m_parent_offset; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const CompilationUnit& m_compilation_unit;
|
const CompilationUnit& m_compilation_unit;
|
||||||
|
@ -42,6 +43,7 @@ private:
|
||||||
EntryTag m_tag { EntryTag::None };
|
EntryTag m_tag { EntryTag::None };
|
||||||
bool m_has_children { false };
|
bool m_has_children { false };
|
||||||
u32 m_size { 0 };
|
u32 m_size { 0 };
|
||||||
|
Optional<u32> m_parent_offset;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue