From 948ce12c252ff996a4faffacaa1e66f2f84ead89 Mon Sep 17 00:00:00 2001 From: Eladash Date: Sun, 4 Jun 2023 17:04:22 +0300 Subject: [PATCH] debugger: Fix use of invalid pointers --- rpcs3/rpcs3qt/debugger_frame.cpp | 60 +++++++++++++++++++++++++------- rpcs3/rpcs3qt/debugger_frame.h | 2 +- 2 files changed, 48 insertions(+), 14 deletions(-) diff --git a/rpcs3/rpcs3qt/debugger_frame.cpp b/rpcs3/rpcs3qt/debugger_frame.cpp index 16451bbf6d2b..e0b300f69261 100644 --- a/rpcs3/rpcs3qt/debugger_frame.cpp +++ b/rpcs3/rpcs3qt/debugger_frame.cpp @@ -767,21 +767,51 @@ cpu_thread* debugger_frame::get_cpu() return m_rsx; } -std::function debugger_frame::make_check_cpu(cpu_thread* cpu) +std::function debugger_frame::make_check_cpu(cpu_thread* cpu, bool unlocked) { const u32 id = cpu ? cpu->id : umax; const u32 type = id >> 24; - std::shared_ptr shared = type == 1 ? static_cast>(idm::get>(id)) : - type == 2 ? idm::get>(id) : nullptr; + std::shared_ptr shared; + + if (g_fxo->try_get>>() && g_fxo->try_get>>()) + { + if (unlocked) + { + if (type == 1) + { + shared = idm::get_unlocked>(id); + } + else if (type == 2) + { + shared = idm::get_unlocked>(id); + } + } + else + { + if (type == 1) + { + shared = idm::get>(id); + } + else if (type == 2) + { + shared = idm::get>(id); + } + } + } if (shared.get() != cpu) { shared.reset(); } - return [&rsx = m_rsx, cpu, type, shared = std::move(shared)]() -> cpu_thread* + return [&rsx = m_rsx, cpu, type, shared = std::move(shared), emu_course = Emu.ProcureCurrentEmulationCourseInformation()]() -> cpu_thread* { + if (emu_course != Emu.ProcureCurrentEmulationCourseInformation()) + { + return nullptr; + } + if (type == 1 || type == 2) { // SPU and PPU @@ -874,7 +904,7 @@ void debugger_frame::UpdateUI() m_ui_update_ctr++; } -using data_type = std::pair; +using data_type = std::function; Q_DECLARE_METATYPE(data_type); @@ -896,21 +926,18 @@ void debugger_frame::UpdateUnitList() return; } - //const int old_size = m_choice_units->count(); QVariant old_cpu = m_choice_units->currentData(); bool reselected = false; const auto on_select = [&](u32 id, cpu_thread& cpu) { - if (emu_state == system_state::stopped) return; - - const QVariant var_cpu = QVariant::fromValue(std::make_pair(&cpu, id)); + const QVariant var_cpu = QVariant::fromValue(make_check_cpu(std::addressof(cpu), true)); // Space at the end is to pad a gap on the right m_choice_units->addItem(qstr((id >> 24 == 0x55 ? "RSX[0x55555555]" : cpu.get_name()) + ' '), var_cpu); - if (!reselected && old_cpu == var_cpu) + if (!reselected && old_cpu.canConvert() && old_cpu.value()() == std::addressof(cpu)) { m_choice_units->setCurrentIndex(m_choice_units->count() - 1); reselected = true; @@ -923,8 +950,11 @@ void debugger_frame::UpdateUnitList() m_choice_units->clear(); m_choice_units->addItem(NoThreadString); - idm::select>(on_select); - idm::select>(on_select); + if (emu_state != system_state::stopped) + { + idm::select>(on_select); + idm::select>(on_select); + } if (const auto render = g_fxo->try_get(); emu_state != system_state::stopped && render && render->ctrl) { @@ -953,7 +983,9 @@ void debugger_frame::UpdateUnitList() void debugger_frame::OnSelectUnit() { - auto [selected, cpu_id] = m_choice_units->currentData().value(); + const QVariant data = m_choice_units->currentData(); + + cpu_thread* selected = data.canConvert() ? data.value()() : nullptr; if (m_emu_state != system_state::stopped) { @@ -984,6 +1016,8 @@ void debugger_frame::OnSelectUnit() if (selected) { + const u32 cpu_id = selected->id; + switch (cpu_id >> 24) { case 1: diff --git a/rpcs3/rpcs3qt/debugger_frame.h b/rpcs3/rpcs3qt/debugger_frame.h index 0bfd9a1563d2..db81cae3434a 100644 --- a/rpcs3/rpcs3qt/debugger_frame.h +++ b/rpcs3/rpcs3qt/debugger_frame.h @@ -76,7 +76,7 @@ class debugger_frame : public custom_dock_widget std::shared_ptr m_gui_settings; cpu_thread* get_cpu(); - std::function make_check_cpu(cpu_thread* cpu); + std::function make_check_cpu(cpu_thread* cpu, bool unlocked = false); void open_breakpoints_settings(); public: