option for debugdump and improvements

This commit is contained in:
georgemoralis 2024-03-11 09:21:49 +02:00
parent ab40a582df
commit eb1a632c64
5 changed files with 31 additions and 5 deletions

View file

@ -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<toml::integer>(general, "screenHeight", false);
}
}
if (data.contains("Debug")) {
auto debugResult = toml::expect<toml::value>(data.at("Debug"));
if (debugResult.is_ok()) {
auto debug = debugResult.unwrap();
isDebugDump = toml::find_or<toml::boolean>(debug, "DebugDump", false);
}
}
}
void save(const std::filesystem::path& path) {
toml::basic_value<toml::preserve_comments> 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;

View file

@ -16,4 +16,6 @@ std::string getLogFilter();
u32 getScreenWidth();
u32 getScreenHeight();
bool debugDump();
}; // namespace Config

View file

@ -2,6 +2,7 @@
// SPDX-License-Identifier: GPL-2.0-or-later
#include <Zydis/Zydis.h>
#include <common/config.h>
#include <common/path_util.h>
#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<Module>();
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");
}
}

View file

@ -100,6 +100,8 @@ struct Module {
u64 aligned_base_size = 0;
u64 base_virtual_addr = 0;
std::string file_name;
std::vector<u8> m_dynamic;
std::vector<u8> m_dynamic_data;
DynamicModuleInfo dynamic_info{};

View file

@ -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();
}