Debugger MemoryWidget: More display types, use combo box for display options. Add alignment and riw length options.

This commit is contained in:
TryTwo 2022-04-06 02:36:09 -07:00
parent 2f90a2c689
commit a2aecc3794
4 changed files with 238 additions and 143 deletions

View file

@ -13,6 +13,8 @@
#include <cmath>
#include "Common/Align.h"
#include "Common/FloatUtils.h"
#include "Common/StringUtil.h"
#include "Core/Core.h"
#include "Core/HW/AddressSpace.h"
@ -62,20 +64,58 @@ void MemoryViewWidget::UpdateFont()
Update();
}
static int GetColumnCount(MemoryViewWidget::Type type)
static int GetTypeSize(MemoryViewWidget::Type type)
{
switch (type)
{
case MemoryViewWidget::Type::ASCII:
case MemoryViewWidget::Type::U8:
return 16;
case MemoryViewWidget::Type::U16:
return 8;
case MemoryViewWidget::Type::U32:
case MemoryViewWidget::Type::Hex8:
case MemoryViewWidget::Type::Unsigned8:
case MemoryViewWidget::Type::Signed8:
return 1;
case MemoryViewWidget::Type::Unsigned16:
case MemoryViewWidget::Type::Signed16:
case MemoryViewWidget::Type::Hex16:
return 2;
case MemoryViewWidget::Type::Hex32:
case MemoryViewWidget::Type::Unsigned32:
case MemoryViewWidget::Type::Signed32:
case MemoryViewWidget::Type::Float32:
return 4;
case MemoryViewWidget::Type::Double:
return 8;
default:
return 0;
return 1;
}
}
static int GetCharacterCount(MemoryViewWidget::Type type)
{
switch (type)
{
case MemoryViewWidget::Type::ASCII:
return 1;
case MemoryViewWidget::Type::Hex8:
return 2;
case MemoryViewWidget::Type::Unsigned8:
return 3;
case MemoryViewWidget::Type::Hex16:
case MemoryViewWidget::Type::Signed8:
return 4;
case MemoryViewWidget::Type::Unsigned16:
return 5;
case MemoryViewWidget::Type::Signed16:
return 6;
case MemoryViewWidget::Type::Hex32:
return 8;
case MemoryViewWidget::Type::Float32:
return 9;
case MemoryViewWidget::Type::Double:
case MemoryViewWidget::Type::Unsigned32:
case MemoryViewWidget::Type::Signed32:
return 10;
default:
return 8;
}
}
@ -83,7 +123,12 @@ void MemoryViewWidget::Update()
{
clearSelection();
setColumnCount(2 + GetColumnCount(m_type));
u32 address = m_address;
address = Common::AlignDown(address, m_alignment);
const int data_columns = m_bytes_per_row / GetTypeSize(m_type);
setColumnCount(2 + data_columns);
if (rowCount() == 0)
setRowCount(1);
@ -102,31 +147,32 @@ void MemoryViewWidget::Update()
for (int i = 0; i < rows; i++)
{
u32 addr = m_address - ((rowCount() / 2) * 16) + i * 16;
u32 row_address = address - ((rowCount() / 2) * m_bytes_per_row) + i * m_bytes_per_row;
auto* bp_item = new QTableWidgetItem;
bp_item->setFlags(Qt::ItemIsEnabled);
bp_item->setData(Qt::UserRole, addr);
bp_item->setData(Qt::UserRole, row_address);
setItem(i, 0, bp_item);
auto* addr_item = new QTableWidgetItem(QStringLiteral("%1").arg(addr, 8, 16, QLatin1Char('0')));
auto* row_item =
new QTableWidgetItem(QStringLiteral("%1").arg(row_address, 8, 16, QLatin1Char('0')));
addr_item->setData(Qt::UserRole, addr);
addr_item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
row_item->setData(Qt::UserRole, row_address);
row_item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
setItem(i, 1, addr_item);
setItem(i, 1, row_item);
if (addr == m_address)
addr_item->setSelected(true);
if (row_address == address)
row_item->setSelected(true);
if (Core::GetState() != Core::State::Paused || !accessors->IsValidAddress(addr))
if (Core::GetState() != Core::State::Paused || !accessors->IsValidAddress(row_address))
{
for (int c = 2; c < columnCount(); c++)
{
auto* item = new QTableWidgetItem(QStringLiteral("-"));
item->setFlags(Qt::ItemIsEnabled);
item->setData(Qt::UserRole, addr);
item->setData(Qt::UserRole, row_address);
setItem(i, c, item);
}
@ -134,51 +180,48 @@ void MemoryViewWidget::Update()
continue;
}
if (m_address_space == AddressSpace::Type::Effective)
{
auto* description_item = new QTableWidgetItem(
QString::fromStdString(PowerPC::debug_interface.GetDescription(addr)));
description_item->setForeground(Qt::blue);
description_item->setFlags(Qt::ItemIsEnabled);
setItem(i, columnCount() - 1, description_item);
}
bool row_breakpoint = true;
auto update_values = [&](auto value_to_string) {
for (int c = 0; c < GetColumnCount(m_type); c++)
for (int c = 0; c < data_columns; c++)
{
auto* hex_item = new QTableWidgetItem;
hex_item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
const u32 address = addr + c * (16 / GetColumnCount(m_type));
auto* cell_item = new QTableWidgetItem;
cell_item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
if (m_type == Type::Signed32 || m_type == Type::Unsigned32 || m_type == Type::Signed16 ||
m_type == Type::Unsigned16 || m_type == Type::Signed8 || m_type == Type::Unsigned8)
cell_item->setTextAlignment(Qt::AlignRight);
const u32 cell_address = row_address + c * GetTypeSize(m_type);
// GetMemCheck is more accurate than OverlapsMemcheck, unless standard alginments are
// enforced.
if (m_address_space == AddressSpace::Type::Effective &&
PowerPC::memchecks.OverlapsMemcheck(address, 16 / GetColumnCount(m_type)))
PowerPC::memchecks.GetMemCheck(cell_address, GetTypeSize(m_type)) != nullptr)
{
hex_item->setBackground(Qt::red);
cell_item->setBackground(Qt::red);
}
else
{
row_breakpoint = false;
}
setItem(i, 2 + c, hex_item);
setItem(i, 2 + c, cell_item);
if (accessors->IsValidAddress(address))
if (accessors->IsValidAddress(cell_address))
{
hex_item->setText(value_to_string(address));
hex_item->setData(Qt::UserRole, address);
cell_item->setText(value_to_string(cell_address));
cell_item->setData(Qt::UserRole, cell_address);
}
else
{
hex_item->setFlags({});
hex_item->setText(QStringLiteral("-"));
cell_item->setFlags({});
cell_item->setText(QStringLiteral("-"));
}
}
};
switch (m_type)
{
case Type::U8:
case Type::Hex8:
update_values([&accessors](u32 address) {
const u8 value = accessors->ReadU8(address);
return QStringLiteral("%1").arg(value, 2, 16, QLatin1Char('0'));
@ -191,18 +234,45 @@ void MemoryViewWidget::Update()
QString{QChar::fromLatin1('.')};
});
break;
case Type::U16:
case Type::Hex16:
update_values([&accessors](u32 address) {
const u16 value = accessors->ReadU16(address);
return QStringLiteral("%1").arg(value, 4, 16, QLatin1Char('0'));
});
break;
case Type::U32:
case Type::Hex32:
update_values([&accessors](u32 address) {
const u32 value = accessors->ReadU32(address);
return QStringLiteral("%1").arg(value, 8, 16, QLatin1Char('0'));
});
break;
case Type::Unsigned8:
update_values(
[&accessors](u32 address) { return QString::number(accessors->ReadU8(address)); });
break;
case Type::Unsigned16:
update_values(
[&accessors](u32 address) { return QString::number(accessors->ReadU16(address)); });
break;
case Type::Unsigned32:
update_values(
[&accessors](u32 address) { return QString::number(accessors->ReadU32(address)); });
break;
case Type::Signed8:
update_values([&accessors](u32 address) {
return QString::number(Common::BitCast<s8>(accessors->ReadU8(address)));
});
break;
case Type::Signed16:
update_values([&accessors](u32 address) {
return QString::number(Common::BitCast<s16>(accessors->ReadU16(address)));
});
break;
case Type::Signed32:
update_values([&accessors](u32 address) {
return QString::number(Common::BitCast<s32>(accessors->ReadU32(address)));
});
break;
case Type::Float32:
update_values([&accessors](u32 address) {
QString string = QString::number(accessors->ReadF32(address), 'g', 4);
@ -213,6 +283,17 @@ void MemoryViewWidget::Update()
return string;
});
break;
case Type::Double:
update_values([&accessors](u32 address) {
QString string =
QString::number(Common::BitCast<double>(accessors->ReadU64(address)), 'g', 4);
// Align to first digit.
if (!string.startsWith(QLatin1Char('-')))
string.prepend(QLatin1Char(' '));
return string;
});
break;
}
if (row_breakpoint)
@ -223,26 +304,14 @@ void MemoryViewWidget::Update()
}
setColumnWidth(0, rowHeight(0));
int width = 0;
switch (m_type)
{
case Type::U8:
width = m_font_width * 3;
break;
case Type::ASCII:
width = m_font_width * 2;
break;
case Type::U16:
width = m_font_width * 5;
break;
case Type::U32:
width = m_font_width * 10;
break;
case Type::Float32:
width = m_font_width * 12;
break;
}
// Number of characters possible.
int max_length = GetCharacterCount(m_type);
// Column width is the max number of characters + 1 or 2 for the space between columns. A longer
// length means less columns, so a bigger spacing is fine.
max_length += max_length < 8 ? 1 : 2;
const int width = m_font_width * max_length;
for (int i = 2; i < columnCount(); i++)
setColumnWidth(i, width);
@ -267,12 +336,16 @@ AddressSpace::Type MemoryViewWidget::GetAddressSpace() const
return m_address_space;
}
void MemoryViewWidget::SetType(Type type)
void MemoryViewWidget::SetDisplay(Type type, int bytes_per_row, int alignment)
{
if (m_type == type)
return;
m_type = type;
m_bytes_per_row = bytes_per_row;
if (alignment == 0)
m_alignment = GetTypeSize(type);
else
m_alignment = alignment;
Update();
}
@ -287,6 +360,7 @@ void MemoryViewWidget::SetAddress(u32 address)
return;
m_address = address;
Update();
}
@ -335,8 +409,8 @@ void MemoryViewWidget::ToggleRowBreakpoint(bool row)
{
TMemCheck check;
const u32 addr = row ? GetContextAddress() & 0xFFFFFFF0 : GetContextAddress();
const auto length = row ? 16 : (16 / GetColumnCount(m_type));
const u32 addr = row ? m_base_address : GetContextAddress();
const auto length = row ? m_bytes_per_row : GetTypeSize(m_type);
if (m_address_space == AddressSpace::Type::Effective)
{
@ -381,21 +455,22 @@ void MemoryViewWidget::wheelEvent(QWheelEvent* event)
void MemoryViewWidget::mousePressEvent(QMouseEvent* event)
{
auto* item = itemAt(event->pos());
if (item == nullptr)
auto* item_selected = itemAt(event->pos());
if (item_selected == nullptr)
return;
const u32 addr = item->data(Qt::UserRole).toUInt();
const u32 addr = item_selected->data(Qt::UserRole).toUInt();
m_context_address = addr;
m_base_address = item(row(item_selected), 1)->data(Qt::UserRole).toUInt();
switch (event->button())
{
case Qt::LeftButton:
if (column(item) == 0)
if (column(item_selected) == 0)
ToggleRowBreakpoint(true);
else
SetAddress(addr & 0xFFFFFFF0);
SetAddress(m_base_address);
Update();
break;
@ -414,7 +489,7 @@ void MemoryViewWidget::OnCopyHex()
{
u32 addr = GetContextAddress();
const auto length = 16 / GetColumnCount(m_type);
const auto length = GetTypeSize(m_type);
const AddressSpace::Accessors* accessors = AddressSpace::GetAccessors(m_address_space);
u64 value = accessors->ReadU64(addr);

View file

@ -16,13 +16,20 @@ class MemoryViewWidget : public QTableWidget
{
Q_OBJECT
public:
enum class Type
enum class Type : int
{
U8,
U16,
U32,
Hex8 = 1,
Hex16,
Hex32,
Unsigned8,
Unsigned16,
Unsigned32,
Signed8,
Signed16,
Signed32,
ASCII,
Float32
Float32,
Double
};
enum class BPType
@ -41,7 +48,7 @@ public:
void SetAddressSpace(AddressSpace::Type address_space);
AddressSpace::Type GetAddressSpace() const;
void SetType(Type type);
void SetDisplay(Type type, int bytes_per_row, int alignment);
void SetBPType(BPType type);
void SetAddress(u32 address);
@ -65,11 +72,14 @@ private:
void OnCopyHex();
AddressSpace::Type m_address_space{};
Type m_type = Type::U8;
Type m_type = Type::Hex8;
BPType m_bp_type = BPType::ReadWrite;
bool m_do_log = true;
u32 m_context_address;
u32 m_base_address;
u32 m_address = 0;
int m_font_width = 0;
int m_font_vspace = 0;
int m_bytes_per_row = 16;
int m_alignment = 16;
};

View file

@ -18,7 +18,6 @@
#include <QLabel>
#include <QLineEdit>
#include <QPushButton>
#include <QRadioButton>
#include <QRegularExpression>
#include <QScrollArea>
#include <QSpacerItem>
@ -69,7 +68,7 @@ MemoryWidget::MemoryWidget(QWidget* parent) : QDockWidget(parent)
ConnectWidgets();
OnAddressSpaceChanged();
OnTypeChanged();
OnDisplayChanged();
}
MemoryWidget::~MemoryWidget()
@ -140,11 +139,19 @@ void MemoryWidget::CreateWidgets()
m_input_combo->addItem(tr("Signed 32"), int(InputID::S32));
// Dump
auto* dump_group = new QGroupBox(tr("Dump"));
auto* dump_layout = new QVBoxLayout;
dump_group->setLayout(dump_layout);
m_dump_mram = new QPushButton(tr("Dump &MRAM"));
m_dump_exram = new QPushButton(tr("Dump &ExRAM"));
m_dump_aram = new QPushButton(tr("Dump &ARAM"));
m_dump_fake_vmem = new QPushButton(tr("Dump &FakeVMEM"));
dump_layout->addWidget(m_dump_mram);
dump_layout->addWidget(m_dump_exram);
dump_layout->addWidget(m_dump_aram);
dump_layout->addWidget(m_dump_fake_vmem);
// Search Options
auto* search_group = new QGroupBox(tr("Search"));
auto* search_layout = new QVBoxLayout;
@ -179,22 +186,38 @@ void MemoryWidget::CreateWidgets()
address_space_layout->setSpacing(1);
// Data Type
auto* datatype_group = new QGroupBox(tr("Data Type"));
auto* datatype_layout = new QVBoxLayout;
datatype_group->setLayout(datatype_layout);
auto* displaytype_group = new QGroupBox(tr("Display Type"));
auto* displaytype_layout = new QVBoxLayout;
displaytype_group->setLayout(displaytype_layout);
m_type_u8 = new QRadioButton(tr("U&8"));
m_type_u16 = new QRadioButton(tr("U&16"));
m_type_u32 = new QRadioButton(tr("U&32"));
m_type_ascii = new QRadioButton(tr("ASCII"));
m_type_float = new QRadioButton(tr("Float"));
m_display_combo = new QComboBox;
m_display_combo->setMaxVisibleItems(20);
m_display_combo->addItem(tr("Hex 8"), int(MemoryViewWidget::Type::Hex8));
m_display_combo->addItem(tr("Hex 16"), int(MemoryViewWidget::Type::Hex16));
m_display_combo->addItem(tr("Hex 32"), int(MemoryViewWidget::Type::Hex32));
m_display_combo->addItem(tr("Unsigned 8"), int(MemoryViewWidget::Type::Unsigned8));
m_display_combo->addItem(tr("Unsigned 16"), int(MemoryViewWidget::Type::Unsigned16));
m_display_combo->addItem(tr("Unsigned 32"), int(MemoryViewWidget::Type::Unsigned32));
m_display_combo->addItem(tr("Signed 8"), int(MemoryViewWidget::Type::Signed8));
m_display_combo->addItem(tr("Signed 16"), int(MemoryViewWidget::Type::Signed16));
m_display_combo->addItem(tr("Signed 32"), int(MemoryViewWidget::Type::Signed32));
m_display_combo->addItem(tr("ASCII"), int(MemoryViewWidget::Type::ASCII));
m_display_combo->addItem(tr("Float"), int(MemoryViewWidget::Type::Float32));
m_display_combo->addItem(tr("Double"), int(MemoryViewWidget::Type::Double));
datatype_layout->addWidget(m_type_u8);
datatype_layout->addWidget(m_type_u16);
datatype_layout->addWidget(m_type_u32);
datatype_layout->addWidget(m_type_ascii);
datatype_layout->addWidget(m_type_float);
datatype_layout->setSpacing(1);
m_align_combo = new QComboBox;
m_align_combo->addItem(tr("Fixed Alignment"));
m_align_combo->addItem(tr("Type-based Alignment"), 0);
m_align_combo->addItem(tr("No Alignment"), 1);
m_row_length_combo = new QComboBox;
m_row_length_combo->addItem(tr("4 Bytes"), 4);
m_row_length_combo->addItem(tr("8 Bytes"), 8);
m_row_length_combo->addItem(tr("16 Bytes"), 16);
displaytype_layout->addWidget(m_display_combo);
displaytype_layout->addWidget(m_align_combo);
displaytype_layout->addWidget(m_row_length_combo);
// MBP options
auto* bp_group = new QGroupBox(tr("Memory breakpoint options"));
@ -232,16 +255,16 @@ void MemoryWidget::CreateWidgets()
sidebar_layout->addWidget(m_data_preview);
sidebar_layout->addWidget(m_set_value);
sidebar_layout->addWidget(m_from_file);
sidebar_layout->addItem(new QSpacerItem(1, 20));
sidebar_layout->addWidget(m_dump_mram);
sidebar_layout->addWidget(m_dump_exram);
sidebar_layout->addWidget(m_dump_aram);
sidebar_layout->addWidget(m_dump_fake_vmem);
sidebar_layout->addItem(new QSpacerItem(1, 15));
sidebar_layout->addItem(new QSpacerItem(1, 10));
sidebar_layout->addWidget(search_group);
sidebar_layout->addItem(new QSpacerItem(1, 10));
sidebar_layout->addWidget(displaytype_group);
sidebar_layout->addItem(new QSpacerItem(1, 10));
sidebar_layout->addWidget(address_space_group);
sidebar_layout->addWidget(datatype_group);
sidebar_layout->addItem(new QSpacerItem(1, 10));
sidebar_layout->addWidget(bp_group);
sidebar_layout->addItem(new QSpacerItem(1, 10));
sidebar_layout->addWidget(dump_group);
sidebar_layout->addItem(new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Expanding));
// Splitter
@ -289,9 +312,11 @@ void MemoryWidget::ConnectWidgets()
{
connect(radio, &QRadioButton::toggled, this, &MemoryWidget::OnAddressSpaceChanged);
}
for (auto* radio : {m_type_u8, m_type_u16, m_type_u32, m_type_ascii, m_type_float})
connect(radio, &QRadioButton::toggled, this, &MemoryWidget::OnTypeChanged);
for (auto* combo : {m_display_combo, m_align_combo, m_row_length_combo})
{
connect(combo, qOverload<int>(&QComboBox::currentIndexChanged), this,
&MemoryWidget::OnDisplayChanged);
}
for (auto* radio : {m_bp_read_write, m_bp_read_only, m_bp_write_only})
connect(radio, &QRadioButton::toggled, this, &MemoryWidget::OnBPTypeChanged);
@ -342,17 +367,9 @@ void MemoryWidget::LoadSettings()
m_address_space_auxiliary->setChecked(address_space_auxiliary);
m_address_space_physical->setChecked(address_space_physical);
const bool type_u8 = settings.value(QStringLiteral("memorywidget/typeu8"), true).toBool();
const bool type_u16 = settings.value(QStringLiteral("memorywidget/typeu16"), false).toBool();
const bool type_u32 = settings.value(QStringLiteral("memorywidget/typeu32"), false).toBool();
const bool type_float = settings.value(QStringLiteral("memorywidget/typefloat"), false).toBool();
const bool type_ascii = settings.value(QStringLiteral("memorywidget/typeascii"), false).toBool();
const int display_index = settings.value(QStringLiteral("memorywidget/display_type"), 1).toInt();
m_type_u8->setChecked(type_u8);
m_type_u16->setChecked(type_u16);
m_type_u32->setChecked(type_u32);
m_type_float->setChecked(type_float);
m_type_ascii->setChecked(type_ascii);
m_display_combo->setCurrentIndex(display_index);
bool bp_rw = settings.value(QStringLiteral("memorywidget/bpreadwrite"), true).toBool();
bool bp_r = settings.value(QStringLiteral("memorywidget/bpread"), false).toBool();
@ -385,11 +402,7 @@ void MemoryWidget::SaveSettings()
settings.setValue(QStringLiteral("memorywidget/addrspace_physical"),
m_address_space_physical->isChecked());
settings.setValue(QStringLiteral("memorywidget/typeu8"), m_type_u8->isChecked());
settings.setValue(QStringLiteral("memorywidget/typeu16"), m_type_u16->isChecked());
settings.setValue(QStringLiteral("memorywidget/typeu32"), m_type_u32->isChecked());
settings.setValue(QStringLiteral("memorywidget/typeascii"), m_type_ascii->isChecked());
settings.setValue(QStringLiteral("memorywidget/typefloat"), m_type_float->isChecked());
settings.setValue(QStringLiteral("memorywidget/display_type"), m_display_combo->currentIndex());
settings.setValue(QStringLiteral("memorywidget/bpreadwrite"), m_bp_read_write->isChecked());
settings.setValue(QStringLiteral("memorywidget/bpread"), m_bp_read_only->isChecked());
@ -413,23 +426,24 @@ void MemoryWidget::OnAddressSpaceChanged()
SaveSettings();
}
void MemoryWidget::OnTypeChanged()
void MemoryWidget::OnDisplayChanged()
{
MemoryViewWidget::Type type;
const auto type = static_cast<MemoryViewWidget::Type>(m_display_combo->currentData().toInt());
int bytes_per_row = m_row_length_combo->currentData().toInt();
int alignment;
if (m_type_u8->isChecked())
type = MemoryViewWidget::Type::U8;
else if (m_type_u16->isChecked())
type = MemoryViewWidget::Type::U16;
else if (m_type_u32->isChecked())
type = MemoryViewWidget::Type::U32;
else if (m_type_ascii->isChecked())
type = MemoryViewWidget::Type::ASCII;
if (type == MemoryViewWidget::Type::Double && bytes_per_row == 4)
bytes_per_row = 8;
// Alignment: First (fixed) option equals bytes per row. 'currentData' is correct for other
// options. Type-based must be calculated in memoryviewwidget and is left at 0. No alignment is
// equivalent to a value of 1.
if (m_align_combo->currentIndex() == 0)
alignment = bytes_per_row;
else
type = MemoryViewWidget::Type::Float32;
alignment = m_align_combo->currentData().toInt();
ValidateAndPreviewInputValue();
m_memory_view->SetType(type);
m_memory_view->SetDisplay(type, bytes_per_row, alignment);
SaveSettings();
}

View file

@ -64,7 +64,7 @@ private:
void SaveSettings();
void OnAddressSpaceChanged();
void OnTypeChanged();
void OnDisplayChanged();
void OnBPLogChanged();
void OnBPTypeChanged();
@ -95,6 +95,9 @@ private:
QLineEdit* m_data_edit;
QCheckBox* m_base_check;
QLabel* m_data_preview;
QComboBox* m_display_combo;
QComboBox* m_align_combo;
QComboBox* m_row_length_combo;
QPushButton* m_set_value;
QPushButton* m_from_file;
QPushButton* m_dump_mram;
@ -113,13 +116,6 @@ private:
QRadioButton* m_address_space_effective;
QRadioButton* m_address_space_auxiliary;
// Datatypes
QRadioButton* m_type_u8;
QRadioButton* m_type_u16;
QRadioButton* m_type_u32;
QRadioButton* m_type_ascii;
QRadioButton* m_type_float;
// Breakpoint options
QRadioButton* m_bp_read_write;
QRadioButton* m_bp_read_only;