/* * Copyright (c) 2021, Itamar S. * * SPDX-License-Identifier: BSD-2-Clause */ #include "Inspector.h" namespace Coredump { OwnPtr Inspector::create(String const& coredump_path, Function on_progress) { auto reader = Reader::create(coredump_path); if (!reader) return {}; return AK::adopt_own_if_nonnull(new (nothrow) Inspector(reader.release_nonnull(), move(on_progress))); } Inspector::Inspector(NonnullOwnPtr&& reader, Function on_progress) : m_reader(move(reader)) { parse_loaded_libraries(move(on_progress)); } size_t Inspector::number_of_libraries_in_coredump() const { size_t count = 0; m_reader->for_each_library([&count](Coredump::Reader::LibraryInfo) { ++count; }); return count; } void Inspector::parse_loaded_libraries(Function on_progress) { size_t number_of_libraries = number_of_libraries_in_coredump(); size_t library_index = 0; m_reader->for_each_library([this, number_of_libraries, &library_index, &on_progress](Coredump::Reader::LibraryInfo library) { ++library_index; if (on_progress) on_progress(library_index / (float)number_of_libraries); auto file_or_error = Core::MappedFile::map(library.path); if (file_or_error.is_error()) return; auto image = make(file_or_error.value()->bytes()); auto debug_info = make(*image, String {}, library.base_address); m_loaded_libraries.append(make(library.name, file_or_error.value(), move(image), move(debug_info), library.base_address)); }); } bool Inspector::poke(void*, FlatPtr) { return false; } Optional Inspector::peek(void* address) const { return m_reader->peek_memory((FlatPtr)address); } PtraceRegisters Inspector::get_registers() const { PtraceRegisters registers {}; m_reader->for_each_thread_info([&](ELF::Core::ThreadInfo const& thread_info) { registers = thread_info.regs; return IterationDecision::Break; }); return registers; } void Inspector::set_registers(PtraceRegisters const&) {}; void Inspector::for_each_loaded_library(Function func) const { for (auto& library : m_loaded_libraries) { if (func(library) == IterationDecision::Break) break; } } }