From 9ab5755db49f29c0fe7d56919639259a2403921a Mon Sep 17 00:00:00 2001 From: Elad Ashkenazi Date: Mon, 10 Jul 2023 17:43:59 +0300 Subject: [PATCH] SPU/PPU Debugger: Add decimal mode to registers panel --- rpcs3/Emu/Cell/PPUThread.cpp | 17 +++++++++++++++-- rpcs3/Emu/Cell/PPUThread.h | 10 ++++++++++ rpcs3/Emu/Cell/SPUThread.cpp | 25 ++++++++++++++++++++++--- rpcs3/Emu/Cell/SPUThread.h | 11 ++++++++++- rpcs3/rpcs3qt/debugger_frame.cpp | 21 +++++++++++++++++---- 5 files changed, 74 insertions(+), 10 deletions(-) diff --git a/rpcs3/Emu/Cell/PPUThread.cpp b/rpcs3/Emu/Cell/PPUThread.cpp index 6c5ccd4c60e2..3d319d45499f 100644 --- a/rpcs3/Emu/Cell/PPUThread.cpp +++ b/rpcs3/Emu/Cell/PPUThread.cpp @@ -1237,6 +1237,12 @@ std::array op_branch_targets(u32 pc, ppu_opcode_t op) void ppu_thread::dump_regs(std::string& ret) const { + const system_state emu_state = Emu.GetStatus(false); + const bool is_stopped_or_frozen = state & cpu_flag::exit || emu_state == system_state::frozen || emu_state <= system_state::stopping; + const ppu_debugger_mode mode = debugger_mode.load(); + + const bool is_decimal = !is_stopped_or_frozen && mode == ppu_debugger_mode::is_decimal; + PPUDisAsm dis_asm(cpu_disasm_mode::normal, vm::g_sudo_addr); for (uint i = 0; i < 32; ++i) @@ -1278,7 +1284,14 @@ void ppu_thread::dump_regs(std::string& ret) const if (!printed_error) { - fmt::append(ret, "0x%-8llx", reg); + if (is_decimal) + { + fmt::append(ret, "%-11d", reg); + } + else + { + fmt::append(ret, "0x%-8llx", reg); + } } constexpr u32 max_str_len = 32; @@ -1824,7 +1837,7 @@ void ppu_thread::cpu_on_stop() } // TODO: More conditions - if (Emu.IsStopped() && g_cfg.core.spu_debug) + if (Emu.IsStopped() && g_cfg.core.ppu_debug) { std::string ret; dump_all(ret); diff --git a/rpcs3/Emu/Cell/PPUThread.h b/rpcs3/Emu/Cell/PPUThread.h index 89543e168fa6..1b799542074a 100644 --- a/rpcs3/Emu/Cell/PPUThread.h +++ b/rpcs3/Emu/Cell/PPUThread.h @@ -125,6 +125,15 @@ struct cmd64 } }; +enum class ppu_debugger_mode : u32 +{ + _default, + is_float, + is_decimal, + + max_mode, +}; + class ppu_thread : public cpu_thread { public: @@ -300,6 +309,7 @@ class ppu_thread : public cpu_thread u64 exec_bytes = 0; // Amount of "bytes" executed (4 for each instruction) u32 dbg_step_pc = 0; + atomic_t debugger_mode{}; struct call_history_t { diff --git a/rpcs3/Emu/Cell/SPUThread.cpp b/rpcs3/Emu/Cell/SPUThread.cpp index 06eb02b1cb70..890613655878 100644 --- a/rpcs3/Emu/Cell/SPUThread.cpp +++ b/rpcs3/Emu/Cell/SPUThread.cpp @@ -1019,7 +1019,12 @@ spu_imm_table_t::spu_imm_table_t() void spu_thread::dump_regs(std::string& ret) const { - const bool floats_only = debugger_float_mode.load(); + const system_state emu_state = Emu.GetStatus(false); + const bool is_stopped_or_frozen = state & cpu_flag::exit || emu_state == system_state::frozen || emu_state <= system_state::stopping; + const spu_debugger_mode mode = debugger_mode.load(); + + const bool floats_only = !is_stopped_or_frozen && mode == spu_debugger_mode::is_float; + const bool is_decimal = !is_stopped_or_frozen && mode == spu_debugger_mode::is_decimal; SPUDisAsm dis_asm(cpu_disasm_mode::normal, ls); @@ -1097,12 +1102,26 @@ void spu_thread::dump_regs(std::string& ret) const if (!printed_error) { // Shortand formatting - fmt::append(ret, "%08x", i3); + if (is_decimal) + { + fmt::append(ret, "%-11d", i3); + } + else + { + fmt::append(ret, "%08x", i3); + } } } else { - fmt::append(ret, "%08x %08x %08x %08x", r.u32r[0], r.u32r[1], r.u32r[2], r.u32r[3]); + if (is_decimal) + { + fmt::append(ret, "%-11d %-11d %-11d %-11d", r.u32r[0], r.u32r[1], r.u32r[2], r.u32r[3]); + } + else + { + fmt::append(ret, "%08x %08x %08x %08x", r.u32r[0], r.u32r[1], r.u32r[2], r.u32r[3]); + } } if (i3 >= 0x80 && is_exec_code(i3, ls)) diff --git a/rpcs3/Emu/Cell/SPUThread.h b/rpcs3/Emu/Cell/SPUThread.h index c4d52d517e0a..0c59344dd12f 100644 --- a/rpcs3/Emu/Cell/SPUThread.h +++ b/rpcs3/Emu/Cell/SPUThread.h @@ -608,6 +608,15 @@ struct spu_memory_segment_dump_data u32 flags = umax; }; +enum class spu_debugger_mode : u32 +{ + _default, + is_float, + is_decimal, + + max_mode, +}; + class spu_thread : public cpu_thread { public: @@ -794,7 +803,7 @@ class spu_thread : public cpu_thread u64 start_time{}; // Starting time of STOP or RDCH bloking function bool unsavable = false; // Flag indicating whether saving the spu thread state is currently unsafe - atomic_t debugger_float_mode = 0; + atomic_t debugger_mode{}; // PC-based breakpoint list std::array, SPU_LS_SIZE / 4> local_breakpoints{}; diff --git a/rpcs3/rpcs3qt/debugger_frame.cpp b/rpcs3/rpcs3qt/debugger_frame.cpp index d2c54ecf39de..964bdbe8ca0f 100644 --- a/rpcs3/rpcs3qt/debugger_frame.cpp +++ b/rpcs3/rpcs3qt/debugger_frame.cpp @@ -620,13 +620,26 @@ void debugger_frame::keyPressEvent(QKeyEvent* event) break; } - if (cpu->id_type() != 2) + if (cpu->id_type() == 1) { - break; + static_cast(cpu)->debugger_mode.atomic_op([](ppu_debugger_mode& mode) + { + mode = static_cast((static_cast(mode) + 1) % static_cast(ppu_debugger_mode::max_mode)); + }); + + return; } + if (cpu->id_type() == 2) + { + static_cast(cpu)->debugger_mode.atomic_op([](spu_debugger_mode& mode) + { + mode = static_cast((static_cast(mode) + 1) % static_cast(spu_debugger_mode::max_mode)); + }); - static_cast(cpu)->debugger_float_mode ^= 1; // Switch mode - return; + return; + } + + break; } case Qt::Key_R: {