From 5e18576f59a2f33134f94f9a4d211fd1468f5f0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Tue, 1 Apr 2025 12:15:46 +0200 Subject: [PATCH] Separate imports and exports for listing. --- Core/HLE/sceKernelModule.cpp | 12 +++++----- Core/HLE/sceKernelModule.h | 28 +++++++++++++++-------- Core/System.cpp | 6 ++--- Core/System.h | 5 +++-- UI/ImDebugger/ImDebugger.cpp | 43 ++++++++++++++++++------------------ 5 files changed, 53 insertions(+), 41 deletions(-) diff --git a/Core/HLE/sceKernelModule.cpp b/Core/HLE/sceKernelModule.cpp index f3a21aadc2..acac012249 100644 --- a/Core/HLE/sceKernelModule.cpp +++ b/Core/HLE/sceKernelModule.cpp @@ -295,14 +295,14 @@ void PSPModule::ImportFunc(const FuncSymbolImport &func, bool reimporting) { // Keep track and actually hook it up if possible. importedFuncs.push_back(func); - impExpModuleNames.insert(func.moduleName); + impModuleNames.insert(func.moduleName); ImportFuncSymbol(func, reimporting, GetName()); } void PSPModule::ImportVar(WriteVarSymbolState &state, const VarSymbolImport &var) { // Keep track and actually hook it up if possible. importedVars.push_back(var); - impExpModuleNames.insert(var.moduleName); + impModuleNames.insert(var.moduleName); ImportVarSymbol(state, var); } @@ -311,7 +311,7 @@ void PSPModule::ExportFunc(const FuncSymbolExport &func) { return; } exportedFuncs.push_back(func); - impExpModuleNames.insert(func.moduleName); + expModuleNames.insert(func.moduleName); ExportFuncSymbol(func); } @@ -320,7 +320,7 @@ void PSPModule::ExportVar(const VarSymbolExport &var) { return; } exportedVars.push_back(var); - impExpModuleNames.insert(var.moduleName); + expModuleNames.insert(var.moduleName); ExportVarSymbol(var); } @@ -1150,11 +1150,11 @@ static PSPModule *__KernelLoadELFFromPtr(const u8 *ptr, size_t elfSize, u32 load // Opportunity to dump the decrypted elf, even if we choose to fake it. // NOTE: filename is not necessarily a good choice! std::string elfFilename(KeepAfterLast(filename, '/')); - if (elfFilename.empty()) { + if (elfFilename.empty() || startsWith(elfFilename, "sce_lbn")) { // Use the name from the header. elfFilename = head->modname; } - DumpFileIfEnabled(ptr, elfSize, elfFilename.c_str(), DumpFileType::PRX); + DumpFileIfEnabled(ptr, (u32)elfSize, elfFilename.c_str(), DumpFileType::PRX); // This should happen for all "kernel" modules. *error_string = "Missing key"; diff --git a/Core/HLE/sceKernelModule.h b/Core/HLE/sceKernelModule.h index c663ab11eb..61ead2a4da 100644 --- a/Core/HLE/sceKernelModule.h +++ b/Core/HLE/sceKernelModule.h @@ -161,22 +161,31 @@ public: void ExportVar(const VarSymbolExport &var); template - void RebuildImpExpList(const std::vector &list) { + void RebuildExpList(const std::vector &list) { for (size_t i = 0; i < list.size(); ++i) { - impExpModuleNames.insert(list[i].moduleName); + expModuleNames.insert(list[i].moduleName); + } + } + + template + void RebuildImpList(const std::vector &list) { + for (size_t i = 0; i < list.size(); ++i) { + impModuleNames.insert(list[i].moduleName); } } void RebuildImpExpModuleNames() { - impExpModuleNames.clear(); - RebuildImpExpList(exportedFuncs); - RebuildImpExpList(importedFuncs); - RebuildImpExpList(exportedVars); - RebuildImpExpList(importedVars); + impModuleNames.clear(); + expModuleNames.clear(); + RebuildExpList(exportedFuncs); + RebuildImpList(importedFuncs); + RebuildExpList(exportedVars); + RebuildImpList(importedVars); } bool ImportsOrExportsModuleName(const std::string &moduleName) { - return impExpModuleNames.find(moduleName) != impExpModuleNames.end(); + return impModuleNames.find(moduleName) != impModuleNames.end() || + expModuleNames.find(moduleName) != expModuleNames.end(); } NativeModule nm{}; @@ -187,7 +196,8 @@ public: std::vector importedFuncs; std::vector exportedVars; std::vector importedVars; - std::set impExpModuleNames; + std::set impModuleNames; + std::set expModuleNames; // Keep track of the code region so we can throw out analysis results // when unloaded. diff --git a/Core/System.cpp b/Core/System.cpp index 5fbe8b9632..ba7d498aee 100644 --- a/Core/System.cpp +++ b/Core/System.cpp @@ -119,7 +119,7 @@ GlobalUIState GetUIState() { return globalUIState; } -void SetGPUBackend(GPUBackend type, const std::string &device) { +void SetGPUBackend(GPUBackend type, std::string_view device) { gpuBackend = type; gpuBackendDevice = device; } @@ -869,7 +869,7 @@ const char *DumpFileTypeToFileExtension(DumpFileType type) { } } -void DumpFileIfEnabled(const u8 *dataPtr, const u32 length, const char *name, DumpFileType type) { +void DumpFileIfEnabled(const u8 *dataPtr, const u32 length, std::string_view name, DumpFileType type) { if (!(g_Config.iDumpFileTypes & (int)type)) { return; } @@ -883,7 +883,7 @@ void DumpFileIfEnabled(const u8 *dataPtr, const u32 length, const char *name, Du } const char *extension = DumpFileTypeToFileExtension(type); - std::string filenameToDumpTo = StringFromFormat("%s_%s", g_paramSFO.GetDiscID().c_str(), name); + std::string filenameToDumpTo = g_paramSFO.GetDiscID() + "_" + std::string(name); if (!endsWithNoCase(filenameToDumpTo, extension)) { filenameToDumpTo += extension; } diff --git a/Core/System.h b/Core/System.h index f867c746aa..9f7bb84bb5 100644 --- a/Core/System.h +++ b/Core/System.h @@ -17,6 +17,7 @@ #pragma once +#include #include "Common/CommonTypes.h" #include "Common/File/Path.h" #include "Core/CoreParameter.h" @@ -68,7 +69,7 @@ void ResetUIState(); void UpdateUIState(GlobalUIState newState); GlobalUIState GetUIState(); -void SetGPUBackend(GPUBackend type, const std::string &device = ""); +void SetGPUBackend(GPUBackend type, std::string_view device = ""); GPUBackend GetGPUBackend(); std::string GetGPUBackendDevice(); @@ -128,4 +129,4 @@ inline CoreParameter &PSP_CoreParameter() { } // Centralized place for dumping useful files, also takes care of checking for dupes and creating a clickable UI popup. -void DumpFileIfEnabled(const u8 *dataPtr, const u32 length, const char *name, DumpFileType type); +void DumpFileIfEnabled(const u8 *dataPtr, const u32 length, std::string_view name, DumpFileType type); diff --git a/UI/ImDebugger/ImDebugger.cpp b/UI/ImDebugger/ImDebugger.cpp index 08c641d2fc..851ecba3bc 100644 --- a/UI/ImDebugger/ImDebugger.cpp +++ b/UI/ImDebugger/ImDebugger.cpp @@ -1489,37 +1489,40 @@ static void DrawModules(const MIPSDebugInterface *debug, ImConfig &cfg, ImContro if (mod->isFake) { ImGui::PopStyleColor(); } - if (ImGui::CollapsingHeader("Import/export modules")) { - for (auto &name : mod->impExpModuleNames) { + if (!mod->impModuleNames.empty() && ImGui::CollapsingHeader("Imported modules")) { + for (auto &name : mod->impModuleNames) { ImGui::TextUnformatted(name); } } - if (ImGui::CollapsingHeader("Imports")) { - if (!mod->importedVars.empty()) { - if (ImGui::CollapsingHeader("Vars")) { + if (!mod->expModuleNames.empty() && ImGui::CollapsingHeader("Exported modules")) { + for (auto &name : mod->expModuleNames) { + ImGui::TextUnformatted(name); + } + } + if (!mod->importedFuncs.empty() || !mod->importedVars.empty()) { + if (ImGui::CollapsingHeader("Imports")) { + if (!mod->importedVars.empty() && ImGui::CollapsingHeader("Vars")) { for (auto &var : mod->importedVars) { ImGui::TextUnformatted("(some var)"); // TODO } } - } - for (auto &import : mod->importedFuncs) { - // Look the name up in our HLE database. - const HLEFunction *func = GetHLEFunc(import.moduleName, import.nid); - ImGui::TextUnformatted(import.moduleName); - if (func) { - ImGui::SameLine(); - ImGui::TextUnformatted(func->name); + for (auto &import : mod->importedFuncs) { + // Look the name up in our HLE database. + const HLEFunction *func = GetHLEFunc(import.moduleName, import.nid); + ImGui::TextUnformatted(import.moduleName); + if (func) { + ImGui::SameLine(); + ImGui::TextUnformatted(func->name); + } + ImGui::SameLine(); ImClickableValue("addr", import.stubAddr, control, ImCmd::SHOW_IN_CPU_DISASM); } - ImGui::SameLine(); ImClickableValue("addr", import.stubAddr, control, ImCmd::SHOW_IN_CPU_DISASM); } } if (!mod->exportedFuncs.empty() || !mod->exportedVars.empty()) { if (ImGui::CollapsingHeader("Exports")) { - if (!mod->exportedVars.empty()) { - if (ImGui::CollapsingHeader("Vars")) { - for (auto &var : mod->importedVars) { - ImGui::TextUnformatted("(some var)"); // TODO - } + if (!mod->exportedVars.empty() && ImGui::CollapsingHeader("Vars")) { + for (auto &var : mod->importedVars) { + ImGui::TextUnformatted("(some var)"); // TODO } } for (auto &exportFunc : mod->exportedFuncs) { @@ -1533,8 +1536,6 @@ static void DrawModules(const MIPSDebugInterface *debug, ImConfig &cfg, ImContro ImGui::SameLine(); ImClickableValue("addr", exportFunc.symAddr, control, ImCmd::SHOW_IN_CPU_DISASM); } } - } else { - ImGui::TextUnformatted("(no symbols exported)"); } } } else {