Skip to content

Commit

Permalink
DebugTools: Fix crash on exit in SymbolGuardian::~SymbolGuardian
Browse files Browse the repository at this point in the history
  • Loading branch information
chaoticgd committed Mar 26, 2024
1 parent a9d49d2 commit aa46f37
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
21 changes: 11 additions & 10 deletions pcsx2/DebugTools/SymbolGuardian.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();
Expand Down Expand Up @@ -141,10 +136,7 @@ void SymbolGuardian::ImportElf(std::vector<u8> elf, std::string elf_file_name, s
std::unique_ptr<ccc::ElfSymbolFile> symbol_file =
std::make_unique<ccc::ElfSymbolFile>(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");
Expand Down Expand Up @@ -178,6 +170,15 @@ void SymbolGuardian::ImportElf(std::vector<u8> 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)
{
Expand Down
10 changes: 5 additions & 5 deletions pcsx2/DebugTools/SymbolGuardian.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<u8> 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);
Expand Down
3 changes: 3 additions & 0 deletions pcsx2/VMManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit aa46f37

Please sign in to comment.