From 2d1f661118cda9b90318aef943afed086dbfc794 Mon Sep 17 00:00:00 2001 From: "Admiral H. Curtiss" Date: Tue, 28 Mar 2023 23:52:36 +0200 Subject: [PATCH] DolphinQt: Avoid ppcState global. --- .../DolphinQt/Debugger/CodeViewWidget.cpp | 56 +++---- .../Core/DolphinQt/Debugger/CodeViewWidget.h | 5 +- Source/Core/DolphinQt/Debugger/CodeWidget.cpp | 60 ++++---- Source/Core/DolphinQt/Debugger/CodeWidget.h | 6 + .../DolphinQt/Debugger/RegisterWidget.cpp | 137 +++++++++--------- .../Core/DolphinQt/Debugger/RegisterWidget.h | 6 + 6 files changed, 143 insertions(+), 127 deletions(-) diff --git a/Source/Core/DolphinQt/Debugger/CodeViewWidget.cpp b/Source/Core/DolphinQt/Debugger/CodeViewWidget.cpp index f954f57ccc..8e8b535b7f 100644 --- a/Source/Core/DolphinQt/Debugger/CodeViewWidget.cpp +++ b/Source/Core/DolphinQt/Debugger/CodeViewWidget.cpp @@ -135,7 +135,7 @@ constexpr int CODE_VIEW_COLUMN_DESCRIPTION = 4; constexpr int CODE_VIEW_COLUMN_BRANCH_ARROWS = 5; constexpr int CODE_VIEW_COLUMNCOUNT = 6; -CodeViewWidget::CodeViewWidget() +CodeViewWidget::CodeViewWidget() : m_system(Core::System::GetInstance()) { setColumnCount(CODE_VIEW_COLUMNCOUNT); setShowGrid(false); @@ -168,11 +168,11 @@ CodeViewWidget::CodeViewWidget() &CodeViewWidget::FontBasedSizing); connect(&Settings::Instance(), &Settings::EmulationStateChanged, this, [this] { - m_address = PowerPC::ppcState.pc; + m_address = m_system.GetPPCState().pc; Update(); }); connect(Host::GetInstance(), &Host::UpdateDisasmDialog, this, [this] { - m_address = PowerPC::ppcState.pc; + m_address = m_system.GetPPCState().pc; Update(); }); @@ -259,7 +259,7 @@ void CodeViewWidget::Update() if (Core::GetState() == Core::State::Paused) { - Core::CPUThreadGuard guard(Core::System::GetInstance()); + Core::CPUThreadGuard guard(m_system); Update(&guard); } else @@ -294,7 +294,8 @@ void CodeViewWidget::Update(const Core::CPUThreadGuard* guard) for (int i = 0; i < rows; i++) setRowHeight(i, rowh); - const std::optional pc = guard ? std::make_optional(PowerPC::ppcState.pc) : std::nullopt; + const std::optional pc = + guard ? std::make_optional(m_system.GetPPCState().pc) : std::nullopt; const bool dark_theme = qApp->palette().color(QPalette::Base).valueF() < 0.5; @@ -533,7 +534,7 @@ void CodeViewWidget::SetAddress(u32 address, SetAddressUpdate update) void CodeViewWidget::ReplaceAddress(u32 address, ReplaceWith replace) { - Core::CPUThreadGuard guard(Core::System::GetInstance()); + Core::CPUThreadGuard guard(m_system); PowerPC::debug_interface.SetPatch(guard, address, replace == ReplaceWith::BLR ? 0x4e800020 : 0x60000000); @@ -595,10 +596,11 @@ void CodeViewWidget::OnContextMenu() bool follow_branch_enabled = false; if (paused) { - Core::CPUThreadGuard guard(Core::System::GetInstance()); - const std::string disasm = PowerPC::debug_interface.Disassemble(&guard, PowerPC::ppcState.pc); + Core::CPUThreadGuard guard(m_system); + const u32 pc = m_system.GetPPCState().pc; + const std::string disasm = PowerPC::debug_interface.Disassemble(&guard, pc); - if (addr == PowerPC::ppcState.pc) + if (addr == pc) { const auto target_it = std::find(disasm.begin(), disasm.end(), '\t'); const auto target_end = std::find(target_it, disasm.end(), ','); @@ -651,7 +653,7 @@ void CodeViewWidget::AutoStep(CodeTrace::AutoStop option) // Autosteps and follows value in the target (left-most) register. The Used and Changed options // silently follows target through reshuffles in memory and registers and stops on use or update. - Core::CPUThreadGuard guard(Core::System::GetInstance()); + Core::CPUThreadGuard guard(m_system); CodeTrace code_trace; bool repeat = false; @@ -741,8 +743,8 @@ void CodeViewWidget::OnCopyTargetAddress() const u32 addr = GetContextAddress(); - const std::string code_line = [addr] { - Core::CPUThreadGuard guard(Core::System::GetInstance()); + const std::string code_line = [this, addr] { + Core::CPUThreadGuard guard(m_system); return PowerPC::debug_interface.Disassemble(&guard, addr); }(); @@ -771,8 +773,8 @@ void CodeViewWidget::OnShowTargetInMemory() const u32 addr = GetContextAddress(); - const std::string code_line = [addr] { - Core::CPUThreadGuard guard(Core::System::GetInstance()); + const std::string code_line = [this, addr] { + Core::CPUThreadGuard guard(m_system); return PowerPC::debug_interface.Disassemble(&guard, addr); }(); @@ -790,8 +792,8 @@ void CodeViewWidget::OnCopyCode() { const u32 addr = GetContextAddress(); - const std::string text = [addr] { - Core::CPUThreadGuard guard(Core::System::GetInstance()); + const std::string text = [this, addr] { + Core::CPUThreadGuard guard(m_system); return PowerPC::debug_interface.Disassemble(&guard, addr); }(); @@ -809,7 +811,7 @@ void CodeViewWidget::OnCopyFunction() std::string text = symbol->name + "\r\n"; { - Core::CPUThreadGuard guard(Core::System::GetInstance()); + Core::CPUThreadGuard guard(m_system); // we got a function const u32 start = symbol->address; @@ -828,8 +830,8 @@ void CodeViewWidget::OnCopyHex() { const u32 addr = GetContextAddress(); - const u32 instruction = [addr] { - Core::CPUThreadGuard guard(Core::System::GetInstance()); + const u32 instruction = [this, addr] { + Core::CPUThreadGuard guard(m_system); return PowerPC::debug_interface.ReadInstruction(guard, addr); }(); @@ -857,7 +859,7 @@ void CodeViewWidget::OnAddFunction() { const u32 addr = GetContextAddress(); - Core::CPUThreadGuard guard(Core::System::GetInstance()); + Core::CPUThreadGuard guard(m_system); g_symbolDB.AddFunction(guard, addr); emit SymbolsChanged(); @@ -882,8 +884,8 @@ void CodeViewWidget::OnFollowBranch() { const u32 addr = GetContextAddress(); - const u32 branch_addr = [addr] { - Core::CPUThreadGuard guard(Core::System::GetInstance()); + const u32 branch_addr = [this, addr] { + Core::CPUThreadGuard guard(m_system); return GetBranchFromAddress(guard, addr); }(); @@ -917,7 +919,7 @@ void CodeViewWidget::OnRenameSymbol() void CodeViewWidget::OnSelectionChanged() { - if (m_address == PowerPC::ppcState.pc) + if (m_address == m_system.GetPPCState().pc) { setStyleSheet( QStringLiteral("QTableView::item:selected {background-color: #00FF00; color: #000000;}")); @@ -946,7 +948,7 @@ void CodeViewWidget::OnSetSymbolSize() if (!good) return; - Core::CPUThreadGuard guard(Core::System::GetInstance()); + Core::CPUThreadGuard guard(m_system); PPCAnalyst::ReanalyzeFunction(guard, symbol->address, *symbol, size); emit SymbolsChanged(); @@ -974,7 +976,7 @@ void CodeViewWidget::OnSetSymbolEndAddress() if (!good) return; - Core::CPUThreadGuard guard(Core::System::GetInstance()); + Core::CPUThreadGuard guard(m_system); PPCAnalyst::ReanalyzeFunction(guard, symbol->address, *symbol, address - symbol->address); emit SymbolsChanged(); @@ -983,7 +985,7 @@ void CodeViewWidget::OnSetSymbolEndAddress() void CodeViewWidget::OnReplaceInstruction() { - Core::CPUThreadGuard guard(Core::System::GetInstance()); + Core::CPUThreadGuard guard(m_system); const u32 addr = GetContextAddress(); @@ -1006,7 +1008,7 @@ void CodeViewWidget::OnReplaceInstruction() void CodeViewWidget::OnRestoreInstruction() { - Core::CPUThreadGuard guard(Core::System::GetInstance()); + Core::CPUThreadGuard guard(m_system); const u32 addr = GetContextAddress(); diff --git a/Source/Core/DolphinQt/Debugger/CodeViewWidget.h b/Source/Core/DolphinQt/Debugger/CodeViewWidget.h index bf06b1e91d..2812d84a92 100644 --- a/Source/Core/DolphinQt/Debugger/CodeViewWidget.h +++ b/Source/Core/DolphinQt/Debugger/CodeViewWidget.h @@ -18,7 +18,8 @@ class QShowEvent; namespace Core { class CPUThreadGuard; -}; +class System; +} // namespace Core struct CodeViewBranch; class BranchDisplayDelegate; @@ -98,6 +99,8 @@ private: void CalculateBranchIndentation(); + Core::System& m_system; + bool m_updating = false; u32 m_address = 0; diff --git a/Source/Core/DolphinQt/Debugger/CodeWidget.cpp b/Source/Core/DolphinQt/Debugger/CodeWidget.cpp index 29d72faf18..02286fa8b1 100644 --- a/Source/Core/DolphinQt/Debugger/CodeWidget.cpp +++ b/Source/Core/DolphinQt/Debugger/CodeWidget.cpp @@ -28,7 +28,7 @@ #include "DolphinQt/Host.h" #include "DolphinQt/Settings.h" -CodeWidget::CodeWidget(QWidget* parent) : QDockWidget(parent) +CodeWidget::CodeWidget(QWidget* parent) : QDockWidget(parent), m_system(Core::System::GetInstance()) { setWindowTitle(tr("Code")); setObjectName(QStringLiteral("code")); @@ -51,7 +51,7 @@ CodeWidget::CodeWidget(QWidget* parent) : QDockWidget(parent) connect(Host::GetInstance(), &Host::UpdateDisasmDialog, this, [this] { if (Core::GetState() == Core::State::Paused) - SetAddress(PowerPC::ppcState.pc, CodeViewWidget::SetAddressUpdate::WithoutUpdate); + SetAddress(m_system.GetPPCState().pc, CodeViewWidget::SetAddressUpdate::WithoutUpdate); Update(); }); @@ -329,9 +329,9 @@ void CodeWidget::UpdateCallstack() std::vector stack; - const bool success = [&stack] { - Core::CPUThreadGuard guard(Core::System::GetInstance()); - return Dolphin_Debugger::GetCallstack(Core::System::GetInstance(), guard, stack); + const bool success = [this, &stack] { + Core::CPUThreadGuard guard(m_system); + return Dolphin_Debugger::GetCallstack(m_system, guard, stack); }(); if (!success) @@ -435,8 +435,7 @@ void CodeWidget::UpdateFunctionCallers(const Common::Symbol* symbol) void CodeWidget::Step() { - auto& system = Core::System::GetInstance(); - auto& cpu = system.GetCPU(); + auto& cpu = m_system.GetCPU(); if (!cpu.IsStepping()) return; @@ -455,21 +454,20 @@ void CodeWidget::Step() void CodeWidget::StepOver() { - auto& system = Core::System::GetInstance(); - auto& cpu = system.GetCPU(); + auto& cpu = m_system.GetCPU(); if (!cpu.IsStepping()) return; const UGeckoInstruction inst = [&] { - Core::CPUThreadGuard guard(system); - return PowerPC::MMU::HostRead_Instruction(guard, PowerPC::ppcState.pc); + Core::CPUThreadGuard guard(m_system); + return PowerPC::MMU::HostRead_Instruction(guard, m_system.GetPPCState().pc); }(); if (inst.LK) { PowerPC::breakpoints.ClearAllTemporary(); - PowerPC::breakpoints.Add(PowerPC::ppcState.pc + 4, true); + PowerPC::breakpoints.Add(m_system.GetPPCState().pc + 4, true); cpu.EnableStepping(false); Core::DisplayMessage(tr("Step over in progress...").toStdString(), 2000); } @@ -480,23 +478,21 @@ void CodeWidget::StepOver() } // Returns true on a rfi, blr or on a bclr that evaluates to true. -static bool WillInstructionReturn(UGeckoInstruction inst) +static bool WillInstructionReturn(Core::System& system, UGeckoInstruction inst) { // Is a rfi instruction if (inst.hex == 0x4C000064u) return true; - bool counter = - (inst.BO_2 >> 2 & 1) != 0 || (CTR(PowerPC::ppcState) != 0) != ((inst.BO_2 >> 1 & 1) != 0); - bool condition = - inst.BO_2 >> 4 != 0 || PowerPC::ppcState.cr.GetBit(inst.BI_2) == (inst.BO_2 >> 3 & 1); + const auto& ppc_state = system.GetPPCState(); + bool counter = (inst.BO_2 >> 2 & 1) != 0 || (CTR(ppc_state) != 0) != ((inst.BO_2 >> 1 & 1) != 0); + bool condition = inst.BO_2 >> 4 != 0 || ppc_state.cr.GetBit(inst.BI_2) == (inst.BO_2 >> 3 & 1); bool isBclr = inst.OPCD_7 == 0b010011 && (inst.hex >> 1 & 0b10000) != 0; return isBclr && counter && condition && !inst.LK_3; } void CodeWidget::StepOut() { - auto& system = Core::System::GetInstance(); - auto& cpu = system.GetCPU(); + auto& cpu = m_system.GetCPU(); if (!cpu.IsStepping()) return; @@ -505,8 +501,9 @@ void CodeWidget::StepOut() using clock = std::chrono::steady_clock; clock::time_point timeout = clock::now() + std::chrono::seconds(5); + auto& ppc_state = m_system.GetPPCState(); { - Core::CPUThreadGuard guard(system); + Core::CPUThreadGuard guard(m_system); PowerPC::breakpoints.ClearAllTemporary(); @@ -516,10 +513,10 @@ void CodeWidget::StepOut() // Loop until either the current instruction is a return instruction with no Link flag // or a breakpoint is detected so it can step at the breakpoint. If the PC is currently // on a breakpoint, skip it. - UGeckoInstruction inst = PowerPC::MMU::HostRead_Instruction(guard, PowerPC::ppcState.pc); + UGeckoInstruction inst = PowerPC::MMU::HostRead_Instruction(guard, ppc_state.pc); do { - if (WillInstructionReturn(inst)) + if (WillInstructionReturn(m_system, inst)) { PowerPC::SingleStep(); break; @@ -528,28 +525,27 @@ void CodeWidget::StepOut() if (inst.LK) { // Step over branches - u32 next_pc = PowerPC::ppcState.pc + 4; + u32 next_pc = ppc_state.pc + 4; do { PowerPC::SingleStep(); - } while (PowerPC::ppcState.pc != next_pc && clock::now() < timeout && - !PowerPC::breakpoints.IsAddressBreakPoint(PowerPC::ppcState.pc)); + } while (ppc_state.pc != next_pc && clock::now() < timeout && + !PowerPC::breakpoints.IsAddressBreakPoint(ppc_state.pc)); } else { PowerPC::SingleStep(); } - inst = PowerPC::MMU::HostRead_Instruction(guard, PowerPC::ppcState.pc); - } while (clock::now() < timeout && - !PowerPC::breakpoints.IsAddressBreakPoint(PowerPC::ppcState.pc)); + inst = PowerPC::MMU::HostRead_Instruction(guard, ppc_state.pc); + } while (clock::now() < timeout && !PowerPC::breakpoints.IsAddressBreakPoint(ppc_state.pc)); PowerPC::SetMode(old_mode); } emit Host::GetInstance()->UpdateDisasmDialog(); - if (PowerPC::breakpoints.IsAddressBreakPoint(PowerPC::ppcState.pc)) + if (PowerPC::breakpoints.IsAddressBreakPoint(ppc_state.pc)) Core::DisplayMessage(tr("Breakpoint encountered! Step out aborted.").toStdString(), 2000); else if (clock::now() >= timeout) Core::DisplayMessage(tr("Step out timed out!").toStdString(), 2000); @@ -559,19 +555,19 @@ void CodeWidget::StepOut() void CodeWidget::Skip() { - PowerPC::ppcState.pc += 4; + m_system.GetPPCState().pc += 4; ShowPC(); } void CodeWidget::ShowPC() { - m_code_view->SetAddress(PowerPC::ppcState.pc, CodeViewWidget::SetAddressUpdate::WithUpdate); + m_code_view->SetAddress(m_system.GetPPCState().pc, CodeViewWidget::SetAddressUpdate::WithUpdate); Update(); } void CodeWidget::SetPC() { - PowerPC::ppcState.pc = m_code_view->GetAddress(); + m_system.GetPPCState().pc = m_code_view->GetAddress(); Update(); } diff --git a/Source/Core/DolphinQt/Debugger/CodeWidget.h b/Source/Core/DolphinQt/Debugger/CodeWidget.h index f198e004cc..1e933a8c70 100644 --- a/Source/Core/DolphinQt/Debugger/CodeWidget.h +++ b/Source/Core/DolphinQt/Debugger/CodeWidget.h @@ -22,6 +22,10 @@ namespace Common { struct Symbol; } +namespace Core +{ +class System; +} class CodeWidget : public QDockWidget { @@ -66,6 +70,8 @@ private: void closeEvent(QCloseEvent*) override; void showEvent(QShowEvent* event) override; + Core::System& m_system; + CodeDiffDialog* m_diff_dialog = nullptr; QLineEdit* m_search_address; QPushButton* m_code_diff; diff --git a/Source/Core/DolphinQt/Debugger/RegisterWidget.cpp b/Source/Core/DolphinQt/Debugger/RegisterWidget.cpp index 9d7079e04a..f11df86444 100644 --- a/Source/Core/DolphinQt/Debugger/RegisterWidget.cpp +++ b/Source/Core/DolphinQt/Debugger/RegisterWidget.cpp @@ -20,7 +20,8 @@ #include "DolphinQt/Host.h" #include "DolphinQt/Settings.h" -RegisterWidget::RegisterWidget(QWidget* parent) : QDockWidget(parent) +RegisterWidget::RegisterWidget(QWidget* parent) + : QDockWidget(parent), m_system(Core::System::GetInstance()) { setWindowTitle(tr("Registers")); setObjectName(QStringLiteral("registers")); @@ -295,8 +296,8 @@ void RegisterWidget::AutoStep(const std::string& reg) const while (true) { - const AutoStepResults results = [&trace] { - Core::CPUThreadGuard guard(Core::System::GetInstance()); + const AutoStepResults results = [this, &trace] { + Core::CPUThreadGuard guard(m_system); return trace.AutoStepping(guard, true); }(); @@ -318,18 +319,19 @@ void RegisterWidget::PopulateTable() { // General purpose registers (int) AddRegister( - i, 0, RegisterType::gpr, "r" + std::to_string(i), [i] { return PowerPC::ppcState.gpr[i]; }, - [i](u64 value) { PowerPC::ppcState.gpr[i] = value; }); + i, 0, RegisterType::gpr, "r" + std::to_string(i), + [this, i] { return m_system.GetPPCState().gpr[i]; }, + [this, i](u64 value) { m_system.GetPPCState().gpr[i] = value; }); // Floating point registers (double) AddRegister( i, 2, RegisterType::fpr, "f" + std::to_string(i), - [i] { return PowerPC::ppcState.ps[i].PS0AsU64(); }, - [i](u64 value) { PowerPC::ppcState.ps[i].SetPS0(value); }); + [this, i] { return m_system.GetPPCState().ps[i].PS0AsU64(); }, + [this, i](u64 value) { m_system.GetPPCState().ps[i].SetPS0(value); }); AddRegister( - i, 4, RegisterType::fpr, "", [i] { return PowerPC::ppcState.ps[i].PS1AsU64(); }, - [i](u64 value) { PowerPC::ppcState.ps[i].SetPS1(value); }); + i, 4, RegisterType::fpr, "", [this, i] { return m_system.GetPPCState().ps[i].PS1AsU64(); }, + [this, i](u64 value) { m_system.GetPPCState().ps[i].SetPS1(value); }); } // The IBAT and DBAT registers have a large gap between @@ -340,32 +342,36 @@ void RegisterWidget::PopulateTable() // IBAT registers AddRegister( i, 5, RegisterType::ibat, "IBAT" + std::to_string(i), - [i] { - return (static_cast(PowerPC::ppcState.spr[SPR_IBAT0U + i * 2]) << 32) + - PowerPC::ppcState.spr[SPR_IBAT0L + i * 2]; + [this, i] { + const auto& ppc_state = m_system.GetPPCState(); + return (static_cast(ppc_state.spr[SPR_IBAT0U + i * 2]) << 32) + + ppc_state.spr[SPR_IBAT0L + i * 2]; }, nullptr); AddRegister( i + 4, 5, RegisterType::ibat, "IBAT" + std::to_string(4 + i), - [i] { - return (static_cast(PowerPC::ppcState.spr[SPR_IBAT4U + i * 2]) << 32) + - PowerPC::ppcState.spr[SPR_IBAT4L + i * 2]; + [this, i] { + const auto& ppc_state = m_system.GetPPCState(); + return (static_cast(ppc_state.spr[SPR_IBAT4U + i * 2]) << 32) + + ppc_state.spr[SPR_IBAT4L + i * 2]; }, nullptr); // DBAT registers AddRegister( i + 8, 5, RegisterType::dbat, "DBAT" + std::to_string(i), - [i] { - return (static_cast(PowerPC::ppcState.spr[SPR_DBAT0U + i * 2]) << 32) + - PowerPC::ppcState.spr[SPR_DBAT0L + i * 2]; + [this, i] { + const auto& ppc_state = m_system.GetPPCState(); + return (static_cast(ppc_state.spr[SPR_DBAT0U + i * 2]) << 32) + + ppc_state.spr[SPR_DBAT0L + i * 2]; }, nullptr); AddRegister( i + 12, 5, RegisterType::dbat, "DBAT" + std::to_string(4 + i), - [i] { - return (static_cast(PowerPC::ppcState.spr[SPR_DBAT4U + i * 2]) << 32) + - PowerPC::ppcState.spr[SPR_DBAT4L + i * 2]; + [this, i] { + const auto& ppc_state = m_system.GetPPCState(); + return (static_cast(ppc_state.spr[SPR_DBAT4U + i * 2]) << 32) + + ppc_state.spr[SPR_DBAT4L + i * 2]; }, nullptr); } @@ -375,29 +381,30 @@ void RegisterWidget::PopulateTable() // Graphics quantization registers AddRegister( i + 16, 7, RegisterType::gqr, "GQR" + std::to_string(i), - [i] { return PowerPC::ppcState.spr[SPR_GQR0 + i]; }, nullptr); + [this, i] { return m_system.GetPPCState().spr[SPR_GQR0 + i]; }, nullptr); } // HID registers AddRegister( - 24, 7, RegisterType::hid, "HID0", [] { return PowerPC::ppcState.spr[SPR_HID0]; }, - [](u64 value) { PowerPC::ppcState.spr[SPR_HID0] = static_cast(value); }); + 24, 7, RegisterType::hid, "HID0", [this] { return m_system.GetPPCState().spr[SPR_HID0]; }, + [this](u64 value) { m_system.GetPPCState().spr[SPR_HID0] = static_cast(value); }); AddRegister( - 25, 7, RegisterType::hid, "HID1", [] { return PowerPC::ppcState.spr[SPR_HID1]; }, - [](u64 value) { PowerPC::ppcState.spr[SPR_HID1] = static_cast(value); }); + 25, 7, RegisterType::hid, "HID1", [this] { return m_system.GetPPCState().spr[SPR_HID1]; }, + [this](u64 value) { m_system.GetPPCState().spr[SPR_HID1] = static_cast(value); }); AddRegister( - 26, 7, RegisterType::hid, "HID2", [] { return PowerPC::ppcState.spr[SPR_HID2]; }, - [](u64 value) { PowerPC::ppcState.spr[SPR_HID2] = static_cast(value); }); + 26, 7, RegisterType::hid, "HID2", [this] { return m_system.GetPPCState().spr[SPR_HID2]; }, + [this](u64 value) { m_system.GetPPCState().spr[SPR_HID2] = static_cast(value); }); AddRegister( - 27, 7, RegisterType::hid, "HID4", [] { return PowerPC::ppcState.spr[SPR_HID4]; }, - [](u64 value) { PowerPC::ppcState.spr[SPR_HID4] = static_cast(value); }); + 27, 7, RegisterType::hid, "HID4", [this] { return m_system.GetPPCState().spr[SPR_HID4]; }, + [this](u64 value) { m_system.GetPPCState().spr[SPR_HID4] = static_cast(value); }); for (int i = 0; i < 16; i++) { // SR registers AddRegister( - i, 7, RegisterType::sr, "SR" + std::to_string(i), [i] { return PowerPC::ppcState.sr[i]; }, - [i](u64 value) { PowerPC::ppcState.sr[i] = value; }); + i, 7, RegisterType::sr, "SR" + std::to_string(i), + [this, i] { return m_system.GetPPCState().sr[i]; }, + [this, i](u64 value) { m_system.GetPPCState().sr[i] = value; }); } // Special registers @@ -406,83 +413,79 @@ void RegisterWidget::PopulateTable() // PC AddRegister( - 17, 5, RegisterType::pc, "PC", [] { return PowerPC::ppcState.pc; }, - [](u64 value) { PowerPC::ppcState.pc = value; }); + 17, 5, RegisterType::pc, "PC", [this] { return m_system.GetPPCState().pc; }, + [this](u64 value) { m_system.GetPPCState().pc = value; }); // LR AddRegister( - 18, 5, RegisterType::lr, "LR", [] { return PowerPC::ppcState.spr[SPR_LR]; }, - [](u64 value) { PowerPC::ppcState.spr[SPR_LR] = value; }); + 18, 5, RegisterType::lr, "LR", [this] { return m_system.GetPPCState().spr[SPR_LR]; }, + [this](u64 value) { m_system.GetPPCState().spr[SPR_LR] = value; }); // CTR AddRegister( - 19, 5, RegisterType::ctr, "CTR", [] { return PowerPC::ppcState.spr[SPR_CTR]; }, - [](u64 value) { PowerPC::ppcState.spr[SPR_CTR] = value; }); + 19, 5, RegisterType::ctr, "CTR", [this] { return m_system.GetPPCState().spr[SPR_CTR]; }, + [this](u64 value) { m_system.GetPPCState().spr[SPR_CTR] = value; }); // CR AddRegister( - 20, 5, RegisterType::cr, "CR", [] { return PowerPC::ppcState.cr.Get(); }, - [](u64 value) { PowerPC::ppcState.cr.Set(value); }); + 20, 5, RegisterType::cr, "CR", [this] { return m_system.GetPPCState().cr.Get(); }, + [this](u64 value) { m_system.GetPPCState().cr.Set(value); }); // XER AddRegister( - 21, 5, RegisterType::xer, "XER", [] { return PowerPC::ppcState.GetXER().Hex; }, - [](u64 value) { PowerPC::ppcState.SetXER(UReg_XER(value)); }); + 21, 5, RegisterType::xer, "XER", [this] { return m_system.GetPPCState().GetXER().Hex; }, + [this](u64 value) { m_system.GetPPCState().SetXER(UReg_XER(value)); }); // FPSCR AddRegister( - 22, 5, RegisterType::fpscr, "FPSCR", [] { return PowerPC::ppcState.fpscr.Hex; }, - [](u64 value) { PowerPC::ppcState.fpscr = static_cast(value); }); + 22, 5, RegisterType::fpscr, "FPSCR", [this] { return m_system.GetPPCState().fpscr.Hex; }, + [this](u64 value) { m_system.GetPPCState().fpscr = static_cast(value); }); // MSR AddRegister( - 23, 5, RegisterType::msr, "MSR", [] { return PowerPC::ppcState.msr.Hex; }, - [](u64 value) { PowerPC::ppcState.msr.Hex = value; }); + 23, 5, RegisterType::msr, "MSR", [this] { return m_system.GetPPCState().msr.Hex; }, + [this](u64 value) { m_system.GetPPCState().msr.Hex = value; }); // SRR 0-1 AddRegister( - 24, 5, RegisterType::srr, "SRR0", [] { return PowerPC::ppcState.spr[SPR_SRR0]; }, - [](u64 value) { PowerPC::ppcState.spr[SPR_SRR0] = value; }); + 24, 5, RegisterType::srr, "SRR0", [this] { return m_system.GetPPCState().spr[SPR_SRR0]; }, + [this](u64 value) { m_system.GetPPCState().spr[SPR_SRR0] = value; }); AddRegister( - 25, 5, RegisterType::srr, "SRR1", [] { return PowerPC::ppcState.spr[SPR_SRR1]; }, - [](u64 value) { PowerPC::ppcState.spr[SPR_SRR1] = value; }); + 25, 5, RegisterType::srr, "SRR1", [this] { return m_system.GetPPCState().spr[SPR_SRR1]; }, + [this](u64 value) { m_system.GetPPCState().spr[SPR_SRR1] = value; }); // Exceptions AddRegister( - 26, 5, RegisterType::exceptions, "Exceptions", [] { return PowerPC::ppcState.Exceptions; }, - [](u64 value) { PowerPC::ppcState.Exceptions = value; }); + 26, 5, RegisterType::exceptions, "Exceptions", + [this] { return m_system.GetPPCState().Exceptions; }, + [this](u64 value) { m_system.GetPPCState().Exceptions = value; }); // Int Mask AddRegister( 27, 5, RegisterType::int_mask, "Int Mask", - [] { - auto& system = Core::System::GetInstance(); - return system.GetProcessorInterface().GetMask(); - }, - nullptr); + [this] { return m_system.GetProcessorInterface().GetMask(); }, nullptr); // Int Cause AddRegister( 28, 5, RegisterType::int_cause, "Int Cause", - [] { - auto& system = Core::System::GetInstance(); - return system.GetProcessorInterface().GetCause(); - }, - nullptr); + [this] { return m_system.GetProcessorInterface().GetCause(); }, nullptr); // DSISR AddRegister( - 29, 5, RegisterType::dsisr, "DSISR", [] { return PowerPC::ppcState.spr[SPR_DSISR]; }, - [](u64 value) { PowerPC::ppcState.spr[SPR_DSISR] = value; }); + 29, 5, RegisterType::dsisr, "DSISR", [this] { return m_system.GetPPCState().spr[SPR_DSISR]; }, + [this](u64 value) { m_system.GetPPCState().spr[SPR_DSISR] = value; }); // DAR AddRegister( - 30, 5, RegisterType::dar, "DAR", [] { return PowerPC::ppcState.spr[SPR_DAR]; }, - [](u64 value) { PowerPC::ppcState.spr[SPR_DAR] = value; }); + 30, 5, RegisterType::dar, "DAR", [this] { return m_system.GetPPCState().spr[SPR_DAR]; }, + [this](u64 value) { m_system.GetPPCState().spr[SPR_DAR] = value; }); // Hash Mask AddRegister( 31, 5, RegisterType::pt_hashmask, "Hash Mask", - [] { return (PowerPC::ppcState.pagetable_hashmask << 6) | PowerPC::ppcState.pagetable_base; }, + [this] { + const auto& ppc_state = m_system.GetPPCState(); + return (ppc_state.pagetable_hashmask << 6) | ppc_state.pagetable_base; + }, nullptr); emit RequestTableUpdate(); diff --git a/Source/Core/DolphinQt/Debugger/RegisterWidget.h b/Source/Core/DolphinQt/Debugger/RegisterWidget.h index f57a3b04d9..13432692a6 100644 --- a/Source/Core/DolphinQt/Debugger/RegisterWidget.h +++ b/Source/Core/DolphinQt/Debugger/RegisterWidget.h @@ -13,6 +13,10 @@ class QTableWidget; class QCloseEvent; class QShowEvent; +namespace Core +{ +class System; +} class RegisterWidget : public QDockWidget { @@ -49,6 +53,8 @@ private: void AutoStep(const std::string& reg) const; void Update(); + Core::System& m_system; + QTableWidget* m_table; bool m_updating = false; };