Debugger: Optimize thread disasm type select

Some correctness fixes as well: dont use raw pointers where its not compatible, use std::weak_ptr instead.
This commit is contained in:
Eladash 2020-10-22 15:52:00 +03:00 committed by Ivan
parent e70f430b5a
commit 6d3c421823

View file

@ -352,6 +352,8 @@ void debugger_frame::UpdateUI()
}
}
Q_DECLARE_METATYPE(std::weak_ptr<cpu_thread>);
void debugger_frame::UpdateUnitList()
{
const u64 threads_created = cpu_thread::g_threads_created;
@ -373,9 +375,11 @@ void debugger_frame::UpdateUnitList()
m_choice_units->clear();
m_choice_units->addItem(NoThreadString);
const auto on_select = [&](u32, cpu_thread& cpu)
const auto on_select = [&](u32 id, cpu_thread& cpu)
{
QVariant var_cpu = QVariant::fromValue<void*>(&cpu);
QVariant var_cpu = QVariant::fromValue<std::weak_ptr<cpu_thread>>(
id >> 24 == 1 ? static_cast<std::weak_ptr<cpu_thread>>(idm::get_unlocked<named_thread<ppu_thread>>(id)) : idm::get_unlocked<named_thread<spu_thread>>(id));
m_choice_units->addItem(qstr(cpu.get_name()), var_cpu);
if (old_cpu == var_cpu) m_choice_units->setCurrentIndex(m_choice_units->count() - 1);
};
@ -405,21 +409,24 @@ void debugger_frame::OnSelectUnit()
if (!m_no_thread_selected)
{
const auto on_select = [&](u32, cpu_thread& cpu)
if (const auto cpu0 = m_choice_units->currentData().value<std::weak_ptr<cpu_thread>>().lock())
{
cpu_thread* data = static_cast<cpu_thread*>(m_choice_units->currentData().value<void*>());
return data == &cpu;
};
if (auto ppu = idm::select<named_thread<ppu_thread>>(on_select))
{
m_disasm = std::make_unique<PPUDisAsm>(CPUDisAsm_InterpreterMode);
cpu = ppu.ptr;
}
else if (auto spu1 = idm::select<named_thread<spu_thread>>(on_select))
{
m_disasm = std::make_unique<SPUDisAsm>(CPUDisAsm_InterpreterMode);
cpu = spu1.ptr;
if (cpu0->id_type() == 1)
{
if (cpu0.get() == idm::check<named_thread<ppu_thread>>(cpu0->id))
{
cpu = cpu0;
m_disasm = std::make_unique<PPUDisAsm>(CPUDisAsm_InterpreterMode);
}
}
else
{
if (cpu0.get() == idm::check<named_thread<spu_thread>>(cpu0->id))
{
cpu = cpu0;
m_disasm = std::make_unique<SPUDisAsm>(CPUDisAsm_InterpreterMode);
}
}
}
}