diff options
author | Itamar <itamar8910@gmail.com> | 2020-11-28 15:04:20 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-12-14 23:05:53 +0100 |
commit | 93b68f5566c54699d4fcf0d982c879aeeb3eb8c1 (patch) | |
tree | b5209eac3eb62f6d92fdc01519943c665c580624 | |
parent | 0220b5361eadf50b536c7e1ed46a4393817d4ad7 (diff) | |
download | serenity-93b68f5566c54699d4fcf0d982c879aeeb3eb8c1.zip |
LibELF: Move the implementation of find_demangled_function to ELF::Image
-rw-r--r-- | Libraries/LibELF/Image.cpp | 20 | ||||
-rw-r--r-- | Libraries/LibELF/Image.h | 2 | ||||
-rw-r--r-- | Libraries/LibELF/Loader.cpp | 19 | ||||
-rw-r--r-- | Libraries/LibELF/Loader.h | 5 |
4 files changed, 26 insertions, 20 deletions
diff --git a/Libraries/LibELF/Image.cpp b/Libraries/LibELF/Image.cpp index 8a5b7f56d8..d91c9558ab 100644 --- a/Libraries/LibELF/Image.cpp +++ b/Libraries/LibELF/Image.cpp @@ -24,6 +24,7 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include <AK/Demangle.h> #include <AK/Memory.h> #include <AK/StringBuilder.h> #include <AK/StringView.h> @@ -301,4 +302,23 @@ StringView Image::Symbol::raw_data() const return { section.raw_data() + (value() - section.address()), size() }; } +Optional<Image::Symbol> Image::find_demangled_function(const String& name) const +{ + Optional<Image::Symbol> found; + for_each_symbol([&](const Image::Symbol symbol) { + if (symbol.type() != STT_FUNC) + return IterationDecision::Continue; + auto demangled = demangle(symbol.name()); + auto index_of_paren = demangled.index_of("("); + if (index_of_paren.has_value()) { + demangled = demangled.substring(0, index_of_paren.value()); + } + if (demangled != name) + return IterationDecision::Continue; + found = symbol; + return IterationDecision::Break; + }); + return found; +} + } // end namespace ELF diff --git a/Libraries/LibELF/Image.h b/Libraries/LibELF/Image.h index 5253ec8aa6..fb45e0e562 100644 --- a/Libraries/LibELF/Image.h +++ b/Libraries/LibELF/Image.h @@ -208,6 +208,8 @@ public: FlatPtr base_address() const { return (FlatPtr)m_buffer; } size_t size() const { return m_size; } + Optional<Symbol> find_demangled_function(const String& name) const; + private: const char* raw_data(unsigned offset) const; const Elf32_Ehdr& header() const; diff --git a/Libraries/LibELF/Loader.cpp b/Libraries/LibELF/Loader.cpp index 1260a862b9..d585dc4b05 100644 --- a/Libraries/LibELF/Loader.cpp +++ b/Libraries/LibELF/Loader.cpp @@ -144,25 +144,6 @@ bool Loader::layout() return !failed; } -Optional<Image::Symbol> Loader::find_demangled_function(const String& name) const -{ - Optional<Image::Symbol> found; - m_image.for_each_symbol([&](const Image::Symbol symbol) { - if (symbol.type() != STT_FUNC) - return IterationDecision::Continue; - auto demangled = demangle(symbol.name()); - auto index_of_paren = demangled.index_of("("); - if (index_of_paren.has_value()) { - demangled = demangled.substring(0, index_of_paren.value()); - } - if (demangled != name) - return IterationDecision::Continue; - found = symbol; - return IterationDecision::Break; - }); - return found; -} - #ifndef KERNEL Optional<Image::Symbol> Loader::find_symbol(u32 address, u32* out_offset) const { diff --git a/Libraries/LibELF/Loader.h b/Libraries/LibELF/Loader.h index adb3b0b17c..cafbcdca6c 100644 --- a/Libraries/LibELF/Loader.h +++ b/Libraries/LibELF/Loader.h @@ -59,7 +59,10 @@ public: return m_image.entry(); } const Image& image() const { return m_image; } - Optional<Image::Symbol> find_demangled_function(const String& name) const; + Optional<Image::Symbol> find_demangled_function(const String& name) const + { + return m_image.find_demangled_function(name); + } bool has_symbols() const { return m_symbol_count; } |