From fe121e4c6eafac094019c727a8162f2488e61019 Mon Sep 17 00:00:00 2001 From: TryTwo Date: Tue, 17 Jun 2025 22:25:13 -0700 Subject: [PATCH] PPCSymbolDB: Move loading map on boot logic from boot.cpp into PPCSymbolDB, as it will be needing a mutex. Cleanup loading code and reduce amount of signals. On boot. allow previously loaded map to be kept, if its filename matches. Useful for restarting a game with a large symbol map. --- Source/Core/Common/SymbolDB.cpp | 9 +++++-- Source/Core/Common/SymbolDB.h | 3 ++- Source/Core/Core/Boot/Boot.cpp | 30 +++++++----------------- Source/Core/Core/Boot/Boot.h | 11 --------- Source/Core/Core/ConfigManager.cpp | 7 ++---- Source/Core/Core/IOS/MIOS.cpp | 12 +++++----- Source/Core/Core/PowerPC/PPCSymbolDB.cpp | 21 +++++++++++++++++ Source/Core/Core/PowerPC/PPCSymbolDB.h | 2 ++ 8 files changed, 49 insertions(+), 46 deletions(-) diff --git a/Source/Core/Common/SymbolDB.cpp b/Source/Core/Common/SymbolDB.cpp index bfdd9f57db..88f281e497 100644 --- a/Source/Core/Common/SymbolDB.cpp +++ b/Source/Core/Common/SymbolDB.cpp @@ -44,15 +44,20 @@ void SymbolDB::List() bool SymbolDB::IsEmpty() const { - return m_functions.empty(); + return m_functions.empty() && m_notes.empty(); } -void SymbolDB::Clear(const char* prefix) +bool SymbolDB::Clear(const char* prefix) { // TODO: honor prefix + m_map_name.clear(); + if (IsEmpty()) + return false; + m_functions.clear(); m_notes.clear(); m_checksum_to_function.clear(); + return true; } void SymbolDB::Index() diff --git a/Source/Core/Common/SymbolDB.h b/Source/Core/Common/SymbolDB.h index 8930b95996..7763999453 100644 --- a/Source/Core/Common/SymbolDB.h +++ b/Source/Core/Common/SymbolDB.h @@ -100,7 +100,7 @@ public: const XNoteMap& Notes() const { return m_notes; } XFuncMap& AccessSymbols() { return m_functions; } bool IsEmpty() const; - void Clear(const char* prefix = ""); + bool Clear(const char* prefix = ""); void List(); void Index(); @@ -108,5 +108,6 @@ protected: XFuncMap m_functions; XNoteMap m_notes; XFuncPtrMap m_checksum_to_function; + std::string m_map_name; }; } // namespace Common diff --git a/Source/Core/Core/Boot/Boot.cpp b/Source/Core/Core/Boot/Boot.cpp index 7521e5978c..1b796952f8 100644 --- a/Source/Core/Core/Boot/Boot.cpp +++ b/Source/Core/Core/Boot/Boot.cpp @@ -354,19 +354,6 @@ bool CBoot::DVDReadDiscID(Core::System& system, const DiscIO::VolumeDisc& disc, return true; } -bool CBoot::LoadMapFromFilename(const Core::CPUThreadGuard& guard, PPCSymbolDB& ppc_symbol_db) -{ - std::string strMapFilename; - bool found = ppc_symbol_db.FindMapFile(&strMapFilename, nullptr); - if (found && ppc_symbol_db.LoadMap(guard, strMapFilename)) - { - Host_PPCSymbolsChanged(); - return true; - } - - return false; -} - // If ipl.bin is not found, this function does *some* of what BS1 does: // loading IPL(BS2) and jumping to it. // It does not initialize the hardware or anything else like BS1 does. @@ -504,12 +491,6 @@ bool CBoot::BootUp(Core::System& system, const Core::CPUThreadGuard& guard, { SConfig& config = SConfig::GetInstance(); - if (auto& ppc_symbol_db = system.GetPPCSymbolDB(); !ppc_symbol_db.IsEmpty()) - { - ppc_symbol_db.Clear(); - Host_PPCSymbolsChanged(); - } - // PAL Wii uses NTSC framerate and linecount in 60Hz modes system.GetVideoInterface().Preset(DiscIO::IsNTSC(config.m_region) || (system.IsWii() && Config::Get(Config::SYSCONF_PAL60))); @@ -591,11 +572,18 @@ bool CBoot::BootUp(Core::System& system, const Core::CPUThreadGuard& guard, const std::string filename = PathToFileName(executable.path); - if (executable.reader->LoadSymbols(guard, system.GetPPCSymbolDB(), filename)) + auto& ppc_symbol_db = system.GetPPCSymbolDB(); + bool symbols_changed = ppc_symbol_db.Clear(); + + if (executable.reader->LoadSymbols(guard, ppc_symbol_db, filename)) { - Host_PPCSymbolsChanged(); + symbols_changed = true; HLE::PatchFunctions(system); } + + if (symbols_changed) + Host_PPCSymbolsChanged(); + return true; } diff --git a/Source/Core/Core/Boot/Boot.h b/Source/Core/Core/Boot/Boot.h index 8b157662cd..d280cc0785 100644 --- a/Source/Core/Core/Boot/Boot.h +++ b/Source/Core/Core/Boot/Boot.h @@ -159,17 +159,6 @@ public: static bool BootUp(Core::System& system, const Core::CPUThreadGuard& guard, std::unique_ptr boot); - // Tries to find a map file for the current game by looking first in the - // local user directory, then in the shared user directory. - // - // If existing_map_file is not nullptr and a map file exists, it is set to the - // path to the existing map file. - // - // If writable_map_file is not nullptr, it is set to the path to where a map - // file should be saved. - // - // Returns true if a map file exists, false if none could be found. - 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, diff --git a/Source/Core/Core/ConfigManager.cpp b/Source/Core/Core/ConfigManager.cpp index e005e78341..4e0b7dd3ac 100644 --- a/Source/Core/Core/ConfigManager.cpp +++ b/Source/Core/Core/ConfigManager.cpp @@ -271,12 +271,9 @@ void SConfig::OnTitleDirectlyBooted(const Core::CPUThreadGuard& guard) return; auto& ppc_symbol_db = system.GetPPCSymbolDB(); - if (!ppc_symbol_db.IsEmpty()) - { - ppc_symbol_db.Clear(); + + if (ppc_symbol_db.LoadMapOnBoot(guard)) Host_PPCSymbolsChanged(); - } - CBoot::LoadMapFromFilename(guard, ppc_symbol_db); HLE::Reload(system); PatchEngine::Reload(system); diff --git a/Source/Core/Core/IOS/MIOS.cpp b/Source/Core/Core/IOS/MIOS.cpp index d8829ee5cc..d47400c9d2 100644 --- a/Source/Core/Core/IOS/MIOS.cpp +++ b/Source/Core/Core/IOS/MIOS.cpp @@ -71,18 +71,18 @@ bool Load(Core::System& system) auto& ppc_symbol_db = power_pc.GetSymbolDB(); // Load symbols for the IPL if they exist. - if (!ppc_symbol_db.IsEmpty()) - { - ppc_symbol_db.Clear(); - Host_PPCSymbolsChanged(); - } + bool symbols_changed = ppc_symbol_db.Clear(); + if (ppc_symbol_db.LoadMap(guard, File::GetUserPath(D_MAPS_IDX) + "mios-ipl.map")) { ::HLE::Clear(); ::HLE::PatchFunctions(system); - Host_PPCSymbolsChanged(); + symbols_changed = true; } + if (symbols_changed) + Host_PPCSymbolsChanged(); + const PowerPC::CoreMode core_mode = power_pc.GetMode(); power_pc.SetMode(PowerPC::CoreMode::Interpreter); diff --git a/Source/Core/Core/PowerPC/PPCSymbolDB.cpp b/Source/Core/Core/PowerPC/PPCSymbolDB.cpp index 09271fc688..4a3ac6084a 100644 --- a/Source/Core/Core/PowerPC/PPCSymbolDB.cpp +++ b/Source/Core/Core/PowerPC/PPCSymbolDB.cpp @@ -301,6 +301,25 @@ bool PPCSymbolDB::FindMapFile(std::string* existing_map_file, std::string* writa return false; } +bool PPCSymbolDB::LoadMapOnBoot(const Core::CPUThreadGuard& guard) +{ + std::string existing_map_file; + if (!PPCSymbolDB::FindMapFile(&existing_map_file, nullptr)) + return Clear(); + + // If the map is already loaded (such as restarting the same game), skip reloading. + if (!IsEmpty() && existing_map_file == m_map_name) + return false; + + // Load map into cleared m_functions. + bool changed = Clear(); + + if (!LoadMap(guard, existing_map_file)) + return changed; + + return true; +} + // The use case for handling bad map files is when you have a game with a map file on the disc, // but you can't tell whether that map file is for the particular release version used in that game, // or when you know that the map file is not for that build, but perhaps half the functions in the @@ -554,6 +573,8 @@ bool PPCSymbolDB::LoadMap(const Core::CPUThreadGuard& guard, const std::string& } } + m_map_name = filename; + Index(); DetermineNoteLayers(); NOTICE_LOG_FMT(SYMBOLS, "{} symbols loaded, {} symbols ignored.", good_count, bad_count); diff --git a/Source/Core/Core/PowerPC/PPCSymbolDB.h b/Source/Core/Core/PowerPC/PPCSymbolDB.h index f3a84b0f18..2da3ce8474 100644 --- a/Source/Core/Core/PowerPC/PPCSymbolDB.h +++ b/Source/Core/Core/PowerPC/PPCSymbolDB.h @@ -37,6 +37,8 @@ public: std::string_view GetDescription(u32 addr); void FillInCallers(); + + bool LoadMapOnBoot(const Core::CPUThreadGuard& guard); bool LoadMap(const Core::CPUThreadGuard& guard, const std::string& filename, bool bad = false); bool SaveSymbolMap(const std::string& filename) const; bool SaveCodeMap(const Core::CPUThreadGuard& guard, const std::string& filename) const;