diff --git a/Applications/CrashDaemon/main.cpp b/Applications/CrashDaemon/main.cpp index eca299c191..479d226a1c 100644 --- a/Applications/CrashDaemon/main.cpp +++ b/Applications/CrashDaemon/main.cpp @@ -31,7 +31,7 @@ #include #include #include -#include +#include #include #include #include @@ -106,7 +106,7 @@ static const ElfObjectInfo* object_info_for_region(const ELF::Core::MemoryRegion return info_ptr; } -static String backtrace_line(const CoreDumpReader& coredump, FlatPtr eip) +static String backtrace_line(const CoreDump::Reader& coredump, FlatPtr eip) { auto* region = coredump.region_containing((FlatPtr)eip); if (!region) @@ -133,7 +133,7 @@ static String backtrace_line(const CoreDumpReader& coredump, FlatPtr eip) static void backtrace(const String& coredump_path) { size_t thread_index = 0; - auto coredump = CoreDumpReader::create(coredump_path); + auto coredump = CoreDump::Reader::create(coredump_path); coredump->for_each_thread_info([&thread_index, &coredump](const ELF::Core::ThreadInfo* thread_info) { dbgln("Backtrace for thread #{}, tid={}", thread_index++, thread_info->tid); diff --git a/DevTools/Profiler/Profile.cpp b/DevTools/Profiler/Profile.cpp index 8de2fe9c82..513756d1af 100644 --- a/DevTools/Profiler/Profile.cpp +++ b/DevTools/Profiler/Profile.cpp @@ -32,7 +32,7 @@ #include #include #include -#include +#include #include #include #include @@ -95,7 +95,7 @@ static String symbolicate(FlatPtr eip, const ELF::Core::MemoryRegionInfo* region return String::format("[%s] %s", name.characters(), lib_data->lib_elf.symbolicate(eip - region->region_start, &offset).characters()); } -static String symbolicate_from_coredump(CoreDumpReader& coredump, u32 ptr, [[maybe_unused]] u32& offset) +static String symbolicate_from_coredump(CoreDump::Reader& coredump, u32 ptr, [[maybe_unused]] u32& offset) { auto* region = coredump.region_containing((FlatPtr)ptr); if (!region) { @@ -277,7 +277,7 @@ Result, String> Profile::load_from_perfcore_file(const St auto& object = json.value().as_object(); auto executable_path = object.get("executable").to_string(); - auto coredump = CoreDumpReader::create(String::formatted("/tmp/profiler_coredumps/{}", object.get("pid").as_u32())); + auto coredump = CoreDump::Reader::create(String::formatted("/tmp/profiler_coredumps/{}", object.get("pid").as_u32())); if (!coredump) return String { "Could not open coredump" }; diff --git a/Libraries/LibCoreDump/CMakeLists.txt b/Libraries/LibCoreDump/CMakeLists.txt index dd85d22d36..4ddec4b1f5 100644 --- a/Libraries/LibCoreDump/CMakeLists.txt +++ b/Libraries/LibCoreDump/CMakeLists.txt @@ -1,5 +1,5 @@ set(SOURCES - CoreDumpReader.cpp + Reader.cpp ) serenity_lib(LibCoreDump coredump) diff --git a/Libraries/LibCoreDump/CoreDumpReader.cpp b/Libraries/LibCoreDump/Reader.cpp similarity index 83% rename from Libraries/LibCoreDump/CoreDumpReader.cpp rename to Libraries/LibCoreDump/Reader.cpp index d4890698fe..13f36f2795 100644 --- a/Libraries/LibCoreDump/CoreDumpReader.cpp +++ b/Libraries/LibCoreDump/Reader.cpp @@ -24,18 +24,20 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "CoreDumpReader.h" +#include "Reader.h" #include -OwnPtr CoreDumpReader::create(const String& path) +namespace CoreDump { + +OwnPtr Reader::create(const String& path) { auto mapped_file = make(path); if (!mapped_file->is_valid()) return nullptr; - return make(move(mapped_file)); + return make(move(mapped_file)); } -CoreDumpReader::CoreDumpReader(OwnPtr&& coredump_file) +Reader::Reader(OwnPtr&& coredump_file) : m_coredump_file(move(coredump_file)) , m_coredump_image((u8*)m_coredump_file->data(), m_coredump_file->size()) { @@ -51,17 +53,17 @@ CoreDumpReader::CoreDumpReader(OwnPtr&& coredump_file) ASSERT(m_notes_segment_index != -1); } -CoreDumpReader::~CoreDumpReader() +Reader::~Reader() { } -CoreDumpReader::NotesEntryIterator::NotesEntryIterator(const u8* notes_data) +Reader::NotesEntryIterator::NotesEntryIterator(const u8* notes_data) : m_current((const ELF::Core::NotesEntry*)notes_data) , start(notes_data) { } -ELF::Core::NotesEntryHeader::Type CoreDumpReader::NotesEntryIterator::type() const +ELF::Core::NotesEntryHeader::Type Reader::NotesEntryIterator::type() const { ASSERT(m_current->header.type == ELF::Core::NotesEntryHeader::Type::MemoryRegionInfo || m_current->header.type == ELF::Core::NotesEntryHeader::Type::ThreadInfo @@ -69,12 +71,12 @@ ELF::Core::NotesEntryHeader::Type CoreDumpReader::NotesEntryIterator::type() con return m_current->header.type; } -const ELF::Core::NotesEntry* CoreDumpReader::NotesEntryIterator::current() const +const ELF::Core::NotesEntry* Reader::NotesEntryIterator::current() const { return m_current; } -void CoreDumpReader::NotesEntryIterator::next() +void Reader::NotesEntryIterator::next() { ASSERT(!at_end()); if (type() == ELF::Core::NotesEntryHeader::Type::ThreadInfo) { @@ -89,12 +91,12 @@ void CoreDumpReader::NotesEntryIterator::next() } } -bool CoreDumpReader::NotesEntryIterator::at_end() const +bool Reader::NotesEntryIterator::at_end() const { return type() == ELF::Core::NotesEntryHeader::Type::Null; } -Optional CoreDumpReader::peek_memory(FlatPtr address) const +Optional Reader::peek_memory(FlatPtr address) const { const auto* region = region_containing(address); if (!region) @@ -105,7 +107,7 @@ Optional CoreDumpReader::peek_memory(FlatPtr address) const return *(const uint32_t*)(®ion_data[offset_in_region]); } -const ELF::Core::MemoryRegionInfo* CoreDumpReader::region_containing(FlatPtr address) const +const ELF::Core::MemoryRegionInfo* Reader::region_containing(FlatPtr address) const { const ELF::Core::MemoryRegionInfo* ret = nullptr; for_each_memory_region_info([&ret, address](const ELF::Core::MemoryRegionInfo* region_info) { @@ -117,3 +119,5 @@ const ELF::Core::MemoryRegionInfo* CoreDumpReader::region_containing(FlatPtr add }); return ret; } + +} diff --git a/Libraries/LibCoreDump/CoreDumpReader.h b/Libraries/LibCoreDump/Reader.h similarity index 91% rename from Libraries/LibCoreDump/CoreDumpReader.h rename to Libraries/LibCoreDump/Reader.h index c898911e4c..294de205a2 100644 --- a/Libraries/LibCoreDump/CoreDumpReader.h +++ b/Libraries/LibCoreDump/Reader.h @@ -32,14 +32,16 @@ #include #include -class CoreDumpReader { - AK_MAKE_NONCOPYABLE(CoreDumpReader); +namespace CoreDump { + +class Reader { + AK_MAKE_NONCOPYABLE(Reader); public: - static OwnPtr create(const String&); - ~CoreDumpReader(); + static OwnPtr create(const String&); + ~Reader(); - CoreDumpReader(OwnPtr&&); + Reader(OwnPtr&&); template void for_each_memory_region_info(Func func) const; @@ -74,7 +76,7 @@ private: }; template -void CoreDumpReader::for_each_memory_region_info(Func func) const +void Reader::for_each_memory_region_info(Func func) const { for (NotesEntryIterator it((const u8*)m_coredump_image.program_header(m_notes_segment_index).raw_data()); !it.at_end(); it.next()) { if (it.type() != ELF::Core::NotesEntryHeader::Type::MemoryRegionInfo) @@ -87,7 +89,7 @@ void CoreDumpReader::for_each_memory_region_info(Func func) const } template -void CoreDumpReader::for_each_thread_info(Func func) const +void Reader::for_each_thread_info(Func func) const { for (NotesEntryIterator it((const u8*)m_coredump_image.program_header(m_notes_segment_index).raw_data()); !it.at_end(); it.next()) { if (it.type() != ELF::Core::NotesEntryHeader::Type::ThreadInfo) @@ -98,3 +100,5 @@ void CoreDumpReader::for_each_thread_info(Func func) const return; } } + +}