Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some improvements for debugging tools #7802

Merged
merged 5 commits into from Mar 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 11 additions & 2 deletions rpcs3/Emu/Cell/PPUThread.cpp
Expand Up @@ -472,8 +472,17 @@ std::string ppu_thread::dump() const
fmt::append(ret, "FPSCR = [FL=%u | FG=%u | FE=%u | FU=%u]\n", fpscr.fl, fpscr.fg, fpscr.fe, fpscr.fu);
fmt::append(ret, "\nCall stack:\n=========\n0x%08x (0x0) called\n", cia);

//std::shared_lock rlock(vm::g_mutex); // Needs optimizations

// Determine stack range
u32 stack_ptr = static_cast<u32>(gpr[1]);

if (!vm::check_addr(stack_ptr, 1, vm::page_writable))
{
// Normally impossible unless the code does not follow ABI rules
return ret;
}

u32 stack_min = stack_ptr & ~0xfff;
u32 stack_max = stack_min + 4096;

Expand All @@ -487,10 +496,10 @@ std::string ppu_thread::dump() const
stack_max += 4096;
}

for (u64 sp = vm::read64(stack_ptr); sp >= stack_min && std::max(sp, sp + 0x200) < stack_max; sp = vm::read64(static_cast<u32>(sp)))
for (u64 sp = *vm::get_super_ptr<u64>(stack_ptr); sp >= stack_min && std::max(sp, sp + 0x200) < stack_max; sp = *vm::get_super_ptr<u64>(static_cast<u32>(sp)))
{
// TODO: print also function addresses
fmt::append(ret, "> from 0x%08llx (0x0)\n", vm::read64(static_cast<u32>(sp + 16)));
fmt::append(ret, "> from 0x%08llx (0x0)\n", *vm::get_super_ptr<u64>(static_cast<u32>(sp + 16)));
}

return ret;
Expand Down
8 changes: 4 additions & 4 deletions rpcs3/rpcs3qt/debugger_list.cpp
Expand Up @@ -73,28 +73,28 @@ void debugger_list::ShowAddress(u32 addr)
{
for (uint i = 0; i < m_item_count; ++i, m_pc += 4)
{
item(i)->setText(qstr(fmt::format("[%08x] illegal address", m_pc)));
item(i)->setText(qstr(fmt::format(" [%08x] illegal address", m_pc)));
}
}
else
{
const bool is_spu = cpu->id_type() != 1;
const u32 cpu_offset = is_spu ? static_cast<spu_thread&>(*cpu).offset : 0;
const u32 address_limits = is_spu ? 0x3ffff : ~0;
const u32 address_limits = (is_spu ? 0x3fffc : ~3);
m_pc &= address_limits;
m_disasm->offset = vm::get_super_ptr(cpu_offset);
for (uint i = 0, count = 4; i<m_item_count; ++i, m_pc = (m_pc + count) & address_limits)
{
if (!vm::check_addr(cpu_offset + m_pc, 4))
{
item(i)->setText((IsBreakpoint(m_pc) ? ">>> " : " ") + qstr(fmt::format("[%08x] illegal address", m_pc)));
item(i)->setText((IsBreakpoint(m_pc) ? ">> " : " ") + qstr(fmt::format("[%08x] illegal address", m_pc)));
count = 4;
continue;
}

count = m_disasm->disasm(m_disasm->dump_pc = m_pc);

item(i)->setText((IsBreakpoint(m_pc) ? ">>> " : " ") + qstr(m_disasm->last_opcode));
item(i)->setText((IsBreakpoint(m_pc) ? ">> " : " ") + qstr(m_disasm->last_opcode));

if (cpu->is_paused() && m_pc == GetPc())
{
Expand Down
24 changes: 17 additions & 7 deletions rpcs3/rpcs3qt/memory_viewer_panel.cpp
@@ -1,5 +1,6 @@
#include "stdafx.h"
#include "Emu/Memory/vm.h"
#include "Utilities/mutex.h"
#include "Emu/Memory/vm_locking.h"

#include "memory_viewer_panel.h"

Expand All @@ -10,6 +11,7 @@
#include <QTextEdit>
#include <QComboBox>
#include <QWheelEvent>
#include <shared_mutex>

constexpr auto qstr = QString::fromStdString;

Expand Down Expand Up @@ -273,10 +275,9 @@ void memory_viewer_panel::ShowMemory()

if (vm::check_addr(addr))
{
const u8 rmem = vm::read8(addr);
const u8 rmem = *vm::get_super_ptr<u8>(addr);
t_mem_hex_str += qstr(fmt::format("%02x ", rmem));
const bool isPrintable = rmem >= 32 && rmem <= 126;
t_mem_ascii_str += qstr(isPrintable ? std::string(1, rmem) : ".");
t_mem_ascii_str += qstr(std::string(1, std::isprint(rmem) ? static_cast<char>(rmem) : '.'));
}
else
{
Expand Down Expand Up @@ -314,8 +315,15 @@ void memory_viewer_panel::SetPC(const uint pc)

void memory_viewer_panel::ShowImage(QWidget* parent, u32 addr, int mode, u32 width, u32 height, bool flipv)
{
uchar* originalBuffer = static_cast<uchar*>(vm::base(addr));
uchar* convertedBuffer = static_cast<uchar*>(std::malloc(width * height * 4));
std::shared_lock rlock(vm::g_mutex);

if (!vm::check_addr(addr, width * height * 4))
{
return;
}

const auto originalBuffer = vm::get_super_ptr<const uchar>(addr);
const auto convertedBuffer = static_cast<uchar*>(std::malloc(width * height * 4));

switch(mode)
{
Expand Down Expand Up @@ -372,6 +380,8 @@ void memory_viewer_panel::ShowImage(QWidget* parent, u32 addr, int mode, u32 wid
break;
}

rlock.unlock();

// Flip vertically
if (flipv)
{
Expand All @@ -386,7 +396,7 @@ void memory_viewer_panel::ShowImage(QWidget* parent, u32 addr, int mode, u32 wid
}
}

QImage image = QImage(convertedBuffer, width, height, QImage::Format_ARGB32);
QImage image = QImage(convertedBuffer, width, height, QImage::Format_ARGB32, [](void* buffer){ std::free(buffer); }, convertedBuffer);
if (image.isNull()) return;

QLabel* canvas = new QLabel();
Expand Down
15 changes: 8 additions & 7 deletions rpcs3/rpcs3qt/rsx_debugger.cpp
Expand Up @@ -497,7 +497,7 @@ void rsx_debugger::OnClickDrawCalls()
if (width && height && !draw_call.color_buffer[i].empty())
{
unsigned char* buffer = convert_to_QImage_buffer(draw_call.state.surface_color(), draw_call.color_buffer[i], width, height);
buffers[i]->showImage(QImage(buffer, static_cast<int>(width), static_cast<int>(height), QImage::Format_RGB32));
buffers[i]->showImage(QImage(buffer, static_cast<int>(width), static_cast<int>(height), QImage::Format_RGB32, [](void* buffer){ std::free(buffer); }, buffer));
}
}

Expand Down Expand Up @@ -538,7 +538,7 @@ void rsx_debugger::OnClickDrawCalls()
}
}
}
m_buffer_depth->showImage(QImage(buffer, static_cast<int>(width), static_cast<int>(height), QImage::Format_RGB32));
m_buffer_depth->showImage(QImage(buffer, static_cast<int>(width), static_cast<int>(height), QImage::Format_RGB32, [](void* buffer){ std::free(buffer); }, buffer));
}
}

Expand Down Expand Up @@ -662,13 +662,14 @@ void rsx_debugger::GetBuffers()
auto buffers = render->display_buffers;
u32 RSXbuffer_addr = rsx::constants::local_mem_base + buffers[bufferId].offset;

if(!vm::check_addr(RSXbuffer_addr))
const u32 width = buffers[bufferId].width;
const u32 height = buffers[bufferId].height;

if(!vm::check_addr(RSXbuffer_addr, width * height * 4))
continue;

auto RSXbuffer = vm::get_super_ptr<u8>(RSXbuffer_addr);
const auto RSXbuffer = vm::get_super_ptr<const u8>(RSXbuffer_addr);

u32 width = buffers[bufferId].width;
u32 height = buffers[bufferId].height;
u8* buffer = static_cast<u8*>(std::malloc(width * height * 4));

// ABGR to ARGB and flip vertically
Expand All @@ -692,7 +693,7 @@ void rsx_debugger::GetBuffers()
case 2: pnl = m_buffer_colorC; break;
default: pnl = m_buffer_colorD; break;
}
pnl->showImage(QImage(buffer, width, height, QImage::Format_RGB32));
pnl->showImage(QImage(buffer, width, height, QImage::Format_RGB32, [](void* buffer){ std::free(buffer); }, buffer));
}

// Draw Texture
Expand Down