2018-03-16 11:39:53 +00:00
|
|
|
// Copyright 2018 Dolphin Emulator Project
|
2021-07-05 01:22:19 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2018-03-16 11:39:53 +00:00
|
|
|
|
2018-07-06 22:40:15 +00:00
|
|
|
#include "DolphinQt/Debugger/MemoryViewWidget.h"
|
2018-03-16 11:39:53 +00:00
|
|
|
|
|
|
|
#include <QApplication>
|
|
|
|
#include <QClipboard>
|
2022-04-25 05:03:26 +00:00
|
|
|
#include <QHBoxLayout>
|
2018-03-16 11:39:53 +00:00
|
|
|
#include <QHeaderView>
|
|
|
|
#include <QMenu>
|
|
|
|
#include <QMouseEvent>
|
|
|
|
#include <QScrollBar>
|
2022-04-25 05:03:26 +00:00
|
|
|
#include <QTableWidget>
|
2022-03-28 23:08:31 +00:00
|
|
|
#include <QtGlobal>
|
2018-05-17 21:09:55 +00:00
|
|
|
|
2018-03-16 11:39:53 +00:00
|
|
|
#include <cmath>
|
|
|
|
|
2022-04-06 09:36:09 +00:00
|
|
|
#include "Common/Align.h"
|
|
|
|
#include "Common/FloatUtils.h"
|
2019-12-30 09:48:11 +00:00
|
|
|
#include "Common/StringUtil.h"
|
2018-03-16 11:39:53 +00:00
|
|
|
#include "Core/Core.h"
|
2019-07-16 03:20:26 +00:00
|
|
|
#include "Core/HW/AddressSpace.h"
|
2018-03-16 11:39:53 +00:00
|
|
|
#include "Core/PowerPC/BreakPoints.h"
|
|
|
|
#include "Core/PowerPC/PowerPC.h"
|
2020-04-14 22:12:35 +00:00
|
|
|
#include "DolphinQt/Host.h"
|
2018-07-06 22:40:15 +00:00
|
|
|
#include "DolphinQt/Resources.h"
|
|
|
|
#include "DolphinQt/Settings.h"
|
2018-03-16 11:39:53 +00:00
|
|
|
|
2018-08-19 11:29:52 +00: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.;
|
|
|
|
|
2022-04-24 04:30:40 +00:00
|
|
|
constexpr auto USER_ROLE_IS_ROW_BREAKPOINT_CELL = Qt::UserRole;
|
|
|
|
constexpr auto USER_ROLE_CELL_ADDRESS = Qt::UserRole + 1;
|
|
|
|
constexpr auto USER_ROLE_HAS_VALUE = Qt::UserRole + 2;
|
|
|
|
|
2022-04-26 00:13:18 +00:00
|
|
|
// Numbers for the scrollbar. These affect how much big the draggable part of the scrollbar is, how
|
|
|
|
// smooth it scrolls, and how much memory it traverses while dragging.
|
|
|
|
constexpr int SCROLLBAR_MINIMUM = 0;
|
|
|
|
constexpr int SCROLLBAR_PAGESTEP = 250;
|
|
|
|
constexpr int SCROLLBAR_MAXIMUM = 20000;
|
|
|
|
constexpr int SCROLLBAR_CENTER = SCROLLBAR_MAXIMUM / 2;
|
|
|
|
|
2022-04-25 05:03:26 +00:00
|
|
|
class MemoryViewTable final : public QTableWidget
|
2018-03-16 11:39:53 +00:00
|
|
|
{
|
2022-04-25 05:03:26 +00:00
|
|
|
public:
|
|
|
|
explicit MemoryViewTable(MemoryViewWidget* parent) : QTableWidget(parent), m_view(parent)
|
|
|
|
{
|
|
|
|
horizontalHeader()->hide();
|
|
|
|
verticalHeader()->hide();
|
|
|
|
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
|
|
|
setShowGrid(false);
|
|
|
|
setContextMenuPolicy(Qt::CustomContextMenu);
|
|
|
|
|
|
|
|
connect(this, &MemoryViewTable::customContextMenuRequested, m_view,
|
|
|
|
&MemoryViewWidget::OnContextMenu);
|
|
|
|
}
|
|
|
|
|
|
|
|
void resizeEvent(QResizeEvent*) override { m_view->Update(); }
|
|
|
|
|
|
|
|
void keyPressEvent(QKeyEvent* event) override
|
|
|
|
{
|
|
|
|
switch (event->key())
|
|
|
|
{
|
|
|
|
case Qt::Key_Up:
|
|
|
|
m_view->m_address -= m_view->m_bytes_per_row;
|
|
|
|
m_view->Update();
|
|
|
|
return;
|
|
|
|
case Qt::Key_Down:
|
|
|
|
m_view->m_address += m_view->m_bytes_per_row;
|
|
|
|
m_view->Update();
|
|
|
|
return;
|
|
|
|
case Qt::Key_PageUp:
|
|
|
|
m_view->m_address -= this->rowCount() * m_view->m_bytes_per_row;
|
|
|
|
m_view->Update();
|
|
|
|
return;
|
|
|
|
case Qt::Key_PageDown:
|
|
|
|
m_view->m_address += this->rowCount() * m_view->m_bytes_per_row;
|
|
|
|
m_view->Update();
|
|
|
|
return;
|
|
|
|
default:
|
|
|
|
QWidget::keyPressEvent(event);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void wheelEvent(QWheelEvent* event) override
|
|
|
|
{
|
|
|
|
auto delta =
|
|
|
|
-static_cast<int>(std::round((event->angleDelta().y() / (SCROLL_FRACTION_DEGREES * 8))));
|
2018-03-16 11:39:53 +00:00
|
|
|
|
2022-04-25 05:03:26 +00:00
|
|
|
if (delta == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_view->m_address += delta * m_view->m_bytes_per_row;
|
|
|
|
m_view->Update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void mousePressEvent(QMouseEvent* event) override
|
|
|
|
{
|
|
|
|
if (event->button() != Qt::LeftButton)
|
|
|
|
return;
|
|
|
|
|
|
|
|
auto* item = this->itemAt(event->pos());
|
|
|
|
if (!item)
|
|
|
|
return;
|
|
|
|
|
|
|
|
const u32 address = item->data(USER_ROLE_CELL_ADDRESS).toUInt();
|
|
|
|
if (item->data(USER_ROLE_IS_ROW_BREAKPOINT_CELL).toBool())
|
|
|
|
m_view->ToggleBreakpoint(address, true);
|
|
|
|
else
|
|
|
|
m_view->SetAddress(address);
|
|
|
|
m_view->Update();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
MemoryViewWidget* m_view;
|
|
|
|
};
|
|
|
|
|
|
|
|
MemoryViewWidget::MemoryViewWidget(QWidget* parent) : QWidget(parent)
|
|
|
|
{
|
|
|
|
auto* layout = new QHBoxLayout();
|
|
|
|
layout->setContentsMargins(0, 0, 0, 0);
|
|
|
|
|
|
|
|
m_table = new MemoryViewTable(this);
|
|
|
|
layout->addWidget(m_table);
|
|
|
|
|
2022-04-26 00:13:18 +00:00
|
|
|
// Since the Memory View is infinitely long -- it wraps around -- we can't use a normal scroll
|
|
|
|
// bar, so this initializes a custom one that is always centered but otherwise still behaves more
|
|
|
|
// or less like a regular scrollbar.
|
|
|
|
m_scrollbar = new QScrollBar(this);
|
|
|
|
m_scrollbar->setRange(SCROLLBAR_MINIMUM, SCROLLBAR_MAXIMUM);
|
|
|
|
m_scrollbar->setPageStep(SCROLLBAR_PAGESTEP);
|
|
|
|
m_scrollbar->setValue(SCROLLBAR_CENTER);
|
|
|
|
connect(m_scrollbar, &QScrollBar::actionTriggered, this,
|
|
|
|
&MemoryViewWidget::ScrollbarActionTriggered);
|
|
|
|
connect(m_scrollbar, &QScrollBar::sliderReleased, this,
|
|
|
|
&MemoryViewWidget::ScrollbarSliderReleased);
|
|
|
|
layout->addWidget(m_scrollbar);
|
|
|
|
|
2022-04-25 05:03:26 +00:00
|
|
|
this->setLayout(layout);
|
2018-03-16 11:39:53 +00:00
|
|
|
|
2022-03-28 23:08:31 +00:00
|
|
|
connect(&Settings::Instance(), &Settings::DebugFontChanged, this, &MemoryViewWidget::UpdateFont);
|
2018-03-16 11:39:53 +00:00
|
|
|
connect(&Settings::Instance(), &Settings::EmulationStateChanged, this, [this] { Update(); });
|
2020-04-14 22:12:35 +00:00
|
|
|
connect(Host::GetInstance(), &Host::UpdateDisasmDialog, this, &MemoryViewWidget::Update);
|
2018-04-11 21:43:47 +00:00
|
|
|
connect(&Settings::Instance(), &Settings::ThemeChanged, this, &MemoryViewWidget::Update);
|
2018-03-16 11:39:53 +00:00
|
|
|
|
2022-03-28 23:08:31 +00:00
|
|
|
// Also calls update.
|
|
|
|
UpdateFont();
|
|
|
|
}
|
2018-03-16 11:39:53 +00:00
|
|
|
|
2022-03-28 23:08:31 +00: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
|
2022-04-25 05:03:26 +00:00
|
|
|
m_table->setFont(Settings::Instance().GetDebugFont());
|
2018-03-16 11:39:53 +00:00
|
|
|
Update();
|
|
|
|
}
|
|
|
|
|
2022-04-17 07:47:05 +00:00
|
|
|
constexpr int GetTypeSize(MemoryViewWidget::Type type)
|
2018-03-16 11:39:53 +00:00
|
|
|
{
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case MemoryViewWidget::Type::ASCII:
|
2022-04-06 09:36:09 +00: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 11:39:53 +00:00
|
|
|
case MemoryViewWidget::Type::Float32:
|
2018-04-16 20:30:37 +00:00
|
|
|
return 4;
|
2022-04-06 09:36:09 +00:00
|
|
|
case MemoryViewWidget::Type::Double:
|
2022-04-17 07:47:05 +00:00
|
|
|
case MemoryViewWidget::Type::Hex64:
|
2022-04-06 09:36:09 +00:00
|
|
|
return 8;
|
|
|
|
default:
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-17 07:47:05 +00:00
|
|
|
constexpr int GetCharacterCount(MemoryViewWidget::Type type)
|
2022-04-06 09:36:09 +00:00
|
|
|
{
|
2022-04-07 05:50:05 +00:00
|
|
|
// Max number of characters +1 for spacing between columns.
|
2022-04-06 09:36:09 +00:00
|
|
|
switch (type)
|
|
|
|
{
|
2022-04-17 07:47:05 +00:00
|
|
|
case MemoryViewWidget::Type::ASCII: // A
|
2022-04-06 09:36:09 +00:00
|
|
|
return 2;
|
2022-04-17 07:47:05 +00:00
|
|
|
case MemoryViewWidget::Type::Hex8: // Byte = FF
|
2022-04-06 09:36:09 +00:00
|
|
|
return 3;
|
2022-04-17 07:47:05 +00:00
|
|
|
case MemoryViewWidget::Type::Unsigned8: // UCHAR_MAX = 255
|
2022-04-07 05:50:05 +00:00
|
|
|
return 4;
|
2022-04-17 07:47:05 +00:00
|
|
|
case MemoryViewWidget::Type::Hex16: // 2 Bytes = FFFF
|
|
|
|
case MemoryViewWidget::Type::Signed8: // CHAR_MIN = -128
|
2022-04-06 09:36:09 +00:00
|
|
|
return 5;
|
2022-04-17 07:47:05 +00:00
|
|
|
case MemoryViewWidget::Type::Unsigned16: // USHORT_MAX = 65535
|
2022-04-06 09:36:09 +00:00
|
|
|
return 6;
|
2022-04-17 07:47:05 +00:00
|
|
|
case MemoryViewWidget::Type::Signed16: // SHORT_MIN = -32768
|
2022-04-07 05:50:05 +00:00
|
|
|
return 7;
|
2022-04-17 07:47:05 +00:00
|
|
|
case MemoryViewWidget::Type::Hex32: // 4 Bytes = FFFFFFFF
|
2022-04-06 09:36:09 +00:00
|
|
|
return 9;
|
2022-04-17 07:47:05 +00:00
|
|
|
case MemoryViewWidget::Type::Float32: // Rounded and Negative FLT_MAX = -3.403e+38
|
|
|
|
case MemoryViewWidget::Type::Unsigned32: // UINT_MAX = 4294967295
|
2022-04-07 05:50:05 +00:00
|
|
|
return 11;
|
2022-04-17 07:47:05 +00:00
|
|
|
case MemoryViewWidget::Type::Double: // Rounded and Negative DBL_MAX = -1.798e+308
|
|
|
|
case MemoryViewWidget::Type::Signed32: // INT_MIN = -2147483648
|
2022-04-07 05:50:05 +00:00
|
|
|
return 12;
|
2022-04-17 07:47:05 +00:00
|
|
|
case MemoryViewWidget::Type::Hex64: // For dual_view + Double. 8 Bytes = FFFFFFFFFFFFFFFF
|
|
|
|
return 17;
|
2018-04-16 20:30:37 +00:00
|
|
|
default:
|
2022-04-07 05:50:05 +00:00
|
|
|
return 10;
|
2018-03-16 11:39:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MemoryViewWidget::Update()
|
|
|
|
{
|
2022-04-25 05:03:26 +00:00
|
|
|
m_table->clearSelection();
|
2018-03-16 11:39:53 +00:00
|
|
|
|
2022-04-06 09:36:09 +00:00
|
|
|
u32 address = m_address;
|
|
|
|
address = Common::AlignDown(address, m_alignment);
|
|
|
|
|
|
|
|
const int data_columns = m_bytes_per_row / GetTypeSize(m_type);
|
|
|
|
|
2022-04-07 05:50:05 +00:00
|
|
|
if (m_dual_view)
|
2022-04-25 05:03:26 +00:00
|
|
|
m_table->setColumnCount(2 + 2 * data_columns);
|
2022-04-07 05:50:05 +00:00
|
|
|
else
|
2022-04-25 05:03:26 +00:00
|
|
|
m_table->setColumnCount(2 + data_columns);
|
2018-03-16 11:39:53 +00:00
|
|
|
|
2022-04-25 05:03:26 +00:00
|
|
|
if (m_table->rowCount() == 0)
|
|
|
|
m_table->setRowCount(1);
|
2018-03-16 11:39:53 +00:00
|
|
|
|
2022-03-28 23:08:31 +00:00
|
|
|
// This sets all row heights and determines horizontal ascii spacing.
|
2022-04-25 05:03:26 +00:00
|
|
|
m_table->verticalHeader()->setDefaultSectionSize(m_font_vspace - 1);
|
|
|
|
m_table->verticalHeader()->setMinimumSectionSize(m_font_vspace - 1);
|
|
|
|
m_table->horizontalHeader()->setMinimumSectionSize(m_font_width * 2);
|
2018-03-16 11:39:53 +00:00
|
|
|
|
2019-04-11 05:50:52 +00:00
|
|
|
const AddressSpace::Accessors* accessors = AddressSpace::GetAccessors(m_address_space);
|
|
|
|
|
2018-03-16 11:39:53 +00:00
|
|
|
// Calculate (roughly) how many rows will fit in our table
|
2022-04-25 05:03:26 +00:00
|
|
|
const int rows =
|
|
|
|
std::round((m_table->height() / static_cast<float>(m_table->rowHeight(0))) - 0.25);
|
2018-03-16 11:39:53 +00:00
|
|
|
|
2022-04-25 05:03:26 +00:00
|
|
|
m_table->setRowCount(rows);
|
2018-03-16 11:39:53 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < rows; i++)
|
|
|
|
{
|
2022-04-25 05:03:26 +00:00
|
|
|
u32 row_address = address - ((m_table->rowCount() / 2) * m_bytes_per_row) + i * m_bytes_per_row;
|
2018-03-16 11:39:53 +00:00
|
|
|
|
|
|
|
auto* bp_item = new QTableWidgetItem;
|
|
|
|
bp_item->setFlags(Qt::ItemIsEnabled);
|
2022-04-24 04:30:40 +00:00
|
|
|
bp_item->setData(USER_ROLE_IS_ROW_BREAKPOINT_CELL, true);
|
|
|
|
bp_item->setData(USER_ROLE_CELL_ADDRESS, row_address);
|
|
|
|
bp_item->setData(USER_ROLE_HAS_VALUE, false);
|
2018-03-16 11:39:53 +00:00
|
|
|
|
2022-04-25 05:03:26 +00:00
|
|
|
m_table->setItem(i, 0, bp_item);
|
2018-03-16 11:39:53 +00:00
|
|
|
|
2022-04-06 09:36:09 +00:00
|
|
|
auto* row_item =
|
|
|
|
new QTableWidgetItem(QStringLiteral("%1").arg(row_address, 8, 16, QLatin1Char('0')));
|
2018-03-16 11:39:53 +00:00
|
|
|
|
2022-04-06 09:36:09 +00:00
|
|
|
row_item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
|
2022-04-24 04:30:40 +00:00
|
|
|
row_item->setData(USER_ROLE_IS_ROW_BREAKPOINT_CELL, false);
|
|
|
|
row_item->setData(USER_ROLE_CELL_ADDRESS, row_address);
|
|
|
|
row_item->setData(USER_ROLE_HAS_VALUE, false);
|
2018-03-16 11:39:53 +00:00
|
|
|
|
2022-04-25 05:03:26 +00:00
|
|
|
m_table->setItem(i, 1, row_item);
|
2018-03-16 11:39:53 +00:00
|
|
|
|
2022-04-06 09:36:09 +00:00
|
|
|
if (row_address == address)
|
|
|
|
row_item->setSelected(true);
|
2018-03-16 11:39:53 +00:00
|
|
|
|
2022-04-06 09:36:09 +00:00
|
|
|
if (Core::GetState() != Core::State::Paused || !accessors->IsValidAddress(row_address))
|
2018-03-16 11:39:53 +00:00
|
|
|
{
|
2022-04-25 05:03:26 +00:00
|
|
|
for (int c = 2; c < m_table->columnCount(); c++)
|
2018-03-16 11:39:53 +00:00
|
|
|
{
|
|
|
|
auto* item = new QTableWidgetItem(QStringLiteral("-"));
|
|
|
|
item->setFlags(Qt::ItemIsEnabled);
|
2022-04-24 04:30:40 +00:00
|
|
|
item->setData(USER_ROLE_IS_ROW_BREAKPOINT_CELL, false);
|
|
|
|
item->setData(USER_ROLE_CELL_ADDRESS, row_address);
|
|
|
|
item->setData(USER_ROLE_HAS_VALUE, false);
|
2018-03-16 11:39:53 +00:00
|
|
|
|
2022-04-25 05:03:26 +00:00
|
|
|
m_table->setItem(i, c, item);
|
2018-03-16 11:39:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
2022-04-07 05:50:05 +00:00
|
|
|
}
|
2018-03-16 11:39:53 +00:00
|
|
|
|
2022-04-07 05:50:05 +00:00
|
|
|
int starting_column = 2;
|
|
|
|
|
|
|
|
if (m_dual_view)
|
|
|
|
{
|
|
|
|
// Match left columns to number of right columns.
|
|
|
|
Type left_type = Type::Hex32;
|
|
|
|
if (GetTypeSize(m_type) == 1)
|
|
|
|
left_type = Type::Hex8;
|
|
|
|
else if (GetTypeSize(m_type) == 2)
|
|
|
|
left_type = Type::Hex16;
|
2022-04-17 07:47:05 +00:00
|
|
|
else if (GetTypeSize(m_type) == 8)
|
|
|
|
left_type = Type::Hex64;
|
2022-04-07 05:50:05 +00:00
|
|
|
|
|
|
|
UpdateColumns(left_type, starting_column);
|
|
|
|
|
2022-04-17 07:47:05 +00:00
|
|
|
const int column_count = m_bytes_per_row / GetTypeSize(left_type);
|
2022-04-07 05:50:05 +00:00
|
|
|
|
|
|
|
// Update column width
|
2022-04-17 07:47:05 +00:00
|
|
|
for (int i = starting_column; i < starting_column + column_count - 1; i++)
|
2022-04-25 05:03:26 +00:00
|
|
|
m_table->setColumnWidth(i, m_font_width * GetCharacterCount(left_type));
|
2022-04-07 05:50:05 +00:00
|
|
|
|
2022-04-17 07:47:05 +00:00
|
|
|
// Extra spacing between dual views.
|
2022-04-25 05:03:26 +00:00
|
|
|
m_table->setColumnWidth(starting_column + column_count - 1,
|
|
|
|
m_font_width * (GetCharacterCount(left_type) + 2));
|
2022-04-17 07:47:05 +00:00
|
|
|
|
2022-04-07 05:50:05 +00:00
|
|
|
starting_column += column_count;
|
|
|
|
}
|
|
|
|
|
|
|
|
UpdateColumns(m_type, starting_column);
|
|
|
|
UpdateBreakpointTags();
|
|
|
|
|
2022-04-25 05:03:26 +00:00
|
|
|
m_table->setColumnWidth(0, m_table->rowHeight(0));
|
2022-04-07 05:50:05 +00:00
|
|
|
|
2022-04-25 05:03:26 +00:00
|
|
|
for (int i = starting_column; i <= m_table->columnCount(); i++)
|
|
|
|
m_table->setColumnWidth(i, m_font_width * GetCharacterCount(m_type));
|
2022-04-07 05:50:05 +00:00
|
|
|
|
2022-04-25 05:03:26 +00:00
|
|
|
m_table->viewport()->update();
|
|
|
|
m_table->update();
|
2022-04-07 05:50:05 +00:00
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MemoryViewWidget::UpdateColumns(Type type, int first_column)
|
|
|
|
{
|
2022-04-17 07:47:05 +00:00
|
|
|
if (Core::GetState() != Core::State::Paused)
|
|
|
|
return;
|
|
|
|
|
2022-04-07 05:50:05 +00:00
|
|
|
const int data_columns = m_bytes_per_row / GetTypeSize(type);
|
|
|
|
const AddressSpace::Accessors* accessors = AddressSpace::GetAccessors(m_address_space);
|
|
|
|
|
|
|
|
auto text_alignment = Qt::AlignLeft;
|
|
|
|
if (type == Type::Signed32 || type == Type::Unsigned32 || type == Type::Signed16 ||
|
|
|
|
type == Type::Unsigned16 || type == Type::Signed8 || type == Type::Unsigned8)
|
2022-04-17 07:47:05 +00:00
|
|
|
{
|
2022-04-07 05:50:05 +00:00
|
|
|
text_alignment = Qt::AlignRight;
|
2022-04-17 07:47:05 +00:00
|
|
|
}
|
2022-04-07 05:50:05 +00:00
|
|
|
|
2022-04-25 05:03:26 +00:00
|
|
|
for (int i = 0; i < m_table->rowCount(); i++)
|
2022-04-07 05:50:05 +00:00
|
|
|
{
|
2022-04-25 05:03:26 +00:00
|
|
|
u32 row_address = m_table->item(i, 1)->data(USER_ROLE_CELL_ADDRESS).toUInt();
|
2022-04-07 05:50:05 +00:00
|
|
|
if (!accessors->IsValidAddress(row_address))
|
|
|
|
continue;
|
2018-05-31 20:07:05 +00:00
|
|
|
|
|
|
|
auto update_values = [&](auto value_to_string) {
|
2022-04-06 09:36:09 +00:00
|
|
|
for (int c = 0; c < data_columns; c++)
|
2018-03-16 11:39:53 +00:00
|
|
|
{
|
2022-04-06 09:36:09 +00:00
|
|
|
auto* cell_item = new QTableWidgetItem;
|
|
|
|
cell_item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
|
2022-04-07 05:50:05 +00:00
|
|
|
cell_item->setTextAlignment(text_alignment);
|
2022-04-06 09:36:09 +00:00
|
|
|
|
2022-04-07 05:50:05 +00:00
|
|
|
const u32 cell_address = row_address + c * GetTypeSize(type);
|
2022-04-06 09:36:09 +00:00
|
|
|
|
2022-04-25 05:03:26 +00:00
|
|
|
m_table->setItem(i, first_column + c, cell_item);
|
2018-05-31 20:07:05 +00:00
|
|
|
|
2022-04-06 09:36:09 +00:00
|
|
|
if (accessors->IsValidAddress(cell_address))
|
2018-03-16 11:39:53 +00:00
|
|
|
{
|
2022-04-06 09:36:09 +00:00
|
|
|
cell_item->setText(value_to_string(cell_address));
|
2022-04-24 04:30:40 +00:00
|
|
|
cell_item->setData(USER_ROLE_IS_ROW_BREAKPOINT_CELL, false);
|
|
|
|
cell_item->setData(USER_ROLE_CELL_ADDRESS, cell_address);
|
|
|
|
cell_item->setData(USER_ROLE_HAS_VALUE, true);
|
2018-03-16 11:39:53 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-04-06 09:36:09 +00:00
|
|
|
cell_item->setFlags({});
|
|
|
|
cell_item->setText(QStringLiteral("-"));
|
2022-04-24 04:30:40 +00:00
|
|
|
cell_item->setData(USER_ROLE_IS_ROW_BREAKPOINT_CELL, false);
|
|
|
|
cell_item->setData(USER_ROLE_CELL_ADDRESS, cell_address);
|
|
|
|
cell_item->setData(USER_ROLE_HAS_VALUE, false);
|
2018-03-16 11:39:53 +00:00
|
|
|
}
|
|
|
|
}
|
2018-04-16 20:30:37 +00:00
|
|
|
};
|
2022-04-07 05:50:05 +00:00
|
|
|
switch (type)
|
2018-04-16 20:30:37 +00:00
|
|
|
{
|
2022-04-06 09:36:09 +00:00
|
|
|
case Type::Hex8:
|
2019-04-11 05:50:52 +00:00
|
|
|
update_values([&accessors](u32 address) {
|
|
|
|
const u8 value = accessors->ReadU8(address);
|
2018-04-16 20:30:37 +00:00
|
|
|
return QStringLiteral("%1").arg(value, 2, 16, QLatin1Char('0'));
|
|
|
|
});
|
2018-03-16 11:39:53 +00:00
|
|
|
break;
|
|
|
|
case Type::ASCII:
|
2019-04-11 05:50:52 +00:00
|
|
|
update_values([&accessors](u32 address) {
|
|
|
|
const char value = accessors->ReadU8(address);
|
2019-12-30 09:48:11 +00:00
|
|
|
return IsPrintableCharacter(value) ? QString{QChar::fromLatin1(value)} :
|
|
|
|
QString{QChar::fromLatin1('.')};
|
2018-04-16 20:30:37 +00:00
|
|
|
});
|
2018-03-16 11:39:53 +00:00
|
|
|
break;
|
2022-04-06 09:36:09 +00:00
|
|
|
case Type::Hex16:
|
2019-04-11 05:50:52 +00:00
|
|
|
update_values([&accessors](u32 address) {
|
|
|
|
const u16 value = accessors->ReadU16(address);
|
2018-04-16 20:30:37 +00:00
|
|
|
return QStringLiteral("%1").arg(value, 4, 16, QLatin1Char('0'));
|
|
|
|
});
|
2018-03-16 11:39:53 +00:00
|
|
|
break;
|
2022-04-06 09:36:09 +00:00
|
|
|
case Type::Hex32:
|
2019-04-11 05:50:52 +00:00
|
|
|
update_values([&accessors](u32 address) {
|
|
|
|
const u32 value = accessors->ReadU32(address);
|
2018-04-16 20:30:37 +00:00
|
|
|
return QStringLiteral("%1").arg(value, 8, 16, QLatin1Char('0'));
|
|
|
|
});
|
2018-03-16 11:39:53 +00:00
|
|
|
break;
|
2022-04-17 07:47:05 +00:00
|
|
|
case Type::Hex64:
|
|
|
|
update_values([&accessors](u32 address) {
|
|
|
|
const u64 value = accessors->ReadU64(address);
|
|
|
|
return QStringLiteral("%1").arg(value, 16, 16, QLatin1Char('0'));
|
|
|
|
});
|
|
|
|
break;
|
2022-04-06 09:36:09 +00: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 11:39:53 +00:00
|
|
|
case Type::Float32:
|
2022-03-28 23:08:31 +00: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 11:39:53 +00:00
|
|
|
break;
|
2022-04-06 09:36:09 +00: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 11:39:53 +00:00
|
|
|
}
|
|
|
|
}
|
2022-04-07 05:50:05 +00:00
|
|
|
}
|
2018-03-16 11:39:53 +00:00
|
|
|
|
2022-04-07 05:50:05 +00:00
|
|
|
void MemoryViewWidget::UpdateBreakpointTags()
|
|
|
|
{
|
2022-04-17 07:47:05 +00:00
|
|
|
if (Core::GetState() != Core::State::Paused)
|
|
|
|
return;
|
|
|
|
|
2022-04-25 05:03:26 +00:00
|
|
|
for (int i = 0; i < m_table->rowCount(); i++)
|
2022-04-07 05:50:05 +00:00
|
|
|
{
|
2022-04-17 07:47:05 +00:00
|
|
|
bool row_breakpoint = false;
|
2022-03-28 23:08:31 +00:00
|
|
|
|
2022-04-25 05:03:26 +00:00
|
|
|
for (int c = 2; c < m_table->columnCount(); c++)
|
2022-04-07 05:50:05 +00:00
|
|
|
{
|
|
|
|
// Pull address from cell itself, helpful for dual column view.
|
2022-04-25 05:03:26 +00:00
|
|
|
auto cell = m_table->item(i, c);
|
2022-04-24 04:30:40 +00:00
|
|
|
u32 address = cell->data(USER_ROLE_CELL_ADDRESS).toUInt();
|
2022-04-06 09:36:09 +00:00
|
|
|
|
2022-04-07 05:50:05 +00:00
|
|
|
if (address == 0)
|
|
|
|
{
|
|
|
|
row_breakpoint = false;
|
|
|
|
continue;
|
|
|
|
}
|
2018-03-16 11:39:53 +00:00
|
|
|
|
2022-04-07 05:50:05 +00:00
|
|
|
// In dual view the only sizes that dont match up on both left and right views are for
|
2022-04-17 07:47:05 +00:00
|
|
|
// Double, which uses two or four columns of hex32.
|
2022-04-07 05:50:05 +00:00
|
|
|
if (m_address_space == AddressSpace::Type::Effective &&
|
2022-04-17 07:47:05 +00:00
|
|
|
PowerPC::memchecks.GetMemCheck(address, GetTypeSize(m_type)) != nullptr)
|
2022-04-07 05:50:05 +00:00
|
|
|
{
|
2022-04-17 07:47:05 +00:00
|
|
|
row_breakpoint = true;
|
2022-04-07 05:50:05 +00:00
|
|
|
cell->setBackground(Qt::red);
|
|
|
|
}
|
|
|
|
}
|
2022-04-17 07:47:05 +00:00
|
|
|
|
2022-04-07 05:50:05 +00:00
|
|
|
if (row_breakpoint)
|
|
|
|
{
|
2022-04-25 05:03:26 +00:00
|
|
|
m_table->item(i, 0)->setData(
|
|
|
|
Qt::DecorationRole,
|
|
|
|
Resources::GetScaledThemeIcon("debugger_breakpoint")
|
|
|
|
.pixmap(QSize(m_table->rowHeight(0) - 3, m_table->rowHeight(0) - 3)));
|
2022-04-07 05:50:05 +00:00
|
|
|
}
|
|
|
|
}
|
2018-03-16 11:39:53 +00:00
|
|
|
}
|
|
|
|
|
2019-04-11 05:50:52 +00: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-25 05:03:26 +00:00
|
|
|
void MemoryViewWidget::SetDisplay(Type type, int bytes_per_row, int alignment, bool dual_view)
|
2018-03-16 11:39:53 +00:00
|
|
|
{
|
|
|
|
m_type = type;
|
2022-04-06 09:36:09 +00:00
|
|
|
m_bytes_per_row = bytes_per_row;
|
2022-04-07 05:50:05 +00:00
|
|
|
m_dual_view = dual_view;
|
2022-04-06 09:36:09 +00:00
|
|
|
if (alignment == 0)
|
|
|
|
m_alignment = GetTypeSize(type);
|
|
|
|
else
|
|
|
|
m_alignment = alignment;
|
|
|
|
|
2018-03-16 11:39:53 +00: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 09:36:09 +00:00
|
|
|
|
2018-03-16 11:39:53 +00:00
|
|
|
Update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MemoryViewWidget::SetBPLoggingEnabled(bool enabled)
|
|
|
|
{
|
|
|
|
m_do_log = enabled;
|
|
|
|
}
|
|
|
|
|
2022-04-24 04:25:42 +00:00
|
|
|
void MemoryViewWidget::ToggleBreakpoint(u32 addr, bool row)
|
2018-03-16 11:39:53 +00:00
|
|
|
{
|
2022-04-17 07:47:05 +00:00
|
|
|
if (m_address_space != AddressSpace::Type::Effective)
|
|
|
|
return;
|
2018-03-16 11:39:53 +00:00
|
|
|
|
2022-04-17 07:47:05 +00:00
|
|
|
const auto length = GetTypeSize(m_type);
|
|
|
|
const int breaks = row ? (m_bytes_per_row / length) : 1;
|
|
|
|
bool overlap = false;
|
|
|
|
|
|
|
|
// Row breakpoint should either remove any breakpoint left on the row, or activate all
|
|
|
|
// breakpoints.
|
|
|
|
if (row && PowerPC::memchecks.OverlapsMemcheck(addr, m_bytes_per_row))
|
|
|
|
overlap = true;
|
2018-03-16 11:39:53 +00:00
|
|
|
|
2022-04-17 07:47:05 +00:00
|
|
|
for (int i = 0; i < breaks; i++)
|
2018-05-31 20:07:05 +00:00
|
|
|
{
|
2022-04-17 07:47:05 +00:00
|
|
|
u32 address = addr + length * i;
|
|
|
|
TMemCheck* check_ptr = PowerPC::memchecks.GetMemCheck(address, length);
|
|
|
|
|
|
|
|
if (check_ptr == nullptr && !overlap)
|
2019-04-11 05:50:52 +00:00
|
|
|
{
|
2022-04-17 07:47:05 +00:00
|
|
|
TMemCheck check;
|
|
|
|
check.start_address = address;
|
2019-04-11 05:50:52 +00:00
|
|
|
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);
|
|
|
|
}
|
2022-04-17 07:47:05 +00:00
|
|
|
else if (check_ptr != nullptr)
|
2019-04-11 05:50:52 +00:00
|
|
|
{
|
2022-04-17 07:47:05 +00:00
|
|
|
// Using the pointer fixes misaligned breakpoints (0x11 breakpoint in 0x10 aligned view).
|
|
|
|
PowerPC::memchecks.Remove(check_ptr->start_address);
|
2019-04-11 05:50:52 +00:00
|
|
|
}
|
2018-03-16 11:39:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
emit BreakpointsChanged();
|
|
|
|
Update();
|
|
|
|
}
|
|
|
|
|
2022-04-24 04:25:42 +00:00
|
|
|
void MemoryViewWidget::OnCopyAddress(u32 addr)
|
2018-03-16 11:39:53 +00:00
|
|
|
{
|
|
|
|
QApplication::clipboard()->setText(QStringLiteral("%1").arg(addr, 8, 16, QLatin1Char('0')));
|
|
|
|
}
|
|
|
|
|
2022-04-24 04:25:42 +00:00
|
|
|
void MemoryViewWidget::OnCopyHex(u32 addr)
|
2018-03-16 11:39:53 +00:00
|
|
|
{
|
2022-04-06 09:36:09 +00:00
|
|
|
const auto length = GetTypeSize(m_type);
|
2018-05-31 20:07:05 +00:00
|
|
|
|
2019-04-11 05:50:52 +00:00
|
|
|
const AddressSpace::Accessors* accessors = AddressSpace::GetAccessors(m_address_space);
|
|
|
|
u64 value = accessors->ReadU64(addr);
|
2018-03-16 11:39:53 +00: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 11:39:53 +00:00
|
|
|
}
|
|
|
|
|
2022-04-24 04:25:42 +00:00
|
|
|
void MemoryViewWidget::OnContextMenu(const QPoint& pos)
|
2018-03-16 11:39:53 +00:00
|
|
|
{
|
2022-04-25 05:03:26 +00:00
|
|
|
auto* item_selected = m_table->itemAt(pos);
|
2022-04-24 04:25:42 +00:00
|
|
|
|
2022-04-24 04:30:40 +00:00
|
|
|
// We don't have a meaningful context menu to show for when the user right-clicks either free
|
|
|
|
// space in the table or the row breakpoint cell.
|
|
|
|
if (!item_selected || item_selected->data(USER_ROLE_IS_ROW_BREAKPOINT_CELL).toBool())
|
2022-04-24 04:25:42 +00:00
|
|
|
return;
|
|
|
|
|
2022-04-24 04:30:40 +00:00
|
|
|
const bool item_has_value = item_selected->data(USER_ROLE_HAS_VALUE).toBool();
|
|
|
|
const u32 addr = item_selected->data(USER_ROLE_CELL_ADDRESS).toUInt();
|
2022-04-24 04:25:42 +00:00
|
|
|
|
2018-03-16 11:39:53 +00:00
|
|
|
auto* menu = new QMenu(this);
|
|
|
|
|
2022-04-24 04:25:42 +00:00
|
|
|
menu->addAction(tr("Copy Address"), this, [this, addr] { OnCopyAddress(addr); });
|
2018-03-16 11:39:53 +00:00
|
|
|
|
2022-04-24 04:25:42 +00:00
|
|
|
auto* copy_hex = menu->addAction(tr("Copy Hex"), this, [this, addr] { OnCopyHex(addr); });
|
2018-03-16 11:39:53 +00:00
|
|
|
|
2019-04-11 05:50:52 +00:00
|
|
|
const AddressSpace::Accessors* accessors = AddressSpace::GetAccessors(m_address_space);
|
2022-04-24 04:30:40 +00:00
|
|
|
copy_hex->setEnabled(item_has_value && Core::GetState() != Core::State::Uninitialized &&
|
2022-04-24 04:25:42 +00:00
|
|
|
accessors->IsValidAddress(addr));
|
2018-03-16 11:39:53 +00:00
|
|
|
|
2022-04-24 04:30:40 +00:00
|
|
|
auto* copy_value = menu->addAction(tr("Copy Value"), this, [this, &pos] {
|
|
|
|
// Re-fetch the item in case the underlying table has refreshed since the menu was opened.
|
2022-04-25 05:03:26 +00:00
|
|
|
auto* item = m_table->itemAt(pos);
|
2022-04-24 04:30:40 +00:00
|
|
|
if (item && item->data(USER_ROLE_HAS_VALUE).toBool())
|
|
|
|
QApplication::clipboard()->setText(item->text());
|
|
|
|
});
|
|
|
|
copy_value->setEnabled(item_has_value);
|
|
|
|
|
2018-03-16 11:39:53 +00:00
|
|
|
menu->addSeparator();
|
|
|
|
|
2022-04-24 04:25:42 +00:00
|
|
|
menu->addAction(tr("Show in code"), this, [this, addr] { emit ShowCode(addr); });
|
2018-12-28 18:12:30 +00:00
|
|
|
|
|
|
|
menu->addSeparator();
|
|
|
|
|
2022-04-24 04:25:42 +00:00
|
|
|
menu->addAction(tr("Add to watch"), this, [this, addr] {
|
|
|
|
const QString name = QStringLiteral("mem_%1").arg(addr, 8, 16, QLatin1Char('0'));
|
|
|
|
emit RequestWatch(name, addr);
|
2021-02-17 17:12:27 +00:00
|
|
|
});
|
2022-04-24 04:25:42 +00:00
|
|
|
|
|
|
|
menu->addAction(tr("Toggle Breakpoint"), this, [this, addr] { ToggleBreakpoint(addr, false); });
|
2018-03-16 11:39:53 +00:00
|
|
|
|
|
|
|
menu->exec(QCursor::pos());
|
|
|
|
}
|
2022-04-26 00:13:18 +00:00
|
|
|
|
|
|
|
void MemoryViewWidget::ScrollbarActionTriggered(int action)
|
|
|
|
{
|
|
|
|
const int difference = m_scrollbar->sliderPosition() - m_scrollbar->value();
|
|
|
|
if (difference == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (m_scrollbar->isSliderDown())
|
|
|
|
{
|
|
|
|
// User is currently dragging the scrollbar.
|
|
|
|
// Adjust the memory view by the exact drag difference.
|
|
|
|
SetAddress(m_address + difference * m_bytes_per_row);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (std::abs(difference) == 1)
|
|
|
|
{
|
|
|
|
// User clicked the arrows at the top or bottom, go up/down one row.
|
|
|
|
SetAddress(m_address + difference * m_bytes_per_row);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// User clicked the free part of the scrollbar, go up/down one page.
|
|
|
|
SetAddress(m_address + (difference < 0 ? -1 : 1) * m_bytes_per_row * m_table->rowCount());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Manually reset the draggable part of the bar back to the center.
|
|
|
|
m_scrollbar->setSliderPosition(SCROLLBAR_CENTER);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MemoryViewWidget::ScrollbarSliderReleased()
|
|
|
|
{
|
|
|
|
// Reset the draggable part of the bar back to the center.
|
|
|
|
m_scrollbar->setValue(SCROLLBAR_CENTER);
|
|
|
|
}
|