From a5f69efa5c3ffd7f26fc0c69b3079c9f40edff71 Mon Sep 17 00:00:00 2001 From: Itamar Date: Sat, 19 Jun 2021 11:39:51 +0300 Subject: [PATCH] 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. --- Userland/Libraries/LibDebug/Dwarf/DIE.cpp | 11 ++++++----- Userland/Libraries/LibDebug/Dwarf/DIE.h | 4 +++- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/Userland/Libraries/LibDebug/Dwarf/DIE.cpp b/Userland/Libraries/LibDebug/Dwarf/DIE.cpp index 65c5353a53..e80835b2ff 100644 --- a/Userland/Libraries/LibDebug/Dwarf/DIE.cpp +++ b/Userland/Libraries/LibDebug/Dwarf/DIE.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, Itamar S. + * Copyright (c) 2020-2021, Itamar S. * * SPDX-License-Identifier: BSD-2-Clause */ @@ -12,7 +12,7 @@ namespace Debug::Dwarf { -DIE::DIE(const CompilationUnit& unit, u32 offset) +DIE::DIE(const CompilationUnit& unit, u32 offset, Optional parent_offset) : m_compilation_unit(unit) , m_offset(offset) { @@ -37,6 +37,7 @@ DIE::DIE(const CompilationUnit& unit, u32 offset) } } m_size = stream.offset() - m_offset; + m_parent_offset = parent_offset; } Optional DIE::get_attribute(const Attribute& attribute) const @@ -61,13 +62,13 @@ void DIE::for_each_child(Function callback) const if (!m_has_children) return; - NonnullOwnPtr current_child = make(m_compilation_unit, m_offset + m_size); + NonnullOwnPtr current_child = make(m_compilation_unit, m_offset + m_size, m_offset); while (true) { callback(*current_child); if (current_child->is_null()) break; if (!current_child->has_children()) { - current_child = make(m_compilation_unit, current_child->offset() + current_child->size()); + current_child = make(m_compilation_unit, current_child->offset() + current_child->size(), m_offset); continue; } @@ -84,7 +85,7 @@ void DIE::for_each_child(Function callback) const sibling_offset = sub_child.offset() + sub_child.size(); }); } - current_child = make(m_compilation_unit, sibling_offset); + current_child = make(m_compilation_unit, sibling_offset, m_offset); } } diff --git a/Userland/Libraries/LibDebug/Dwarf/DIE.h b/Userland/Libraries/LibDebug/Dwarf/DIE.h index 67fc1e1e2e..5ee98c6a29 100644 --- a/Userland/Libraries/LibDebug/Dwarf/DIE.h +++ b/Userland/Libraries/LibDebug/Dwarf/DIE.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, Itamar S. + * Copyright (c) 2020-2021, Itamar S. * * SPDX-License-Identifier: BSD-2-Clause */ @@ -33,6 +33,7 @@ public: bool is_null() const { return m_tag == EntryTag::None; } const CompilationUnit& compilation_unit() const { return m_compilation_unit; } + Optional parent_offset() const { return m_parent_offset; } private: const CompilationUnit& m_compilation_unit; @@ -42,6 +43,7 @@ private: EntryTag m_tag { EntryTag::None }; bool m_has_children { false }; u32 m_size { 0 }; + Optional m_parent_offset; }; }