diff --git a/pcsx2-qt/Debugger/StackModel.cpp b/pcsx2-qt/Debugger/StackModel.cpp index 4ebcf60d9d..08418ce728 100644 --- a/pcsx2-qt/Debugger/StackModel.cpp +++ b/pcsx2-qt/Debugger/StackModel.cpp @@ -107,14 +107,21 @@ void StackModel::refreshData() // Hopefully in the near future we can get a stack frame for // each thread beginResetModel(); - for (const auto& thread : m_cpu.GetThreadList()) + + std::unique_ptr found_thread = nullptr; + + for (auto& thread : m_cpu.GetThreadList()) { if (thread->Status() == ThreadStatus::THS_RUN) { - m_stackFrames = m_cpu.StackTrace(*thread); + found_thread = std::move(thread); break; } } + + // Will do best effort with current context if found_thread is nullptr. + m_stackFrames = m_cpu.StackTrace(found_thread.get()); + endResetModel(); } diff --git a/pcsx2/DebugTools/DebugInterface.cpp b/pcsx2/DebugTools/DebugInterface.cpp index 50bb09c051..033102de86 100644 --- a/pcsx2/DebugTools/DebugInterface.cpp +++ b/pcsx2/DebugTools/DebugInterface.cpp @@ -677,21 +677,26 @@ std::vector> R5900DebugInterface::GetThreadList() co return getEEThreads(); } -std::vector R5900DebugInterface::StackTrace(const BiosThread& thread) +std::vector R5900DebugInterface::StackTrace(const BiosThread* thread) { - if (thread.Status() == ThreadStatus::THS_RUN) + if (!thread) { - return MipsStackWalk::Walk(this, getPC(), getRegister(0, 31), getRegister(0, 29), - thread.EntryPoint()); + return MipsStackWalk::Walk(this, getPC(), getRegister(0, 31), getRegister(0, 29), 0); } - EEInternalCtx* ctx = static_cast(PSM(thread.RegCtx())); - u32 pc = thread.PC(); + if (thread->Status() == ThreadStatus::THS_RUN) + { + return MipsStackWalk::Walk(this, getPC(), getRegister(0, 31), getRegister(0, 29), + thread->EntryPoint()); + } + + EEInternalCtx* ctx = static_cast(PSM(thread->RegCtx())); + u32 pc = thread->PC(); // $zero is not in the array so subtract 1 u32 ra = ctx->gpr[31 - 1]._u32[0]; u32 sp = ctx->gpr[29 - 1]._u32[0]; - return MipsStackWalk::Walk(this, pc, ra, sp, thread.EntryPoint()); + return MipsStackWalk::Walk(this, pc, ra, sp, thread->EntryPoint()); } std::vector R5900DebugInterface::GetModuleList() const @@ -1035,20 +1040,25 @@ std::vector> R3000DebugInterface::GetThreadList() co return getIOPThreads(); } -std::vector R3000DebugInterface::StackTrace(const BiosThread& thread) +std::vector R3000DebugInterface::StackTrace(const BiosThread* thread) { - if (thread.Status() == ThreadStatus::THS_RUN) + if (!thread) { - return MipsStackWalk::Walk(this, getPC(), getRegister(0, 31), getRegister(0, 29), - thread.EntryPoint()); + return MipsStackWalk::Walk(this, getPC(), getRegister(0, 31), getRegister(0, 29), 0); } - u32 p = thread.RegCtx(); + if (thread->Status() == ThreadStatus::THS_RUN) + { + return MipsStackWalk::Walk(this, getPC(), getRegister(0, 31), getRegister(0, 29), + thread->EntryPoint()); + } + + u32 p = thread->RegCtx(); u32 pc = Read32(p + 0x8c); u32 ra = Read32(p + 0x7c); u32 sp = Read32(p + 0x74); - return MipsStackWalk::Walk(this, pc, ra, sp, thread.EntryPoint()); + return MipsStackWalk::Walk(this, pc, ra, sp, thread->EntryPoint()); } std::vector R3000DebugInterface::GetModuleList() const diff --git a/pcsx2/DebugTools/DebugInterface.h b/pcsx2/DebugTools/DebugInterface.h index be642e4824..a6dbb0fd90 100644 --- a/pcsx2/DebugTools/DebugInterface.h +++ b/pcsx2/DebugTools/DebugInterface.h @@ -73,7 +73,7 @@ public: virtual SymbolGuardian& GetSymbolGuardian() const = 0; virtual SymbolImporter* GetSymbolImporter() const = 0; virtual std::vector> GetThreadList() const = 0; - virtual std::vector StackTrace(const BiosThread& thread) = 0; + virtual std::vector StackTrace(const BiosThread* thread) = 0; virtual std::vector GetModuleList() const = 0; bool isAlive(); @@ -136,7 +136,7 @@ public: SymbolGuardian& GetSymbolGuardian() const override; SymbolImporter* GetSymbolImporter() const override; std::vector> GetThreadList() const override; - std::vector StackTrace(const BiosThread& thread) override; + std::vector StackTrace(const BiosThread* thread) override; std::vector GetModuleList() const override; std::string disasm(u32 address, bool simplify) override; @@ -182,7 +182,7 @@ public: SymbolGuardian& GetSymbolGuardian() const override; SymbolImporter* GetSymbolImporter() const override; std::vector> GetThreadList() const override; - std::vector StackTrace(const BiosThread& thread) override; + std::vector StackTrace(const BiosThread* thread) override; std::vector GetModuleList() const override; std::string disasm(u32 address, bool simplify) override;