Debugger: rewrite GetPc()

This commit is contained in:
Eladash 2020-11-23 17:58:59 +02:00 committed by Ivan
parent af8c661a64
commit 427cf91447
6 changed files with 35 additions and 54 deletions

View File

@ -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<const ppu_thread*>(this)->cia;
break;
}
case 2:
{
pc = &static_cast<const spu_thread*>(this)->pc;
break;
}
default: break;
}
return pc ? atomic_storage<u32>::load(*pc) : UINT32_MAX;
}
std::string cpu_thread::dump_all() const
{
return {};

View File

@ -84,6 +84,8 @@ public:
return id >> 24;
}
u32 get_pc() const;
void notify();
private:

View File

@ -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<ppu_thread*>(cpu.get())->cia;
}
if (cpu->id_type() == 2)
{
return static_cast<spu_thread*>(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<u32>(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<u32>(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;

View File

@ -66,7 +66,6 @@ public:
void UpdateUI();
void UpdateUnitList();
u32 GetPc() const;
void DoUpdate();
void WritePanels();
void EnableButtons(bool enable);

View File

@ -34,28 +34,6 @@ void debugger_list::UpdateCPUData(std::weak_ptr<cpu_thread> 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<ppu_thread*>(cpu.get())->cia;
}
if (cpu->id_type() == 2)
{
return static_cast<spu_thread*>(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; i<m_item_count; ++i, pc = (pc + count) & address_limits)
{
if (cpu->is_paused() && pc == GetPc())
if (cpu->is_paused() && pc == cpu->get_pc())
{
item(i)->setForeground(m_text_color_pc);
item(i)->setBackground(m_color_pc);

View File

@ -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<gui_settings> xgui_settings;