diff options
author | Itamar <itamar8910@gmail.com> | 2021-09-28 13:26:49 +0300 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-09-28 16:54:39 +0200 |
commit | 2b04a86d4d7398947aab66ebfcd4ce3b0392383f (patch) | |
tree | 12283d1b53cd1dfa231eb45c1a8f578af252ce34 /Userland/Libraries/LibDebug | |
parent | 01417c82c585162ec516736213245a347c4a3c01 (diff) | |
download | serenity-2b04a86d4d7398947aab66ebfcd4ce3b0392383f.zip |
LibDebug: Add Dwarf::CompilationUnit::base_address()
The base address of the compilation unit is used in some range lists
entry types.
Diffstat (limited to 'Userland/Libraries/LibDebug')
-rw-r--r-- | Userland/Libraries/LibDebug/Dwarf/CompilationUnit.cpp | 14 | ||||
-rw-r--r-- | Userland/Libraries/LibDebug/Dwarf/CompilationUnit.h | 3 |
2 files changed, 17 insertions, 0 deletions
diff --git a/Userland/Libraries/LibDebug/Dwarf/CompilationUnit.cpp b/Userland/Libraries/LibDebug/Dwarf/CompilationUnit.cpp index 07ffc30993..d78472cc7b 100644 --- a/Userland/Libraries/LibDebug/Dwarf/CompilationUnit.cpp +++ b/Userland/Libraries/LibDebug/Dwarf/CompilationUnit.cpp @@ -30,4 +30,18 @@ DIE CompilationUnit::get_die_at_offset(u32 die_offset) const return DIE(*this, die_offset); } +Optional<FlatPtr> CompilationUnit::base_address() const +{ + if (m_has_cached_base_address) + return m_cached_base_address; + + auto die = root_die(); + auto res = die.get_attribute(Attribute::LowPc); + if (res.has_value()) { + m_cached_base_address = res->data.as_addr; + } + m_has_cached_base_address = true; + return m_cached_base_address; +} + } diff --git a/Userland/Libraries/LibDebug/Dwarf/CompilationUnit.h b/Userland/Libraries/LibDebug/Dwarf/CompilationUnit.h index 5acb1a2088..c860d1237a 100644 --- a/Userland/Libraries/LibDebug/Dwarf/CompilationUnit.h +++ b/Userland/Libraries/LibDebug/Dwarf/CompilationUnit.h @@ -34,6 +34,7 @@ public: DwarfInfo const& dwarf_info() const { return m_dwarf_info; } AbbreviationsMap const& abbreviations_map() const { return m_abbreviations; } LineProgram const& line_program() const { return *m_line_program; } + Optional<FlatPtr> base_address() const; private: DwarfInfo const& m_dwarf_info; @@ -41,6 +42,8 @@ private: CompilationUnitHeader m_header; AbbreviationsMap m_abbreviations; NonnullOwnPtr<LineProgram> m_line_program; + mutable bool m_has_cached_base_address { false }; + mutable Optional<FlatPtr> m_cached_base_address; }; } |