From c24fa93965a68b8adf5d0df9005212792d029146 Mon Sep 17 00:00:00 2001 From: mitaclaw <140017135+mitaclaw@users.noreply.github.com> Date: Sun, 10 Mar 2024 11:43:12 -0700 Subject: [PATCH] PPCSymbolDB: Move instance to PowerPCManager --- Source/Core/Core/Boot/Boot.cpp | 10 +-- Source/Core/Core/Boot/Boot.h | 6 +- Source/Core/Core/Boot/DolReader.h | 5 +- Source/Core/Core/Boot/ElfReader.cpp | 6 +- Source/Core/Core/Boot/ElfReader.h | 2 +- Source/Core/Core/ConfigManager.cpp | 9 +-- .../Core/Core/Debugger/Debugger_SymbolMap.cpp | 25 ++++--- .../Core/Core/Debugger/PPCDebugInterface.cpp | 7 +- Source/Core/Core/Debugger/PPCDebugInterface.h | 4 +- Source/Core/Core/HLE/HLE.cpp | 22 ++++--- Source/Core/Core/HLE/HLE.h | 7 +- Source/Core/Core/IOS/MIOS.cpp | 11 ++-- Source/Core/Core/PowerPC/BreakPoints.cpp | 8 +-- Source/Core/Core/PowerPC/BreakPoints.h | 7 +- .../CachedInterpreter/CachedInterpreter.cpp | 2 +- .../Core/PowerPC/Interpreter/Interpreter.cpp | 8 ++- .../Core/PowerPC/Interpreter/Interpreter.h | 4 +- Source/Core/Core/PowerPC/Jit64/Jit.cpp | 2 +- Source/Core/Core/PowerPC/JitArm64/Jit.cpp | 2 +- .../Core/Core/PowerPC/JitCommon/JitBase.cpp | 3 +- Source/Core/Core/PowerPC/JitCommon/JitBase.h | 2 + .../Core/Core/PowerPC/JitCommon/JitCache.cpp | 2 +- Source/Core/Core/PowerPC/JitInterface.cpp | 2 +- Source/Core/Core/PowerPC/MMU.cpp | 3 +- Source/Core/Core/PowerPC/PPCAnalyst.cpp | 17 +++-- Source/Core/Core/PowerPC/PPCSymbolDB.cpp | 2 - Source/Core/Core/PowerPC/PPCSymbolDB.h | 2 - Source/Core/Core/PowerPC/PowerPC.cpp | 5 +- Source/Core/Core/PowerPC/PowerPC.h | 4 ++ Source/Core/Core/System.cpp | 8 ++- Source/Core/Core/System.h | 2 + .../DolphinQt/Debugger/BranchWatchDialog.cpp | 11 ++-- .../DolphinQt/Debugger/BranchWatchDialog.h | 5 +- .../Debugger/BranchWatchTableModel.cpp | 4 +- .../Debugger/BranchWatchTableModel.h | 7 +- .../DolphinQt/Debugger/BreakpointWidget.cpp | 12 ++-- .../DolphinQt/Debugger/CodeViewWidget.cpp | 19 +++--- .../Core/DolphinQt/Debugger/CodeViewWidget.h | 2 + Source/Core/DolphinQt/Debugger/CodeWidget.cpp | 35 ++++------ Source/Core/DolphinQt/Debugger/CodeWidget.h | 2 + Source/Core/DolphinQt/MenuBar.cpp | 65 +++++++++---------- 41 files changed, 201 insertions(+), 160 deletions(-) diff --git a/Source/Core/Core/Boot/Boot.cpp b/Source/Core/Core/Boot/Boot.cpp index ef87f3c396..f1380270a6 100644 --- a/Source/Core/Core/Boot/Boot.cpp +++ b/Source/Core/Core/Boot/Boot.cpp @@ -376,11 +376,11 @@ bool CBoot::FindMapFile(std::string* existing_map_file, std::string* writable_ma return false; } -bool CBoot::LoadMapFromFilename(const Core::CPUThreadGuard& guard) +bool CBoot::LoadMapFromFilename(const Core::CPUThreadGuard& guard, PPCSymbolDB& ppc_symbol_db) { std::string strMapFilename; bool found = FindMapFile(&strMapFilename, nullptr); - if (found && g_symbolDB.LoadMap(guard, strMapFilename)) + if (found && ppc_symbol_db.LoadMap(guard, strMapFilename)) { UpdateDebugger_MapLoaded(); return true; @@ -514,9 +514,9 @@ bool CBoot::BootUp(Core::System& system, const Core::CPUThreadGuard& guard, { SConfig& config = SConfig::GetInstance(); - if (!g_symbolDB.IsEmpty()) + if (auto& ppc_symbol_db = system.GetPPCSymbolDB(); !ppc_symbol_db.IsEmpty()) { - g_symbolDB.Clear(); + ppc_symbol_db.Clear(); UpdateDebugger_MapLoaded(); } @@ -595,7 +595,7 @@ bool CBoot::BootUp(Core::System& system, const Core::CPUThreadGuard& guard, ppc_state.pc = executable.reader->GetEntryPoint(); - if (executable.reader->LoadSymbols(guard)) + if (executable.reader->LoadSymbols(guard, system.GetPPCSymbolDB())) { UpdateDebugger_MapLoaded(); HLE::PatchFunctions(system); diff --git a/Source/Core/Core/Boot/Boot.h b/Source/Core/Core/Boot/Boot.h index cb162b6b33..e119cae955 100644 --- a/Source/Core/Core/Boot/Boot.h +++ b/Source/Core/Core/Boot/Boot.h @@ -19,6 +19,8 @@ #include "DiscIO/VolumeDisc.h" #include "DiscIO/VolumeWad.h" +class PPCSymbolDB; + namespace Core { class CPUThreadGuard; @@ -168,7 +170,7 @@ public: // // Returns true if a map file exists, false if none could be found. static bool FindMapFile(std::string* existing_map_file, std::string* writable_map_file); - static bool LoadMapFromFilename(const Core::CPUThreadGuard& guard); + static bool LoadMapFromFilename(const Core::CPUThreadGuard& guard, PPCSymbolDB& ppc_symbol_db); private: static bool DVDRead(Core::System& system, const DiscIO::VolumeDisc& disc, u64 dvd_offset, @@ -215,7 +217,7 @@ public: virtual bool IsValid() const = 0; virtual bool IsWii() const = 0; virtual bool LoadIntoMemory(Core::System& system, bool only_in_mem1 = false) const = 0; - virtual bool LoadSymbols(const Core::CPUThreadGuard& guard) const = 0; + virtual bool LoadSymbols(const Core::CPUThreadGuard& guard, PPCSymbolDB& ppc_symbol_db) const = 0; protected: std::vector m_bytes; diff --git a/Source/Core/Core/Boot/DolReader.h b/Source/Core/Core/Boot/DolReader.h index af227bb3fe..807f13432b 100644 --- a/Source/Core/Core/Boot/DolReader.h +++ b/Source/Core/Core/Boot/DolReader.h @@ -27,7 +27,10 @@ public: bool IsAncast() const { return m_is_ancast; }; u32 GetEntryPoint() const override { return m_dolheader.entryPoint; } bool LoadIntoMemory(Core::System& system, bool only_in_mem1 = false) const override; - bool LoadSymbols(const Core::CPUThreadGuard& guard) const override { return false; } + bool LoadSymbols(const Core::CPUThreadGuard& guard, PPCSymbolDB& ppc_symbol_db) const override + { + return false; + } private: enum diff --git a/Source/Core/Core/Boot/ElfReader.cpp b/Source/Core/Core/Boot/ElfReader.cpp index f1281601ea..2fc428399a 100644 --- a/Source/Core/Core/Boot/ElfReader.cpp +++ b/Source/Core/Core/Boot/ElfReader.cpp @@ -180,7 +180,7 @@ SectionID ElfReader::GetSectionByName(const char* name, int firstSection) const return -1; } -bool ElfReader::LoadSymbols(const Core::CPUThreadGuard& guard) const +bool ElfReader::LoadSymbols(const Core::CPUThreadGuard& guard, PPCSymbolDB& ppc_symbol_db) const { bool hasSymbols = false; SectionID sec = GetSectionByName(".symtab"); @@ -218,11 +218,11 @@ bool ElfReader::LoadSymbols(const Core::CPUThreadGuard& guard) const default: continue; } - g_symbolDB.AddKnownSymbol(guard, value, size, name, symtype); + ppc_symbol_db.AddKnownSymbol(guard, value, size, name, symtype); hasSymbols = true; } } - g_symbolDB.Index(); + ppc_symbol_db.Index(); return hasSymbols; } diff --git a/Source/Core/Core/Boot/ElfReader.h b/Source/Core/Core/Boot/ElfReader.h index 28b4631c6e..4213bd1090 100644 --- a/Source/Core/Core/Boot/ElfReader.h +++ b/Source/Core/Core/Boot/ElfReader.h @@ -36,7 +36,7 @@ public: u32 GetEntryPoint() const override { return entryPoint; } u32 GetFlags() const { return (u32)(header->e_flags); } bool LoadIntoMemory(Core::System& system, bool only_in_mem1 = false) const override; - bool LoadSymbols(const Core::CPUThreadGuard& guard) const override; + bool LoadSymbols(const Core::CPUThreadGuard& guard, PPCSymbolDB& ppc_symbol_db) const override; // TODO: actually check for validity. bool IsValid() const override { return true; } bool IsWii() const override; diff --git a/Source/Core/Core/ConfigManager.cpp b/Source/Core/Core/ConfigManager.cpp index 5ad626f56e..693b2fb439 100644 --- a/Source/Core/Core/ConfigManager.cpp +++ b/Source/Core/Core/ConfigManager.cpp @@ -205,13 +205,14 @@ void SConfig::OnNewTitleLoad(const Core::CPUThreadGuard& guard) if (!Core::IsRunning()) return; - if (!g_symbolDB.IsEmpty()) + auto& system = guard.GetSystem(); + auto& ppc_symbol_db = system.GetPPCSymbolDB(); + if (!ppc_symbol_db.IsEmpty()) { - g_symbolDB.Clear(); + ppc_symbol_db.Clear(); Host_NotifyMapLoaded(); } - CBoot::LoadMapFromFilename(guard); - auto& system = Core::System::GetInstance(); + CBoot::LoadMapFromFilename(guard, ppc_symbol_db); HLE::Reload(system); PatchEngine::Reload(); HiresTexture::Update(); diff --git a/Source/Core/Core/Debugger/Debugger_SymbolMap.cpp b/Source/Core/Core/Debugger/Debugger_SymbolMap.cpp index b235d15286..893efdbd4a 100644 --- a/Source/Core/Core/Debugger/Debugger_SymbolMap.cpp +++ b/Source/Core/Core/Debugger/Debugger_SymbolMap.cpp @@ -54,7 +54,8 @@ static void WalkTheStack(const Core::CPUThreadGuard& guard, // instead of "pointing ahead" bool GetCallstack(const Core::CPUThreadGuard& guard, std::vector& output) { - const auto& ppc_state = guard.GetSystem().GetPPCState(); + auto& power_pc = guard.GetSystem().GetPowerPC(); + const auto& ppc_state = power_pc.GetPPCState(); if (!Core::IsRunning() || !PowerPC::MMU::HostIsRAMAddress(guard, ppc_state.gpr[1])) return false; @@ -68,14 +69,16 @@ bool GetCallstack(const Core::CPUThreadGuard& guard, std::vector return false; } + auto& ppc_symbol_db = power_pc.GetSymbolDB(); + output.push_back({ - .Name = fmt::format(" * {} [ LR = {:08x} ]\n", g_symbolDB.GetDescription(LR(ppc_state)), + .Name = fmt::format(" * {} [ LR = {:08x} ]\n", ppc_symbol_db.GetDescription(LR(ppc_state)), LR(ppc_state) - 4), .vAddress = LR(ppc_state) - 4, }); - WalkTheStack(guard, [&output](u32 func_addr) { - std::string func_desc = g_symbolDB.GetDescription(func_addr); + WalkTheStack(guard, [&output, &ppc_symbol_db](u32 func_addr) { + std::string func_desc = ppc_symbol_db.GetDescription(func_addr); if (func_desc.empty() || func_desc == "Invalid") func_desc = "(unknown)"; @@ -91,7 +94,9 @@ bool GetCallstack(const Core::CPUThreadGuard& guard, std::vector void PrintCallstack(const Core::CPUThreadGuard& guard, Common::Log::LogType type, Common::Log::LogLevel level) { - const auto& ppc_state = guard.GetSystem().GetPPCState(); + auto& power_pc = guard.GetSystem().GetPowerPC(); + const auto& ppc_state = power_pc.GetPPCState(); + auto& ppc_symbol_db = power_pc.GetSymbolDB(); GENERIC_LOG_FMT(type, level, "== STACK TRACE - SP = {:08x} ==", ppc_state.gpr[1]); @@ -100,14 +105,14 @@ void PrintCallstack(const Core::CPUThreadGuard& guard, Common::Log::LogType type GENERIC_LOG_FMT(type, level, " LR = 0 - this is bad"); } - if (g_symbolDB.GetDescription(ppc_state.pc) != g_symbolDB.GetDescription(LR(ppc_state))) + if (ppc_symbol_db.GetDescription(ppc_state.pc) != ppc_symbol_db.GetDescription(LR(ppc_state))) { - GENERIC_LOG_FMT(type, level, " * {} [ LR = {:08x} ]", g_symbolDB.GetDescription(LR(ppc_state)), - LR(ppc_state)); + GENERIC_LOG_FMT(type, level, " * {} [ LR = {:08x} ]", + ppc_symbol_db.GetDescription(LR(ppc_state)), LR(ppc_state)); } - WalkTheStack(guard, [type, level](u32 func_addr) { - std::string func_desc = g_symbolDB.GetDescription(func_addr); + WalkTheStack(guard, [type, level, &ppc_symbol_db](u32 func_addr) { + std::string func_desc = ppc_symbol_db.GetDescription(func_addr); if (func_desc.empty() || func_desc == "Invalid") func_desc = "(unknown)"; GENERIC_LOG_FMT(type, level, " * {} [ addr = {:08x} ]", func_desc, func_addr); diff --git a/Source/Core/Core/Debugger/PPCDebugInterface.cpp b/Source/Core/Core/Debugger/PPCDebugInterface.cpp index d6afc64e69..c9d0346858 100644 --- a/Source/Core/Core/Debugger/PPCDebugInterface.cpp +++ b/Source/Core/Core/Debugger/PPCDebugInterface.cpp @@ -90,7 +90,8 @@ void PPCPatches::UnPatch(std::size_t index) PatchEngine::RemoveMemoryPatch(index); } -PPCDebugInterface::PPCDebugInterface(Core::System& system) : m_system(system) +PPCDebugInterface::PPCDebugInterface(Core::System& system, PPCSymbolDB& ppc_symbol_db) + : m_system(system), m_ppc_symbol_db(ppc_symbol_db) { } @@ -423,7 +424,7 @@ u32 PPCDebugInterface::GetColor(const Core::CPUThreadGuard* guard, u32 address) if (!PowerPC::MMU::HostIsRAMAddress(*guard, address)) return 0xeeeeee; - Common::Symbol* symbol = g_symbolDB.GetSymbolFromAddr(address); + const Common::Symbol* const symbol = m_ppc_symbol_db.GetSymbolFromAddr(address); if (!symbol) return 0xFFFFFF; if (symbol->type != Common::Symbol::Type::Function) @@ -443,7 +444,7 @@ u32 PPCDebugInterface::GetColor(const Core::CPUThreadGuard* guard, u32 address) std::string PPCDebugInterface::GetDescription(u32 address) const { - return g_symbolDB.GetDescription(address); + return m_ppc_symbol_db.GetDescription(address); } std::optional diff --git a/Source/Core/Core/Debugger/PPCDebugInterface.h b/Source/Core/Core/Debugger/PPCDebugInterface.h index ca12de23f8..579a779209 100644 --- a/Source/Core/Core/Debugger/PPCDebugInterface.h +++ b/Source/Core/Core/Debugger/PPCDebugInterface.h @@ -17,6 +17,7 @@ namespace Core class CPUThreadGuard; class System; } // namespace Core +class PPCSymbolDB; void ApplyMemoryPatch(const Core::CPUThreadGuard&, Common::Debug::MemoryPatch& patch, bool store_existing_value = true); @@ -36,7 +37,7 @@ private: class PPCDebugInterface final : public Core::DebugInterface { public: - explicit PPCDebugInterface(Core::System& system); + explicit PPCDebugInterface(Core::System& system, PPCSymbolDB& ppc_symbol_db); ~PPCDebugInterface() override; // Watches @@ -112,4 +113,5 @@ private: PPCPatches m_patches; std::shared_ptr m_network_logger; Core::System& m_system; + PPCSymbolDB& m_ppc_symbol_db; }; diff --git a/Source/Core/Core/HLE/HLE.cpp b/Source/Core/Core/HLE/HLE.cpp index a8bc7c9901..94548d84ef 100644 --- a/Source/Core/Core/HLE/HLE.cpp +++ b/Source/Core/Core/HLE/HLE.cpp @@ -106,7 +106,9 @@ void PatchFixedFunctions(Core::System& system) void PatchFunctions(Core::System& system) { - auto& ppc_state = system.GetPPCState(); + auto& power_pc = system.GetPowerPC(); + auto& ppc_state = power_pc.GetPPCState(); + auto& ppc_symbol_db = power_pc.GetSymbolDB(); // Remove all hooks that aren't fixed address hooks for (auto i = s_hooked_addresses.begin(); i != s_hooked_addresses.end();) @@ -128,7 +130,7 @@ void PatchFunctions(Core::System& system) if (os_patches[i].flags == HookFlag::Fixed) continue; - for (const auto& symbol : g_symbolDB.GetSymbolsFromName(os_patches[i].name)) + for (const auto& symbol : ppc_symbol_db.GetSymbolsFromName(os_patches[i].name)) { for (u32 addr = symbol->address; addr < symbol->address + symbol->size; addr += 4) { @@ -178,14 +180,14 @@ u32 GetHookByAddress(u32 address) return (iter != s_hooked_addresses.end()) ? iter->second : 0; } -u32 GetHookByFunctionAddress(u32 address) +u32 GetHookByFunctionAddress(PPCSymbolDB& ppc_symbol_db, u32 address) { const u32 index = GetHookByAddress(address); // Fixed hooks use a fixed address and don't patch the whole function if (index == 0 || os_patches[index].flags == HookFlag::Fixed) return index; - const auto symbol = g_symbolDB.GetSymbolFromAddr(address); + const Common::Symbol* const symbol = ppc_symbol_db.GetSymbolFromAddr(address); return (symbol && symbol->address == address) ? index : 0; } @@ -199,9 +201,10 @@ HookFlag GetHookFlagsByIndex(u32 index) return os_patches[index].flags; } -TryReplaceFunctionResult TryReplaceFunction(u32 address, PowerPC::CoreMode mode) +TryReplaceFunctionResult TryReplaceFunction(PPCSymbolDB& ppc_symbol_db, u32 address, + PowerPC::CoreMode mode) { - const u32 hook_index = GetHookByFunctionAddress(address); + const u32 hook_index = GetHookByFunctionAddress(ppc_symbol_db, address); if (hook_index == 0) return {}; @@ -229,7 +232,8 @@ u32 UnPatch(Core::System& system, std::string_view patch_name) if (patch == std::end(os_patches)) return 0; - auto& ppc_state = system.GetPPCState(); + auto& power_pc = system.GetPowerPC(); + auto& ppc_state = power_pc.GetPPCState(); if (patch->flags == HookFlag::Fixed) { @@ -252,10 +256,10 @@ u32 UnPatch(Core::System& system, std::string_view patch_name) return addr; } - const auto& symbols = g_symbolDB.GetSymbolsFromName(patch_name); + const auto symbols = power_pc.GetSymbolDB().GetSymbolsFromName(patch_name); if (!symbols.empty()) { - const auto& symbol = symbols[0]; + const Common::Symbol* const symbol = symbols.front(); for (u32 addr = symbol->address; addr < symbol->address + symbol->size; addr += 4) { s_hooked_addresses.erase(addr); diff --git a/Source/Core/Core/HLE/HLE.h b/Source/Core/Core/HLE/HLE.h index 3935ce4c5e..e273e8b4d7 100644 --- a/Source/Core/Core/HLE/HLE.h +++ b/Source/Core/Core/HLE/HLE.h @@ -18,6 +18,8 @@ namespace PowerPC enum class CoreMode; } +class PPCSymbolDB; + namespace HLE { using HookFunction = void (*)(const Core::CPUThreadGuard&); @@ -66,7 +68,7 @@ void ExecuteFromJIT(u32 current_pc, u32 hook_index, Core::System& system); // Returns the HLE hook index of the address u32 GetHookByAddress(u32 address); // Returns the HLE hook index if the address matches the function start -u32 GetHookByFunctionAddress(u32 address); +u32 GetHookByFunctionAddress(PPCSymbolDB& ppc_symbol_db, u32 address); HookType GetHookTypeByIndex(u32 index); HookFlag GetHookFlagsByIndex(u32 index); @@ -74,6 +76,7 @@ bool IsEnabled(HookFlag flag, PowerPC::CoreMode mode); // Performs the backend-independent preliminary checking for whether a function // can be HLEd. If it can be, the information needed for HLEing it is returned. -TryReplaceFunctionResult TryReplaceFunction(u32 address, PowerPC::CoreMode mode); +TryReplaceFunctionResult TryReplaceFunction(PPCSymbolDB& ppc_symbol_db, u32 address, + PowerPC::CoreMode mode); } // namespace HLE diff --git a/Source/Core/Core/IOS/MIOS.cpp b/Source/Core/Core/IOS/MIOS.cpp index 43b959acc0..e4babae253 100644 --- a/Source/Core/Core/IOS/MIOS.cpp +++ b/Source/Core/Core/IOS/MIOS.cpp @@ -67,21 +67,22 @@ bool Load(Core::System& system) ReinitHardware(system); NOTICE_LOG_FMT(IOS, "Reinitialised hardware."); + auto& power_pc = system.GetPowerPC(); + auto& ppc_symbol_db = power_pc.GetSymbolDB(); + // Load symbols for the IPL if they exist. - if (!g_symbolDB.IsEmpty()) + if (!ppc_symbol_db.IsEmpty()) { - g_symbolDB.Clear(); + ppc_symbol_db.Clear(); Host_NotifyMapLoaded(); } - if (g_symbolDB.LoadMap(guard, File::GetUserPath(D_MAPS_IDX) + "mios-ipl.map")) + if (ppc_symbol_db.LoadMap(guard, File::GetUserPath(D_MAPS_IDX) + "mios-ipl.map")) { ::HLE::Clear(); ::HLE::PatchFunctions(system); Host_NotifyMapLoaded(); } - auto& power_pc = system.GetPowerPC(); - const PowerPC::CoreMode core_mode = power_pc.GetMode(); power_pc.SetMode(PowerPC::CoreMode::Interpreter); diff --git a/Source/Core/Core/PowerPC/BreakPoints.cpp b/Source/Core/Core/PowerPC/BreakPoints.cpp index 2d62dd569c..0365fd81c6 100644 --- a/Source/Core/Core/PowerPC/BreakPoints.cpp +++ b/Source/Core/Core/PowerPC/BreakPoints.cpp @@ -365,8 +365,7 @@ bool MemChecks::OverlapsMemcheck(u32 address, u32 length) const }); } -bool TMemCheck::Action(Core::System& system, Core::DebugInterface* debug_interface, u64 value, - u32 addr, bool write, size_t size, u32 pc) +bool TMemCheck::Action(Core::System& system, u64 value, u32 addr, bool write, size_t size, u32 pc) { if (!is_enabled) return false; @@ -376,9 +375,10 @@ bool TMemCheck::Action(Core::System& system, Core::DebugInterface* debug_interfa { if (log_on_hit) { + auto& ppc_symbol_db = system.GetPPCSymbolDB(); NOTICE_LOG_FMT(MEMMAP, "MBP {:08x} ({}) {}{} {:x} at {:08x} ({})", pc, - debug_interface->GetDescription(pc), write ? "Write" : "Read", size * 8, value, - addr, debug_interface->GetDescription(addr)); + ppc_symbol_db.GetDescription(pc), write ? "Write" : "Read", size * 8, value, + addr, ppc_symbol_db.GetDescription(addr)); } if (break_on_hit) return true; diff --git a/Source/Core/Core/PowerPC/BreakPoints.h b/Source/Core/Core/PowerPC/BreakPoints.h index 40d0499868..ce509e5d97 100644 --- a/Source/Core/Core/PowerPC/BreakPoints.h +++ b/Source/Core/Core/PowerPC/BreakPoints.h @@ -11,10 +11,6 @@ #include "Common/CommonTypes.h" #include "Core/PowerPC/Expression.h" -namespace Core -{ -class DebugInterface; -} namespace Core { class System; @@ -49,8 +45,7 @@ struct TMemCheck std::optional condition; // returns whether to break - bool Action(Core::System& system, Core::DebugInterface* debug_interface, u64 value, u32 addr, - bool write, size_t size, u32 pc); + bool Action(Core::System& system, u64 value, u32 addr, bool write, size_t size, u32 pc); }; // Code breakpoints. diff --git a/Source/Core/Core/PowerPC/CachedInterpreter/CachedInterpreter.cpp b/Source/Core/Core/PowerPC/CachedInterpreter/CachedInterpreter.cpp index 291321f97a..b9d78514d5 100644 --- a/Source/Core/Core/PowerPC/CachedInterpreter/CachedInterpreter.cpp +++ b/Source/Core/Core/PowerPC/CachedInterpreter/CachedInterpreter.cpp @@ -271,7 +271,7 @@ bool CachedInterpreter::HandleFunctionHooking(u32 address) { // CachedInterpreter inherits from JitBase and is considered a JIT by relevant code. // (see JitInterface and how m_mode is set within PowerPC.cpp) - const auto result = HLE::TryReplaceFunction(address, PowerPC::CoreMode::JIT); + const auto result = HLE::TryReplaceFunction(m_ppc_symbol_db, address, PowerPC::CoreMode::JIT); if (!result) return false; diff --git a/Source/Core/Core/PowerPC/Interpreter/Interpreter.cpp b/Source/Core/Core/PowerPC/Interpreter/Interpreter.cpp index fc5f1d2aba..a7c2fbed52 100644 --- a/Source/Core/Core/PowerPC/Interpreter/Interpreter.cpp +++ b/Source/Core/Core/PowerPC/Interpreter/Interpreter.cpp @@ -65,8 +65,9 @@ void Interpreter::UpdatePC() } Interpreter::Interpreter(Core::System& system, PowerPC::PowerPCState& ppc_state, PowerPC::MMU& mmu, - Core::BranchWatch& branch_watch) - : m_system(system), m_ppc_state(ppc_state), m_mmu(mmu), m_branch_watch(branch_watch) + Core::BranchWatch& branch_watch, PPCSymbolDB& ppc_symbol_db) + : m_system(system), m_ppc_state(ppc_state), m_mmu(mmu), m_branch_watch(branch_watch), + m_ppc_symbol_db(ppc_symbol_db) { } @@ -107,7 +108,8 @@ void Interpreter::Trace(const UGeckoInstruction& inst) bool Interpreter::HandleFunctionHooking(u32 address) { - const auto result = HLE::TryReplaceFunction(address, PowerPC::CoreMode::Interpreter); + const auto result = + HLE::TryReplaceFunction(m_ppc_symbol_db, address, PowerPC::CoreMode::Interpreter); if (!result) return false; diff --git a/Source/Core/Core/PowerPC/Interpreter/Interpreter.h b/Source/Core/Core/PowerPC/Interpreter/Interpreter.h index d51ad1a2dd..d0c87b1c90 100644 --- a/Source/Core/Core/PowerPC/Interpreter/Interpreter.h +++ b/Source/Core/Core/PowerPC/Interpreter/Interpreter.h @@ -19,12 +19,13 @@ namespace PowerPC class MMU; struct PowerPCState; } // namespace PowerPC +class PPCSymbolDB; class Interpreter : public CPUCoreBase { public: Interpreter(Core::System& system, PowerPC::PowerPCState& ppc_state, PowerPC::MMU& mmu, - Core::BranchWatch& branch_watch); + Core::BranchWatch& branch_watch, PPCSymbolDB& ppc_symbol_db); Interpreter(const Interpreter&) = delete; Interpreter(Interpreter&&) = delete; Interpreter& operator=(const Interpreter&) = delete; @@ -317,6 +318,7 @@ private: PowerPC::PowerPCState& m_ppc_state; PowerPC::MMU& m_mmu; Core::BranchWatch& m_branch_watch; + PPCSymbolDB& m_ppc_symbol_db; UGeckoInstruction m_prev_inst{}; u32 m_last_pc = 0; diff --git a/Source/Core/Core/PowerPC/Jit64/Jit.cpp b/Source/Core/Core/PowerPC/Jit64/Jit.cpp index e83b9204aa..ce1dc906d3 100644 --- a/Source/Core/Core/PowerPC/Jit64/Jit.cpp +++ b/Source/Core/Core/PowerPC/Jit64/Jit.cpp @@ -1285,7 +1285,7 @@ void Jit64::IntializeSpeculativeConstants() bool Jit64::HandleFunctionHooking(u32 address) { - const auto result = HLE::TryReplaceFunction(address, PowerPC::CoreMode::JIT); + const auto result = HLE::TryReplaceFunction(m_ppc_symbol_db, address, PowerPC::CoreMode::JIT); if (!result) return false; diff --git a/Source/Core/Core/PowerPC/JitArm64/Jit.cpp b/Source/Core/Core/PowerPC/JitArm64/Jit.cpp index 49b4238cce..b8fada1dcb 100644 --- a/Source/Core/Core/PowerPC/JitArm64/Jit.cpp +++ b/Source/Core/Core/PowerPC/JitArm64/Jit.cpp @@ -781,7 +781,7 @@ void JitArm64::WriteConditionalExceptionExit(int exception, ARM64Reg temp_gpr, A bool JitArm64::HandleFunctionHooking(u32 address) { - const auto result = HLE::TryReplaceFunction(address, PowerPC::CoreMode::JIT); + const auto result = HLE::TryReplaceFunction(m_ppc_symbol_db, address, PowerPC::CoreMode::JIT); if (!result) return false; diff --git a/Source/Core/Core/PowerPC/JitCommon/JitBase.cpp b/Source/Core/Core/PowerPC/JitCommon/JitBase.cpp index 87f017f7f8..c999388760 100644 --- a/Source/Core/Core/PowerPC/JitCommon/JitBase.cpp +++ b/Source/Core/Core/PowerPC/JitCommon/JitBase.cpp @@ -94,7 +94,8 @@ void JitTrampoline(JitBase& jit, u32 em_address) JitBase::JitBase(Core::System& system) : m_code_buffer(code_buffer_size), m_system(system), m_ppc_state(system.GetPPCState()), - m_mmu(system.GetMMU()), m_branch_watch(system.GetPowerPC().GetBranchWatch()) + m_mmu(system.GetMMU()), m_branch_watch(system.GetPowerPC().GetBranchWatch()), + m_ppc_symbol_db(system.GetPPCSymbolDB()) { m_registered_config_callback_id = CPUThreadConfigCallback::AddConfigChangedCallback([this] { if (DoesConfigNeedRefresh()) diff --git a/Source/Core/Core/PowerPC/JitCommon/JitBase.h b/Source/Core/Core/PowerPC/JitCommon/JitBase.h index 1d947da5ea..d3579368f4 100644 --- a/Source/Core/Core/PowerPC/JitCommon/JitBase.h +++ b/Source/Core/Core/PowerPC/JitCommon/JitBase.h @@ -31,6 +31,7 @@ namespace PowerPC class MMU; struct PowerPCState; } // namespace PowerPC +class PPCSymbolDB; //#define JIT_LOG_GENERATED_CODE // Enables logging of generated code //#define JIT_LOG_GPR // Enables logging of the PPC general purpose regs @@ -208,6 +209,7 @@ public: PowerPC::PowerPCState& m_ppc_state; PowerPC::MMU& m_mmu; Core::BranchWatch& m_branch_watch; + PPCSymbolDB& m_ppc_symbol_db; }; void JitTrampoline(JitBase& jit, u32 em_address); diff --git a/Source/Core/Core/PowerPC/JitCommon/JitCache.cpp b/Source/Core/Core/PowerPC/JitCommon/JitCache.cpp index ecd7600700..d8d6e8d13b 100644 --- a/Source/Core/Core/PowerPC/JitCommon/JitCache.cpp +++ b/Source/Core/Core/PowerPC/JitCommon/JitCache.cpp @@ -152,7 +152,7 @@ void JitBaseBlockCache::FinalizeBlock(JitBlock& block, bool block_link, Common::Symbol* symbol = nullptr; if (Common::JitRegister::IsEnabled() && - (symbol = g_symbolDB.GetSymbolFromAddr(block.effectiveAddress)) != nullptr) + (symbol = m_jit.m_ppc_symbol_db.GetSymbolFromAddr(block.effectiveAddress)) != nullptr) { Common::JitRegister::Register(block.normalEntry, block.codeSize, "JIT_PPC_{}_{:08x}", symbol->function_name.c_str(), block.physicalAddress); diff --git a/Source/Core/Core/PowerPC/JitInterface.cpp b/Source/Core/Core/PowerPC/JitInterface.cpp index ed60b4d489..80ac9f873f 100644 --- a/Source/Core/Core/PowerPC/JitInterface.cpp +++ b/Source/Core/Core/PowerPC/JitInterface.cpp @@ -138,7 +138,7 @@ void JitInterface::WriteProfileResults(const std::string& filename) const "ms)\tblkCodeSize\n"); for (auto& stat : prof_stats.block_stats) { - std::string name = g_symbolDB.GetDescription(stat.addr); + std::string name = m_system.GetPPCSymbolDB().GetDescription(stat.addr); double percent = 100.0 * (double)stat.cost / (double)prof_stats.cost_sum; double timePercent = 100.0 * (double)stat.tick_counter / (double)prof_stats.timecost_sum; f.WriteString(fmt::format("{0:08x}\t{1}\t{2}\t{3}\t{4}\t{5:.2f}\t{6:.2f}\t{7:.2f}\t{8}\n", diff --git a/Source/Core/Core/PowerPC/MMU.cpp b/Source/Core/Core/PowerPC/MMU.cpp index c43f58ab86..59f574ad65 100644 --- a/Source/Core/Core/PowerPC/MMU.cpp +++ b/Source/Core/Core/PowerPC/MMU.cpp @@ -558,8 +558,7 @@ void MMU::Memcheck(u32 address, u64 var, bool write, size_t size) mc->num_hits++; - const bool pause = mc->Action(m_system, &m_power_pc.GetDebugInterface(), var, address, write, - size, m_ppc_state.pc); + const bool pause = mc->Action(m_system, var, address, write, size, m_ppc_state.pc); if (!pause) return; diff --git a/Source/Core/Core/PowerPC/PPCAnalyst.cpp b/Source/Core/Core/PowerPC/PPCAnalyst.cpp index 978edfba80..b568656968 100644 --- a/Source/Core/Core/PowerPC/PPCAnalyst.cpp +++ b/Source/Core/Core/PowerPC/PPCAnalyst.cpp @@ -187,12 +187,12 @@ bool ReanalyzeFunction(const Core::CPUThreadGuard& guard, u32 start_addr, Common // Second pass analysis, done after the first pass is done for all functions // so we have more information to work with -static void AnalyzeFunction2(Common::Symbol* func) +static void AnalyzeFunction2(PPCSymbolDB* func_db, Common::Symbol* func) { u32 flags = func->flags; - bool nonleafcall = std::any_of(func->calls.begin(), func->calls.end(), [](const auto& call) { - const Common::Symbol* called_func = g_symbolDB.GetSymbolFromAddr(call.function); + bool nonleafcall = std::any_of(func->calls.begin(), func->calls.end(), [&](const auto& call) { + const Common::Symbol* const called_func = func_db->GetSymbolFromAddr(call.function); return called_func && (called_func->flags & Common::FFLAG_LEAF) == 0; }); @@ -408,7 +408,7 @@ void FindFunctions(const Core::CPUThreadGuard& guard, u32 startAddr, u32 endAddr WARN_LOG_FMT(SYMBOLS, "Weird function"); continue; } - AnalyzeFunction2(&(func.second)); + AnalyzeFunction2(func_db, &(func.second)); Common::Symbol& f = func.second; if (f.name.substr(0, 3) == "zzz") { @@ -824,7 +824,8 @@ u32 PPCAnalyzer::Analyze(u32 address, CodeBlock* block, CodeBuffer* buffer, const bool enable_follow = m_enable_branch_following; - auto& mmu = Core::System::GetInstance().GetMMU(); + auto& system = Core::System::GetInstance(); + auto& mmu = system.GetMMU(); for (std::size_t i = 0; i < block_size; ++i) { auto result = mmu.TryReadInstruction(address); @@ -979,6 +980,8 @@ u32 PPCAnalyzer::Analyze(u32 address, CodeBlock* block, CodeBuffer* buffer, block->m_broken = true; } + auto& power_pc = system.GetPowerPC(); + auto& ppc_symbol_db = power_pc.GetSymbolDB(); // Scan for flag dependencies; assume the next block (or any branch that can leave the block) // wants flags, to be safe. bool wantsFPRF = true; @@ -998,8 +1001,8 @@ u32 PPCAnalyzer::Analyze(u32 address, CodeBlock* block, CodeBuffer* buffer, crDiscardable = BitSet8{}; } - const auto ppc_mode = Core::System::GetInstance().GetPowerPC().GetMode(); - const bool hle = !!HLE::TryReplaceFunction(op.address, ppc_mode); + const auto ppc_mode = power_pc.GetMode(); + const bool hle = !!HLE::TryReplaceFunction(ppc_symbol_db, op.address, ppc_mode); const bool may_exit_block = hle || op.canEndBlock || op.canCauseException; const bool opWantsFPRF = op.wantsFPRF; diff --git a/Source/Core/Core/PowerPC/PPCSymbolDB.cpp b/Source/Core/Core/PowerPC/PPCSymbolDB.cpp index bf0229f292..d1f2a5a719 100644 --- a/Source/Core/Core/PowerPC/PPCSymbolDB.cpp +++ b/Source/Core/Core/PowerPC/PPCSymbolDB.cpp @@ -26,8 +26,6 @@ #include "Core/PowerPC/SignatureDB/SignatureDB.h" #include "Core/System.h" -PPCSymbolDB g_symbolDB; - PPCSymbolDB::PPCSymbolDB() = default; PPCSymbolDB::~PPCSymbolDB() = default; diff --git a/Source/Core/Core/PowerPC/PPCSymbolDB.h b/Source/Core/Core/PowerPC/PPCSymbolDB.h index 74714d011c..7c5861ff43 100644 --- a/Source/Core/Core/PowerPC/PPCSymbolDB.h +++ b/Source/Core/Core/PowerPC/PPCSymbolDB.h @@ -39,5 +39,3 @@ public: void PrintCallers(u32 funcAddr) const; void LogFunctionCall(u32 addr); }; - -extern PPCSymbolDB g_symbolDB; diff --git a/Source/Core/Core/PowerPC/PowerPC.cpp b/Source/Core/Core/PowerPC/PowerPC.cpp index 4534139216..b1d76aac45 100644 --- a/Source/Core/Core/PowerPC/PowerPC.cpp +++ b/Source/Core/Core/PowerPC/PowerPC.cpp @@ -85,7 +85,8 @@ std::ostream& operator<<(std::ostream& os, CPUCore core) } PowerPCManager::PowerPCManager(Core::System& system) - : m_breakpoints(system), m_memchecks(system), m_debug_interface(system), m_system(system) + : m_breakpoints(system), m_memchecks(system), m_debug_interface(system, m_symbol_db), + m_system(system) { } @@ -668,7 +669,7 @@ void PowerPCManager::CheckBreakPoints() NOTICE_LOG_FMT(MEMMAP, "BP {:08x} {}({:08x} {:08x} {:08x} {:08x} {:08x} {:08x} {:08x} {:08x} {:08x} " "{:08x}) LR={:08x}", - m_ppc_state.pc, g_symbolDB.GetDescription(m_ppc_state.pc), m_ppc_state.gpr[3], + m_ppc_state.pc, m_symbol_db.GetDescription(m_ppc_state.pc), m_ppc_state.gpr[3], m_ppc_state.gpr[4], m_ppc_state.gpr[5], m_ppc_state.gpr[6], m_ppc_state.gpr[7], m_ppc_state.gpr[8], m_ppc_state.gpr[9], m_ppc_state.gpr[10], m_ppc_state.gpr[11], m_ppc_state.gpr[12], LR(m_ppc_state)); diff --git a/Source/Core/Core/PowerPC/PowerPC.h b/Source/Core/Core/PowerPC/PowerPC.h index 750f0c6f69..e4d00ec884 100644 --- a/Source/Core/Core/PowerPC/PowerPC.h +++ b/Source/Core/Core/PowerPC/PowerPC.h @@ -20,6 +20,7 @@ #include "Core/PowerPC/ConditionRegister.h" #include "Core/PowerPC/Gekko.h" #include "Core/PowerPC/PPCCache.h" +#include "Core/PowerPC/PPCSymbolDB.h" class CPUCoreBase; class PointerWrap; @@ -299,6 +300,8 @@ public: const MemChecks& GetMemChecks() const { return m_memchecks; } PPCDebugInterface& GetDebugInterface() { return m_debug_interface; } const PPCDebugInterface& GetDebugInterface() const { return m_debug_interface; } + PPCSymbolDB& GetSymbolDB() { return m_symbol_db; } + const PPCSymbolDB& GetSymbolDB() const { return m_symbol_db; } Core::BranchWatch& GetBranchWatch() { return m_branch_watch; } const Core::BranchWatch& GetBranchWatch() const { return m_branch_watch; } @@ -316,6 +319,7 @@ private: BreakPoints m_breakpoints; MemChecks m_memchecks; + PPCSymbolDB m_symbol_db; PPCDebugInterface m_debug_interface; Core::BranchWatch m_branch_watch; diff --git a/Source/Core/Core/System.cpp b/Source/Core/Core/System.cpp index 2da55975de..695d5861fc 100644 --- a/Source/Core/Core/System.cpp +++ b/Source/Core/Core/System.cpp @@ -52,7 +52,8 @@ struct System::Impl m_memory(system), m_pixel_engine{system}, m_power_pc(system), m_mmu(system, m_memory, m_power_pc), m_processor_interface(system), m_serial_interface(system), m_system_timers(system), m_video_interface(system), - m_interpreter(system, m_power_pc.GetPPCState(), m_mmu, m_power_pc.GetBranchWatch()), + m_interpreter(system, m_power_pc.GetPPCState(), m_mmu, m_power_pc.GetBranchWatch(), + m_power_pc.GetSymbolDB()), m_jit_interface(system), m_fifo_player(system), m_fifo_recorder(system), m_movie(system) { } @@ -287,6 +288,11 @@ PowerPC::PowerPCState& System::GetPPCState() const return m_impl->m_power_pc.GetPPCState(); } +PPCSymbolDB& System::GetPPCSymbolDB() const +{ + return m_impl->m_power_pc.GetSymbolDB(); +} + ProcessorInterface::ProcessorInterfaceManager& System::GetProcessorInterface() const { return m_impl->m_processor_interface; diff --git a/Source/Core/Core/System.h b/Source/Core/Core/System.h index acaf2daad7..a1422ac84d 100644 --- a/Source/Core/Core/System.h +++ b/Source/Core/Core/System.h @@ -92,6 +92,7 @@ class MMU; class PowerPCManager; struct PowerPCState; } // namespace PowerPC +class PPCSymbolDB; namespace ProcessorInterface { class ProcessorInterfaceManager; @@ -184,6 +185,7 @@ public: PixelShaderManager& GetPixelShaderManager() const; PowerPC::PowerPCManager& GetPowerPC() const; PowerPC::PowerPCState& GetPPCState() const; + PPCSymbolDB& GetPPCSymbolDB() const; ProcessorInterface::ProcessorInterfaceManager& GetProcessorInterface() const; SerialInterface::SerialInterfaceManager& GetSerialInterface() const; Sram& GetSRAM() const; diff --git a/Source/Core/DolphinQt/Debugger/BranchWatchDialog.cpp b/Source/Core/DolphinQt/Debugger/BranchWatchDialog.cpp index 39d755efc9..d9ff18db03 100644 --- a/Source/Core/DolphinQt/Debugger/BranchWatchDialog.cpp +++ b/Source/Core/DolphinQt/Debugger/BranchWatchDialog.cpp @@ -194,25 +194,26 @@ void BranchWatchProxyModel::SetInspected(const QModelIndex& index) } BranchWatchDialog::BranchWatchDialog(Core::System& system, Core::BranchWatch& branch_watch, - CodeWidget* code_widget, QWidget* parent) + PPCSymbolDB& ppc_symbol_db, CodeWidget* code_widget, + QWidget* parent) : QDialog(parent), m_system(system), m_branch_watch(branch_watch), m_code_widget(code_widget) { setWindowTitle(tr("Branch Watch Tool")); setWindowFlags((windowFlags() | Qt::WindowMinMaxButtonsHint) & ~Qt::WindowContextHelpButtonHint); SetQWidgetWindowDecorations(this); - setLayout([this]() { + setLayout([this, &ppc_symbol_db]() { auto* main_layout = new QVBoxLayout; // Controls Toolbar (widgets are added later) main_layout->addWidget(m_control_toolbar = new QToolBar); // Branch Watch Table - main_layout->addWidget(m_table_view = [this]() { + main_layout->addWidget(m_table_view = [this, &ppc_symbol_db]() { const auto& ui_settings = Settings::Instance(); m_table_proxy = new BranchWatchProxyModel(m_branch_watch); - m_table_proxy->setSourceModel(m_table_model = - new BranchWatchTableModel(m_system, m_branch_watch)); + m_table_proxy->setSourceModel( + m_table_model = new BranchWatchTableModel(m_system, m_branch_watch, ppc_symbol_db)); m_table_proxy->setSortRole(UserRole::SortRole); m_table_model->setFont(ui_settings.GetDebugFont()); diff --git a/Source/Core/DolphinQt/Debugger/BranchWatchDialog.h b/Source/Core/DolphinQt/Debugger/BranchWatchDialog.h index d97972980c..22181c0699 100644 --- a/Source/Core/DolphinQt/Debugger/BranchWatchDialog.h +++ b/Source/Core/DolphinQt/Debugger/BranchWatchDialog.h @@ -17,6 +17,8 @@ class BranchWatch; class CPUThreadGuard; class System; } // namespace Core +class PPCSymbolDB; + class BranchWatchProxyModel; class BranchWatchTableModel; class CodeWidget; @@ -48,7 +50,8 @@ class BranchWatchDialog : public QDialog public: explicit BranchWatchDialog(Core::System& system, Core::BranchWatch& branch_watch, - CodeWidget* code_widget, QWidget* parent = nullptr); + PPCSymbolDB& ppc_symbol_db, CodeWidget* code_widget, + QWidget* parent = nullptr); ~BranchWatchDialog() override; protected: diff --git a/Source/Core/DolphinQt/Debugger/BranchWatchTableModel.cpp b/Source/Core/DolphinQt/Debugger/BranchWatchTableModel.cpp index 800973a6dd..08d7ae021d 100644 --- a/Source/Core/DolphinQt/Debugger/BranchWatchTableModel.cpp +++ b/Source/Core/DolphinQt/Debugger/BranchWatchTableModel.cpp @@ -285,8 +285,8 @@ void BranchWatchTableModel::PrefetchSymbols() for (const Core::BranchWatch::Selection::value_type& value : selection) { const Core::BranchWatch::Collection::value_type* const kv = value.collection_ptr; - m_symbol_list.emplace_back(g_symbolDB.GetSymbolFromAddr(kv->first.origin_addr), - g_symbolDB.GetSymbolFromAddr(kv->first.destin_addr)); + m_symbol_list.emplace_back(m_ppc_symbol_db.GetSymbolFromAddr(kv->first.origin_addr), + m_ppc_symbol_db.GetSymbolFromAddr(kv->first.destin_addr)); } } diff --git a/Source/Core/DolphinQt/Debugger/BranchWatchTableModel.h b/Source/Core/DolphinQt/Debugger/BranchWatchTableModel.h index 7b3cf42bb1..b91dba37d2 100644 --- a/Source/Core/DolphinQt/Debugger/BranchWatchTableModel.h +++ b/Source/Core/DolphinQt/Debugger/BranchWatchTableModel.h @@ -18,6 +18,7 @@ class BranchWatch; class CPUThreadGuard; class System; } // namespace Core +class PPCSymbolDB; namespace BranchWatchTableModelColumn { @@ -69,8 +70,9 @@ public: using SymbolList = QList; explicit BranchWatchTableModel(Core::System& system, Core::BranchWatch& branch_watch, - QObject* parent = nullptr) - : QAbstractTableModel(parent), m_system(system), m_branch_watch(branch_watch) + PPCSymbolDB& ppc_symbol_db, QObject* parent = nullptr) + : QAbstractTableModel(parent), m_system(system), m_branch_watch(branch_watch), + m_ppc_symbol_db(ppc_symbol_db) { } QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override; @@ -113,6 +115,7 @@ private: Core::System& m_system; Core::BranchWatch& m_branch_watch; + PPCSymbolDB& m_ppc_symbol_db; SymbolList m_symbol_list; mutable QFont m_font; diff --git a/Source/Core/DolphinQt/Debugger/BreakpointWidget.cpp b/Source/Core/DolphinQt/Debugger/BreakpointWidget.cpp index bf29361973..bf35c52cd5 100644 --- a/Source/Core/DolphinQt/Debugger/BreakpointWidget.cpp +++ b/Source/Core/DolphinQt/Debugger/BreakpointWidget.cpp @@ -178,6 +178,7 @@ void BreakpointWidget::Update() auto& power_pc = m_system.GetPowerPC(); auto& breakpoints = power_pc.GetBreakPoints(); auto& memchecks = power_pc.GetMemChecks(); + auto& ppc_symbol_db = power_pc.GetSymbolDB(); // Breakpoints for (const auto& bp : breakpoints.GetBreakPoints()) @@ -192,10 +193,10 @@ void BreakpointWidget::Update() m_table->setItem(i, 0, active); m_table->setItem(i, 1, create_item(QStringLiteral("BP"))); - if (g_symbolDB.GetSymbolFromAddr(bp.address)) + if (ppc_symbol_db.GetSymbolFromAddr(bp.address)) { - m_table->setItem(i, 2, - create_item(QString::fromStdString(g_symbolDB.GetDescription(bp.address)))); + m_table->setItem( + i, 2, create_item(QString::fromStdString(ppc_symbol_db.GetDescription(bp.address)))); } m_table->setItem(i, 3, @@ -233,10 +234,11 @@ void BreakpointWidget::Update() m_table->setItem(i, 0, active); m_table->setItem(i, 1, create_item(QStringLiteral("MBP"))); - if (g_symbolDB.GetSymbolFromAddr(mbp.start_address)) + if (ppc_symbol_db.GetSymbolFromAddr(mbp.start_address)) { m_table->setItem( - i, 2, create_item(QString::fromStdString(g_symbolDB.GetDescription(mbp.start_address)))); + i, 2, + create_item(QString::fromStdString(ppc_symbol_db.GetDescription(mbp.start_address)))); } if (mbp.is_ranged) diff --git a/Source/Core/DolphinQt/Debugger/CodeViewWidget.cpp b/Source/Core/DolphinQt/Debugger/CodeViewWidget.cpp index df6ccc6a5b..a7b097b93c 100644 --- a/Source/Core/DolphinQt/Debugger/CodeViewWidget.cpp +++ b/Source/Core/DolphinQt/Debugger/CodeViewWidget.cpp @@ -138,7 +138,8 @@ constexpr int CODE_VIEW_COLUMN_DESCRIPTION = 4; constexpr int CODE_VIEW_COLUMN_BRANCH_ARROWS = 5; constexpr int CODE_VIEW_COLUMNCOUNT = 6; -CodeViewWidget::CodeViewWidget() : m_system(Core::System::GetInstance()) +CodeViewWidget::CodeViewWidget() + : m_system(Core::System::GetInstance()), m_ppc_symbol_db(m_system.GetPPCSymbolDB()) { setColumnCount(CODE_VIEW_COLUMNCOUNT); setShowGrid(false); @@ -382,7 +383,7 @@ void CodeViewWidget::Update(const Core::CPUThreadGuard* guard) if (debug_interface.IsBreakpoint(addr)) { auto icon = Resources::GetThemeIcon("debugger_breakpoint").pixmap(QSize(rowh - 2, rowh - 2)); - if (!m_system.GetPowerPC().GetBreakPoints().IsBreakPointEnable(addr)) + if (!power_pc.GetBreakPoints().IsBreakPointEnable(addr)) { QPixmap disabled_icon(icon.size()); disabled_icon.fill(Qt::transparent); @@ -410,7 +411,7 @@ void CodeViewWidget::Update(const Core::CPUThreadGuard* guard) CalculateBranchIndentation(); - g_symbolDB.FillInCallers(); + m_ppc_symbol_db.FillInCallers(); repaint(); m_updating = false; @@ -561,7 +562,7 @@ void CodeViewWidget::OnContextMenu() const u32 addr = GetContextAddress(); - bool has_symbol = g_symbolDB.GetSymbolFromAddr(addr); + const bool has_symbol = m_ppc_symbol_db.GetSymbolFromAddr(addr); auto* follow_branch_action = menu->addAction(tr("Follow &branch"), this, &CodeViewWidget::OnFollowBranch); @@ -819,7 +820,7 @@ void CodeViewWidget::OnCopyFunction() { const u32 address = GetContextAddress(); - const Common::Symbol* symbol = g_symbolDB.GetSymbolFromAddr(address); + const Common::Symbol* const symbol = m_ppc_symbol_db.GetSymbolFromAddr(address); if (!symbol) return; @@ -877,7 +878,7 @@ void CodeViewWidget::OnAddFunction() Core::CPUThreadGuard guard(m_system); - g_symbolDB.AddFunction(guard, addr); + m_ppc_symbol_db.AddFunction(guard, addr); emit SymbolsChanged(); Update(&guard); } @@ -915,7 +916,7 @@ void CodeViewWidget::OnRenameSymbol() { const u32 addr = GetContextAddress(); - Common::Symbol* const symbol = g_symbolDB.GetSymbolFromAddr(addr); + Common::Symbol* const symbol = m_ppc_symbol_db.GetSymbolFromAddr(addr); if (!symbol) return; @@ -950,7 +951,7 @@ void CodeViewWidget::OnSetSymbolSize() { const u32 addr = GetContextAddress(); - Common::Symbol* const symbol = g_symbolDB.GetSymbolFromAddr(addr); + Common::Symbol* const symbol = m_ppc_symbol_db.GetSymbolFromAddr(addr); if (!symbol) return; @@ -975,7 +976,7 @@ void CodeViewWidget::OnSetSymbolEndAddress() { const u32 addr = GetContextAddress(); - Common::Symbol* const symbol = g_symbolDB.GetSymbolFromAddr(addr); + Common::Symbol* const symbol = m_ppc_symbol_db.GetSymbolFromAddr(addr); if (!symbol) return; diff --git a/Source/Core/DolphinQt/Debugger/CodeViewWidget.h b/Source/Core/DolphinQt/Debugger/CodeViewWidget.h index 5e63eb96a4..81e747c21a 100644 --- a/Source/Core/DolphinQt/Debugger/CodeViewWidget.h +++ b/Source/Core/DolphinQt/Debugger/CodeViewWidget.h @@ -23,6 +23,7 @@ class System; struct CodeViewBranch; class BranchDisplayDelegate; +class PPCSymbolDB; class CodeViewWidget : public QTableWidget { @@ -102,6 +103,7 @@ private: void CalculateBranchIndentation(); Core::System& m_system; + PPCSymbolDB& m_ppc_symbol_db; bool m_updating = false; diff --git a/Source/Core/DolphinQt/Debugger/CodeWidget.cpp b/Source/Core/DolphinQt/Debugger/CodeWidget.cpp index 382ec03861..dbee26c6ec 100644 --- a/Source/Core/DolphinQt/Debugger/CodeWidget.cpp +++ b/Source/Core/DolphinQt/Debugger/CodeWidget.cpp @@ -36,7 +36,9 @@ static const QString BOX_SPLITTER_STYLESHEET = QStringLiteral( "QSplitter::handle { border-top: 1px dashed black; width: 1px; margin-left: 10px; " "margin-right: 10px; }"); -CodeWidget::CodeWidget(QWidget* parent) : QDockWidget(parent), m_system(Core::System::GetInstance()) +CodeWidget::CodeWidget(QWidget* parent) + : QDockWidget(parent), m_system(Core::System::GetInstance()), + m_ppc_symbol_db(m_system.GetPPCSymbolDB()) { setWindowTitle(tr("Code")); setObjectName(QStringLiteral("code")); @@ -171,13 +173,11 @@ void CodeWidget::ConnectWidgets() connect(m_search_address, &QLineEdit::returnPressed, this, &CodeWidget::OnSearchAddress); connect(m_search_symbols, &QLineEdit::textChanged, this, &CodeWidget::OnSearchSymbols); connect(m_search_calls, &QLineEdit::textChanged, this, [this]() { - const Common::Symbol* symbol = g_symbolDB.GetSymbolFromAddr(m_code_view->GetAddress()); - if (symbol) + if (const Common::Symbol* symbol = m_ppc_symbol_db.GetSymbolFromAddr(m_code_view->GetAddress())) UpdateFunctionCalls(symbol); }); connect(m_search_callers, &QLineEdit::textChanged, this, [this]() { - const Common::Symbol* symbol = g_symbolDB.GetSymbolFromAddr(m_code_view->GetAddress()); - if (symbol) + if (const Common::Symbol* symbol = m_ppc_symbol_db.GetSymbolFromAddr(m_code_view->GetAddress())) UpdateFunctionCallers(symbol); }); connect(m_search_callstack, &QLineEdit::textChanged, this, &CodeWidget::UpdateCallstack); @@ -194,8 +194,7 @@ void CodeWidget::ConnectWidgets() connect(m_code_view, &CodeViewWidget::SymbolsChanged, this, [this]() { UpdateCallstack(); UpdateSymbols(); - const Common::Symbol* symbol = g_symbolDB.GetSymbolFromAddr(m_code_view->GetAddress()); - if (symbol) + if (const Common::Symbol* symbol = m_ppc_symbol_db.GetSymbolFromAddr(m_code_view->GetAddress())) { UpdateFunctionCalls(symbol); UpdateFunctionCallers(symbol); @@ -214,8 +213,8 @@ void CodeWidget::OnBranchWatchDialog() { if (m_branch_watch_dialog == nullptr) { - m_branch_watch_dialog = - new BranchWatchDialog(m_system, m_system.GetPowerPC().GetBranchWatch(), this, this); + m_branch_watch_dialog = new BranchWatchDialog(m_system, m_system.GetPowerPC().GetBranchWatch(), + m_ppc_symbol_db, this, this); } m_branch_watch_dialog->show(); m_branch_watch_dialog->raise(); @@ -260,7 +259,7 @@ void CodeWidget::OnSelectSymbol() return; const u32 address = items[0]->data(Qt::UserRole).toUInt(); - const Common::Symbol* symbol = g_symbolDB.GetSymbolFromAddr(address); + const Common::Symbol* const symbol = m_ppc_symbol_db.GetSymbolFromAddr(address); m_code_view->SetAddress(address, CodeViewWidget::SetAddressUpdate::WithUpdate); UpdateCallstack(); @@ -321,7 +320,7 @@ void CodeWidget::Update() if (!isVisible()) return; - const Common::Symbol* symbol = g_symbolDB.GetSymbolFromAddr(m_code_view->GetAddress()); + const Common::Symbol* const symbol = m_ppc_symbol_db.GetSymbolFromAddr(m_code_view->GetAddress()); UpdateCallstack(); @@ -343,13 +342,7 @@ void CodeWidget::UpdateCallstack() return; std::vector stack; - - const bool success = [this, &stack] { - Core::CPUThreadGuard guard(m_system); - return Dolphin_Debugger::GetCallstack(guard, stack); - }(); - - if (!success) + if (!Dolphin_Debugger::GetCallstack(Core::CPUThreadGuard{m_system}, stack)) { m_callstack_list->addItem(tr("Invalid callstack")); return; @@ -377,7 +370,7 @@ void CodeWidget::UpdateSymbols() m_symbols_list->selectedItems()[0]->text(); m_symbols_list->clear(); - for (const auto& symbol : g_symbolDB.Symbols()) + for (const auto& symbol : m_ppc_symbol_db.Symbols()) { QString name = QString::fromStdString(symbol.second.name); @@ -411,7 +404,7 @@ void CodeWidget::UpdateFunctionCalls(const Common::Symbol* symbol) for (const auto& call : symbol->calls) { const u32 addr = call.function; - const Common::Symbol* call_symbol = g_symbolDB.GetSymbolFromAddr(addr); + const Common::Symbol* const call_symbol = m_ppc_symbol_db.GetSymbolFromAddr(addr); if (call_symbol) { @@ -436,7 +429,7 @@ void CodeWidget::UpdateFunctionCallers(const Common::Symbol* symbol) for (const auto& caller : symbol->callers) { const u32 addr = caller.call_address; - const Common::Symbol* caller_symbol = g_symbolDB.GetSymbolFromAddr(addr); + const Common::Symbol* const caller_symbol = m_ppc_symbol_db.GetSymbolFromAddr(addr); if (caller_symbol) { diff --git a/Source/Core/DolphinQt/Debugger/CodeWidget.h b/Source/Core/DolphinQt/Debugger/CodeWidget.h index 7ccd2af2f3..e5465130a2 100644 --- a/Source/Core/DolphinQt/Debugger/CodeWidget.h +++ b/Source/Core/DolphinQt/Debugger/CodeWidget.h @@ -26,6 +26,7 @@ namespace Core { class System; } +class PPCSymbolDB; class CodeWidget : public QDockWidget { @@ -71,6 +72,7 @@ private: void showEvent(QShowEvent* event) override; Core::System& m_system; + PPCSymbolDB& m_ppc_symbol_db; BranchWatchDialog* m_branch_watch_dialog = nullptr; QLineEdit* m_search_address; diff --git a/Source/Core/DolphinQt/MenuBar.cpp b/Source/Core/DolphinQt/MenuBar.cpp index 07d4d21cbb..a7cab0aebb 100644 --- a/Source/Core/DolphinQt/MenuBar.cpp +++ b/Source/Core/DolphinQt/MenuBar.cpp @@ -1261,35 +1261,37 @@ void MenuBar::ClearSymbols() if (result == QMessageBox::Cancel) return; - g_symbolDB.Clear(); + Core::System::GetInstance().GetPPCSymbolDB().Clear(); emit NotifySymbolsUpdated(); } void MenuBar::GenerateSymbolsFromAddress() { - Core::CPUThreadGuard guard(Core::System::GetInstance()); - auto& system = Core::System::GetInstance(); auto& memory = system.GetMemory(); + auto& ppc_symbol_db = system.GetPPCSymbolDB(); + + const Core::CPUThreadGuard guard(system); PPCAnalyst::FindFunctions(guard, Memory::MEM1_BASE_ADDR, - Memory::MEM1_BASE_ADDR + memory.GetRamSizeReal(), &g_symbolDB); + Memory::MEM1_BASE_ADDR + memory.GetRamSizeReal(), &ppc_symbol_db); emit NotifySymbolsUpdated(); } void MenuBar::GenerateSymbolsFromSignatureDB() { - Core::CPUThreadGuard guard(Core::System::GetInstance()); - auto& system = Core::System::GetInstance(); auto& memory = system.GetMemory(); + auto& ppc_symbol_db = system.GetPPCSymbolDB(); + + const Core::CPUThreadGuard guard(system); PPCAnalyst::FindFunctions(guard, Memory::MEM1_BASE_ADDR, - Memory::MEM1_BASE_ADDR + memory.GetRamSizeReal(), &g_symbolDB); + Memory::MEM1_BASE_ADDR + memory.GetRamSizeReal(), &ppc_symbol_db); SignatureDB db(SignatureDB::HandlerType::DSY); if (db.Load(File::GetSysDirectory() + TOTALDB)) { - db.Apply(guard, &g_symbolDB); + db.Apply(guard, &ppc_symbol_db); ModalMessageBox::information( this, tr("Information"), tr("Generated symbol names from '%1'").arg(QString::fromStdString(TOTALDB))); @@ -1325,12 +1327,13 @@ void MenuBar::GenerateSymbolsFromRSO() return; } - Core::CPUThreadGuard guard(Core::System::GetInstance()); + auto& system = Core::System::GetInstance(); + const Core::CPUThreadGuard guard(system); RSOChainView rso_chain; if (rso_chain.Load(guard, static_cast(address))) { - rso_chain.Apply(guard, &g_symbolDB); + rso_chain.Apply(guard, &system.GetPPCSymbolDB()); emit NotifySymbolsUpdated(); } else @@ -1382,11 +1385,12 @@ void MenuBar::GenerateSymbolsFromRSOAuto() RSOChainView rso_chain; const u32 address = item.mid(0, item.indexOf(QLatin1Char(' '))).toUInt(nullptr, 16); - Core::CPUThreadGuard guard(Core::System::GetInstance()); + auto& system = Core::System::GetInstance(); + const Core::CPUThreadGuard guard(system); if (rso_chain.Load(guard, address)) { - rso_chain.Apply(guard, &g_symbolDB); + rso_chain.Apply(guard, &system.GetPPCSymbolDB()); emit NotifySymbolsUpdated(); } else @@ -1502,22 +1506,23 @@ void MenuBar::LoadSymbolMap() { auto& system = Core::System::GetInstance(); auto& memory = system.GetMemory(); + auto& ppc_symbol_db = system.GetPPCSymbolDB(); std::string existing_map_file, writable_map_file; bool map_exists = CBoot::FindMapFile(&existing_map_file, &writable_map_file); if (!map_exists) { - g_symbolDB.Clear(); + ppc_symbol_db.Clear(); { - Core::CPUThreadGuard guard(Core::System::GetInstance()); + const Core::CPUThreadGuard guard(system); PPCAnalyst::FindFunctions(guard, Memory::MEM1_BASE_ADDR + 0x1300000, - Memory::MEM1_BASE_ADDR + memory.GetRamSizeReal(), &g_symbolDB); + Memory::MEM1_BASE_ADDR + memory.GetRamSizeReal(), &ppc_symbol_db); SignatureDB db(SignatureDB::HandlerType::DSY); if (db.Load(File::GetSysDirectory() + TOTALDB)) - db.Apply(guard, &g_symbolDB); + db.Apply(guard, &ppc_symbol_db); } ModalMessageBox::warning(this, tr("Warning"), @@ -1603,13 +1608,8 @@ void MenuBar::SaveCode() const std::string path = writable_map_file.substr(0, writable_map_file.find_last_of('.')) + "_code.map"; - bool success; - { - Core::CPUThreadGuard guard(Core::System::GetInstance()); - success = g_symbolDB.SaveCodeMap(guard, path); - } - - if (!success) + auto& system = Core::System::GetInstance(); + if (!system.GetPPCSymbolDB().SaveCodeMap(Core::CPUThreadGuard{system}, path)) { ModalMessageBox::warning( this, tr("Error"), @@ -1619,9 +1619,10 @@ void MenuBar::SaveCode() bool MenuBar::TryLoadMapFile(const QString& path, const bool bad) { - Core::CPUThreadGuard guard(Core::System::GetInstance()); + auto& system = Core::System::GetInstance(); + auto& ppc_symbol_db = system.GetPPCSymbolDB(); - if (!g_symbolDB.LoadMap(guard, path.toStdString(), bad)) + if (!ppc_symbol_db.LoadMap(Core::CPUThreadGuard{system}, path.toStdString(), bad)) { ModalMessageBox::warning(this, tr("Error"), tr("Failed to load map file '%1'").arg(path)); return false; @@ -1632,7 +1633,7 @@ bool MenuBar::TryLoadMapFile(const QString& path, const bool bad) void MenuBar::TrySaveSymbolMap(const QString& path) { - if (g_symbolDB.SaveSymbolMap(path.toStdString())) + if (Core::System::GetInstance().GetPPCSymbolDB().SaveSymbolMap(path.toStdString())) return; ModalMessageBox::warning(this, tr("Error"), @@ -1653,7 +1654,7 @@ void MenuBar::CreateSignatureFile() const std::string prefix = text.toStdString(); const std::string save_path = file.toStdString(); SignatureDB db(save_path); - db.Populate(&g_symbolDB, prefix); + db.Populate(&Core::System::GetInstance().GetPPCSymbolDB(), prefix); if (!db.Save(save_path)) { @@ -1678,7 +1679,7 @@ void MenuBar::AppendSignatureFile() const std::string prefix = text.toStdString(); const std::string signature_path = file.toStdString(); SignatureDB db(signature_path); - db.Populate(&g_symbolDB, prefix); + db.Populate(&Core::System::GetInstance().GetPPCSymbolDB(), prefix); db.List(); db.Load(signature_path); if (!db.Save(signature_path)) @@ -1699,15 +1700,13 @@ void MenuBar::ApplySignatureFile() if (file.isEmpty()) return; + auto& system = Core::System::GetInstance(); + const std::string load_path = file.toStdString(); SignatureDB db(load_path); db.Load(load_path); - { - Core::CPUThreadGuard guard(Core::System::GetInstance()); - db.Apply(guard, &g_symbolDB); - } + db.Apply(Core::CPUThreadGuard{system}, &system.GetPPCSymbolDB()); db.List(); - auto& system = Core::System::GetInstance(); HLE::PatchFunctions(system); emit NotifySymbolsUpdated(); }