2018-03-16 12:39:53 +01:00
|
|
|
// Copyright 2018 Dolphin Emulator Project
|
2021-07-05 03:22:19 +02:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2018-03-16 12:39:53 +01:00
|
|
|
|
2018-07-07 00:40:15 +02:00
|
|
|
#include "DolphinQt/Debugger/MemoryViewWidget.h"
|
2018-03-16 12:39:53 +01:00
|
|
|
|
|
|
|
#include <QApplication>
|
|
|
|
#include <QClipboard>
|
|
|
|
#include <QHeaderView>
|
|
|
|
#include <QMenu>
|
|
|
|
#include <QMouseEvent>
|
|
|
|
#include <QScrollBar>
|
2022-03-28 16:08:31 -07:00
|
|
|
#include <QtGlobal>
|
2018-05-17 17:09:55 -04:00
|
|
|
|
2018-03-16 12:39:53 +01:00
|
|
|
#include <cmath>
|
|
|
|
|
2022-04-06 02:36:09 -07:00
|
|
|
#include "Common/Align.h"
|
|
|
|
#include "Common/FloatUtils.h"
|
2019-12-30 10:48:11 +01:00
|
|
|
#include "Common/StringUtil.h"
|
2018-03-16 12:39:53 +01:00
|
|
|
#include "Core/Core.h"
|
2019-07-15 23:20:26 -04:00
|
|
|
#include "Core/HW/AddressSpace.h"
|
2018-03-16 12:39:53 +01:00
|
|
|
#include "Core/PowerPC/BreakPoints.h"
|
|
|
|
#include "Core/PowerPC/PowerPC.h"
|
2020-04-15 00:12:35 +02:00
|
|
|
#include "DolphinQt/Host.h"
|
2018-07-07 00:40:15 +02:00
|
|
|
#include "DolphinQt/Resources.h"
|
|
|
|
#include "DolphinQt/Settings.h"
|
2018-03-16 12:39:53 +01:00
|
|
|
|
2018-08-19 13:29:52 +02:00
|
|
|
// "Most mouse types work in steps of 15 degrees, in which case the delta value is a multiple of
|
|
|
|
// 120; i.e., 120 units * 1/8 = 15 degrees." (http://doc.qt.io/qt-5/qwheelevent.html#angleDelta)
|
|
|
|
constexpr double SCROLL_FRACTION_DEGREES = 15.;
|
|
|
|
|
2018-03-16 12:39:53 +01:00
|
|
|
MemoryViewWidget::MemoryViewWidget(QWidget* parent) : QTableWidget(parent)
|
|
|
|
{
|
|
|
|
horizontalHeader()->hide();
|
|
|
|
verticalHeader()->hide();
|
2018-08-02 21:50:23 +02:00
|
|
|
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
2018-03-16 12:39:53 +01:00
|
|
|
setShowGrid(false);
|
|
|
|
|
2022-03-28 16:08:31 -07:00
|
|
|
setContextMenuPolicy(Qt::CustomContextMenu);
|
2018-03-16 12:39:53 +01:00
|
|
|
|
2022-03-28 16:08:31 -07:00
|
|
|
connect(&Settings::Instance(), &Settings::DebugFontChanged, this, &MemoryViewWidget::UpdateFont);
|
2018-03-16 12:39:53 +01:00
|
|
|
connect(&Settings::Instance(), &Settings::EmulationStateChanged, this, [this] { Update(); });
|
2020-04-15 00:12:35 +02:00
|
|
|
connect(Host::GetInstance(), &Host::UpdateDisasmDialog, this, &MemoryViewWidget::Update);
|
2018-03-16 12:39:53 +01:00
|
|
|
connect(this, &MemoryViewWidget::customContextMenuRequested, this,
|
|
|
|
&MemoryViewWidget::OnContextMenu);
|
2018-04-11 23:43:47 +02:00
|
|
|
connect(&Settings::Instance(), &Settings::ThemeChanged, this, &MemoryViewWidget::Update);
|
2018-03-16 12:39:53 +01:00
|
|
|
|
2022-03-28 16:08:31 -07:00
|
|
|
// Also calls update.
|
|
|
|
UpdateFont();
|
|
|
|
}
|
2018-03-16 12:39:53 +01:00
|
|
|
|
2022-03-28 16:08:31 -07:00
|
|
|
void MemoryViewWidget::UpdateFont()
|
|
|
|
{
|
|
|
|
const QFontMetrics fm(Settings::Instance().GetDebugFont());
|
|
|
|
m_font_vspace = fm.lineSpacing();
|
|
|
|
// BoundingRect is too unpredictable, a custom one would be needed for each view type. Different
|
|
|
|
// fonts have wildly different spacing between two characters and horizontalAdvance includes
|
|
|
|
// spacing.
|
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
|
|
|
|
m_font_width = fm.horizontalAdvance(QLatin1Char('0'));
|
|
|
|
#else
|
|
|
|
m_font_width = fm.width(QLatin1Char('0'));
|
|
|
|
#endif
|
|
|
|
setFont(Settings::Instance().GetDebugFont());
|
2018-03-16 12:39:53 +01:00
|
|
|
Update();
|
|
|
|
}
|
|
|
|
|
2022-04-06 02:36:09 -07:00
|
|
|
static int GetTypeSize(MemoryViewWidget::Type type)
|
2018-03-16 12:39:53 +01:00
|
|
|
{
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case MemoryViewWidget::Type::ASCII:
|
2022-04-06 02:36:09 -07:00
|
|
|
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:
|
2018-03-16 12:39:53 +01:00
|
|
|
case MemoryViewWidget::Type::Float32:
|
2018-04-16 22:30:37 +02:00
|
|
|
return 4;
|
2022-04-06 02:36:09 -07:00
|
|
|
case MemoryViewWidget::Type::Double:
|
|
|
|
return 8;
|
|
|
|
default:
|
|
|
|
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;
|
2018-04-16 22:30:37 +02:00
|
|
|
default:
|
2022-04-06 02:36:09 -07:00
|
|
|
return 8;
|
2018-03-16 12:39:53 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MemoryViewWidget::Update()
|
|
|
|
{
|
|
|
|
clearSelection();
|
|
|
|
|
2022-04-06 02:36:09 -07:00
|
|
|
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);
|
2018-03-16 12:39:53 +01:00
|
|
|
|
|
|
|
if (rowCount() == 0)
|
|
|
|
setRowCount(1);
|
|
|
|
|
2022-03-28 16:08:31 -07:00
|
|
|
// This sets all row heights and determines horizontal ascii spacing.
|
|
|
|
verticalHeader()->setDefaultSectionSize(m_font_vspace - 1);
|
|
|
|
verticalHeader()->setMinimumSectionSize(m_font_vspace - 1);
|
|
|
|
horizontalHeader()->setMinimumSectionSize(m_font_width * 2);
|
2018-03-16 12:39:53 +01:00
|
|
|
|
2019-04-11 01:50:52 -04:00
|
|
|
const AddressSpace::Accessors* accessors = AddressSpace::GetAccessors(m_address_space);
|
|
|
|
|
2018-03-16 12:39:53 +01:00
|
|
|
// Calculate (roughly) how many rows will fit in our table
|
|
|
|
int rows = std::round((height() / static_cast<float>(rowHeight(0))) - 0.25);
|
|
|
|
|
|
|
|
setRowCount(rows);
|
|
|
|
|
|
|
|
for (int i = 0; i < rows; i++)
|
|
|
|
{
|
2022-04-06 02:36:09 -07:00
|
|
|
u32 row_address = address - ((rowCount() / 2) * m_bytes_per_row) + i * m_bytes_per_row;
|
2018-03-16 12:39:53 +01:00
|
|
|
|
|
|
|
auto* bp_item = new QTableWidgetItem;
|
|
|
|
bp_item->setFlags(Qt::ItemIsEnabled);
|
2022-04-06 02:36:09 -07:00
|
|
|
bp_item->setData(Qt::UserRole, row_address);
|
2018-03-16 12:39:53 +01:00
|
|
|
|
|
|
|
setItem(i, 0, bp_item);
|
|
|
|
|
2022-04-06 02:36:09 -07:00
|
|
|
auto* row_item =
|
|
|
|
new QTableWidgetItem(QStringLiteral("%1").arg(row_address, 8, 16, QLatin1Char('0')));
|
2018-03-16 12:39:53 +01:00
|
|
|
|
2022-04-06 02:36:09 -07:00
|
|
|
row_item->setData(Qt::UserRole, row_address);
|
|
|
|
row_item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
|
2018-03-16 12:39:53 +01:00
|
|
|
|
2022-04-06 02:36:09 -07:00
|
|
|
setItem(i, 1, row_item);
|
2018-03-16 12:39:53 +01:00
|
|
|
|
2022-04-06 02:36:09 -07:00
|
|
|
if (row_address == address)
|
|
|
|
row_item->setSelected(true);
|
2018-03-16 12:39:53 +01:00
|
|
|
|
2022-04-06 02:36:09 -07:00
|
|
|
if (Core::GetState() != Core::State::Paused || !accessors->IsValidAddress(row_address))
|
2018-03-16 12:39:53 +01:00
|
|
|
{
|
|
|
|
for (int c = 2; c < columnCount(); c++)
|
|
|
|
{
|
|
|
|
auto* item = new QTableWidgetItem(QStringLiteral("-"));
|
|
|
|
item->setFlags(Qt::ItemIsEnabled);
|
2022-04-06 02:36:09 -07:00
|
|
|
item->setData(Qt::UserRole, row_address);
|
2018-03-16 12:39:53 +01:00
|
|
|
|
|
|
|
setItem(i, c, item);
|
|
|
|
}
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2018-05-31 22:07:05 +02:00
|
|
|
bool row_breakpoint = true;
|
|
|
|
|
|
|
|
auto update_values = [&](auto value_to_string) {
|
2022-04-06 02:36:09 -07:00
|
|
|
for (int c = 0; c < data_columns; c++)
|
2018-03-16 12:39:53 +01:00
|
|
|
{
|
2022-04-06 02:36:09 -07:00
|
|
|
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);
|
2018-05-31 22:07:05 +02:00
|
|
|
|
2022-04-06 02:36:09 -07:00
|
|
|
const u32 cell_address = row_address + c * GetTypeSize(m_type);
|
|
|
|
|
|
|
|
// GetMemCheck is more accurate than OverlapsMemcheck, unless standard alginments are
|
|
|
|
// enforced.
|
2019-04-11 01:50:52 -04:00
|
|
|
if (m_address_space == AddressSpace::Type::Effective &&
|
2022-04-06 02:36:09 -07:00
|
|
|
PowerPC::memchecks.GetMemCheck(cell_address, GetTypeSize(m_type)) != nullptr)
|
2019-04-11 01:50:52 -04:00
|
|
|
{
|
2022-04-06 02:36:09 -07:00
|
|
|
cell_item->setBackground(Qt::red);
|
2019-04-11 01:50:52 -04:00
|
|
|
}
|
2018-05-31 22:07:05 +02:00
|
|
|
else
|
2019-04-11 01:50:52 -04:00
|
|
|
{
|
2018-05-31 22:07:05 +02:00
|
|
|
row_breakpoint = false;
|
2019-04-11 01:50:52 -04:00
|
|
|
}
|
2022-04-06 02:36:09 -07:00
|
|
|
setItem(i, 2 + c, cell_item);
|
2018-05-31 22:07:05 +02:00
|
|
|
|
2022-04-06 02:36:09 -07:00
|
|
|
if (accessors->IsValidAddress(cell_address))
|
2018-03-16 12:39:53 +01:00
|
|
|
{
|
2022-04-06 02:36:09 -07:00
|
|
|
cell_item->setText(value_to_string(cell_address));
|
|
|
|
cell_item->setData(Qt::UserRole, cell_address);
|
2018-03-16 12:39:53 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-04-06 02:36:09 -07:00
|
|
|
cell_item->setFlags({});
|
|
|
|
cell_item->setText(QStringLiteral("-"));
|
2018-03-16 12:39:53 +01:00
|
|
|
}
|
|
|
|
}
|
2018-04-16 22:30:37 +02:00
|
|
|
};
|
|
|
|
switch (m_type)
|
|
|
|
{
|
2022-04-06 02:36:09 -07:00
|
|
|
case Type::Hex8:
|
2019-04-11 01:50:52 -04:00
|
|
|
update_values([&accessors](u32 address) {
|
|
|
|
const u8 value = accessors->ReadU8(address);
|
2018-04-16 22:30:37 +02:00
|
|
|
return QStringLiteral("%1").arg(value, 2, 16, QLatin1Char('0'));
|
|
|
|
});
|
2018-03-16 12:39:53 +01:00
|
|
|
break;
|
|
|
|
case Type::ASCII:
|
2019-04-11 01:50:52 -04:00
|
|
|
update_values([&accessors](u32 address) {
|
|
|
|
const char value = accessors->ReadU8(address);
|
2019-12-30 10:48:11 +01:00
|
|
|
return IsPrintableCharacter(value) ? QString{QChar::fromLatin1(value)} :
|
|
|
|
QString{QChar::fromLatin1('.')};
|
2018-04-16 22:30:37 +02:00
|
|
|
});
|
2018-03-16 12:39:53 +01:00
|
|
|
break;
|
2022-04-06 02:36:09 -07:00
|
|
|
case Type::Hex16:
|
2019-04-11 01:50:52 -04:00
|
|
|
update_values([&accessors](u32 address) {
|
|
|
|
const u16 value = accessors->ReadU16(address);
|
2018-04-16 22:30:37 +02:00
|
|
|
return QStringLiteral("%1").arg(value, 4, 16, QLatin1Char('0'));
|
|
|
|
});
|
2018-03-16 12:39:53 +01:00
|
|
|
break;
|
2022-04-06 02:36:09 -07:00
|
|
|
case Type::Hex32:
|
2019-04-11 01:50:52 -04:00
|
|
|
update_values([&accessors](u32 address) {
|
|
|
|
const u32 value = accessors->ReadU32(address);
|
2018-04-16 22:30:37 +02:00
|
|
|
return QStringLiteral("%1").arg(value, 8, 16, QLatin1Char('0'));
|
|
|
|
});
|
2018-03-16 12:39:53 +01:00
|
|
|
break;
|
2022-04-06 02:36:09 -07:00
|
|
|
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;
|
2018-03-16 12:39:53 +01:00
|
|
|
case Type::Float32:
|
2022-03-28 16:08:31 -07:00
|
|
|
update_values([&accessors](u32 address) {
|
|
|
|
QString string = QString::number(accessors->ReadF32(address), 'g', 4);
|
|
|
|
// Align to first digit.
|
|
|
|
if (!string.startsWith(QLatin1Char('-')))
|
|
|
|
string.prepend(QLatin1Char(' '));
|
|
|
|
|
|
|
|
return string;
|
|
|
|
});
|
2018-03-16 12:39:53 +01:00
|
|
|
break;
|
2022-04-06 02:36:09 -07:00
|
|
|
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;
|
2018-03-16 12:39:53 +01:00
|
|
|
}
|
2018-05-31 22:07:05 +02:00
|
|
|
|
|
|
|
if (row_breakpoint)
|
|
|
|
{
|
2022-03-28 16:08:31 -07:00
|
|
|
bp_item->setData(Qt::DecorationRole, Resources::GetScaledThemeIcon("debugger_breakpoint")
|
|
|
|
.pixmap(QSize(rowHeight(0) - 3, rowHeight(0) - 3)));
|
2018-05-31 22:07:05 +02:00
|
|
|
}
|
2018-03-16 12:39:53 +01:00
|
|
|
}
|
|
|
|
|
2022-03-28 16:08:31 -07:00
|
|
|
setColumnWidth(0, rowHeight(0));
|
|
|
|
|
2022-04-06 02:36:09 -07:00
|
|
|
// 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;
|
2018-03-16 12:39:53 +01:00
|
|
|
|
2022-03-28 16:08:31 -07:00
|
|
|
for (int i = 2; i < columnCount(); i++)
|
|
|
|
setColumnWidth(i, width);
|
|
|
|
|
2018-03-16 12:39:53 +01:00
|
|
|
viewport()->update();
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
2019-04-11 01:50:52 -04:00
|
|
|
void MemoryViewWidget::SetAddressSpace(AddressSpace::Type address_space)
|
|
|
|
{
|
|
|
|
if (m_address_space == address_space)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_address_space = address_space;
|
|
|
|
Update();
|
|
|
|
}
|
|
|
|
|
|
|
|
AddressSpace::Type MemoryViewWidget::GetAddressSpace() const
|
|
|
|
{
|
|
|
|
return m_address_space;
|
|
|
|
}
|
|
|
|
|
2022-04-06 02:36:09 -07:00
|
|
|
void MemoryViewWidget::SetDisplay(Type type, int bytes_per_row, int alignment)
|
2018-03-16 12:39:53 +01:00
|
|
|
{
|
|
|
|
m_type = type;
|
2022-04-06 02:36:09 -07:00
|
|
|
m_bytes_per_row = bytes_per_row;
|
|
|
|
|
|
|
|
if (alignment == 0)
|
|
|
|
m_alignment = GetTypeSize(type);
|
|
|
|
else
|
|
|
|
m_alignment = alignment;
|
|
|
|
|
2018-03-16 12:39:53 +01:00
|
|
|
Update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MemoryViewWidget::SetBPType(BPType type)
|
|
|
|
{
|
|
|
|
m_bp_type = type;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MemoryViewWidget::SetAddress(u32 address)
|
|
|
|
{
|
|
|
|
if (m_address == address)
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_address = address;
|
2022-04-06 02:36:09 -07:00
|
|
|
|
2018-03-16 12:39:53 +01:00
|
|
|
Update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MemoryViewWidget::SetBPLoggingEnabled(bool enabled)
|
|
|
|
{
|
|
|
|
m_do_log = enabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MemoryViewWidget::resizeEvent(QResizeEvent*)
|
|
|
|
{
|
|
|
|
Update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MemoryViewWidget::keyPressEvent(QKeyEvent* event)
|
|
|
|
{
|
|
|
|
switch (event->key())
|
|
|
|
{
|
|
|
|
case Qt::Key_Up:
|
2018-08-19 13:29:52 +02:00
|
|
|
m_address -= 16;
|
2018-03-16 12:39:53 +01:00
|
|
|
Update();
|
|
|
|
return;
|
|
|
|
case Qt::Key_Down:
|
2018-08-19 13:29:52 +02:00
|
|
|
m_address += 16;
|
2018-03-16 12:39:53 +01:00
|
|
|
Update();
|
|
|
|
return;
|
|
|
|
case Qt::Key_PageUp:
|
|
|
|
m_address -= rowCount() * 16;
|
|
|
|
Update();
|
|
|
|
return;
|
|
|
|
case Qt::Key_PageDown:
|
|
|
|
m_address += rowCount() * 16;
|
|
|
|
Update();
|
|
|
|
return;
|
|
|
|
default:
|
|
|
|
QWidget::keyPressEvent(event);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
u32 MemoryViewWidget::GetContextAddress() const
|
|
|
|
{
|
|
|
|
return m_context_address;
|
|
|
|
}
|
|
|
|
|
2018-05-31 22:07:05 +02:00
|
|
|
void MemoryViewWidget::ToggleRowBreakpoint(bool row)
|
2018-03-16 12:39:53 +01:00
|
|
|
{
|
2018-05-31 22:07:05 +02:00
|
|
|
TMemCheck check;
|
2018-03-16 12:39:53 +01:00
|
|
|
|
2022-04-06 02:36:09 -07:00
|
|
|
const u32 addr = row ? m_base_address : GetContextAddress();
|
|
|
|
const auto length = row ? m_bytes_per_row : GetTypeSize(m_type);
|
2018-03-16 12:39:53 +01:00
|
|
|
|
2019-04-11 01:50:52 -04:00
|
|
|
if (m_address_space == AddressSpace::Type::Effective)
|
2018-05-31 22:07:05 +02:00
|
|
|
{
|
2019-04-11 01:50:52 -04:00
|
|
|
if (!PowerPC::memchecks.OverlapsMemcheck(addr, length))
|
|
|
|
{
|
|
|
|
check.start_address = addr;
|
|
|
|
check.end_address = check.start_address + length - 1;
|
|
|
|
check.is_ranged = length > 0;
|
|
|
|
check.is_break_on_read = (m_bp_type == BPType::ReadOnly || m_bp_type == BPType::ReadWrite);
|
|
|
|
check.is_break_on_write = (m_bp_type == BPType::WriteOnly || m_bp_type == BPType::ReadWrite);
|
|
|
|
check.log_on_hit = m_do_log;
|
|
|
|
check.break_on_hit = true;
|
|
|
|
|
|
|
|
PowerPC::memchecks.Add(check);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PowerPC::memchecks.Remove(addr);
|
|
|
|
}
|
2018-03-16 12:39:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
emit BreakpointsChanged();
|
|
|
|
Update();
|
|
|
|
}
|
|
|
|
|
2018-05-31 22:07:05 +02:00
|
|
|
void MemoryViewWidget::ToggleBreakpoint()
|
|
|
|
{
|
|
|
|
ToggleRowBreakpoint(false);
|
|
|
|
}
|
|
|
|
|
2018-03-16 12:39:53 +01:00
|
|
|
void MemoryViewWidget::wheelEvent(QWheelEvent* event)
|
|
|
|
{
|
2018-08-19 13:29:52 +02:00
|
|
|
auto delta =
|
|
|
|
-static_cast<int>(std::round((event->angleDelta().y() / (SCROLL_FRACTION_DEGREES * 8))));
|
|
|
|
|
|
|
|
if (delta == 0)
|
|
|
|
return;
|
2018-03-16 12:39:53 +01:00
|
|
|
|
2018-08-19 13:29:52 +02:00
|
|
|
m_address += delta * 16;
|
2018-03-16 12:39:53 +01:00
|
|
|
Update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MemoryViewWidget::mousePressEvent(QMouseEvent* event)
|
|
|
|
{
|
2022-04-06 02:36:09 -07:00
|
|
|
auto* item_selected = itemAt(event->pos());
|
|
|
|
if (item_selected == nullptr)
|
2018-03-16 12:39:53 +01:00
|
|
|
return;
|
|
|
|
|
2022-04-06 02:36:09 -07:00
|
|
|
const u32 addr = item_selected->data(Qt::UserRole).toUInt();
|
2018-03-16 12:39:53 +01:00
|
|
|
|
|
|
|
m_context_address = addr;
|
2022-04-06 02:36:09 -07:00
|
|
|
m_base_address = item(row(item_selected), 1)->data(Qt::UserRole).toUInt();
|
2018-03-16 12:39:53 +01:00
|
|
|
|
|
|
|
switch (event->button())
|
|
|
|
{
|
|
|
|
case Qt::LeftButton:
|
2022-04-06 02:36:09 -07:00
|
|
|
if (column(item_selected) == 0)
|
2018-05-31 22:07:05 +02:00
|
|
|
ToggleRowBreakpoint(true);
|
2018-03-16 12:39:53 +01:00
|
|
|
else
|
2022-04-06 02:36:09 -07:00
|
|
|
SetAddress(m_base_address);
|
2018-03-16 12:39:53 +01:00
|
|
|
|
|
|
|
Update();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MemoryViewWidget::OnCopyAddress()
|
|
|
|
{
|
|
|
|
u32 addr = GetContextAddress();
|
|
|
|
QApplication::clipboard()->setText(QStringLiteral("%1").arg(addr, 8, 16, QLatin1Char('0')));
|
|
|
|
}
|
|
|
|
|
|
|
|
void MemoryViewWidget::OnCopyHex()
|
|
|
|
{
|
|
|
|
u32 addr = GetContextAddress();
|
|
|
|
|
2022-04-06 02:36:09 -07:00
|
|
|
const auto length = GetTypeSize(m_type);
|
2018-05-31 22:07:05 +02:00
|
|
|
|
2019-04-11 01:50:52 -04:00
|
|
|
const AddressSpace::Accessors* accessors = AddressSpace::GetAccessors(m_address_space);
|
|
|
|
u64 value = accessors->ReadU64(addr);
|
2018-03-16 12:39:53 +01:00
|
|
|
|
|
|
|
QApplication::clipboard()->setText(
|
2019-11-19 18:47:00 +00:00
|
|
|
QStringLiteral("%1").arg(value, sizeof(u64) * 2, 16, QLatin1Char('0')).left(length * 2));
|
2018-03-16 12:39:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void MemoryViewWidget::OnContextMenu()
|
|
|
|
{
|
|
|
|
auto* menu = new QMenu(this);
|
|
|
|
|
2018-07-09 10:02:10 +02:00
|
|
|
menu->addAction(tr("Copy Address"), this, &MemoryViewWidget::OnCopyAddress);
|
2018-03-16 12:39:53 +01:00
|
|
|
|
2018-07-09 10:02:10 +02:00
|
|
|
auto* copy_hex = menu->addAction(tr("Copy Hex"), this, &MemoryViewWidget::OnCopyHex);
|
2018-03-16 12:39:53 +01:00
|
|
|
|
2019-04-11 01:50:52 -04:00
|
|
|
const AddressSpace::Accessors* accessors = AddressSpace::GetAccessors(m_address_space);
|
2018-03-16 12:39:53 +01:00
|
|
|
copy_hex->setEnabled(Core::GetState() != Core::State::Uninitialized &&
|
2019-04-11 01:50:52 -04:00
|
|
|
accessors->IsValidAddress(GetContextAddress()));
|
2018-03-16 12:39:53 +01:00
|
|
|
|
|
|
|
menu->addSeparator();
|
|
|
|
|
2018-12-28 19:12:30 +01:00
|
|
|
menu->addAction(tr("Show in code"), this, [this] { emit ShowCode(GetContextAddress()); });
|
|
|
|
|
|
|
|
menu->addSeparator();
|
|
|
|
|
2021-02-17 21:12:27 +04:00
|
|
|
menu->addAction(tr("Add to watch"), this, [this] {
|
|
|
|
const u32 address = GetContextAddress();
|
|
|
|
const QString name = QStringLiteral("mem_%1").arg(address, 8, 16, QLatin1Char('0'));
|
|
|
|
emit RequestWatch(name, address);
|
|
|
|
});
|
2018-07-09 10:02:10 +02:00
|
|
|
menu->addAction(tr("Toggle Breakpoint"), this, &MemoryViewWidget::ToggleBreakpoint);
|
2018-03-16 12:39:53 +01:00
|
|
|
|
|
|
|
menu->exec(QCursor::pos());
|
|
|
|
}
|