From 0776ee01a84e7f85ef87ee42bd5ba60ab48c5ed9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Fri, 8 Nov 2024 10:40:01 +0100 Subject: [PATCH] ImDebugger: Add initial HLE module explorer window` --- Core/HLE/HLE.cpp | 14 ++++++--- Core/HLE/HLE.h | 11 +++---- Core/MIPS/MIPSStackWalk.cpp | 5 +++ UI/ImDebugger/ImDebugger.cpp | 60 +++++++++++++++++++++++++----------- UI/ImDebugger/ImDebugger.h | 20 ++++++++---- 5 files changed, 76 insertions(+), 34 deletions(-) diff --git a/Core/HLE/HLE.cpp b/Core/HLE/HLE.cpp index 6fbe816b45..cdc8a8d7ba 100644 --- a/Core/HLE/HLE.cpp +++ b/Core/HLE/HLE.cpp @@ -162,14 +162,20 @@ void HLEShutdown() { mipsCallActions.clear(); } -void RegisterModule(const char *name, int numFunctions, const HLEFunction *funcTable) -{ +int GetNumRegisteredModules() { + return (int)moduleDB.size(); +} + +void RegisterModule(const char *name, int numFunctions, const HLEFunction *funcTable) { HLEModule module = {name, numFunctions, funcTable}; moduleDB.push_back(module); } -int GetModuleIndex(const char *moduleName) -{ +const HLEModule *GetModuleByIndex(int index) { + return &moduleDB[index]; +} + +int GetModuleIndex(const char *moduleName) { for (size_t i = 0; i < moduleDB.size(); i++) if (strcmp(moduleName, moduleDB[i].name) == 0) return (int)i; diff --git a/Core/HLE/HLE.h b/Core/HLE/HLE.h index ba96ef4570..12a0590351 100644 --- a/Core/HLE/HLE.h +++ b/Core/HLE/HLE.h @@ -44,8 +44,7 @@ enum { HLE_KERNEL_SYSCALL = 1 << 11, }; -struct HLEFunction -{ +struct HLEFunction { // This is the id, or nid, of the function (which is how it's linked.) // Generally, the truncated least significant 32 bits of a SHA-1 hash. u32 ID; @@ -72,8 +71,7 @@ struct HLEFunction u32 stackBytesToClear; }; -struct HLEModule -{ +struct HLEModule { const char *name; int numFunctions; const HLEFunction *funcTable; @@ -81,8 +79,7 @@ struct HLEModule typedef char SyscallModuleName[32]; -struct Syscall -{ +struct Syscall { SyscallModuleName moduleName; u32 symAddr; u32 nid; @@ -102,6 +99,8 @@ int GetFuncIndex(int moduleIndex, u32 nib); int GetModuleIndex(const char *modulename); void RegisterModule(const char *name, int numFunctions, const HLEFunction *funcTable); +int GetNumRegisteredModules(); +const HLEModule *GetModuleByIndex(int index); // Run the current thread's callbacks after the syscall finishes. void hleCheckCurrentCallbacks(); diff --git a/Core/MIPS/MIPSStackWalk.cpp b/Core/MIPS/MIPSStackWalk.cpp index 60e38a0658..065e211e02 100644 --- a/Core/MIPS/MIPSStackWalk.cpp +++ b/Core/MIPS/MIPSStackWalk.cpp @@ -15,6 +15,7 @@ // Official git repository and contact information can be found at // https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/. +#include "Common/Log.h" #include "Core/MemMap.h" #include "Core/Debugger/SymbolMap.h" #include "Core/MIPS/MIPSCodeUtils.h" @@ -176,6 +177,10 @@ namespace MIPSStackWalk { u32 prevEntry = INVALIDTARGET; while (pc != threadEntry) { + if (!Memory::IsValidAddress(current.pc)) { + break; + } + u32 possibleEntry = GuessEntry(current.pc); if (DetermineFrameInfo(current, possibleEntry, threadEntry, ra)) { frames.push_back(current); diff --git a/UI/ImDebugger/ImDebugger.cpp b/UI/ImDebugger/ImDebugger.cpp index b9a3273499..a4ab7d0a72 100644 --- a/UI/ImDebugger/ImDebugger.cpp +++ b/UI/ImDebugger/ImDebugger.cpp @@ -11,6 +11,7 @@ #include "Core/MIPS/MIPSTables.h" #include "Core/Debugger/SymbolMap.h" #include "Core/MemMap.h" +#include "Core/HLE/HLE.h" #include "Common/System/Request.h" // Threads window @@ -233,6 +234,27 @@ void DrawModules(MIPSDebugInterface *debug, bool *open) { ImGui::End(); } +void DrawHLEModules(ImConfig &config) { + if (!ImGui::Begin("HLE Modules", &config.hleModulesOpen)) { + ImGui::End(); + return; + } + + const int moduleCount = GetNumRegisteredModules(); + for (int i = 0; i < moduleCount; i++) { + const HLEModule *module = GetModuleByIndex(i); + if (ImGui::TreeNode(module->name)) { + for (int j = 0; j < module->numFunctions; j++) { + auto &func = module->funcTable[j]; + ImGui::Text("%s(%s)", func.name, func.argmask); + } + ImGui::TreePop(); + } + } + + ImGui::End(); +} + void ImDebugger::Frame(MIPSDebugInterface *mipsDebug) { // Snapshot the coreState to avoid inconsistency. const CoreState coreState = ::coreState; @@ -272,40 +294,42 @@ void ImDebugger::Frame(MIPSDebugInterface *mipsDebug) { ImGui::EndMenu(); } if (ImGui::BeginMenu("Window")) { - ImGui::Checkbox("Dear ImGUI Demo", &demoOpen_); - ImGui::Checkbox("CPU debugger", &disasmOpen_); - ImGui::Checkbox("Registers", ®sOpen_); - ImGui::Checkbox("Callstacks", &callstackOpen_); - ImGui::Checkbox("HLE Modules", &modulesOpen_); - ImGui::Checkbox("HLE Threads", &threadsOpen_); + ImGui::Checkbox("Dear ImGUI Demo", &cfg_.demoOpen); + ImGui::Checkbox("CPU debugger", &cfg_.disasmOpen); + ImGui::Checkbox("Registers", &cfg_.regsOpen); + ImGui::Checkbox("Callstacks", &cfg_.callstackOpen); + ImGui::Checkbox("HLE Modules", &cfg_.modulesOpen); + ImGui::Checkbox("HLE Threads", &cfg_.threadsOpen); ImGui::EndMenu(); } ImGui::EndMainMenuBar(); } - if (demoOpen_) { - ImGui::ShowDemoWindow(&demoOpen_); + if (cfg_.demoOpen) { + ImGui::ShowDemoWindow(&cfg_.demoOpen); } - if (disasmOpen_) { - disasm_.Draw(mipsDebug, &disasmOpen_, coreState); + if (cfg_.disasmOpen) { + disasm_.Draw(mipsDebug, &cfg_.disasmOpen, coreState); } - if (regsOpen_) { - DrawRegisterView(mipsDebug, ®sOpen_); + if (cfg_.regsOpen) { + DrawRegisterView(mipsDebug, &cfg_.regsOpen); } - if (threadsOpen_) { - DrawThreadView(&threadsOpen_); + if (cfg_.threadsOpen) { + DrawThreadView(&cfg_.threadsOpen); } - if (callstackOpen_) { - DrawCallStacks(mipsDebug, &callstackOpen_); + if (cfg_.callstackOpen) { + DrawCallStacks(mipsDebug, &cfg_.callstackOpen); } - if (modulesOpen_) { - DrawModules(mipsDebug, &modulesOpen_); + if (cfg_.modulesOpen) { + DrawModules(mipsDebug, &cfg_.modulesOpen); } + + DrawHLEModules(cfg_); } void ImDisasmWindow::Draw(MIPSDebugInterface *mipsDebug, bool *open, CoreState coreState) { diff --git a/UI/ImDebugger/ImDebugger.h b/UI/ImDebugger/ImDebugger.h index 1eba71030c..cb2279bb93 100644 --- a/UI/ImDebugger/ImDebugger.h +++ b/UI/ImDebugger/ImDebugger.h @@ -48,6 +48,19 @@ public: // Stub }; +struct ImConfig { + bool disasmOpen = true; + bool demoOpen = false; + bool regsOpen = true; + bool threadsOpen = true; + bool callstackOpen = true; + bool modulesOpen = true; + bool hleModulesOpen = true; + + // HLE explorer settings + // bool filterByUsed = true; +}; + struct ImDebugger { void Frame(MIPSDebugInterface *mipsDebug); @@ -55,10 +68,5 @@ struct ImDebugger { ImLuaConsole luaConsole_; // Open variables. - bool disasmOpen_ = true; - bool demoOpen_ = false; - bool regsOpen_ = true; - bool threadsOpen_ = true; - bool callstackOpen_ = true; - bool modulesOpen_ = true; + ImConfig cfg_; };