2017-10-03 10:43:44 -06:00
|
|
|
// Copyright 2017 Dolphin Emulator Project
|
|
|
|
// Licensed under GPLv2+
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2018-07-06 16:40:15 -06:00
|
|
|
#include "DolphinQt/Debugger/BreakpointWidget.h"
|
2017-10-03 10:43:44 -06:00
|
|
|
|
|
|
|
#include <QHeaderView>
|
|
|
|
#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"
|
|
|
|
#include "Core/PowerPC/PPCSymbolDB.h"
|
|
|
|
#include "Core/PowerPC/PowerPC.h"
|
2018-04-11 15:43:47 -06:00
|
|
|
|
2018-07-06 16:40:15 -06:00
|
|
|
#include "DolphinQt/Debugger/NewBreakpointDialog.h"
|
|
|
|
#include "DolphinQt/Resources.h"
|
|
|
|
#include "DolphinQt/Settings.h"
|
2017-10-03 10:43:44 -06:00
|
|
|
|
|
|
|
BreakpointWidget::BreakpointWidget(QWidget* parent) : QDockWidget(parent)
|
|
|
|
{
|
|
|
|
setWindowTitle(tr("Breakpoints"));
|
2018-04-19 03:32:00 -06:00
|
|
|
setObjectName(QStringLiteral("breakpoints"));
|
|
|
|
|
2019-02-28 13:19:04 -07:00
|
|
|
setHidden(!Settings::Instance().IsBreakpointsVisible() ||
|
|
|
|
!Settings::Instance().IsDebugModeEnabled());
|
|
|
|
|
2017-10-03 10:43:44 -06:00
|
|
|
setAllowedAreas(Qt::AllDockWidgetAreas);
|
|
|
|
|
2018-03-23 05:10:53 -06:00
|
|
|
auto& settings = Settings::GetQSettings();
|
2017-10-03 10:43:44 -06:00
|
|
|
|
|
|
|
restoreGeometry(settings.value(QStringLiteral("breakpointwidget/geometry")).toByteArray());
|
2019-02-28 13:19:04 -07:00
|
|
|
// macOS: setHidden() needs to be evaluated before setFloating() for proper window presentation
|
|
|
|
// according to Settings
|
2017-10-03 10:43:44 -06:00
|
|
|
setFloating(settings.value(QStringLiteral("breakpointwidget/floating")).toBool());
|
|
|
|
|
|
|
|
CreateWidgets();
|
|
|
|
|
|
|
|
connect(&Settings::Instance(), &Settings::EmulationStateChanged, [this](Core::State state) {
|
2019-07-06 02:50:11 -06:00
|
|
|
UpdateButtonsEnabled();
|
|
|
|
if (state == Core::State::Uninitialized)
|
2018-05-05 23:55:30 -06:00
|
|
|
{
|
|
|
|
PowerPC::breakpoints.Clear();
|
|
|
|
PowerPC::memchecks.Clear();
|
|
|
|
Update();
|
|
|
|
}
|
2017-10-03 10:43:44 -06:00
|
|
|
});
|
|
|
|
|
|
|
|
connect(&Settings::Instance(), &Settings::BreakpointsVisibilityChanged,
|
|
|
|
[this](bool visible) { setHidden(!visible); });
|
|
|
|
|
|
|
|
connect(&Settings::Instance(), &Settings::DebugModeToggled, [this](bool enabled) {
|
|
|
|
setHidden(!enabled || !Settings::Instance().IsBreakpointsVisible());
|
|
|
|
});
|
|
|
|
|
2018-04-11 15:43:47 -06:00
|
|
|
connect(&Settings::Instance(), &Settings::ThemeChanged, this, &BreakpointWidget::UpdateIcons);
|
|
|
|
UpdateIcons();
|
2017-10-03 10:43:44 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
BreakpointWidget::~BreakpointWidget()
|
|
|
|
{
|
2018-03-23 05:10:53 -06:00
|
|
|
auto& settings = Settings::GetQSettings();
|
2017-10-03 10:43:44 -06:00
|
|
|
|
|
|
|
settings.setValue(QStringLiteral("breakpointwidget/geometry"), saveGeometry());
|
|
|
|
settings.setValue(QStringLiteral("breakpointwidget/floating"), isFloating());
|
|
|
|
}
|
|
|
|
|
|
|
|
void BreakpointWidget::CreateWidgets()
|
|
|
|
{
|
|
|
|
m_toolbar = new QToolBar;
|
2018-08-02 13:50:23 -06:00
|
|
|
m_toolbar->setContentsMargins(0, 0, 0, 0);
|
2018-04-11 15:43:47 -06:00
|
|
|
m_toolbar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
|
|
|
|
|
2017-10-03 10:43:44 -06:00
|
|
|
m_table = new QTableWidget;
|
2020-02-06 19:34:27 -07:00
|
|
|
m_table->setTabKeyNavigation(false);
|
2018-08-02 13:50:23 -06:00
|
|
|
m_table->setContentsMargins(0, 0, 0, 0);
|
2017-10-03 10:43:44 -06:00
|
|
|
m_table->setColumnCount(5);
|
|
|
|
m_table->setSelectionMode(QAbstractItemView::SingleSelection);
|
|
|
|
m_table->setSelectionBehavior(QAbstractItemView::SelectRows);
|
2018-05-05 20:07:56 -06:00
|
|
|
m_table->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
2017-10-03 10:43:44 -06:00
|
|
|
m_table->verticalHeader()->hide();
|
|
|
|
|
2018-05-05 20:55:10 -06:00
|
|
|
connect(m_table, &QTableWidget::itemClicked, [this](QTableWidgetItem* item) {
|
|
|
|
if (m_table->selectedItems()[0]->row() == item->row() &&
|
|
|
|
Core::GetState() == Core::State::Paused)
|
|
|
|
{
|
|
|
|
auto address = m_table->selectedItems()[0]->data(Qt::UserRole).toUInt();
|
|
|
|
emit SelectedBreakpoint(address);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-10-03 10:43:44 -06:00
|
|
|
auto* layout = new QVBoxLayout;
|
|
|
|
|
|
|
|
layout->addWidget(m_toolbar);
|
|
|
|
layout->addWidget(m_table);
|
2018-08-02 13:50:23 -06:00
|
|
|
layout->setContentsMargins(2, 2, 2, 2);
|
|
|
|
layout->setSpacing(0);
|
2017-10-03 10:43:44 -06:00
|
|
|
|
2018-07-09 02:02:10 -06:00
|
|
|
m_new = m_toolbar->addAction(tr("New"), this, &BreakpointWidget::OnNewBreakpoint);
|
|
|
|
m_delete = m_toolbar->addAction(tr("Delete"), this, &BreakpointWidget::OnDelete);
|
|
|
|
m_clear = m_toolbar->addAction(tr("Clear"), this, &BreakpointWidget::OnClear);
|
2017-10-03 10:43:44 -06:00
|
|
|
|
2018-07-09 02:02:10 -06:00
|
|
|
m_load = m_toolbar->addAction(tr("Load"), this, &BreakpointWidget::OnLoad);
|
|
|
|
m_save = m_toolbar->addAction(tr("Save"), this, &BreakpointWidget::OnSave);
|
2017-10-03 10:43:44 -06:00
|
|
|
|
2018-05-05 23:55:30 -06:00
|
|
|
m_new->setEnabled(false);
|
2017-10-03 10:43:44 -06:00
|
|
|
m_load->setEnabled(false);
|
|
|
|
m_save->setEnabled(false);
|
|
|
|
|
|
|
|
QWidget* widget = new QWidget;
|
|
|
|
widget->setLayout(layout);
|
|
|
|
|
|
|
|
setWidget(widget);
|
|
|
|
}
|
|
|
|
|
2018-04-11 15:43:47 -06:00
|
|
|
void BreakpointWidget::UpdateIcons()
|
|
|
|
{
|
|
|
|
m_new->setIcon(Resources::GetScaledThemeIcon("debugger_add_breakpoint"));
|
|
|
|
m_delete->setIcon(Resources::GetScaledThemeIcon("debugger_delete"));
|
|
|
|
m_clear->setIcon(Resources::GetScaledThemeIcon("debugger_clear"));
|
|
|
|
m_load->setIcon(Resources::GetScaledThemeIcon("debugger_load"));
|
|
|
|
m_save->setIcon(Resources::GetScaledThemeIcon("debugger_save"));
|
|
|
|
}
|
|
|
|
|
2017-10-03 10:43:44 -06:00
|
|
|
void BreakpointWidget::closeEvent(QCloseEvent*)
|
|
|
|
{
|
|
|
|
Settings::Instance().SetBreakpointsVisible(false);
|
|
|
|
}
|
|
|
|
|
2019-07-06 02:50:11 -06:00
|
|
|
void BreakpointWidget::showEvent(QShowEvent* event)
|
|
|
|
{
|
|
|
|
UpdateButtonsEnabled();
|
|
|
|
Update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void BreakpointWidget::UpdateButtonsEnabled()
|
|
|
|
{
|
|
|
|
if (!isVisible())
|
|
|
|
return;
|
|
|
|
|
|
|
|
const bool is_initialised = Core::GetState() != Core::State::Uninitialized;
|
|
|
|
m_new->setEnabled(is_initialised);
|
|
|
|
m_load->setEnabled(is_initialised);
|
|
|
|
m_save->setEnabled(is_initialised);
|
|
|
|
}
|
|
|
|
|
2017-10-03 10:43:44 -06:00
|
|
|
void BreakpointWidget::Update()
|
|
|
|
{
|
2019-07-06 02:50:11 -06:00
|
|
|
if (!isVisible())
|
|
|
|
return;
|
|
|
|
|
2017-10-03 10:43:44 -06:00
|
|
|
m_table->clear();
|
|
|
|
|
|
|
|
m_table->setHorizontalHeaderLabels(
|
|
|
|
{tr("Active"), tr("Type"), tr("Function"), tr("Address"), tr("Flags")});
|
|
|
|
|
|
|
|
int i = 0;
|
2018-05-05 20:07:56 -06:00
|
|
|
m_table->setRowCount(i);
|
2017-10-03 10:43:44 -06:00
|
|
|
|
2019-07-30 05:57:06 -06:00
|
|
|
const auto create_item = [](const QString string = {}) {
|
2017-10-03 10:43:44 -06:00
|
|
|
QTableWidgetItem* item = new QTableWidgetItem(string);
|
|
|
|
item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
|
|
|
|
return item;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Breakpoints
|
|
|
|
for (const auto& bp : PowerPC::breakpoints.GetBreakPoints())
|
|
|
|
{
|
|
|
|
m_table->setRowCount(i + 1);
|
|
|
|
|
|
|
|
auto* active = create_item(bp.is_enabled ? tr("on") : QString());
|
|
|
|
|
|
|
|
active->setData(Qt::UserRole, bp.address);
|
|
|
|
|
|
|
|
m_table->setItem(i, 0, active);
|
|
|
|
m_table->setItem(i, 1, create_item(QStringLiteral("BP")));
|
|
|
|
|
|
|
|
if (g_symbolDB.GetSymbolFromAddr(bp.address))
|
|
|
|
{
|
|
|
|
m_table->setItem(i, 2,
|
|
|
|
create_item(QString::fromStdString(g_symbolDB.GetDescription(bp.address))));
|
|
|
|
}
|
|
|
|
|
|
|
|
m_table->setItem(i, 3,
|
|
|
|
create_item(QStringLiteral("%1").arg(bp.address, 8, 16, QLatin1Char('0'))));
|
|
|
|
|
|
|
|
m_table->setItem(i, 4, create_item());
|
|
|
|
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Memory Breakpoints
|
|
|
|
for (const auto& mbp : PowerPC::memchecks.GetMemChecks())
|
|
|
|
{
|
|
|
|
m_table->setRowCount(i + 1);
|
2018-02-06 03:06:14 -07:00
|
|
|
auto* active = create_item(mbp.break_on_hit || mbp.log_on_hit ? tr("on") : QString());
|
|
|
|
active->setData(Qt::UserRole, mbp.start_address);
|
|
|
|
|
|
|
|
m_table->setItem(i, 0, active);
|
2017-10-03 10:43:44 -06:00
|
|
|
m_table->setItem(i, 1, create_item(QStringLiteral("MBP")));
|
|
|
|
|
|
|
|
if (g_symbolDB.GetSymbolFromAddr(mbp.start_address))
|
|
|
|
{
|
|
|
|
m_table->setItem(
|
|
|
|
i, 2, create_item(QString::fromStdString(g_symbolDB.GetDescription(mbp.start_address))));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mbp.is_ranged)
|
|
|
|
{
|
2018-04-12 06:18:04 -06:00
|
|
|
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'))));
|
2017-10-03 10:43:44 -06:00
|
|
|
}
|
|
|
|
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 05:57:06 -06:00
|
|
|
flags.append(QLatin1Char{'r'});
|
2017-10-03 10:43:44 -06:00
|
|
|
|
|
|
|
if (mbp.is_break_on_write)
|
2019-07-30 05:57:06 -06:00
|
|
|
flags.append(QLatin1Char{'w'});
|
2017-10-03 10:43:44 -06:00
|
|
|
|
|
|
|
m_table->setItem(i, 4, create_item(flags));
|
|
|
|
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void BreakpointWidget::OnDelete()
|
|
|
|
{
|
2019-02-12 15:47:17 -07:00
|
|
|
if (m_table->selectedItems().empty())
|
2017-10-03 10:43:44 -06:00
|
|
|
return;
|
|
|
|
|
|
|
|
auto address = m_table->selectedItems()[0]->data(Qt::UserRole).toUInt();
|
|
|
|
|
|
|
|
PowerPC::breakpoints.Remove(address);
|
2018-05-05 16:17:06 -06:00
|
|
|
Settings::Instance().blockSignals(true);
|
2017-10-03 10:43:44 -06:00
|
|
|
PowerPC::memchecks.Remove(address);
|
2018-05-05 16:17:06 -06:00
|
|
|
Settings::Instance().blockSignals(false);
|
2017-10-03 10:43:44 -06:00
|
|
|
|
|
|
|
Update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void BreakpointWidget::OnClear()
|
|
|
|
{
|
|
|
|
PowerPC::debug_interface.ClearAllBreakpoints();
|
2018-05-05 16:17:06 -06:00
|
|
|
Settings::Instance().blockSignals(true);
|
2017-10-03 10:43:44 -06:00
|
|
|
PowerPC::debug_interface.ClearAllMemChecks();
|
2018-05-05 16:17:06 -06:00
|
|
|
Settings::Instance().blockSignals(false);
|
2017-10-03 10:43:44 -06:00
|
|
|
|
|
|
|
m_table->setRowCount(0);
|
|
|
|
Update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void BreakpointWidget::OnNewBreakpoint()
|
|
|
|
{
|
|
|
|
NewBreakpointDialog* dialog = new NewBreakpointDialog(this);
|
|
|
|
dialog->exec();
|
|
|
|
}
|
|
|
|
|
|
|
|
void BreakpointWidget::OnLoad()
|
|
|
|
{
|
|
|
|
IniFile ini;
|
|
|
|
if (!ini.Load(File::GetUserPath(D_GAMESETTINGS_IDX) + SConfig::GetInstance().GetGameID() + ".ini",
|
|
|
|
false))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-05-13 15:52:26 -06:00
|
|
|
BreakPoints::TBreakPointsStr new_bps;
|
|
|
|
if (ini.GetLines("BreakPoints", &new_bps, false))
|
2017-10-03 10:43:44 -06:00
|
|
|
{
|
|
|
|
PowerPC::breakpoints.Clear();
|
2018-05-13 15:52:26 -06:00
|
|
|
PowerPC::breakpoints.AddFromStrings(new_bps);
|
2017-10-03 10:43:44 -06:00
|
|
|
}
|
|
|
|
|
2018-05-13 15:52:26 -06:00
|
|
|
MemChecks::TMemChecksStr new_mcs;
|
|
|
|
if (ini.GetLines("MemoryBreakPoints", &new_mcs, false))
|
2017-10-03 10:43:44 -06:00
|
|
|
{
|
|
|
|
PowerPC::memchecks.Clear();
|
2018-05-05 16:17:06 -06:00
|
|
|
Settings::Instance().blockSignals(true);
|
2018-05-13 15:52:26 -06:00
|
|
|
PowerPC::memchecks.AddFromStrings(new_mcs);
|
2018-05-05 16:17:06 -06:00
|
|
|
Settings::Instance().blockSignals(false);
|
2017-10-03 10:43:44 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
Update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void BreakpointWidget::OnSave()
|
|
|
|
{
|
|
|
|
IniFile ini;
|
|
|
|
ini.Load(File::GetUserPath(D_GAMESETTINGS_IDX) + SConfig::GetInstance().GetGameID() + ".ini",
|
|
|
|
false);
|
|
|
|
ini.SetLines("BreakPoints", PowerPC::breakpoints.GetStrings());
|
|
|
|
ini.SetLines("MemoryBreakPoints", PowerPC::memchecks.GetStrings());
|
|
|
|
ini.Save(File::GetUserPath(D_GAMESETTINGS_IDX) + SConfig::GetInstance().GetGameID() + ".ini");
|
|
|
|
}
|
|
|
|
|
|
|
|
void BreakpointWidget::AddBP(u32 addr)
|
|
|
|
{
|
|
|
|
PowerPC::breakpoints.Add(addr);
|
|
|
|
|
|
|
|
Update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void BreakpointWidget::AddAddressMBP(u32 addr, bool on_read, bool on_write, bool do_log,
|
|
|
|
bool do_break)
|
|
|
|
{
|
|
|
|
TMemCheck check;
|
|
|
|
|
|
|
|
check.start_address = addr;
|
2018-04-14 15:05:23 -06:00
|
|
|
check.end_address = addr;
|
|
|
|
check.is_ranged = false;
|
2017-10-03 10:43:44 -06: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;
|
|
|
|
|
2018-05-05 16:17:06 -06:00
|
|
|
Settings::Instance().blockSignals(true);
|
2017-10-03 10:43:44 -06:00
|
|
|
PowerPC::memchecks.Add(check);
|
2018-05-05 16:17:06 -06:00
|
|
|
Settings::Instance().blockSignals(false);
|
2017-10-03 10:43:44 -06:00
|
|
|
|
|
|
|
Update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void BreakpointWidget::AddRangedMBP(u32 from, u32 to, bool on_read, bool on_write, bool do_log,
|
|
|
|
bool do_break)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
|
2018-05-05 16:17:06 -06:00
|
|
|
Settings::Instance().blockSignals(true);
|
2017-10-03 10:43:44 -06:00
|
|
|
PowerPC::memchecks.Add(check);
|
2018-05-05 16:17:06 -06:00
|
|
|
Settings::Instance().blockSignals(false);
|
2017-10-03 10:43:44 -06:00
|
|
|
|
|
|
|
Update();
|
|
|
|
}
|