diff --git a/rpcs3/Emu/CPU/CPUThread.cpp b/rpcs3/Emu/CPU/CPUThread.cpp index 75182ec548..2bfae8f20b 100644 --- a/rpcs3/Emu/CPU/CPUThread.cpp +++ b/rpcs3/Emu/CPU/CPUThread.cpp @@ -809,6 +809,28 @@ std::string cpu_thread::get_name() const } } +u32 cpu_thread::get_pc() const +{ + const u32* pc = nullptr; + + switch (id_type()) + { + case 1: + { + pc = &static_cast(this)->cia; + break; + } + case 2: + { + pc = &static_cast(this)->pc; + break; + } + default: break; + } + + return pc ? atomic_storage::load(*pc) : UINT32_MAX; +} + std::string cpu_thread::dump_all() const { return {}; diff --git a/rpcs3/Emu/CPU/CPUThread.h b/rpcs3/Emu/CPU/CPUThread.h index 445330145c..cf38b367b1 100644 --- a/rpcs3/Emu/CPU/CPUThread.h +++ b/rpcs3/Emu/CPU/CPUThread.h @@ -84,6 +84,8 @@ public: return id >> 24; } + u32 get_pc() const; + void notify(); private: diff --git a/rpcs3/rpcs3qt/debugger_frame.cpp b/rpcs3/rpcs3qt/debugger_frame.cpp index fbaf68d8c1..a311e0d8ce 100644 --- a/rpcs3/rpcs3qt/debugger_frame.cpp +++ b/rpcs3/rpcs3qt/debugger_frame.cpp @@ -229,7 +229,7 @@ void debugger_frame::keyPressEvent(QKeyEvent* event) return; } - const u32 pc = i >= 0 ? m_debugger_list->m_pc + i * 4 : GetPc(); + const u32 pc = i >= 0 ? m_debugger_list->m_pc + i * 4 : cpu->get_pc(); const auto modifiers = QApplication::keyboardModifiers(); @@ -297,28 +297,6 @@ void debugger_frame::keyPressEvent(QKeyEvent* event) } } -u32 debugger_frame::GetPc() const -{ - const auto cpu = this->cpu.lock(); - - if (!cpu) - { - return 0; - } - - if (cpu->id_type() == 1) - { - return static_cast(cpu.get())->cia; - } - - if (cpu->id_type() == 2) - { - return static_cast(cpu.get())->pc; - } - - return 0; -} - void debugger_frame::UpdateUI() { UpdateUnitList(); @@ -342,7 +320,7 @@ void debugger_frame::UpdateUI() } else { - const auto cia = GetPc(); + const auto cia = cpu->get_pc(); const auto size_context = cpu->id_type() == 1 ? sizeof(ppu_thread) : sizeof(spu_thread); if (m_last_pc != cia || m_last_query_state.size() != size_context || std::memcmp(m_last_query_state.data(), cpu.get(), size_context)) @@ -460,7 +438,7 @@ void debugger_frame::OnSelectUnit() void debugger_frame::DoUpdate() { // Check if we need to disable a step over bp - if (m_last_step_over_breakpoint != umax && GetPc() == m_last_step_over_breakpoint) + if (auto cpu0 = cpu.lock(); cpu0 && m_last_step_over_breakpoint != umax && cpu0->get_pc() == m_last_step_over_breakpoint) { m_breakpoint_handler->RemoveBreakpoint(m_last_step_over_breakpoint); m_last_step_over_breakpoint = -1; @@ -541,7 +519,8 @@ void debugger_frame::ShowGotoAddressDialog() if (cpu) { - unsigned long pc = cpu ? GetPc() : 0x0; + // -1 turns into 0 + u32 pc = ::align(cpu->get_pc(), 4); address_preview_label->setText(QString("Address: 0x%1").arg(pc, 8, 16, QChar('0'))); expression_input->setPlaceholderText(QString("0x%1").arg(pc, 8, 16, QChar('0'))); } @@ -572,7 +551,8 @@ void debugger_frame::ShowGotoAddressDialog() if (diag->exec() == QDialog::Accepted) { - u32 address = cpu ? GetPc() : 0x0; + // -1 turns into 0 + u32 address = ::align(cpu ? cpu->get_pc() : 0, 4); if (expression_input->text().isEmpty()) { @@ -613,7 +593,8 @@ void debugger_frame::ClearCallStack() void debugger_frame::ShowPC() { - m_debugger_list->ShowAddress(GetPc()); + const auto cpu0 = cpu.lock(); + m_debugger_list->ShowAddress(cpu0 ? cpu0->get_pc() : 0); } void debugger_frame::DoStep(bool stepOver) @@ -632,7 +613,7 @@ void debugger_frame::DoStep(bool stepOver) { if (should_step_over) { - u32 current_instruction_pc = GetPc(); + u32 current_instruction_pc = cpu->get_pc(); // Set breakpoint on next instruction u32 next_instruction_pc = current_instruction_pc + 4; diff --git a/rpcs3/rpcs3qt/debugger_frame.h b/rpcs3/rpcs3qt/debugger_frame.h index d42b505ffb..89e508d29c 100644 --- a/rpcs3/rpcs3qt/debugger_frame.h +++ b/rpcs3/rpcs3qt/debugger_frame.h @@ -66,7 +66,6 @@ public: void UpdateUI(); void UpdateUnitList(); - u32 GetPc() const; void DoUpdate(); void WritePanels(); void EnableButtons(bool enable); diff --git a/rpcs3/rpcs3qt/debugger_list.cpp b/rpcs3/rpcs3qt/debugger_list.cpp index 09fb76c170..eb656bf6ef 100644 --- a/rpcs3/rpcs3qt/debugger_list.cpp +++ b/rpcs3/rpcs3qt/debugger_list.cpp @@ -34,28 +34,6 @@ void debugger_list::UpdateCPUData(std::weak_ptr cpu, std::shared_ptr m_disasm = disasm; } -u32 debugger_list::GetPc() const -{ - const auto cpu = this->cpu.lock(); - - if (!cpu) - { - return 0; - } - - if (cpu->id_type() == 1) - { - return static_cast(cpu.get())->cia; - } - - if (cpu->id_type() == 2) - { - return static_cast(cpu.get())->pc; - } - - return 0; -} - u32 debugger_list::GetCenteredAddress(u32 address) const { return address - ((m_item_count / 2) * 4); @@ -110,7 +88,7 @@ void debugger_list::ShowAddress(u32 addr, bool force) for (uint i = 0, count = 4; iis_paused() && pc == GetPc()) + if (cpu->is_paused() && pc == cpu->get_pc()) { item(i)->setForeground(m_text_color_pc); item(i)->setBackground(m_color_pc); diff --git a/rpcs3/rpcs3qt/debugger_list.h b/rpcs3/rpcs3qt/debugger_list.h index d1ad38c3c0..9af9e498fd 100644 --- a/rpcs3/rpcs3qt/debugger_list.h +++ b/rpcs3/rpcs3qt/debugger_list.h @@ -38,7 +38,6 @@ private: /** * It really upsetted me I had to copy this code to make debugger_list/frame not circularly dependent. */ - u32 GetPc() const; u32 GetCenteredAddress(u32 address) const; std::shared_ptr xgui_settings;