2018-03-16 11:39:53 +00:00
|
|
|
// Copyright 2018 Dolphin Emulator Project
|
|
|
|
// Licensed under GPLv2+
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2018-07-06 22:40:15 +00:00
|
|
|
#include "DolphinQt/Debugger/MemoryWidget.h"
|
2018-03-16 11:39:53 +00:00
|
|
|
|
2019-04-11 05:50:52 +00:00
|
|
|
#include <optional>
|
2018-03-16 11:39:53 +00:00
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#include <QCheckBox>
|
|
|
|
#include <QGroupBox>
|
|
|
|
#include <QHBoxLayout>
|
|
|
|
#include <QLabel>
|
|
|
|
#include <QLineEdit>
|
|
|
|
#include <QPushButton>
|
|
|
|
#include <QRadioButton>
|
|
|
|
#include <QScrollArea>
|
|
|
|
#include <QSpacerItem>
|
|
|
|
#include <QSplitter>
|
|
|
|
#include <QTableWidget>
|
|
|
|
#include <QVBoxLayout>
|
|
|
|
|
|
|
|
#include "Common/FileUtil.h"
|
2020-09-15 10:29:41 +00:00
|
|
|
#include "Common/IOFile.h"
|
2018-03-16 11:39:53 +00:00
|
|
|
#include "Core/ConfigManager.h"
|
2020-09-13 16:03:17 +00:00
|
|
|
#include "Core/Core.h"
|
2019-07-16 03:20:26 +00:00
|
|
|
#include "Core/HW/AddressSpace.h"
|
2018-07-06 22:40:15 +00:00
|
|
|
#include "DolphinQt/Debugger/MemoryViewWidget.h"
|
2020-04-14 22:12:35 +00:00
|
|
|
#include "DolphinQt/Host.h"
|
2019-03-04 19:49:00 +00:00
|
|
|
#include "DolphinQt/QtUtils/ModalMessageBox.h"
|
2018-07-06 22:40:15 +00:00
|
|
|
#include "DolphinQt/Settings.h"
|
2018-03-16 11:39:53 +00:00
|
|
|
|
|
|
|
MemoryWidget::MemoryWidget(QWidget* parent) : QDockWidget(parent)
|
|
|
|
{
|
|
|
|
setWindowTitle(tr("Memory"));
|
2018-04-19 09:32:00 +00:00
|
|
|
setObjectName(QStringLiteral("memory"));
|
|
|
|
|
2019-02-28 20:19:04 +00:00
|
|
|
setHidden(!Settings::Instance().IsMemoryVisible() || !Settings::Instance().IsDebugModeEnabled());
|
|
|
|
|
2018-03-16 11:39:53 +00:00
|
|
|
setAllowedAreas(Qt::AllDockWidgetAreas);
|
|
|
|
|
|
|
|
CreateWidgets();
|
|
|
|
|
|
|
|
QSettings& settings = Settings::GetQSettings();
|
|
|
|
|
|
|
|
restoreGeometry(settings.value(QStringLiteral("memorywidget/geometry")).toByteArray());
|
2019-02-28 20:19:04 +00:00
|
|
|
// macOS: setHidden() needs to be evaluated before setFloating() for proper window presentation
|
|
|
|
// according to Settings
|
2018-03-16 11:39:53 +00:00
|
|
|
setFloating(settings.value(QStringLiteral("memorywidget/floating")).toBool());
|
|
|
|
m_splitter->restoreState(settings.value(QStringLiteral("codewidget/splitter")).toByteArray());
|
|
|
|
|
2020-09-12 22:53:17 +00:00
|
|
|
connect(&Settings::Instance(), &Settings::MemoryVisibilityChanged, this,
|
2018-03-16 11:39:53 +00:00
|
|
|
[this](bool visible) { setHidden(!visible); });
|
|
|
|
|
2020-09-12 22:53:17 +00:00
|
|
|
connect(&Settings::Instance(), &Settings::DebugModeToggled, this,
|
2018-03-16 11:39:53 +00:00
|
|
|
[this](bool enabled) { setHidden(!enabled || !Settings::Instance().IsMemoryVisible()); });
|
|
|
|
|
|
|
|
connect(&Settings::Instance(), &Settings::EmulationStateChanged, this, &MemoryWidget::Update);
|
2020-04-14 22:12:35 +00:00
|
|
|
connect(Host::GetInstance(), &Host::UpdateDisasmDialog, this, &MemoryWidget::Update);
|
2018-03-16 11:39:53 +00:00
|
|
|
|
|
|
|
LoadSettings();
|
|
|
|
|
|
|
|
ConnectWidgets();
|
2019-04-11 05:50:52 +00:00
|
|
|
OnAddressSpaceChanged();
|
2018-03-16 11:39:53 +00:00
|
|
|
OnTypeChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
MemoryWidget::~MemoryWidget()
|
|
|
|
{
|
|
|
|
QSettings& settings = Settings::GetQSettings();
|
|
|
|
|
|
|
|
settings.setValue(QStringLiteral("memorywidget/geometry"), saveGeometry());
|
|
|
|
settings.setValue(QStringLiteral("memorywidget/floating"), isFloating());
|
|
|
|
settings.setValue(QStringLiteral("memorywidget/splitter"), m_splitter->saveState());
|
|
|
|
|
|
|
|
SaveSettings();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MemoryWidget::CreateWidgets()
|
|
|
|
{
|
|
|
|
auto* layout = new QHBoxLayout;
|
|
|
|
|
2018-08-02 19:50:23 +00:00
|
|
|
layout->setContentsMargins(2, 2, 2, 2);
|
|
|
|
layout->setSpacing(0);
|
|
|
|
|
2018-03-16 11:39:53 +00:00
|
|
|
//// Sidebar
|
|
|
|
|
|
|
|
// Search
|
2020-09-13 16:03:17 +00:00
|
|
|
auto* m_address_splitter = new QSplitter(Qt::Horizontal);
|
|
|
|
|
2018-03-16 11:39:53 +00:00
|
|
|
m_search_address = new QLineEdit;
|
2020-09-13 16:03:17 +00:00
|
|
|
m_search_offset = new QLineEdit;
|
2018-03-16 11:39:53 +00:00
|
|
|
m_data_edit = new QLineEdit;
|
|
|
|
m_set_value = new QPushButton(tr("Set &Value"));
|
|
|
|
|
|
|
|
m_search_address->setPlaceholderText(tr("Search Address"));
|
2020-09-13 16:03:17 +00:00
|
|
|
m_search_offset->setPlaceholderText(tr("Offset"));
|
2018-03-16 11:39:53 +00:00
|
|
|
m_data_edit->setPlaceholderText(tr("Value"));
|
|
|
|
|
2020-09-13 16:03:17 +00:00
|
|
|
m_address_splitter->addWidget(m_search_address);
|
|
|
|
m_address_splitter->addWidget(m_search_offset);
|
|
|
|
m_address_splitter->setHandleWidth(1);
|
|
|
|
m_address_splitter->setCollapsible(0, false);
|
|
|
|
m_address_splitter->setStretchFactor(1, 2);
|
|
|
|
|
2018-03-16 11:39:53 +00:00
|
|
|
// Dump
|
|
|
|
m_dump_mram = new QPushButton(tr("Dump &MRAM"));
|
|
|
|
m_dump_exram = new QPushButton(tr("Dump &ExRAM"));
|
2019-04-11 05:50:52 +00:00
|
|
|
m_dump_aram = new QPushButton(tr("Dump &ARAM"));
|
2018-03-16 11:39:53 +00:00
|
|
|
m_dump_fake_vmem = new QPushButton(tr("Dump &FakeVMEM"));
|
|
|
|
|
|
|
|
// Search Options
|
|
|
|
auto* search_group = new QGroupBox(tr("Search"));
|
|
|
|
auto* search_layout = new QVBoxLayout;
|
|
|
|
search_group->setLayout(search_layout);
|
|
|
|
|
|
|
|
m_find_next = new QPushButton(tr("Find &Next"));
|
|
|
|
m_find_previous = new QPushButton(tr("Find &Previous"));
|
|
|
|
m_find_ascii = new QRadioButton(tr("ASCII"));
|
|
|
|
m_find_hex = new QRadioButton(tr("Hex"));
|
|
|
|
m_result_label = new QLabel;
|
|
|
|
|
|
|
|
search_layout->addWidget(m_find_next);
|
|
|
|
search_layout->addWidget(m_find_previous);
|
|
|
|
search_layout->addWidget(m_result_label);
|
2018-08-02 19:50:23 +00:00
|
|
|
search_layout->setSpacing(1);
|
2018-03-16 11:39:53 +00:00
|
|
|
|
2019-04-11 05:50:52 +00:00
|
|
|
// Address Space
|
|
|
|
auto* address_space_group = new QGroupBox(tr("Address Space"));
|
|
|
|
auto* address_space_layout = new QVBoxLayout;
|
|
|
|
address_space_group->setLayout(address_space_layout);
|
|
|
|
|
|
|
|
// i18n: "Effective" addresses are the addresses used directly by the CPU and may be subject to
|
|
|
|
// translation via the MMU to physical addresses.
|
|
|
|
m_address_space_effective = new QRadioButton(tr("Effective"));
|
|
|
|
// i18n: The "Auxiliary" address space is the address space of ARAM (Auxiliary RAM).
|
|
|
|
m_address_space_auxiliary = new QRadioButton(tr("Auxiliary"));
|
|
|
|
// i18n: The "Physical" address space is the address space that reflects how devices (e.g. RAM) is
|
|
|
|
// physically wired up.
|
|
|
|
m_address_space_physical = new QRadioButton(tr("Physical"));
|
|
|
|
|
|
|
|
address_space_layout->addWidget(m_address_space_effective);
|
|
|
|
address_space_layout->addWidget(m_address_space_auxiliary);
|
|
|
|
address_space_layout->addWidget(m_address_space_physical);
|
|
|
|
address_space_layout->setSpacing(1);
|
|
|
|
|
2018-03-16 11:39:53 +00:00
|
|
|
// Data Type
|
|
|
|
auto* datatype_group = new QGroupBox(tr("Data Type"));
|
|
|
|
auto* datatype_layout = new QVBoxLayout;
|
|
|
|
datatype_group->setLayout(datatype_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"));
|
|
|
|
|
|
|
|
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);
|
2018-08-02 19:50:23 +00:00
|
|
|
datatype_layout->setSpacing(1);
|
2018-03-16 11:39:53 +00:00
|
|
|
|
|
|
|
// MBP options
|
|
|
|
auto* bp_group = new QGroupBox(tr("Memory breakpoint options"));
|
|
|
|
auto* bp_layout = new QVBoxLayout;
|
|
|
|
bp_group->setLayout(bp_layout);
|
|
|
|
|
2018-04-16 17:08:58 +00:00
|
|
|
// i18n: This string is used for a radio button that represents the type of
|
|
|
|
// memory breakpoint that gets triggered when a read operation or write operation occurs.
|
|
|
|
// The string is not a command to read and write something or to allow reading and writing.
|
|
|
|
m_bp_read_write = new QRadioButton(tr("Read and write"));
|
|
|
|
// i18n: This string is used for a radio button that represents the type of
|
|
|
|
// memory breakpoint that gets triggered when a read operation occurs.
|
|
|
|
// The string does not mean "read-only" in the sense that something cannot be written to.
|
2018-03-16 11:39:53 +00:00
|
|
|
m_bp_read_only = new QRadioButton(tr("Read only"));
|
2018-04-16 17:08:58 +00:00
|
|
|
// i18n: This string is used for a radio button that represents the type of
|
|
|
|
// memory breakpoint that gets triggered when a write operation occurs.
|
|
|
|
// The string does not mean "write-only" in the sense that something cannot be read from.
|
2018-03-16 11:39:53 +00:00
|
|
|
m_bp_write_only = new QRadioButton(tr("Write only"));
|
|
|
|
m_bp_log_check = new QCheckBox(tr("Log"));
|
|
|
|
|
|
|
|
bp_layout->addWidget(m_bp_read_write);
|
|
|
|
bp_layout->addWidget(m_bp_read_only);
|
|
|
|
bp_layout->addWidget(m_bp_write_only);
|
|
|
|
bp_layout->addWidget(m_bp_log_check);
|
2018-08-02 19:50:23 +00:00
|
|
|
bp_layout->setSpacing(1);
|
2018-03-16 11:39:53 +00:00
|
|
|
|
|
|
|
// Sidebar
|
|
|
|
auto* sidebar = new QWidget;
|
|
|
|
auto* sidebar_layout = new QVBoxLayout;
|
2018-08-02 19:50:23 +00:00
|
|
|
sidebar_layout->setSpacing(1);
|
|
|
|
|
2018-03-16 11:39:53 +00:00
|
|
|
sidebar->setLayout(sidebar_layout);
|
|
|
|
|
2020-09-13 16:03:17 +00:00
|
|
|
sidebar_layout->addWidget(m_address_splitter);
|
2018-03-16 11:39:53 +00:00
|
|
|
sidebar_layout->addWidget(m_data_edit);
|
2020-09-13 16:03:17 +00:00
|
|
|
|
|
|
|
auto* types_layout = new QHBoxLayout;
|
|
|
|
types_layout->addWidget(m_find_ascii);
|
|
|
|
types_layout->addItem(new QSpacerItem(20, 1));
|
|
|
|
types_layout->addWidget(m_find_hex);
|
|
|
|
types_layout->setAlignment(Qt::AlignCenter);
|
|
|
|
sidebar_layout->addLayout(types_layout);
|
|
|
|
|
2018-03-16 11:39:53 +00:00
|
|
|
sidebar_layout->addWidget(m_set_value);
|
2020-09-13 16:03:17 +00:00
|
|
|
sidebar_layout->addItem(new QSpacerItem(1, 20));
|
2018-03-16 11:39:53 +00:00
|
|
|
sidebar_layout->addWidget(m_dump_mram);
|
|
|
|
sidebar_layout->addWidget(m_dump_exram);
|
2019-04-11 05:50:52 +00:00
|
|
|
sidebar_layout->addWidget(m_dump_aram);
|
2018-03-16 11:39:53 +00:00
|
|
|
sidebar_layout->addWidget(m_dump_fake_vmem);
|
2020-09-13 16:03:17 +00:00
|
|
|
sidebar_layout->addItem(new QSpacerItem(1, 15));
|
2018-03-16 11:39:53 +00:00
|
|
|
sidebar_layout->addWidget(search_group);
|
2019-04-11 05:50:52 +00:00
|
|
|
sidebar_layout->addWidget(address_space_group);
|
2018-03-16 11:39:53 +00:00
|
|
|
sidebar_layout->addWidget(datatype_group);
|
|
|
|
sidebar_layout->addWidget(bp_group);
|
2018-05-30 21:23:02 +00:00
|
|
|
sidebar_layout->addItem(new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Expanding));
|
2018-03-16 11:39:53 +00:00
|
|
|
|
|
|
|
// Splitter
|
|
|
|
m_splitter = new QSplitter(Qt::Horizontal);
|
|
|
|
|
|
|
|
auto* sidebar_scroll = new QScrollArea;
|
|
|
|
sidebar_scroll->setWidget(sidebar);
|
|
|
|
sidebar_scroll->setWidgetResizable(true);
|
2018-08-02 19:50:23 +00:00
|
|
|
sidebar_scroll->setFixedWidth(190);
|
2018-03-16 11:39:53 +00:00
|
|
|
|
|
|
|
m_memory_view = new MemoryViewWidget(this);
|
|
|
|
|
|
|
|
m_splitter->addWidget(m_memory_view);
|
|
|
|
m_splitter->addWidget(sidebar_scroll);
|
|
|
|
|
|
|
|
layout->addWidget(m_splitter);
|
|
|
|
|
|
|
|
auto* widget = new QWidget;
|
|
|
|
widget->setLayout(layout);
|
|
|
|
setWidget(widget);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MemoryWidget::ConnectWidgets()
|
|
|
|
{
|
|
|
|
connect(m_search_address, &QLineEdit::textChanged, this, &MemoryWidget::OnSearchAddress);
|
2020-09-13 16:03:17 +00:00
|
|
|
connect(m_search_offset, &QLineEdit::textChanged, this, &MemoryWidget::OnSearchAddress);
|
2018-03-16 11:39:53 +00:00
|
|
|
|
|
|
|
connect(m_data_edit, &QLineEdit::textChanged, this, &MemoryWidget::ValidateSearchValue);
|
|
|
|
connect(m_find_ascii, &QRadioButton::toggled, this, &MemoryWidget::ValidateSearchValue);
|
|
|
|
connect(m_find_hex, &QRadioButton::toggled, this, &MemoryWidget::ValidateSearchValue);
|
|
|
|
|
2019-07-23 22:18:58 +00:00
|
|
|
connect(m_set_value, &QPushButton::clicked, this, &MemoryWidget::OnSetValue);
|
2018-03-16 11:39:53 +00:00
|
|
|
|
2019-07-23 22:18:58 +00:00
|
|
|
connect(m_dump_mram, &QPushButton::clicked, this, &MemoryWidget::OnDumpMRAM);
|
|
|
|
connect(m_dump_exram, &QPushButton::clicked, this, &MemoryWidget::OnDumpExRAM);
|
|
|
|
connect(m_dump_aram, &QPushButton::clicked, this, &MemoryWidget::OnDumpARAM);
|
|
|
|
connect(m_dump_fake_vmem, &QPushButton::clicked, this, &MemoryWidget::OnDumpFakeVMEM);
|
2018-03-16 11:39:53 +00:00
|
|
|
|
2019-07-23 22:18:58 +00:00
|
|
|
connect(m_find_next, &QPushButton::clicked, this, &MemoryWidget::OnFindNextValue);
|
|
|
|
connect(m_find_previous, &QPushButton::clicked, this, &MemoryWidget::OnFindPreviousValue);
|
2018-03-16 11:39:53 +00:00
|
|
|
|
2019-04-11 05:50:52 +00:00
|
|
|
for (auto* radio :
|
|
|
|
{m_address_space_effective, m_address_space_auxiliary, m_address_space_physical})
|
|
|
|
{
|
|
|
|
connect(radio, &QRadioButton::toggled, this, &MemoryWidget::OnAddressSpaceChanged);
|
|
|
|
}
|
|
|
|
|
2018-03-16 11:39:53 +00:00
|
|
|
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* radio : {m_bp_read_write, m_bp_read_only, m_bp_write_only})
|
|
|
|
connect(radio, &QRadioButton::toggled, this, &MemoryWidget::OnBPTypeChanged);
|
|
|
|
|
|
|
|
connect(m_bp_log_check, &QCheckBox::toggled, this, &MemoryWidget::OnBPLogChanged);
|
|
|
|
connect(m_memory_view, &MemoryViewWidget::BreakpointsChanged, this,
|
|
|
|
&MemoryWidget::BreakpointsChanged);
|
2018-12-28 18:12:30 +00:00
|
|
|
connect(m_memory_view, &MemoryViewWidget::ShowCode, this, &MemoryWidget::ShowCode);
|
2018-03-16 11:39:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MemoryWidget::closeEvent(QCloseEvent*)
|
|
|
|
{
|
|
|
|
Settings::Instance().SetMemoryVisible(false);
|
|
|
|
}
|
|
|
|
|
2019-07-06 08:50:11 +00:00
|
|
|
void MemoryWidget::showEvent(QShowEvent* event)
|
|
|
|
{
|
|
|
|
Update();
|
|
|
|
}
|
|
|
|
|
2018-03-16 11:39:53 +00:00
|
|
|
void MemoryWidget::Update()
|
|
|
|
{
|
2019-07-06 08:50:11 +00:00
|
|
|
if (!isVisible())
|
|
|
|
return;
|
|
|
|
|
2018-03-16 11:39:53 +00:00
|
|
|
m_memory_view->Update();
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MemoryWidget::LoadSettings()
|
|
|
|
{
|
|
|
|
QSettings& settings = Settings::GetQSettings();
|
|
|
|
|
|
|
|
const bool search_ascii =
|
|
|
|
settings.value(QStringLiteral("memorywidget/searchascii"), true).toBool();
|
|
|
|
const bool search_hex = settings.value(QStringLiteral("memorywidget/searchhex"), false).toBool();
|
|
|
|
|
|
|
|
m_find_ascii->setChecked(search_ascii);
|
|
|
|
m_find_hex->setChecked(search_hex);
|
|
|
|
|
2019-04-11 05:50:52 +00:00
|
|
|
const bool address_space_effective =
|
|
|
|
settings.value(QStringLiteral("memorywidget/addrspace_effective"), true).toBool();
|
|
|
|
const bool address_space_auxiliary =
|
|
|
|
settings.value(QStringLiteral("memorywidget/addrspace_auxiliary"), false).toBool();
|
|
|
|
const bool address_space_physical =
|
|
|
|
settings.value(QStringLiteral("memorywidget/addrspace_physical"), false).toBool();
|
|
|
|
|
|
|
|
m_address_space_effective->setChecked(address_space_effective);
|
|
|
|
m_address_space_auxiliary->setChecked(address_space_auxiliary);
|
|
|
|
m_address_space_physical->setChecked(address_space_physical);
|
|
|
|
|
2018-03-16 11:39:53 +00:00
|
|
|
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();
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
bool bp_rw = settings.value(QStringLiteral("memorywidget/bpreadwrite"), true).toBool();
|
|
|
|
bool bp_r = settings.value(QStringLiteral("memorywidget/bpread"), false).toBool();
|
|
|
|
bool bp_w = settings.value(QStringLiteral("memorywidget/bpwrite"), false).toBool();
|
|
|
|
bool bp_log = settings.value(QStringLiteral("memorywidget/bplog"), true).toBool();
|
|
|
|
|
2018-09-25 22:45:18 +00:00
|
|
|
if (bp_rw)
|
|
|
|
m_memory_view->SetBPType(MemoryViewWidget::BPType::ReadWrite);
|
|
|
|
else if (bp_r)
|
|
|
|
m_memory_view->SetBPType(MemoryViewWidget::BPType::ReadOnly);
|
|
|
|
else
|
|
|
|
m_memory_view->SetBPType(MemoryViewWidget::BPType::WriteOnly);
|
|
|
|
|
2018-03-16 11:39:53 +00:00
|
|
|
m_bp_read_write->setChecked(bp_rw);
|
|
|
|
m_bp_read_only->setChecked(bp_r);
|
|
|
|
m_bp_write_only->setChecked(bp_w);
|
|
|
|
m_bp_log_check->setChecked(bp_log);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MemoryWidget::SaveSettings()
|
|
|
|
{
|
|
|
|
QSettings& settings = Settings::GetQSettings();
|
|
|
|
|
|
|
|
settings.setValue(QStringLiteral("memorywidget/searchascii"), m_find_ascii->isChecked());
|
|
|
|
settings.setValue(QStringLiteral("memorywidget/searchhex"), m_find_hex->isChecked());
|
|
|
|
|
2019-04-11 05:50:52 +00:00
|
|
|
settings.setValue(QStringLiteral("memorywidget/addrspace_effective"),
|
|
|
|
m_address_space_effective->isChecked());
|
|
|
|
settings.setValue(QStringLiteral("memorywidget/addrspace_auxiliary"),
|
|
|
|
m_address_space_auxiliary->isChecked());
|
|
|
|
settings.setValue(QStringLiteral("memorywidget/addrspace_physical"),
|
|
|
|
m_address_space_physical->isChecked());
|
|
|
|
|
2018-03-16 11:39:53 +00:00
|
|
|
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/bpreadwrite"), m_bp_read_write->isChecked());
|
|
|
|
settings.setValue(QStringLiteral("memorywidget/bpread"), m_bp_read_only->isChecked());
|
|
|
|
settings.setValue(QStringLiteral("memorywidget/bpwrite"), m_bp_write_only->isChecked());
|
|
|
|
settings.setValue(QStringLiteral("memorywidget/bplog"), m_bp_log_check->isChecked());
|
|
|
|
}
|
|
|
|
|
2019-04-11 05:50:52 +00:00
|
|
|
void MemoryWidget::OnAddressSpaceChanged()
|
|
|
|
{
|
|
|
|
AddressSpace::Type space;
|
|
|
|
|
|
|
|
if (m_address_space_effective->isChecked())
|
|
|
|
space = AddressSpace::Type::Effective;
|
|
|
|
else if (m_address_space_auxiliary->isChecked())
|
|
|
|
space = AddressSpace::Type::Auxiliary;
|
|
|
|
else
|
|
|
|
space = AddressSpace::Type::Physical;
|
|
|
|
|
|
|
|
m_memory_view->SetAddressSpace(space);
|
|
|
|
|
|
|
|
SaveSettings();
|
|
|
|
}
|
|
|
|
|
2018-03-16 11:39:53 +00:00
|
|
|
void MemoryWidget::OnTypeChanged()
|
|
|
|
{
|
|
|
|
MemoryViewWidget::Type type;
|
|
|
|
|
|
|
|
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;
|
|
|
|
else
|
|
|
|
type = MemoryViewWidget::Type::Float32;
|
|
|
|
|
|
|
|
m_memory_view->SetType(type);
|
|
|
|
|
|
|
|
SaveSettings();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MemoryWidget::OnBPLogChanged()
|
|
|
|
{
|
|
|
|
m_memory_view->SetBPLoggingEnabled(m_bp_log_check->isChecked());
|
|
|
|
SaveSettings();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MemoryWidget::OnBPTypeChanged()
|
|
|
|
{
|
|
|
|
bool read_write = m_bp_read_write->isChecked();
|
|
|
|
bool read_only = m_bp_read_only->isChecked();
|
|
|
|
|
|
|
|
MemoryViewWidget::BPType type;
|
|
|
|
|
|
|
|
if (read_write)
|
|
|
|
type = MemoryViewWidget::BPType::ReadWrite;
|
|
|
|
else if (read_only)
|
|
|
|
type = MemoryViewWidget::BPType::ReadOnly;
|
|
|
|
else
|
|
|
|
type = MemoryViewWidget::BPType::WriteOnly;
|
|
|
|
|
|
|
|
m_memory_view->SetBPType(type);
|
|
|
|
|
|
|
|
SaveSettings();
|
|
|
|
}
|
|
|
|
|
2018-12-28 18:12:30 +00:00
|
|
|
void MemoryWidget::SetAddress(u32 address)
|
|
|
|
{
|
|
|
|
m_memory_view->SetAddress(address);
|
|
|
|
Settings::Instance().SetMemoryVisible(true);
|
|
|
|
raise();
|
|
|
|
|
|
|
|
m_memory_view->setFocus();
|
|
|
|
}
|
|
|
|
|
2018-03-16 11:39:53 +00:00
|
|
|
void MemoryWidget::OnSearchAddress()
|
|
|
|
{
|
2020-09-13 16:03:17 +00:00
|
|
|
bool good_addr, good_offset;
|
|
|
|
// Returns 0 if conversion fails
|
|
|
|
const u32 addr = m_search_address->text().toUInt(&good_addr, 16);
|
|
|
|
const u32 offset = m_search_offset->text().toUInt(&good_offset, 16);
|
2018-03-16 11:39:53 +00:00
|
|
|
|
2020-09-13 16:03:17 +00:00
|
|
|
QFont addr_font, offset_font;
|
|
|
|
QPalette addr_palette, offset_palette;
|
2018-03-16 11:39:53 +00:00
|
|
|
|
2020-09-13 16:03:17 +00:00
|
|
|
if (good_addr || m_search_address->text().isEmpty())
|
2018-03-16 11:39:53 +00:00
|
|
|
{
|
2020-09-13 16:03:17 +00:00
|
|
|
if (good_addr)
|
|
|
|
m_memory_view->SetAddress(addr + offset);
|
2018-03-16 11:39:53 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-09-13 16:03:17 +00:00
|
|
|
addr_font.setBold(true);
|
|
|
|
addr_palette.setColor(QPalette::Text, Qt::red);
|
2018-03-16 11:39:53 +00:00
|
|
|
}
|
|
|
|
|
2020-09-13 16:03:17 +00:00
|
|
|
if (!good_offset && !m_search_offset->text().isEmpty())
|
|
|
|
{
|
|
|
|
offset_font.setBold(true);
|
|
|
|
offset_palette.setColor(QPalette::Text, Qt::red);
|
|
|
|
}
|
|
|
|
|
|
|
|
m_search_address->setFont(addr_font);
|
|
|
|
m_search_address->setPalette(addr_palette);
|
|
|
|
m_search_offset->setFont(offset_font);
|
|
|
|
m_search_offset->setPalette(offset_palette);
|
2018-03-16 11:39:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MemoryWidget::ValidateSearchValue()
|
|
|
|
{
|
|
|
|
QFont font;
|
|
|
|
QPalette palette;
|
|
|
|
|
|
|
|
if (m_find_hex->isChecked() && !m_data_edit->text().isEmpty())
|
|
|
|
{
|
|
|
|
bool good;
|
|
|
|
m_data_edit->text().toULongLong(&good, 16);
|
|
|
|
|
|
|
|
if (!good)
|
|
|
|
{
|
|
|
|
font.setBold(true);
|
|
|
|
palette.setColor(QPalette::Text, Qt::red);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m_data_edit->setFont(font);
|
|
|
|
m_data_edit->setPalette(palette);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MemoryWidget::OnSetValue()
|
|
|
|
{
|
2020-09-13 16:03:17 +00:00
|
|
|
if (!Core::IsRunning())
|
|
|
|
return;
|
|
|
|
|
|
|
|
bool good_address, good_offset;
|
|
|
|
// Returns 0 if conversion fails
|
2018-03-16 11:39:53 +00:00
|
|
|
u32 addr = m_search_address->text().toUInt(&good_address, 16);
|
2020-09-13 16:03:17 +00:00
|
|
|
addr += m_search_offset->text().toUInt(&good_offset, 16);
|
2018-03-16 11:39:53 +00:00
|
|
|
|
|
|
|
if (!good_address)
|
|
|
|
{
|
2019-03-04 19:49:00 +00:00
|
|
|
ModalMessageBox::critical(this, tr("Error"), tr("Bad address provided."));
|
2018-03-16 11:39:53 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-09-13 16:03:17 +00:00
|
|
|
if (!good_offset)
|
|
|
|
{
|
|
|
|
ModalMessageBox::critical(this, tr("Error"), tr("Bad offset provided."));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-03-16 11:39:53 +00:00
|
|
|
if (m_data_edit->text().isEmpty())
|
|
|
|
{
|
2019-03-04 19:49:00 +00:00
|
|
|
ModalMessageBox::critical(this, tr("Error"), tr("No value provided."));
|
2018-03-16 11:39:53 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-04-11 05:50:52 +00:00
|
|
|
AddressSpace::Accessors* accessors = AddressSpace::GetAccessors(m_memory_view->GetAddressSpace());
|
|
|
|
|
2018-03-16 11:39:53 +00:00
|
|
|
if (m_find_ascii->isChecked())
|
|
|
|
{
|
2018-05-11 01:39:56 +00:00
|
|
|
const QByteArray bytes = m_data_edit->text().toUtf8();
|
2018-03-16 11:39:53 +00:00
|
|
|
|
2018-05-11 01:39:56 +00:00
|
|
|
for (char c : bytes)
|
2019-11-19 18:47:00 +00:00
|
|
|
accessors->WriteU8(addr++, static_cast<u8>(c));
|
2018-03-16 11:39:53 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
bool good_value;
|
2019-11-19 18:47:00 +00:00
|
|
|
const QString text = m_data_edit->text();
|
|
|
|
const int length =
|
|
|
|
text.startsWith(QStringLiteral("0x"), Qt::CaseInsensitive) ? text.size() - 2 : text.size();
|
|
|
|
const u64 value = text.toULongLong(&good_value, 16);
|
2018-03-16 11:39:53 +00:00
|
|
|
|
|
|
|
if (!good_value)
|
|
|
|
{
|
2019-03-04 19:49:00 +00:00
|
|
|
ModalMessageBox::critical(this, tr("Error"), tr("Bad value provided."));
|
2018-03-16 11:39:53 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-11-19 18:47:00 +00:00
|
|
|
if (length <= 2)
|
2018-03-16 11:39:53 +00:00
|
|
|
{
|
2019-05-10 22:16:27 +00:00
|
|
|
accessors->WriteU8(addr, static_cast<u8>(value));
|
2018-03-16 11:39:53 +00:00
|
|
|
}
|
2019-11-19 18:47:00 +00:00
|
|
|
else if (length <= 4)
|
2018-03-16 11:39:53 +00:00
|
|
|
{
|
2019-05-10 22:16:27 +00:00
|
|
|
accessors->WriteU16(addr, static_cast<u16>(value));
|
2018-03-16 11:39:53 +00:00
|
|
|
}
|
2019-11-19 18:47:00 +00:00
|
|
|
else if (length <= 8)
|
2018-03-16 11:39:53 +00:00
|
|
|
{
|
2019-05-10 22:16:27 +00:00
|
|
|
accessors->WriteU32(addr, static_cast<u32>(value));
|
2018-03-16 11:39:53 +00:00
|
|
|
}
|
|
|
|
else
|
2019-05-10 22:16:27 +00:00
|
|
|
accessors->WriteU64(addr, value);
|
2018-03-16 11:39:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Update();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void DumpArray(const std::string& filename, const u8* data, size_t length)
|
|
|
|
{
|
|
|
|
if (!data)
|
|
|
|
return;
|
|
|
|
|
|
|
|
File::IOFile f(filename, "wb");
|
|
|
|
|
|
|
|
if (!f)
|
|
|
|
{
|
2019-03-04 19:49:00 +00:00
|
|
|
ModalMessageBox::critical(
|
2018-03-16 11:39:53 +00:00
|
|
|
nullptr, QObject::tr("Error"),
|
|
|
|
QObject::tr("Failed to dump %1: Can't open file").arg(QString::fromStdString(filename)));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!f.WriteBytes(data, length))
|
|
|
|
{
|
2019-03-04 19:49:00 +00:00
|
|
|
ModalMessageBox::critical(nullptr, QObject::tr("Error"),
|
|
|
|
QObject::tr("Failed to dump %1: Failed to write to file")
|
|
|
|
.arg(QString::fromStdString(filename)));
|
2018-03-16 11:39:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MemoryWidget::OnDumpMRAM()
|
|
|
|
{
|
2019-04-11 05:50:52 +00:00
|
|
|
AddressSpace::Accessors* accessors = AddressSpace::GetAccessors(AddressSpace::Type::Mem1);
|
|
|
|
DumpArray(File::GetUserPath(F_MEM1DUMP_IDX), accessors->begin(),
|
|
|
|
std::distance(accessors->begin(), accessors->end()));
|
2018-03-16 11:39:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MemoryWidget::OnDumpExRAM()
|
|
|
|
{
|
2019-04-11 05:50:52 +00:00
|
|
|
AddressSpace::Accessors* accessors = AddressSpace::GetAccessors(AddressSpace::Type::Mem2);
|
|
|
|
DumpArray(File::GetUserPath(F_MEM2DUMP_IDX), accessors->begin(),
|
|
|
|
std::distance(accessors->begin(), accessors->end()));
|
|
|
|
}
|
|
|
|
|
|
|
|
void MemoryWidget::OnDumpARAM()
|
|
|
|
{
|
|
|
|
AddressSpace::Accessors* accessors = AddressSpace::GetAccessors(AddressSpace::Type::Auxiliary);
|
|
|
|
DumpArray(File::GetUserPath(F_ARAMDUMP_IDX), accessors->begin(),
|
|
|
|
std::distance(accessors->begin(), accessors->end()));
|
2018-03-16 11:39:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MemoryWidget::OnDumpFakeVMEM()
|
|
|
|
{
|
2019-04-11 05:50:52 +00:00
|
|
|
AddressSpace::Accessors* accessors = AddressSpace::GetAccessors(AddressSpace::Type::Fake);
|
|
|
|
DumpArray(File::GetUserPath(F_FAKEVMEMDUMP_IDX), accessors->begin(),
|
|
|
|
std::distance(accessors->begin(), accessors->end()));
|
2018-03-16 11:39:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<u8> MemoryWidget::GetValueData() const
|
|
|
|
{
|
|
|
|
std::vector<u8> search_for; // Series of bytes we want to look for
|
|
|
|
|
|
|
|
if (m_find_ascii->isChecked())
|
|
|
|
{
|
2018-05-11 01:39:56 +00:00
|
|
|
const QByteArray bytes = m_data_edit->text().toUtf8();
|
|
|
|
search_for.assign(bytes.begin(), bytes.end());
|
2018-03-16 11:39:53 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
bool good;
|
|
|
|
u64 value = m_data_edit->text().toULongLong(&good, 16);
|
|
|
|
|
|
|
|
if (!good)
|
|
|
|
return {};
|
|
|
|
|
|
|
|
int size;
|
|
|
|
|
|
|
|
if (value == static_cast<u8>(value))
|
|
|
|
size = sizeof(u8);
|
|
|
|
else if (value == static_cast<u16>(value))
|
|
|
|
size = sizeof(u16);
|
|
|
|
else if (value == static_cast<u32>(value))
|
|
|
|
size = sizeof(u32);
|
|
|
|
else
|
|
|
|
size = sizeof(u64);
|
|
|
|
|
|
|
|
for (int i = size - 1; i >= 0; i--)
|
|
|
|
search_for.push_back((value >> (i * 8)) & 0xFF);
|
|
|
|
}
|
|
|
|
|
|
|
|
return search_for;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MemoryWidget::FindValue(bool next)
|
|
|
|
{
|
|
|
|
std::vector<u8> search_for = GetValueData();
|
|
|
|
|
|
|
|
if (search_for.empty())
|
2018-05-06 00:44:35 +00:00
|
|
|
{
|
|
|
|
m_result_label->setText(tr("No Value Given"));
|
2018-03-16 11:39:53 +00:00
|
|
|
return;
|
2018-05-06 00:44:35 +00:00
|
|
|
}
|
2018-03-16 11:39:53 +00:00
|
|
|
u32 addr = 0;
|
|
|
|
|
|
|
|
if (!m_search_address->text().isEmpty())
|
|
|
|
{
|
2019-04-11 05:50:52 +00:00
|
|
|
// skip the quoted address so we don't potentially refind the last result
|
2020-09-13 16:03:17 +00:00
|
|
|
addr = m_search_address->text().toUInt(nullptr, 16) +
|
|
|
|
m_search_offset->text().toUInt(nullptr, 16) + (next ? 1 : -1);
|
2018-03-16 11:39:53 +00:00
|
|
|
}
|
|
|
|
|
2019-04-11 05:50:52 +00:00
|
|
|
AddressSpace::Accessors* accessors = AddressSpace::GetAccessors(m_memory_view->GetAddressSpace());
|
2018-03-16 11:39:53 +00:00
|
|
|
|
2019-04-11 05:50:52 +00:00
|
|
|
auto found_addr =
|
|
|
|
accessors->Search(addr, search_for.data(), static_cast<u32>(search_for.size()), next);
|
2018-03-16 11:39:53 +00:00
|
|
|
|
2019-04-11 05:50:52 +00:00
|
|
|
if (found_addr.has_value())
|
2018-03-16 11:39:53 +00:00
|
|
|
{
|
|
|
|
m_result_label->setText(tr("Match Found"));
|
|
|
|
|
2019-04-11 05:50:52 +00:00
|
|
|
u32 offset = *found_addr;
|
2018-03-16 11:39:53 +00:00
|
|
|
|
|
|
|
m_search_address->setText(QStringLiteral("%1").arg(offset, 8, 16, QLatin1Char('0')));
|
2020-09-13 16:03:17 +00:00
|
|
|
m_search_offset->clear();
|
2018-03-16 11:39:53 +00:00
|
|
|
|
|
|
|
m_memory_view->SetAddress(offset);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_result_label->setText(tr("No Match"));
|
|
|
|
}
|
|
|
|
|
|
|
|
void MemoryWidget::OnFindNextValue()
|
|
|
|
{
|
|
|
|
FindValue(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MemoryWidget::OnFindPreviousValue()
|
|
|
|
{
|
|
|
|
FindValue(false);
|
|
|
|
}
|