Skip to content

Commit

Permalink
SPU/PPU Debugger: Add decimal mode to registers panel
Browse files Browse the repository at this point in the history
  • Loading branch information
elad335 committed Jul 10, 2023
1 parent 16f910e commit 9ab5755
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 10 deletions.
17 changes: 15 additions & 2 deletions rpcs3/Emu/Cell/PPUThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1237,6 +1237,12 @@ std::array<u32, 2> 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)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
10 changes: 10 additions & 0 deletions rpcs3/Emu/Cell/PPUThread.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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<ppu_debugger_mode> debugger_mode{};

struct call_history_t
{
Expand Down
25 changes: 22 additions & 3 deletions rpcs3/Emu/Cell/SPUThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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))
Expand Down
11 changes: 10 additions & 1 deletion rpcs3/Emu/Cell/SPUThread.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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<u8> debugger_float_mode = 0;
atomic_t<spu_debugger_mode> debugger_mode{};

// PC-based breakpoint list
std::array<atomic_t<bool>, SPU_LS_SIZE / 4> local_breakpoints{};
Expand Down
21 changes: 17 additions & 4 deletions rpcs3/rpcs3qt/debugger_frame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -620,13 +620,26 @@ void debugger_frame::keyPressEvent(QKeyEvent* event)
break;
}

if (cpu->id_type() != 2)
if (cpu->id_type() == 1)
{
break;
static_cast<ppu_thread*>(cpu)->debugger_mode.atomic_op([](ppu_debugger_mode& mode)
{
mode = static_cast<ppu_debugger_mode>((static_cast<u32>(mode) + 1) % static_cast<u32>(ppu_debugger_mode::max_mode));
});

return;
}
if (cpu->id_type() == 2)
{
static_cast<spu_thread*>(cpu)->debugger_mode.atomic_op([](spu_debugger_mode& mode)
{
mode = static_cast<spu_debugger_mode>((static_cast<u32>(mode) + 1) % static_cast<u32>(spu_debugger_mode::max_mode));
});

static_cast<spu_thread*>(cpu)->debugger_float_mode ^= 1; // Switch mode
return;
return;
}

break;
}
case Qt::Key_R:
{
Expand Down

0 comments on commit 9ab5755

Please sign in to comment.