2017-10-03 16:43:44 +00:00
|
|
|
// Copyright 2017 Dolphin Emulator Project
|
2021-07-05 01:22:19 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2017-10-03 16:43:44 +00:00
|
|
|
|
2018-07-06 22:40:15 +00:00
|
|
|
#include "DolphinQt/Debugger/BreakpointWidget.h"
|
2017-10-03 16:43:44 +00:00
|
|
|
|
2024-05-14 20:07:17 +00:00
|
|
|
#include <QApplication>
|
2017-10-03 16:43:44 +00:00
|
|
|
#include <QHeaderView>
|
2021-02-28 08:44:03 +00:00
|
|
|
#include <QMenu>
|
2024-05-14 20:07:17 +00:00
|
|
|
#include <QPainter>
|
2021-03-05 09:13:12 +00:00
|
|
|
#include <QSignalBlocker>
|
2024-05-14 20:07:17 +00:00
|
|
|
#include <QStyleOptionViewItem>
|
|
|
|
#include <QStyledItemDelegate>
|
2017-10-03 16:43:44 +00:00
|
|
|
#include <QTableWidget>
|
|
|
|
#include <QToolBar>
|
|
|
|
#include <QVBoxLayout>
|
|
|
|
|
|
|
|
#include "Common/FileUtil.h"
|
|
|
|
#include "Common/IniFile.h"
|
|
|
|
#include "Core/ConfigManager.h"
|
|
|
|
#include "Core/Core.h"
|
|
|
|
#include "Core/PowerPC/BreakPoints.h"
|
2020-12-16 23:40:20 +00:00
|
|
|
#include "Core/PowerPC/Expression.h"
|
2017-10-03 16:43:44 +00:00
|
|
|
#include "Core/PowerPC/PPCSymbolDB.h"
|
|
|
|
#include "Core/PowerPC/PowerPC.h"
|
2023-03-28 18:26:52 +00:00
|
|
|
#include "Core/System.h"
|
2018-04-11 21:43:47 +00:00
|
|
|
|
2022-11-21 04:11:15 +00:00
|
|
|
#include "DolphinQt/Debugger/BreakpointDialog.h"
|
2022-05-28 00:34:47 +00:00
|
|
|
#include "DolphinQt/Debugger/MemoryWidget.h"
|
2023-07-30 22:42:15 +00:00
|
|
|
#include "DolphinQt/QtUtils/SetWindowDecorations.h"
|
2018-07-06 22:40:15 +00:00
|
|
|
#include "DolphinQt/Resources.h"
|
|
|
|
#include "DolphinQt/Settings.h"
|
2017-10-03 16:43:44 +00:00
|
|
|
|
2021-03-04 17:42:53 +00:00
|
|
|
// Qt constants
|
|
|
|
namespace
|
|
|
|
{
|
|
|
|
enum CustomRole
|
|
|
|
{
|
|
|
|
ADDRESS_ROLE = Qt::UserRole,
|
|
|
|
IS_MEMCHECK_ROLE
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2024-05-14 20:07:17 +00:00
|
|
|
// Fix icons not centering properly in a QTableWidget.
|
|
|
|
class CustomDelegate : public QStyledItemDelegate
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CustomDelegate(BreakpointWidget* parent) : QStyledItemDelegate(parent) {}
|
|
|
|
|
|
|
|
private:
|
|
|
|
void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
|
|
|
|
{
|
|
|
|
Q_ASSERT(index.isValid());
|
|
|
|
|
|
|
|
// Fetch normal drawing logic.
|
|
|
|
QStyleOptionViewItem opt = option;
|
|
|
|
initStyleOption(&opt, index);
|
|
|
|
|
|
|
|
// Disable drawing icon the normal way.
|
|
|
|
opt.icon = QIcon();
|
|
|
|
opt.decorationSize = QSize(0, 0);
|
|
|
|
|
|
|
|
// Default draw command for paint.
|
|
|
|
QApplication::style()->drawControl(QStyle::CE_ItemViewItem, &opt, painter, 0);
|
|
|
|
|
|
|
|
// Draw pixmap at the center of the tablewidget cell
|
|
|
|
QPixmap pix = qvariant_cast<QPixmap>(index.data(Qt::DecorationRole));
|
|
|
|
if (!pix.isNull())
|
|
|
|
{
|
|
|
|
const QRect r = option.rect;
|
|
|
|
const QPoint p = QPoint((r.width() - pix.width()) / 2, (r.height() - pix.height()) / 2);
|
|
|
|
painter->drawPixmap(r.topLeft() + p, pix);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-03-28 18:26:52 +00:00
|
|
|
BreakpointWidget::BreakpointWidget(QWidget* parent)
|
|
|
|
: QDockWidget(parent), m_system(Core::System::GetInstance())
|
2017-10-03 16:43:44 +00:00
|
|
|
{
|
|
|
|
setWindowTitle(tr("Breakpoints"));
|
2018-04-19 09:32:00 +00:00
|
|
|
setObjectName(QStringLiteral("breakpoints"));
|
|
|
|
|
2019-02-28 20:19:04 +00:00
|
|
|
setHidden(!Settings::Instance().IsBreakpointsVisible() ||
|
|
|
|
!Settings::Instance().IsDebugModeEnabled());
|
|
|
|
|
2017-10-03 16:43:44 +00:00
|
|
|
setAllowedAreas(Qt::AllDockWidgetAreas);
|
|
|
|
|
2020-02-09 07:32:04 +00:00
|
|
|
CreateWidgets();
|
|
|
|
|
2018-03-23 11:10:53 +00:00
|
|
|
auto& settings = Settings::GetQSettings();
|
2017-10-03 16:43:44 +00:00
|
|
|
|
|
|
|
restoreGeometry(settings.value(QStringLiteral("breakpointwidget/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
|
2017-10-03 16:43:44 +00:00
|
|
|
setFloating(settings.value(QStringLiteral("breakpointwidget/floating")).toBool());
|
|
|
|
|
2020-09-12 22:53:17 +00:00
|
|
|
connect(&Settings::Instance(), &Settings::EmulationStateChanged, this, [this](Core::State state) {
|
2019-07-06 08:50:11 +00:00
|
|
|
UpdateButtonsEnabled();
|
|
|
|
if (state == Core::State::Uninitialized)
|
2018-05-06 05:55:30 +00:00
|
|
|
Update();
|
2017-10-03 16:43:44 +00:00
|
|
|
});
|
|
|
|
|
2020-09-12 22:53:17 +00:00
|
|
|
connect(&Settings::Instance(), &Settings::BreakpointsVisibilityChanged, this,
|
2017-10-03 16:43:44 +00:00
|
|
|
[this](bool visible) { setHidden(!visible); });
|
|
|
|
|
2020-09-12 22:53:17 +00:00
|
|
|
connect(&Settings::Instance(), &Settings::DebugModeToggled, this, [this](bool enabled) {
|
2017-10-03 16:43:44 +00:00
|
|
|
setHidden(!enabled || !Settings::Instance().IsBreakpointsVisible());
|
|
|
|
});
|
|
|
|
|
2018-04-11 21:43:47 +00:00
|
|
|
connect(&Settings::Instance(), &Settings::ThemeChanged, this, &BreakpointWidget::UpdateIcons);
|
|
|
|
UpdateIcons();
|
2017-10-03 16:43:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BreakpointWidget::~BreakpointWidget()
|
|
|
|
{
|
2018-03-23 11:10:53 +00:00
|
|
|
auto& settings = Settings::GetQSettings();
|
2017-10-03 16:43:44 +00:00
|
|
|
|
|
|
|
settings.setValue(QStringLiteral("breakpointwidget/geometry"), saveGeometry());
|
|
|
|
settings.setValue(QStringLiteral("breakpointwidget/floating"), isFloating());
|
|
|
|
}
|
|
|
|
|
|
|
|
void BreakpointWidget::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-10-03 16:43:44 +00:00
|
|
|
m_table = new QTableWidget;
|
2024-05-14 20:07:17 +00:00
|
|
|
m_table->setItemDelegate(new CustomDelegate(this));
|
2020-02-07 02:34:27 +00:00
|
|
|
m_table->setTabKeyNavigation(false);
|
2018-08-02 19:50:23 +00:00
|
|
|
m_table->setContentsMargins(0, 0, 0, 0);
|
2020-12-16 23:40:20 +00:00
|
|
|
m_table->setColumnCount(6);
|
2017-10-03 16:43:44 +00:00
|
|
|
m_table->setSelectionMode(QAbstractItemView::SingleSelection);
|
|
|
|
m_table->setSelectionBehavior(QAbstractItemView::SelectRows);
|
2018-05-06 02:07:56 +00:00
|
|
|
m_table->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
2017-10-03 16:43:44 +00:00
|
|
|
m_table->verticalHeader()->hide();
|
|
|
|
|
2021-02-28 08:44:03 +00:00
|
|
|
connect(m_table, &QTableWidget::customContextMenuRequested, this,
|
|
|
|
&BreakpointWidget::OnContextMenu);
|
|
|
|
|
|
|
|
m_table->setContextMenuPolicy(Qt::ContextMenuPolicy::CustomContextMenu);
|
2018-05-06 02:55:10 +00:00
|
|
|
|
2017-10-03 16:43:44 +00:00
|
|
|
auto* layout = new QVBoxLayout;
|
|
|
|
|
|
|
|
layout->addWidget(m_toolbar);
|
|
|
|
layout->addWidget(m_table);
|
2018-08-02 19:50:23 +00:00
|
|
|
layout->setContentsMargins(2, 2, 2, 2);
|
|
|
|
layout->setSpacing(0);
|
2017-10-03 16:43:44 +00:00
|
|
|
|
2018-07-09 08:02:10 +00:00
|
|
|
m_new = m_toolbar->addAction(tr("New"), this, &BreakpointWidget::OnNewBreakpoint);
|
|
|
|
m_clear = m_toolbar->addAction(tr("Clear"), this, &BreakpointWidget::OnClear);
|
2017-10-03 16:43:44 +00:00
|
|
|
|
2018-07-09 08:02:10 +00:00
|
|
|
m_load = m_toolbar->addAction(tr("Load"), this, &BreakpointWidget::OnLoad);
|
|
|
|
m_save = m_toolbar->addAction(tr("Save"), this, &BreakpointWidget::OnSave);
|
2017-10-03 16:43:44 +00:00
|
|
|
|
2018-05-06 05:55:30 +00:00
|
|
|
m_new->setEnabled(false);
|
2017-10-03 16:43:44 +00:00
|
|
|
m_load->setEnabled(false);
|
|
|
|
m_save->setEnabled(false);
|
|
|
|
|
|
|
|
QWidget* widget = new QWidget;
|
|
|
|
widget->setLayout(layout);
|
|
|
|
|
|
|
|
setWidget(widget);
|
|
|
|
}
|
|
|
|
|
2018-04-11 21:43:47 +00:00
|
|
|
void BreakpointWidget::UpdateIcons()
|
|
|
|
{
|
2023-04-23 10:43:49 +00:00
|
|
|
m_new->setIcon(Resources::GetThemeIcon("debugger_add_breakpoint"));
|
|
|
|
m_clear->setIcon(Resources::GetThemeIcon("debugger_clear"));
|
|
|
|
m_load->setIcon(Resources::GetThemeIcon("debugger_load"));
|
|
|
|
m_save->setIcon(Resources::GetThemeIcon("debugger_save"));
|
2018-04-11 21:43:47 +00:00
|
|
|
}
|
|
|
|
|
2017-10-03 16:43:44 +00:00
|
|
|
void BreakpointWidget::closeEvent(QCloseEvent*)
|
|
|
|
{
|
|
|
|
Settings::Instance().SetBreakpointsVisible(false);
|
|
|
|
}
|
|
|
|
|
2019-07-06 08:50:11 +00:00
|
|
|
void BreakpointWidget::showEvent(QShowEvent* event)
|
|
|
|
{
|
|
|
|
UpdateButtonsEnabled();
|
|
|
|
Update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void BreakpointWidget::UpdateButtonsEnabled()
|
|
|
|
{
|
|
|
|
if (!isVisible())
|
|
|
|
return;
|
|
|
|
|
2024-03-28 18:35:13 +00:00
|
|
|
const bool is_initialised = Core::GetState(m_system) != Core::State::Uninitialized;
|
2019-07-06 08:50:11 +00:00
|
|
|
m_new->setEnabled(is_initialised);
|
|
|
|
m_load->setEnabled(is_initialised);
|
|
|
|
m_save->setEnabled(is_initialised);
|
|
|
|
}
|
|
|
|
|
2017-10-03 16:43:44 +00:00
|
|
|
void BreakpointWidget::Update()
|
|
|
|
{
|
2019-07-06 08:50:11 +00:00
|
|
|
if (!isVisible())
|
|
|
|
return;
|
|
|
|
|
2017-10-03 16:43:44 +00:00
|
|
|
m_table->clear();
|
|
|
|
|
|
|
|
m_table->setHorizontalHeaderLabels(
|
2020-12-16 23:40:20 +00:00
|
|
|
{tr("Active"), tr("Type"), tr("Function"), tr("Address"), tr("Flags"), tr("Condition")});
|
2017-10-03 16:43:44 +00:00
|
|
|
|
|
|
|
int i = 0;
|
2018-05-06 02:07:56 +00:00
|
|
|
m_table->setRowCount(i);
|
2017-10-03 16:43:44 +00:00
|
|
|
|
2023-06-08 15:46:14 +00:00
|
|
|
const auto create_item = [](const QString& string = {}) {
|
2017-10-03 16:43:44 +00:00
|
|
|
QTableWidgetItem* item = new QTableWidgetItem(string);
|
|
|
|
item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
|
|
|
|
return item;
|
|
|
|
};
|
|
|
|
|
2023-03-28 18:26:52 +00:00
|
|
|
auto& power_pc = m_system.GetPowerPC();
|
|
|
|
auto& breakpoints = power_pc.GetBreakPoints();
|
|
|
|
auto& memchecks = power_pc.GetMemChecks();
|
2024-03-10 18:43:12 +00:00
|
|
|
auto& ppc_symbol_db = power_pc.GetSymbolDB();
|
2023-03-28 18:26:52 +00:00
|
|
|
|
2017-10-03 16:43:44 +00:00
|
|
|
// Breakpoints
|
2023-03-28 18:26:52 +00:00
|
|
|
for (const auto& bp : breakpoints.GetBreakPoints())
|
2017-10-03 16:43:44 +00:00
|
|
|
{
|
|
|
|
m_table->setRowCount(i + 1);
|
|
|
|
|
2021-02-28 08:44:03 +00:00
|
|
|
auto* active = create_item(bp.is_enabled ? tr("on") : tr("off"));
|
2017-10-03 16:43:44 +00:00
|
|
|
|
2021-03-04 17:42:53 +00:00
|
|
|
active->setData(ADDRESS_ROLE, bp.address);
|
|
|
|
active->setData(IS_MEMCHECK_ROLE, false);
|
2017-10-03 16:43:44 +00:00
|
|
|
|
|
|
|
m_table->setItem(i, 0, active);
|
|
|
|
m_table->setItem(i, 1, create_item(QStringLiteral("BP")));
|
|
|
|
|
2024-04-13 06:25:03 +00:00
|
|
|
if (const Common::Symbol* const symbol = ppc_symbol_db.GetSymbolFromAddr(bp.address))
|
|
|
|
m_table->setItem(i, 2, create_item(QString::fromStdString(symbol->name)));
|
2017-10-03 16:43:44 +00:00
|
|
|
|
|
|
|
m_table->setItem(i, 3,
|
|
|
|
create_item(QStringLiteral("%1").arg(bp.address, 8, 16, QLatin1Char('0'))));
|
|
|
|
|
2020-07-06 22:16:32 +00:00
|
|
|
QString flags;
|
|
|
|
|
|
|
|
if (bp.break_on_hit)
|
|
|
|
flags.append(QLatin1Char{'b'});
|
|
|
|
|
|
|
|
if (bp.log_on_hit)
|
|
|
|
flags.append(QLatin1Char{'l'});
|
|
|
|
|
|
|
|
m_table->setItem(i, 4, create_item(flags));
|
2017-10-03 16:43:44 +00:00
|
|
|
|
2020-12-16 23:40:20 +00:00
|
|
|
QString condition;
|
|
|
|
|
|
|
|
if (bp.condition)
|
|
|
|
condition = QString::fromStdString(bp.condition->GetText());
|
|
|
|
|
|
|
|
m_table->setItem(i, 5, create_item(condition));
|
|
|
|
|
2017-10-03 16:43:44 +00:00
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Memory Breakpoints
|
2023-03-28 18:26:52 +00:00
|
|
|
for (const auto& mbp : memchecks.GetMemChecks())
|
2017-10-03 16:43:44 +00:00
|
|
|
{
|
|
|
|
m_table->setRowCount(i + 1);
|
2021-02-28 08:44:03 +00:00
|
|
|
auto* active =
|
|
|
|
create_item(mbp.is_enabled && (mbp.break_on_hit || mbp.log_on_hit) ? tr("on") : tr("off"));
|
2021-03-04 17:42:53 +00:00
|
|
|
active->setData(ADDRESS_ROLE, mbp.start_address);
|
|
|
|
active->setData(IS_MEMCHECK_ROLE, true);
|
2018-02-06 10:06:14 +00:00
|
|
|
|
|
|
|
m_table->setItem(i, 0, active);
|
2017-10-03 16:43:44 +00:00
|
|
|
m_table->setItem(i, 1, create_item(QStringLiteral("MBP")));
|
|
|
|
|
2024-04-13 06:25:03 +00:00
|
|
|
if (const Common::Symbol* const symbol = ppc_symbol_db.GetSymbolFromAddr(mbp.start_address))
|
|
|
|
m_table->setItem(i, 2, create_item(QString::fromStdString(symbol->name)));
|
2017-10-03 16:43:44 +00:00
|
|
|
|
|
|
|
if (mbp.is_ranged)
|
|
|
|
{
|
|
|
|
m_table->setItem(i, 3,
|
|
|
|
create_item(QStringLiteral("%1 - %2")
|
|
|
|
.arg(mbp.start_address, 8, 16, QLatin1Char('0'))
|
|
|
|
.arg(mbp.end_address, 8, 16, QLatin1Char('0'))));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_table->setItem(
|
|
|
|
i, 3, create_item(QStringLiteral("%1").arg(mbp.start_address, 8, 16, QLatin1Char('0'))));
|
|
|
|
}
|
|
|
|
|
|
|
|
QString flags;
|
|
|
|
|
|
|
|
if (mbp.is_break_on_read)
|
2019-07-30 11:57:06 +00:00
|
|
|
flags.append(QLatin1Char{'r'});
|
2017-10-03 16:43:44 +00:00
|
|
|
|
|
|
|
if (mbp.is_break_on_write)
|
2019-07-30 11:57:06 +00:00
|
|
|
flags.append(QLatin1Char{'w'});
|
2017-10-03 16:43:44 +00:00
|
|
|
|
|
|
|
m_table->setItem(i, 4, create_item(flags));
|
|
|
|
|
2022-09-02 09:57:30 +00:00
|
|
|
QString condition;
|
|
|
|
|
|
|
|
if (mbp.condition)
|
|
|
|
condition = QString::fromStdString(mbp.condition->GetText());
|
|
|
|
|
|
|
|
m_table->setItem(i, 5, create_item(condition));
|
|
|
|
|
2017-10-03 16:43:44 +00:00
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void BreakpointWidget::OnClear()
|
|
|
|
{
|
2023-03-28 18:26:52 +00:00
|
|
|
m_system.GetPowerPC().GetDebugInterface().ClearAllBreakpoints();
|
2021-03-05 09:13:12 +00:00
|
|
|
{
|
|
|
|
const QSignalBlocker blocker(Settings::Instance());
|
2023-03-28 18:26:52 +00:00
|
|
|
m_system.GetPowerPC().GetDebugInterface().ClearAllMemChecks();
|
2021-03-05 09:13:12 +00:00
|
|
|
}
|
2017-10-03 16:43:44 +00:00
|
|
|
|
|
|
|
m_table->setRowCount(0);
|
2021-03-04 17:10:37 +00:00
|
|
|
|
|
|
|
emit BreakpointsChanged();
|
2017-10-03 16:43:44 +00:00
|
|
|
Update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void BreakpointWidget::OnNewBreakpoint()
|
|
|
|
{
|
2022-11-21 04:11:15 +00:00
|
|
|
BreakpointDialog* dialog = new BreakpointDialog(this);
|
2024-04-30 17:58:16 +00:00
|
|
|
dialog->setAttribute(Qt::WA_DeleteOnClose, true);
|
2023-07-30 22:42:15 +00:00
|
|
|
SetQWidgetWindowDecorations(dialog);
|
2017-10-03 16:43:44 +00:00
|
|
|
dialog->exec();
|
|
|
|
}
|
|
|
|
|
2022-11-21 04:11:15 +00:00
|
|
|
void BreakpointWidget::OnEditBreakpoint(u32 address, bool is_instruction_bp)
|
|
|
|
{
|
|
|
|
if (is_instruction_bp)
|
|
|
|
{
|
2023-03-28 18:26:52 +00:00
|
|
|
auto* dialog =
|
|
|
|
new BreakpointDialog(this, m_system.GetPowerPC().GetBreakPoints().GetBreakpoint(address));
|
2024-04-30 17:58:16 +00:00
|
|
|
dialog->setAttribute(Qt::WA_DeleteOnClose, true);
|
2023-07-30 22:42:15 +00:00
|
|
|
SetQWidgetWindowDecorations(dialog);
|
2022-11-21 04:11:15 +00:00
|
|
|
dialog->exec();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-03-28 18:26:52 +00:00
|
|
|
auto* dialog =
|
|
|
|
new BreakpointDialog(this, m_system.GetPowerPC().GetMemChecks().GetMemCheck(address));
|
2024-04-30 17:58:16 +00:00
|
|
|
dialog->setAttribute(Qt::WA_DeleteOnClose, true);
|
2023-07-30 22:42:15 +00:00
|
|
|
SetQWidgetWindowDecorations(dialog);
|
2022-11-21 04:11:15 +00:00
|
|
|
dialog->exec();
|
|
|
|
}
|
|
|
|
|
|
|
|
emit BreakpointsChanged();
|
|
|
|
Update();
|
|
|
|
}
|
|
|
|
|
2017-10-03 16:43:44 +00:00
|
|
|
void BreakpointWidget::OnLoad()
|
|
|
|
{
|
2023-04-13 13:38:09 +00:00
|
|
|
Common::IniFile ini;
|
2017-10-03 16:43:44 +00:00
|
|
|
if (!ini.Load(File::GetUserPath(D_GAMESETTINGS_IDX) + SConfig::GetInstance().GetGameID() + ".ini",
|
|
|
|
false))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-05-13 21:52:26 +00:00
|
|
|
BreakPoints::TBreakPointsStr new_bps;
|
|
|
|
if (ini.GetLines("BreakPoints", &new_bps, false))
|
2017-10-03 16:43:44 +00:00
|
|
|
{
|
2023-03-28 18:26:52 +00:00
|
|
|
auto& breakpoints = m_system.GetPowerPC().GetBreakPoints();
|
|
|
|
breakpoints.Clear();
|
|
|
|
breakpoints.AddFromStrings(new_bps);
|
2017-10-03 16:43:44 +00:00
|
|
|
}
|
|
|
|
|
2018-05-13 21:52:26 +00:00
|
|
|
MemChecks::TMemChecksStr new_mcs;
|
|
|
|
if (ini.GetLines("MemoryBreakPoints", &new_mcs, false))
|
2017-10-03 16:43:44 +00:00
|
|
|
{
|
2023-03-28 18:26:52 +00:00
|
|
|
auto& memchecks = m_system.GetPowerPC().GetMemChecks();
|
|
|
|
memchecks.Clear();
|
2021-03-05 09:13:12 +00:00
|
|
|
const QSignalBlocker blocker(Settings::Instance());
|
2023-03-28 18:26:52 +00:00
|
|
|
memchecks.AddFromStrings(new_mcs);
|
2017-10-03 16:43:44 +00:00
|
|
|
}
|
|
|
|
|
2021-03-04 17:10:37 +00:00
|
|
|
emit BreakpointsChanged();
|
2017-10-03 16:43:44 +00:00
|
|
|
Update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void BreakpointWidget::OnSave()
|
|
|
|
{
|
2023-04-13 13:38:09 +00:00
|
|
|
Common::IniFile ini;
|
2017-10-03 16:43:44 +00:00
|
|
|
ini.Load(File::GetUserPath(D_GAMESETTINGS_IDX) + SConfig::GetInstance().GetGameID() + ".ini",
|
|
|
|
false);
|
2023-03-28 18:26:52 +00:00
|
|
|
ini.SetLines("BreakPoints", m_system.GetPowerPC().GetBreakPoints().GetStrings());
|
|
|
|
ini.SetLines("MemoryBreakPoints", m_system.GetPowerPC().GetMemChecks().GetStrings());
|
2017-10-03 16:43:44 +00:00
|
|
|
ini.Save(File::GetUserPath(D_GAMESETTINGS_IDX) + SConfig::GetInstance().GetGameID() + ".ini");
|
|
|
|
}
|
|
|
|
|
2021-02-28 08:44:03 +00:00
|
|
|
void BreakpointWidget::OnContextMenu()
|
|
|
|
{
|
|
|
|
const auto& selected_items = m_table->selectedItems();
|
|
|
|
if (selected_items.isEmpty())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto& selected_item = selected_items.constFirst();
|
2021-03-04 17:42:53 +00:00
|
|
|
const auto bp_address = static_cast<u32>(selected_item->data(ADDRESS_ROLE).toUInt());
|
|
|
|
const auto is_memory_breakpoint = selected_item->data(IS_MEMCHECK_ROLE).toBool();
|
2021-02-28 08:44:03 +00:00
|
|
|
|
|
|
|
auto* menu = new QMenu(this);
|
2024-04-30 17:58:16 +00:00
|
|
|
menu->setAttribute(Qt::WA_DeleteOnClose, true);
|
2021-02-28 08:44:03 +00:00
|
|
|
|
2021-03-04 17:42:53 +00:00
|
|
|
if (!is_memory_breakpoint)
|
2021-02-28 08:44:03 +00:00
|
|
|
{
|
2023-03-28 18:26:52 +00:00
|
|
|
const auto& inst_breakpoints = m_system.GetPowerPC().GetBreakPoints().GetBreakPoints();
|
2021-03-04 17:42:53 +00:00
|
|
|
const auto bp_iter =
|
|
|
|
std::find_if(inst_breakpoints.begin(), inst_breakpoints.end(),
|
|
|
|
[bp_address](const auto& bp) { return bp.address == bp_address; });
|
|
|
|
if (bp_iter == inst_breakpoints.end())
|
|
|
|
return;
|
|
|
|
|
2022-05-28 00:34:47 +00:00
|
|
|
menu->addAction(tr("Show in Code"), [this, bp_address] { emit ShowCode(bp_address); });
|
2024-05-14 20:02:11 +00:00
|
|
|
menu->addAction(tr("Edit..."), [this, bp_address] { OnEditBreakpoint(bp_address, true); });
|
|
|
|
menu->addAction(tr("Delete"), [this, &bp_address]() {
|
|
|
|
m_system.GetPowerPC().GetBreakPoints().Remove(bp_address);
|
2021-03-04 17:10:37 +00:00
|
|
|
emit BreakpointsChanged();
|
2021-02-28 08:44:03 +00:00
|
|
|
Update();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-03-28 18:26:52 +00:00
|
|
|
const auto& memory_breakpoints = m_system.GetPowerPC().GetMemChecks().GetMemChecks();
|
2021-02-28 08:44:03 +00:00
|
|
|
const auto mb_iter =
|
|
|
|
std::find_if(memory_breakpoints.begin(), memory_breakpoints.end(),
|
|
|
|
[bp_address](const auto& bp) { return bp.start_address == bp_address; });
|
|
|
|
if (mb_iter == memory_breakpoints.end())
|
|
|
|
return;
|
|
|
|
|
2022-05-28 00:34:47 +00:00
|
|
|
menu->addAction(tr("Show in Memory"), [this, bp_address] { emit ShowMemory(bp_address); });
|
2024-05-14 20:02:11 +00:00
|
|
|
menu->addAction(tr("Edit..."), [this, bp_address] { OnEditBreakpoint(bp_address, false); });
|
|
|
|
menu->addAction(tr("Delete"), [this, &bp_address]() {
|
|
|
|
const QSignalBlocker blocker(Settings::Instance());
|
|
|
|
m_system.GetPowerPC().GetMemChecks().Remove(bp_address);
|
2021-03-04 17:10:37 +00:00
|
|
|
emit BreakpointsChanged();
|
2021-02-28 08:44:03 +00:00
|
|
|
Update();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
menu->exec(QCursor::pos());
|
|
|
|
}
|
|
|
|
|
2017-10-03 16:43:44 +00:00
|
|
|
void BreakpointWidget::AddBP(u32 addr)
|
|
|
|
{
|
2020-12-16 23:40:20 +00:00
|
|
|
AddBP(addr, false, true, true, {});
|
2020-07-06 22:16:32 +00:00
|
|
|
}
|
|
|
|
|
2020-12-16 23:40:20 +00:00
|
|
|
void BreakpointWidget::AddBP(u32 addr, bool temp, bool break_on_hit, bool log_on_hit,
|
|
|
|
const QString& condition)
|
2020-07-06 22:16:32 +00:00
|
|
|
{
|
2023-03-28 18:26:52 +00:00
|
|
|
m_system.GetPowerPC().GetBreakPoints().Add(
|
2020-12-16 23:40:20 +00:00
|
|
|
addr, temp, break_on_hit, log_on_hit,
|
|
|
|
!condition.isEmpty() ? Expression::TryParse(condition.toUtf8().constData()) : std::nullopt);
|
2017-10-03 16:43:44 +00:00
|
|
|
|
2021-03-04 17:10:37 +00:00
|
|
|
emit BreakpointsChanged();
|
2017-10-03 16:43:44 +00:00
|
|
|
Update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void BreakpointWidget::AddAddressMBP(u32 addr, bool on_read, bool on_write, bool do_log,
|
2022-09-02 09:57:30 +00:00
|
|
|
bool do_break, const QString& condition)
|
2017-10-03 16:43:44 +00:00
|
|
|
{
|
|
|
|
TMemCheck check;
|
|
|
|
|
|
|
|
check.start_address = addr;
|
2018-04-14 21:05:23 +00:00
|
|
|
check.end_address = addr;
|
|
|
|
check.is_ranged = false;
|
2017-10-03 16:43:44 +00:00
|
|
|
check.is_break_on_read = on_read;
|
|
|
|
check.is_break_on_write = on_write;
|
|
|
|
check.log_on_hit = do_log;
|
|
|
|
check.break_on_hit = do_break;
|
2022-09-02 09:57:30 +00:00
|
|
|
check.condition =
|
|
|
|
!condition.isEmpty() ? Expression::TryParse(condition.toUtf8().constData()) : std::nullopt;
|
2021-03-05 09:13:12 +00:00
|
|
|
{
|
|
|
|
const QSignalBlocker blocker(Settings::Instance());
|
2023-03-28 18:26:52 +00:00
|
|
|
m_system.GetPowerPC().GetMemChecks().Add(std::move(check));
|
2021-03-05 09:13:12 +00:00
|
|
|
}
|
2017-10-03 16:43:44 +00:00
|
|
|
|
2021-03-04 17:10:37 +00:00
|
|
|
emit BreakpointsChanged();
|
2017-10-03 16:43:44 +00:00
|
|
|
Update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void BreakpointWidget::AddRangedMBP(u32 from, u32 to, bool on_read, bool on_write, bool do_log,
|
2022-09-02 09:57:30 +00:00
|
|
|
bool do_break, const QString& condition)
|
2017-10-03 16:43:44 +00:00
|
|
|
{
|
|
|
|
TMemCheck check;
|
|
|
|
|
|
|
|
check.start_address = from;
|
|
|
|
check.end_address = to;
|
|
|
|
check.is_ranged = true;
|
|
|
|
check.is_break_on_read = on_read;
|
|
|
|
check.is_break_on_write = on_write;
|
|
|
|
check.log_on_hit = do_log;
|
|
|
|
check.break_on_hit = do_break;
|
2022-09-02 09:57:30 +00:00
|
|
|
check.condition =
|
|
|
|
!condition.isEmpty() ? Expression::TryParse(condition.toUtf8().constData()) : std::nullopt;
|
2021-03-05 09:13:12 +00:00
|
|
|
{
|
|
|
|
const QSignalBlocker blocker(Settings::Instance());
|
2023-03-28 18:26:52 +00:00
|
|
|
m_system.GetPowerPC().GetMemChecks().Add(std::move(check));
|
2021-03-05 09:13:12 +00:00
|
|
|
}
|
2017-10-03 16:43:44 +00:00
|
|
|
|
2021-03-04 17:10:37 +00:00
|
|
|
emit BreakpointsChanged();
|
2017-10-03 16:43:44 +00:00
|
|
|
Update();
|
|
|
|
}
|