diff options
author | Itamar <itamar8910@gmail.com> | 2021-01-09 11:11:02 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-01-09 10:56:04 +0100 |
commit | 4728d0dd6a0afcc117da1e83158ad3ab772d24c0 (patch) | |
tree | 22dbccac52ceadb6ec294098256c81d1e07807d4 | |
parent | 1af2f65df513ad6dc6505c3f136ff04065425170 (diff) | |
download | serenity-4728d0dd6a0afcc117da1e83158ad3ab772d24c0.zip |
Profiler: Fix disassembly view to work with shared libraries
Also, update path to kernel image from "boot/kernel" to "boot/Kernel".
Fixes #4555
-rw-r--r-- | DevTools/Profiler/DisassemblyModel.cpp | 39 | ||||
-rw-r--r-- | DevTools/Profiler/DisassemblyModel.h | 2 |
2 files changed, 27 insertions, 14 deletions
diff --git a/DevTools/Profiler/DisassemblyModel.cpp b/DevTools/Profiler/DisassemblyModel.cpp index d45b165c2e..825d76f4a1 100644 --- a/DevTools/Profiler/DisassemblyModel.cpp +++ b/DevTools/Profiler/DisassemblyModel.cpp @@ -55,26 +55,39 @@ DisassemblyModel::DisassemblyModel(Profile& profile, ProfileNode& node) : m_profile(profile) , m_node(node) { - String path; - if (m_node.address() >= 0xc0000000) - path = "/boot/Kernel"; - else - path = profile.executable_path(); - m_file = make<MappedFile>(path); - - if (!m_file->is_valid()) - return; + OwnPtr<ELF::Image> kernel_elf; + const ELF::Image* elf; + FlatPtr base_address = 0; + if (m_node.address() >= 0xc0000000) { + if (!m_kernel_file) { + m_kernel_file = new MappedFile("/boot/Kernel"); + if (!m_kernel_file->is_valid()) + return; + } + kernel_elf = make<ELF::Image>((const u8*)m_kernel_file->data(), m_kernel_file->size()); + elf = kernel_elf.ptr(); + } else { + auto library_data = profile.coredump().library_containing(node.address()); + if (!library_data) { + dbgln("no library data"); + return; + } + elf = &library_data->lib_elf; + base_address = library_data->base_address; + } - auto elf = ELF::Image((const u8*)m_file->data(), m_file->size()); + ASSERT(elf != nullptr); - auto symbol = elf.find_symbol(node.address()); - if (!symbol.has_value()) + auto symbol = elf->find_symbol(node.address() - base_address); + if (!symbol.has_value()) { + dbgln("DisassemblyModel: symbol not found"); return; + } ASSERT(symbol.has_value()); auto view = symbol.value().raw_data(); - X86::ELFSymbolProvider symbol_provider(elf); + X86::ELFSymbolProvider symbol_provider(*elf); X86::SimpleInstructionStream stream((const u8*)view.characters_without_null_termination(), view.length()); X86::Disassembler disassembler(stream); diff --git a/DevTools/Profiler/DisassemblyModel.h b/DevTools/Profiler/DisassemblyModel.h index 52465d0818..cd856d6e21 100644 --- a/DevTools/Profiler/DisassemblyModel.h +++ b/DevTools/Profiler/DisassemblyModel.h @@ -69,7 +69,7 @@ private: Profile& m_profile; ProfileNode& m_node; - OwnPtr<MappedFile> m_file; + OwnPtr<MappedFile> m_kernel_file; Vector<InstructionData> m_instructions; }; |