From eb1a632c649c44ce5b692a54b68d0fbeee49ee65 Mon Sep 17 00:00:00 2001 From: georgemoralis Date: Mon, 11 Mar 2024 09:21:49 +0200 Subject: [PATCH] option for debugdump and improvements --- src/common/config.cpp | 14 ++++++++++++++ src/common/config.h | 2 ++ src/core/linker.cpp | 12 ++++++++++-- src/core/linker.h | 2 ++ src/core/loader/symbols_resolver.cpp | 6 +++--- 5 files changed, 31 insertions(+), 5 deletions(-) diff --git a/src/common/config.cpp b/src/common/config.cpp index 3d2027427..89007ab0b 100644 --- a/src/common/config.cpp +++ b/src/common/config.cpp @@ -13,6 +13,7 @@ bool isNeo = false; u32 screenWidth = 1280; u32 screenHeight = 720; std::string logFilter; +bool isDebugDump = false; bool isNeoMode() { return isNeo; @@ -30,6 +31,10 @@ std::string getLogFilter() { return logFilter; } +bool debugDump() { + return isDebugDump; +} + void load(const std::filesystem::path& path) { // If the configuration file does not exist, create it and return std::error_code error; @@ -65,6 +70,14 @@ void load(const std::filesystem::path& path) { screenHeight = toml::find_or(general, "screenHeight", false); } } + if (data.contains("Debug")) { + auto debugResult = toml::expect(data.at("Debug")); + if (debugResult.is_ok()) { + auto debug = debugResult.unwrap(); + + isDebugDump = toml::find_or(debug, "DebugDump", false); + } + } } void save(const std::filesystem::path& path) { toml::basic_value data; @@ -89,6 +102,7 @@ void save(const std::filesystem::path& path) { data["General"]["logFilter"] = logFilter; data["GPU"]["screenWidth"] = screenWidth; data["GPU"]["screenHeight"] = screenHeight; + data["Debug"]["DebugDump"] = isDebugDump; std::ofstream file(path, std::ios::out); file << data; diff --git a/src/common/config.h b/src/common/config.h index e776cf09c..4dcb12647 100644 --- a/src/common/config.h +++ b/src/common/config.h @@ -16,4 +16,6 @@ std::string getLogFilter(); u32 getScreenWidth(); u32 getScreenHeight(); +bool debugDump(); + }; // namespace Config diff --git a/src/core/linker.cpp b/src/core/linker.cpp index 86fb6cbc2..524b2e8b6 100644 --- a/src/core/linker.cpp +++ b/src/core/linker.cpp @@ -2,6 +2,7 @@ // SPDX-License-Identifier: GPL-2.0-or-later #include +#include #include #include "common/logging/log.h" #include "common/string_util.h" @@ -67,6 +68,7 @@ Module* Linker::LoadModule(const std::filesystem::path& elf_name) { auto& m = m_modules.emplace_back(); m = std::make_unique(); m->elf.Open(elf_name); + m->file_name = std::filesystem::path(elf_name).filename().string(); if (m->elf.IsElfFile()) { LoadModuleToMemory(m.get()); @@ -646,7 +648,10 @@ static void RunMainEntry(u64 addr, EntryParams* params, exit_func_t exit_func) { } void Linker::Execute() { - DebugDump(); + if (Config::debugDump()) { + DebugDump(); + } + Core::Libraries::LibKernel::pthreadInitSelfMainThread(); EntryParams p{}; p.argc = 1; @@ -662,7 +667,10 @@ void Linker::DebugDump() { const std::filesystem::path debug(log_dir / "debugdump"); std::filesystem::create_directory(debug); for (const auto& m : m_modules) { - m.get()->import_sym.DebugDump(debug / "imports.txt"); + const std::filesystem::path filepath(debug / m.get()->file_name); + std::filesystem::create_directory(filepath); + m.get()->import_sym.DebugDump(filepath / "imports.txt"); + m.get()->export_sym.DebugDump(filepath / "exports.txt"); } } diff --git a/src/core/linker.h b/src/core/linker.h index 20e35268c..9d97648a2 100644 --- a/src/core/linker.h +++ b/src/core/linker.h @@ -100,6 +100,8 @@ struct Module { u64 aligned_base_size = 0; u64 base_virtual_addr = 0; + std::string file_name; + std::vector m_dynamic; std::vector m_dynamic_data; DynamicModuleInfo dynamic_info{}; diff --git a/src/core/loader/symbols_resolver.cpp b/src/core/loader/symbols_resolver.cpp index a44c5aaea..6c5ac118e 100644 --- a/src/core/loader/symbols_resolver.cpp +++ b/src/core/loader/symbols_resolver.cpp @@ -46,9 +46,9 @@ void SymbolsResolver::DebugDump(const std::filesystem::path& file_name) { } else { nidName = "UNK"; } - f.WriteString(fmt::format("{:<20} {:<16} {:<60} {:<30} {:<2} {:<30} {:<2} {:<2} {:<10}\n", symbol.virtual_address, ids.at(0), - nidName, ids.at(1), ids.at(2), ids.at(3), ids.at(4), ids.at(5), - ids.at(6))); + f.WriteString(fmt::format("{:<20} {:<16} {:<60} {:<30} {:<2} {:<30} {:<2} {:<2} {:<10}\n", + symbol.virtual_address, ids.at(0), nidName, ids.at(1), ids.at(2), + ids.at(3), ids.at(4), ids.at(5), ids.at(6))); } f.Close(); }