From aa46f37647f7744414d892e81d5c47b7745431af Mon Sep 17 00:00:00 2001 From: chaoticgd <43898262+chaoticgd@users.noreply.github.com> Date: Tue, 26 Mar 2024 21:54:16 +0000 Subject: [PATCH] DebugTools: Fix crash on exit in SymbolGuardian::~SymbolGuardian --- pcsx2/DebugTools/SymbolGuardian.cpp | 21 +++++++++++---------- pcsx2/DebugTools/SymbolGuardian.h | 10 +++++----- pcsx2/VMManager.cpp | 3 +++ 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/pcsx2/DebugTools/SymbolGuardian.cpp b/pcsx2/DebugTools/SymbolGuardian.cpp index d42a9e595fcb5..c272c0953193d 100644 --- a/pcsx2/DebugTools/SymbolGuardian.cpp +++ b/pcsx2/DebugTools/SymbolGuardian.cpp @@ -45,8 +45,6 @@ SymbolGuardian::SymbolGuardian() SymbolGuardian::~SymbolGuardian() { - // TODO: Fix crash on exit here. - m_interrupt_import_thread = true; } void SymbolGuardian::Read(ReadCallback callback) const noexcept @@ -65,10 +63,7 @@ void SymbolGuardian::ReadWrite(ReadWriteCallback callback) noexcept void SymbolGuardian::Reset() { - m_interrupt_import_thread = true; - if (m_import_thread.joinable()) - m_import_thread.join(); - m_interrupt_import_thread = false; + ShutdownWorkerThread(); ReadWrite([&](ccc::SymbolDatabase& database) { database.clear(); @@ -141,10 +136,7 @@ void SymbolGuardian::ImportElf(std::vector elf, std::string elf_file_name, s std::unique_ptr symbol_file = std::make_unique(std::move(*parsed_elf), std::move(elf_file_name)); - m_interrupt_import_thread = true; - if (m_import_thread.joinable()) - m_import_thread.join(); - m_interrupt_import_thread = false; + ShutdownWorkerThread(); m_import_thread = std::thread([this, nocash_path, file = std::move(symbol_file)]() { Threading::SetNameOfCurrentThread("Symbol Worker"); @@ -178,6 +170,15 @@ void SymbolGuardian::ImportElf(std::vector elf, std::string elf_file_name, s }); } +void SymbolGuardian::ShutdownWorkerThread() +{ + m_interrupt_import_thread = true; + if (m_import_thread.joinable()) + m_import_thread.join(); + m_interrupt_import_thread = false; +} + + ccc::ModuleHandle SymbolGuardian::ImportSymbolTables( ccc::SymbolDatabase& database, const ccc::SymbolFile& symbol_file, const std::atomic_bool* interrupt) { diff --git a/pcsx2/DebugTools/SymbolGuardian.h b/pcsx2/DebugTools/SymbolGuardian.h index e37ed70c62823..b84c51395eb19 100644 --- a/pcsx2/DebugTools/SymbolGuardian.h +++ b/pcsx2/DebugTools/SymbolGuardian.h @@ -52,16 +52,16 @@ struct SymbolGuardian // Take an exclusive lock on the symbol database and run the callback. void ReadWrite(ReadWriteCallback callback) noexcept; - // Interrupt the import thread, delete all symbols, create built-ins. Call - // on the CPU thread. + // Delete all stored symbols and create some default built-ins. Should be + // called from the CPU thread. void Reset(); // Import symbols from the ELF file, nocash symbols, and scan for functions. - // Call on the CPU thread. + // Should be called from the CPU thread. void ImportElf(std::vector elf, std::string elf_file_name, std::string nocash_path); - void SetElfTextRange(u32 begin, u32 size); - void SetNocashPath(std::string nocash_path); + // Interrupt the import thread. Should be called from the CPU thread. + void ShutdownWorkerThread(); static ccc::ModuleHandle ImportSymbolTables( ccc::SymbolDatabase& database, const ccc::SymbolFile& symbol_file, const std::atomic_bool* interrupt); diff --git a/pcsx2/VMManager.cpp b/pcsx2/VMManager.cpp index 7b4cde4a509f1..d1d20b9a57aa8 100644 --- a/pcsx2/VMManager.cpp +++ b/pcsx2/VMManager.cpp @@ -437,6 +437,9 @@ void VMManager::Internal::CPUThreadShutdown() // Ensure emulog gets flushed. Log::SetFileOutputLevel(LOGLEVEL_NONE, std::string()); + + R3000SymbolGuardian.ShutdownWorkerThread(); + R5900SymbolGuardian.ShutdownWorkerThread(); } void VMManager::Internal::SetFileLogPath(std::string path)