2017-09-27 06:53:05 +00:00
|
|
|
// Copyright 2017 Dolphin Emulator Project
|
|
|
|
// Licensed under GPLv2+
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2018-07-06 22:40:15 +00:00
|
|
|
#include "DolphinQt/Debugger/WatchWidget.h"
|
2017-09-27 06:53:05 +00:00
|
|
|
|
|
|
|
#include "Common/FileUtil.h"
|
|
|
|
#include "Common/IniFile.h"
|
|
|
|
#include "Core/ConfigManager.h"
|
|
|
|
#include "Core/Core.h"
|
2018-05-17 21:09:55 +00:00
|
|
|
#include "Core/PowerPC/MMU.h"
|
2017-09-27 06:53:05 +00:00
|
|
|
#include "Core/PowerPC/PowerPC.h"
|
2018-04-11 21:43:47 +00:00
|
|
|
|
2018-07-06 22:40:15 +00:00
|
|
|
#include "DolphinQt/Resources.h"
|
|
|
|
#include "DolphinQt/Settings.h"
|
2017-09-27 06:53:05 +00:00
|
|
|
|
|
|
|
#include <QHeaderView>
|
|
|
|
#include <QMenu>
|
|
|
|
#include <QMessageBox>
|
|
|
|
#include <QTableWidget>
|
|
|
|
#include <QToolBar>
|
|
|
|
#include <QVBoxLayout>
|
|
|
|
|
|
|
|
WatchWidget::WatchWidget(QWidget* parent) : QDockWidget(parent)
|
|
|
|
{
|
2018-01-21 15:25:58 +00:00
|
|
|
// i18n: This kind of "watch" is used for watching emulated memory.
|
|
|
|
// It's not related to timekeeping devices.
|
2017-09-27 06:53:05 +00:00
|
|
|
setWindowTitle(tr("Watch"));
|
2018-04-19 09:32:00 +00:00
|
|
|
setObjectName(QStringLiteral("watch"));
|
|
|
|
|
2017-09-27 06:53:05 +00:00
|
|
|
setAllowedAreas(Qt::AllDockWidgetAreas);
|
|
|
|
|
2018-03-23 11:10:53 +00:00
|
|
|
auto& settings = Settings::GetQSettings();
|
2017-09-27 06:53:05 +00:00
|
|
|
|
|
|
|
restoreGeometry(settings.value(QStringLiteral("watchwidget/geometry")).toByteArray());
|
|
|
|
setFloating(settings.value(QStringLiteral("watchwidget/floating")).toBool());
|
|
|
|
|
|
|
|
CreateWidgets();
|
|
|
|
ConnectWidgets();
|
|
|
|
|
|
|
|
connect(&Settings::Instance(), &Settings::EmulationStateChanged, [this](Core::State state) {
|
|
|
|
if (!Settings::Instance().IsDebugModeEnabled())
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_load->setEnabled(Core::IsRunning());
|
|
|
|
m_save->setEnabled(Core::IsRunning());
|
|
|
|
|
|
|
|
if (state != Core::State::Starting)
|
|
|
|
Update();
|
|
|
|
});
|
|
|
|
|
|
|
|
connect(&Settings::Instance(), &Settings::WatchVisibilityChanged,
|
|
|
|
[this](bool visible) { setHidden(!visible); });
|
|
|
|
|
|
|
|
connect(&Settings::Instance(), &Settings::DebugModeToggled,
|
|
|
|
[this](bool enabled) { setHidden(!enabled || !Settings::Instance().IsWatchVisible()); });
|
|
|
|
|
2018-04-11 21:43:47 +00:00
|
|
|
connect(&Settings::Instance(), &Settings::ThemeChanged, this, &WatchWidget::UpdateIcons);
|
|
|
|
UpdateIcons();
|
|
|
|
|
2017-09-27 06:53:05 +00:00
|
|
|
setHidden(!Settings::Instance().IsWatchVisible() || !Settings::Instance().IsDebugModeEnabled());
|
|
|
|
|
|
|
|
Update();
|
|
|
|
}
|
|
|
|
|
|
|
|
WatchWidget::~WatchWidget()
|
|
|
|
{
|
2018-03-23 11:10:53 +00:00
|
|
|
auto& settings = Settings::GetQSettings();
|
2017-09-27 06:53:05 +00:00
|
|
|
|
|
|
|
settings.setValue(QStringLiteral("watchwidget/geometry"), saveGeometry());
|
|
|
|
settings.setValue(QStringLiteral("watchwidget/floating"), isFloating());
|
|
|
|
}
|
|
|
|
|
|
|
|
void WatchWidget::CreateWidgets()
|
|
|
|
{
|
|
|
|
m_toolbar = new QToolBar;
|
2018-08-02 19:50:23 +00:00
|
|
|
m_toolbar->setContentsMargins(0, 0, 0, 0);
|
2018-04-11 21:43:47 +00:00
|
|
|
m_toolbar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
|
|
|
|
|
2017-09-27 06:53:05 +00:00
|
|
|
m_table = new QTableWidget;
|
|
|
|
|
2018-08-02 19:50:23 +00:00
|
|
|
m_table->setContentsMargins(0, 0, 0, 0);
|
2017-09-27 06:53:05 +00:00
|
|
|
m_table->setColumnCount(5);
|
|
|
|
m_table->verticalHeader()->setHidden(true);
|
|
|
|
m_table->setContextMenuPolicy(Qt::CustomContextMenu);
|
|
|
|
m_table->setSelectionMode(QAbstractItemView::SingleSelection);
|
|
|
|
|
2018-07-09 08:02:10 +00:00
|
|
|
m_load = m_toolbar->addAction(tr("Load"), this, &WatchWidget::OnLoad);
|
|
|
|
m_save = m_toolbar->addAction(tr("Save"), this, &WatchWidget::OnSave);
|
2017-09-27 06:53:05 +00:00
|
|
|
|
|
|
|
m_load->setEnabled(false);
|
|
|
|
m_save->setEnabled(false);
|
|
|
|
|
|
|
|
auto* layout = new QVBoxLayout;
|
2018-08-02 19:50:23 +00:00
|
|
|
layout->setContentsMargins(2, 2, 2, 2);
|
|
|
|
layout->setSpacing(0);
|
2017-09-27 06:53:05 +00:00
|
|
|
layout->addWidget(m_toolbar);
|
|
|
|
layout->addWidget(m_table);
|
|
|
|
|
|
|
|
QWidget* widget = new QWidget;
|
|
|
|
widget->setLayout(layout);
|
|
|
|
|
|
|
|
setWidget(widget);
|
|
|
|
}
|
|
|
|
|
|
|
|
void WatchWidget::ConnectWidgets()
|
|
|
|
{
|
|
|
|
connect(m_table, &QTableWidget::customContextMenuRequested, this, &WatchWidget::ShowContextMenu);
|
|
|
|
connect(m_table, &QTableWidget::itemChanged, this, &WatchWidget::OnItemChanged);
|
|
|
|
}
|
|
|
|
|
2018-04-11 21:43:47 +00:00
|
|
|
void WatchWidget::UpdateIcons()
|
|
|
|
{
|
|
|
|
m_load->setIcon(Resources::GetScaledThemeIcon("debugger_load"));
|
|
|
|
m_save->setIcon(Resources::GetScaledThemeIcon("debugger_save"));
|
|
|
|
}
|
|
|
|
|
2017-09-27 06:53:05 +00:00
|
|
|
void WatchWidget::Update()
|
|
|
|
{
|
|
|
|
m_updating = true;
|
|
|
|
|
|
|
|
m_table->clear();
|
|
|
|
|
2018-01-29 16:58:02 +00:00
|
|
|
int size = static_cast<int>(PowerPC::debug_interface.GetWatches().size());
|
2017-09-27 06:53:05 +00:00
|
|
|
|
|
|
|
m_table->setRowCount(size + 1);
|
|
|
|
|
2018-09-08 13:58:15 +00:00
|
|
|
m_table->setHorizontalHeaderLabels(
|
|
|
|
{tr("Label"), tr("Address"), tr("Hexadecimal"),
|
|
|
|
// i18n: The base 10 numeral system. Not related to non-integer numbers
|
|
|
|
tr("Decimal"),
|
|
|
|
// i18n: Data type used in computing
|
|
|
|
tr("String")});
|
2017-09-27 06:53:05 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < size; i++)
|
|
|
|
{
|
2018-01-29 16:58:02 +00:00
|
|
|
auto entry = PowerPC::debug_interface.GetWatch(i);
|
2017-09-27 06:53:05 +00:00
|
|
|
|
|
|
|
auto* label = new QTableWidgetItem(QString::fromStdString(entry.name));
|
|
|
|
auto* address =
|
|
|
|
new QTableWidgetItem(QStringLiteral("%1").arg(entry.address, 8, 16, QLatin1Char('0')));
|
|
|
|
auto* hex = new QTableWidgetItem;
|
|
|
|
auto* decimal = new QTableWidgetItem;
|
|
|
|
auto* string = new QTableWidgetItem;
|
|
|
|
|
|
|
|
QBrush brush = QPalette().brush(QPalette::Text);
|
|
|
|
|
|
|
|
if (!Core::IsRunning() || !PowerPC::HostIsRAMAddress(entry.address))
|
|
|
|
brush.setColor(Qt::red);
|
|
|
|
|
|
|
|
if (Core::IsRunning())
|
|
|
|
{
|
|
|
|
if (PowerPC::HostIsRAMAddress(entry.address))
|
|
|
|
{
|
|
|
|
hex->setText(QStringLiteral("%1").arg(PowerPC::HostRead_U32(entry.address), 8, 16,
|
|
|
|
QLatin1Char('0')));
|
|
|
|
decimal->setText(QString::number(PowerPC::HostRead_U32(entry.address)));
|
|
|
|
string->setText(QString::fromStdString(PowerPC::HostGetString(entry.address, 32)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
address->setForeground(brush);
|
|
|
|
|
|
|
|
int column = 0;
|
|
|
|
|
|
|
|
for (auto* item : {label, address, hex, decimal, string})
|
|
|
|
{
|
|
|
|
item->setData(Qt::UserRole, i);
|
|
|
|
item->setData(Qt::UserRole + 1, column++);
|
|
|
|
}
|
|
|
|
|
|
|
|
string->setFlags(Qt::ItemIsEnabled);
|
|
|
|
|
|
|
|
m_table->setItem(i, 0, label);
|
|
|
|
m_table->setItem(i, 1, address);
|
|
|
|
m_table->setItem(i, 2, hex);
|
|
|
|
m_table->setItem(i, 3, decimal);
|
|
|
|
m_table->setItem(i, 4, string);
|
|
|
|
}
|
|
|
|
|
|
|
|
auto* label = new QTableWidgetItem;
|
|
|
|
label->setData(Qt::UserRole, -1);
|
|
|
|
|
|
|
|
m_table->setItem(size, 0, label);
|
|
|
|
|
|
|
|
for (int i = 1; i < 5; i++)
|
|
|
|
{
|
|
|
|
auto* no_edit = new QTableWidgetItem;
|
|
|
|
no_edit->setFlags(Qt::ItemIsEnabled);
|
|
|
|
m_table->setItem(size, i, no_edit);
|
|
|
|
}
|
|
|
|
|
|
|
|
m_updating = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void WatchWidget::closeEvent(QCloseEvent*)
|
|
|
|
{
|
|
|
|
Settings::Instance().SetWatchVisible(false);
|
|
|
|
}
|
2017-10-03 16:43:44 +00:00
|
|
|
|
2017-09-27 06:53:05 +00:00
|
|
|
void WatchWidget::OnLoad()
|
|
|
|
{
|
|
|
|
IniFile ini;
|
|
|
|
|
2018-01-29 16:58:02 +00:00
|
|
|
std::vector<std::string> watches;
|
2017-09-27 06:53:05 +00:00
|
|
|
|
|
|
|
if (!ini.Load(File::GetUserPath(D_GAMESETTINGS_IDX) + SConfig::GetInstance().GetGameID() + ".ini",
|
|
|
|
false))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ini.GetLines("Watches", &watches, false))
|
|
|
|
{
|
2018-01-29 16:58:02 +00:00
|
|
|
PowerPC::debug_interface.ClearWatches();
|
|
|
|
PowerPC::debug_interface.LoadWatchesFromStrings(watches);
|
2017-09-27 06:53:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void WatchWidget::OnSave()
|
|
|
|
{
|
|
|
|
IniFile ini;
|
|
|
|
ini.Load(File::GetUserPath(D_GAMESETTINGS_IDX) + SConfig::GetInstance().GetGameID() + ".ini",
|
|
|
|
false);
|
2018-01-29 16:58:02 +00:00
|
|
|
ini.SetLines("Watches", PowerPC::debug_interface.SaveWatchesToStrings());
|
2017-09-27 06:53:05 +00:00
|
|
|
ini.Save(File::GetUserPath(D_GAMESETTINGS_IDX) + SConfig::GetInstance().GetGameID() + ".ini");
|
|
|
|
}
|
|
|
|
|
|
|
|
void WatchWidget::ShowContextMenu()
|
|
|
|
{
|
|
|
|
QMenu* menu = new QMenu(this);
|
|
|
|
|
2019-02-12 22:47:17 +00:00
|
|
|
if (!m_table->selectedItems().empty())
|
2017-09-27 06:53:05 +00:00
|
|
|
{
|
|
|
|
auto row_variant = m_table->selectedItems()[0]->data(Qt::UserRole);
|
|
|
|
|
|
|
|
if (!row_variant.isNull())
|
|
|
|
{
|
|
|
|
int row = row_variant.toInt();
|
|
|
|
|
|
|
|
if (row >= 0)
|
|
|
|
{
|
2018-01-21 15:25:58 +00:00
|
|
|
// i18n: This kind of "watch" is used for watching emulated memory.
|
|
|
|
// It's not related to timekeeping devices.
|
2018-07-09 08:02:10 +00:00
|
|
|
menu->addAction(tr("&Delete Watch"), this, [this, row] { DeleteWatch(row); });
|
|
|
|
menu->addAction(tr("&Add Memory Breakpoint"), this,
|
|
|
|
[this, row] { AddWatchBreakpoint(row); });
|
2017-09-27 06:53:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
menu->addSeparator();
|
|
|
|
|
2018-07-09 08:02:10 +00:00
|
|
|
menu->addAction(tr("Update"), this, &WatchWidget::Update);
|
2017-09-27 06:53:05 +00:00
|
|
|
|
|
|
|
menu->exec(QCursor::pos());
|
|
|
|
}
|
|
|
|
|
|
|
|
void WatchWidget::OnItemChanged(QTableWidgetItem* item)
|
|
|
|
{
|
|
|
|
if (m_updating || item->data(Qt::UserRole).isNull())
|
|
|
|
return;
|
|
|
|
|
|
|
|
int row = item->data(Qt::UserRole).toInt();
|
|
|
|
int column = item->data(Qt::UserRole + 1).toInt();
|
|
|
|
|
|
|
|
if (row == -1)
|
|
|
|
{
|
|
|
|
if (!item->text().isEmpty())
|
|
|
|
{
|
|
|
|
AddWatch(item->text(), 0);
|
|
|
|
|
|
|
|
Update();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
switch (column)
|
|
|
|
{
|
|
|
|
// Label
|
|
|
|
case 0:
|
|
|
|
if (item->text().isEmpty())
|
|
|
|
DeleteWatch(row);
|
|
|
|
else
|
2018-01-29 16:58:02 +00:00
|
|
|
PowerPC::debug_interface.UpdateWatchName(row, item->text().toStdString());
|
2017-09-27 06:53:05 +00:00
|
|
|
break;
|
|
|
|
// Address
|
|
|
|
// Hexadecimal
|
|
|
|
// Decimal
|
|
|
|
case 1:
|
|
|
|
case 2:
|
|
|
|
case 3:
|
|
|
|
{
|
|
|
|
bool good;
|
|
|
|
quint32 value = item->text().toUInt(&good, column < 3 ? 16 : 10);
|
|
|
|
|
|
|
|
if (good)
|
|
|
|
{
|
|
|
|
if (column == 1)
|
2018-01-29 16:58:02 +00:00
|
|
|
PowerPC::debug_interface.UpdateWatchAddress(row, value);
|
2017-09-27 06:53:05 +00:00
|
|
|
else
|
2018-01-29 16:58:02 +00:00
|
|
|
PowerPC::HostWrite_U32(value, PowerPC::debug_interface.GetWatch(row).address);
|
2017-09-27 06:53:05 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-01-21 15:25:58 +00:00
|
|
|
QMessageBox::critical(this, tr("Error"), tr("Invalid input provided"));
|
2017-09-27 06:53:05 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void WatchWidget::DeleteWatch(int row)
|
|
|
|
{
|
2018-01-29 16:58:02 +00:00
|
|
|
PowerPC::debug_interface.RemoveWatch(row);
|
2017-09-27 06:53:05 +00:00
|
|
|
Update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void WatchWidget::AddWatchBreakpoint(int row)
|
|
|
|
{
|
2018-01-29 16:58:02 +00:00
|
|
|
emit RequestMemoryBreakpoint(PowerPC::debug_interface.GetWatch(row).address);
|
2017-09-27 06:53:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void WatchWidget::AddWatch(QString name, u32 addr)
|
|
|
|
{
|
2018-01-29 16:58:02 +00:00
|
|
|
PowerPC::debug_interface.SetWatch(addr, name.toStdString());
|
2017-09-27 06:53:05 +00:00
|
|
|
}
|