2018-02-14 22:25:01 +00:00
|
|
|
// Copyright 2018 Dolphin Emulator Project
|
2021-07-05 01:22:19 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2018-02-14 22:25:01 +00:00
|
|
|
|
2018-07-06 22:40:15 +00:00
|
|
|
#include "DolphinQt/Debugger/CodeViewWidget.h"
|
2018-02-14 22:25:01 +00:00
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
#include <cmath>
|
|
|
|
|
2022-10-12 02:21:51 +00:00
|
|
|
#include <fmt/format.h>
|
|
|
|
|
2018-02-14 22:25:01 +00:00
|
|
|
#include <QApplication>
|
|
|
|
#include <QClipboard>
|
|
|
|
#include <QHeaderView>
|
|
|
|
#include <QInputDialog>
|
|
|
|
#include <QKeyEvent>
|
|
|
|
#include <QMenu>
|
2022-03-26 21:48:25 +00:00
|
|
|
#include <QMessageBox>
|
2018-02-14 22:25:01 +00:00
|
|
|
#include <QMouseEvent>
|
2020-02-23 17:57:08 +00:00
|
|
|
#include <QPainter>
|
2018-02-14 22:25:01 +00:00
|
|
|
#include <QResizeEvent>
|
|
|
|
#include <QScrollBar>
|
2020-02-23 17:57:08 +00:00
|
|
|
#include <QStyledItemDelegate>
|
2018-02-14 22:25:01 +00:00
|
|
|
#include <QTableWidgetItem>
|
|
|
|
#include <QWheelEvent>
|
|
|
|
|
2021-12-09 01:10:39 +00:00
|
|
|
#include "Common/Assert.h"
|
2022-03-26 21:48:25 +00:00
|
|
|
#include "Common/Debug/CodeTrace.h"
|
2020-03-07 01:06:10 +00:00
|
|
|
#include "Common/GekkoDisassembler.h"
|
2018-02-14 22:25:01 +00:00
|
|
|
#include "Common/StringUtil.h"
|
|
|
|
#include "Core/Core.h"
|
|
|
|
#include "Core/Debugger/PPCDebugInterface.h"
|
2018-05-17 21:09:55 +00:00
|
|
|
#include "Core/PowerPC/MMU.h"
|
2018-02-14 22:25:01 +00:00
|
|
|
#include "Core/PowerPC/PPCAnalyst.h"
|
|
|
|
#include "Core/PowerPC/PPCSymbolDB.h"
|
|
|
|
#include "Core/PowerPC/PowerPC.h"
|
2023-03-08 00:58:05 +00:00
|
|
|
#include "Core/System.h"
|
2019-04-23 19:42:37 +00:00
|
|
|
#include "DolphinQt/Debugger/PatchInstructionDialog.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-02-14 22:25:01 +00:00
|
|
|
|
2020-02-23 17:57:08 +00:00
|
|
|
struct CodeViewBranch
|
|
|
|
{
|
2021-09-04 04:43:19 +00:00
|
|
|
u32 src_addr = 0;
|
|
|
|
u32 dst_addr = 0;
|
2020-02-26 20:33:43 +00:00
|
|
|
u32 indentation = 0;
|
2021-09-04 04:43:19 +00:00
|
|
|
bool is_link = false;
|
2020-02-23 17:57:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
constexpr u32 WIDTH_PER_BRANCH_ARROW = 16;
|
|
|
|
|
|
|
|
class BranchDisplayDelegate : public QStyledItemDelegate
|
|
|
|
{
|
|
|
|
public:
|
2023-02-18 02:20:50 +00:00
|
|
|
BranchDisplayDelegate(CodeViewWidget* parent) : QStyledItemDelegate(parent), m_parent(parent) {}
|
2020-02-23 17:57:08 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
CodeViewWidget* m_parent;
|
|
|
|
|
|
|
|
void paint(QPainter* painter, const QStyleOptionViewItem& option,
|
|
|
|
const QModelIndex& index) const override
|
|
|
|
{
|
|
|
|
QStyledItemDelegate::paint(painter, option, index);
|
|
|
|
|
|
|
|
painter->save();
|
|
|
|
painter->setClipRect(option.rect);
|
|
|
|
painter->setPen(m_parent->palette().text().color());
|
|
|
|
|
|
|
|
constexpr u32 x_offset_in_branch_for_vertical_line = 10;
|
|
|
|
const u32 addr = m_parent->AddressForRow(index.row());
|
|
|
|
for (const CodeViewBranch& branch : m_parent->m_branches)
|
|
|
|
{
|
|
|
|
const int y_center = option.rect.top() + option.rect.height() / 2;
|
2020-02-26 20:33:43 +00:00
|
|
|
const int x_left = option.rect.left() + WIDTH_PER_BRANCH_ARROW * branch.indentation;
|
2020-02-23 17:57:08 +00:00
|
|
|
const int x_right = x_left + x_offset_in_branch_for_vertical_line;
|
|
|
|
|
|
|
|
if (branch.is_link)
|
|
|
|
{
|
|
|
|
// just draw an arrow pointing right from the branch instruction for link branches, they
|
|
|
|
// rarely are close enough to actually see the target and are just visual noise otherwise
|
|
|
|
if (addr == branch.src_addr)
|
|
|
|
{
|
|
|
|
painter->drawLine(x_left, y_center, x_right, y_center);
|
|
|
|
painter->drawLine(x_right, y_center, x_right - 6, y_center - 3);
|
|
|
|
painter->drawLine(x_right, y_center, x_right - 6, y_center + 3);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const u32 addr_lower = std::min(branch.src_addr, branch.dst_addr);
|
|
|
|
const u32 addr_higher = std::max(branch.src_addr, branch.dst_addr);
|
|
|
|
const bool in_range = addr >= addr_lower && addr <= addr_higher;
|
|
|
|
|
|
|
|
if (in_range)
|
|
|
|
{
|
|
|
|
const bool is_lowest = addr == addr_lower;
|
|
|
|
const bool is_highest = addr == addr_higher;
|
|
|
|
const int top = (is_lowest ? y_center : option.rect.top());
|
|
|
|
const int bottom = (is_highest ? y_center : option.rect.bottom());
|
|
|
|
|
|
|
|
// draw vertical part of the branch line
|
|
|
|
painter->drawLine(x_right, top, x_right, bottom);
|
|
|
|
|
|
|
|
if (is_lowest || is_highest)
|
|
|
|
{
|
|
|
|
// draw horizontal part of the branch line if this is either the source or destination
|
|
|
|
painter->drawLine(x_left, y_center, x_right, y_center);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (addr == branch.dst_addr)
|
|
|
|
{
|
|
|
|
// draw arrow if this is the destination address
|
|
|
|
painter->drawLine(x_left, y_center, x_left + 6, y_center - 3);
|
|
|
|
painter->drawLine(x_left, y_center, x_left + 6, y_center + 3);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
painter->restore();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
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.;
|
|
|
|
|
2018-02-14 22:25:01 +00:00
|
|
|
constexpr size_t VALID_BRANCH_LENGTH = 10;
|
|
|
|
|
2020-02-23 17:49:18 +00:00
|
|
|
constexpr int CODE_VIEW_COLUMN_BREAKPOINT = 0;
|
|
|
|
constexpr int CODE_VIEW_COLUMN_ADDRESS = 1;
|
|
|
|
constexpr int CODE_VIEW_COLUMN_INSTRUCTION = 2;
|
|
|
|
constexpr int CODE_VIEW_COLUMN_PARAMETERS = 3;
|
|
|
|
constexpr int CODE_VIEW_COLUMN_DESCRIPTION = 4;
|
2020-02-23 17:57:08 +00:00
|
|
|
constexpr int CODE_VIEW_COLUMN_BRANCH_ARROWS = 5;
|
|
|
|
constexpr int CODE_VIEW_COLUMNCOUNT = 6;
|
2020-02-23 17:49:18 +00:00
|
|
|
|
2023-03-28 21:52:36 +00:00
|
|
|
CodeViewWidget::CodeViewWidget() : m_system(Core::System::GetInstance())
|
2018-02-14 22:25:01 +00:00
|
|
|
{
|
2020-02-23 17:49:18 +00:00
|
|
|
setColumnCount(CODE_VIEW_COLUMNCOUNT);
|
2018-02-14 22:25:01 +00:00
|
|
|
setShowGrid(false);
|
|
|
|
setContextMenuPolicy(Qt::CustomContextMenu);
|
|
|
|
setSelectionMode(QAbstractItemView::SingleSelection);
|
2018-05-05 08:21:15 +00:00
|
|
|
setSelectionBehavior(QAbstractItemView::SelectRows);
|
2018-08-02 19:50:23 +00:00
|
|
|
|
|
|
|
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
2019-01-12 01:25:28 +00:00
|
|
|
setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel);
|
2018-02-14 22:25:01 +00:00
|
|
|
|
|
|
|
verticalHeader()->hide();
|
2020-03-07 01:06:10 +00:00
|
|
|
horizontalHeader()->setSectionResizeMode(CODE_VIEW_COLUMN_BREAKPOINT, QHeaderView::Fixed);
|
|
|
|
horizontalHeader()->setStretchLastSection(true);
|
|
|
|
setHorizontalHeaderItem(CODE_VIEW_COLUMN_BREAKPOINT, new QTableWidgetItem());
|
|
|
|
setHorizontalHeaderItem(CODE_VIEW_COLUMN_ADDRESS, new QTableWidgetItem(tr("Address")));
|
|
|
|
setHorizontalHeaderItem(CODE_VIEW_COLUMN_INSTRUCTION, new QTableWidgetItem(tr("Instr.")));
|
|
|
|
setHorizontalHeaderItem(CODE_VIEW_COLUMN_PARAMETERS, new QTableWidgetItem(tr("Parameters")));
|
|
|
|
setHorizontalHeaderItem(CODE_VIEW_COLUMN_DESCRIPTION, new QTableWidgetItem(tr("Symbols")));
|
|
|
|
setHorizontalHeaderItem(CODE_VIEW_COLUMN_BRANCH_ARROWS, new QTableWidgetItem(tr("Branches")));
|
2018-02-14 22:25:01 +00:00
|
|
|
|
|
|
|
setFont(Settings::Instance().GetDebugFont());
|
2020-02-23 17:57:08 +00:00
|
|
|
setItemDelegateForColumn(CODE_VIEW_COLUMN_BRANCH_ARROWS, new BranchDisplayDelegate(this));
|
2018-02-14 22:25:01 +00:00
|
|
|
|
2019-01-12 01:25:28 +00:00
|
|
|
FontBasedSizing();
|
2018-02-14 22:25:01 +00:00
|
|
|
|
|
|
|
connect(this, &CodeViewWidget::customContextMenuRequested, this, &CodeViewWidget::OnContextMenu);
|
2018-05-05 08:21:15 +00:00
|
|
|
connect(this, &CodeViewWidget::itemSelectionChanged, this, &CodeViewWidget::OnSelectionChanged);
|
2018-02-14 22:25:01 +00:00
|
|
|
connect(&Settings::Instance(), &Settings::DebugFontChanged, this, &QWidget::setFont);
|
2019-01-12 01:25:28 +00:00
|
|
|
connect(&Settings::Instance(), &Settings::DebugFontChanged, this,
|
|
|
|
&CodeViewWidget::FontBasedSizing);
|
|
|
|
|
2018-02-14 22:25:01 +00:00
|
|
|
connect(&Settings::Instance(), &Settings::EmulationStateChanged, this, [this] {
|
2023-03-28 21:52:36 +00:00
|
|
|
m_address = m_system.GetPPCState().pc;
|
2018-02-14 22:25:01 +00:00
|
|
|
Update();
|
|
|
|
});
|
2020-04-14 22:12:35 +00:00
|
|
|
connect(Host::GetInstance(), &Host::UpdateDisasmDialog, this, [this] {
|
2023-03-28 21:52:36 +00:00
|
|
|
m_address = m_system.GetPPCState().pc;
|
2020-04-14 22:12:35 +00:00
|
|
|
Update();
|
|
|
|
});
|
2018-04-11 21:43:47 +00:00
|
|
|
|
2023-02-12 10:07:11 +00:00
|
|
|
connect(&Settings::Instance(), &Settings::ThemeChanged, this,
|
|
|
|
qOverload<>(&CodeViewWidget::Update));
|
2018-02-14 22:25:01 +00:00
|
|
|
}
|
|
|
|
|
2020-02-23 17:57:08 +00:00
|
|
|
CodeViewWidget::~CodeViewWidget() = default;
|
|
|
|
|
2023-02-12 10:07:11 +00:00
|
|
|
static u32 GetBranchFromAddress(const Core::CPUThreadGuard& guard, u32 addr)
|
2018-02-14 22:25:01 +00:00
|
|
|
{
|
2023-03-28 18:26:52 +00:00
|
|
|
std::string disasm = guard.GetSystem().GetPowerPC().GetDebugInterface().Disassemble(&guard, addr);
|
2018-02-14 22:25:01 +00:00
|
|
|
size_t pos = disasm.find("->0x");
|
|
|
|
|
|
|
|
if (pos == std::string::npos)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
std::string hex = disasm.substr(pos + 2);
|
|
|
|
return std::stoul(hex, nullptr, 16);
|
|
|
|
}
|
|
|
|
|
2019-01-12 01:25:28 +00:00
|
|
|
void CodeViewWidget::FontBasedSizing()
|
|
|
|
{
|
2020-03-07 01:06:10 +00:00
|
|
|
// just text width is too small with some fonts, so increase by a bit
|
|
|
|
constexpr int extra_text_width = 8;
|
|
|
|
|
2019-01-12 01:25:28 +00:00
|
|
|
const QFontMetrics fm(Settings::Instance().GetDebugFont());
|
2020-05-02 17:01:11 +00:00
|
|
|
|
2019-01-12 01:25:28 +00:00
|
|
|
const int rowh = fm.height() + 1;
|
|
|
|
verticalHeader()->setMaximumSectionSize(rowh);
|
|
|
|
horizontalHeader()->setMinimumSectionSize(rowh + 5);
|
2020-02-23 17:49:18 +00:00
|
|
|
setColumnWidth(CODE_VIEW_COLUMN_BREAKPOINT, rowh + 5);
|
2020-05-17 22:39:57 +00:00
|
|
|
setColumnWidth(CODE_VIEW_COLUMN_ADDRESS,
|
2020-06-08 10:19:10 +00:00
|
|
|
fm.boundingRect(QStringLiteral("80000000")).width() + extra_text_width);
|
2020-03-07 01:06:10 +00:00
|
|
|
|
|
|
|
// The longest instruction is technically 'ps_merge00' (0x10000420u), but those instructions are
|
|
|
|
// very rare and would needlessly increase the column size, so let's go with 'rlwinm.' instead.
|
|
|
|
// Similarly, the longest parameter set is 'rtoc, rtoc, r10, 10, 10 (00000800)' (0x5c425294u),
|
|
|
|
// but one is unlikely to encounter that in practice, so let's use a slightly more reasonable
|
|
|
|
// 'r31, r31, 16, 16, 31 (ffff0000)'. The user can resize the columns as necessary anyway.
|
|
|
|
const std::string disas = Common::GekkoDisassembler::Disassemble(0x57ff843fu, 0);
|
|
|
|
const auto split = disas.find('\t');
|
|
|
|
const std::string ins = (split == std::string::npos ? disas : disas.substr(0, split));
|
|
|
|
const std::string param = (split == std::string::npos ? "" : disas.substr(split + 1));
|
|
|
|
setColumnWidth(CODE_VIEW_COLUMN_INSTRUCTION,
|
2020-06-08 10:19:10 +00:00
|
|
|
fm.boundingRect(QString::fromStdString(ins)).width() + extra_text_width);
|
2020-03-07 01:06:10 +00:00
|
|
|
setColumnWidth(CODE_VIEW_COLUMN_PARAMETERS,
|
2020-06-08 10:19:10 +00:00
|
|
|
fm.boundingRect(QString::fromStdString(param)).width() + extra_text_width);
|
2020-05-17 22:39:57 +00:00
|
|
|
setColumnWidth(CODE_VIEW_COLUMN_DESCRIPTION,
|
2020-06-08 10:19:10 +00:00
|
|
|
fm.boundingRect(QChar(u'0')).width() * 25 + extra_text_width);
|
2020-03-07 01:06:10 +00:00
|
|
|
|
2019-01-12 01:25:28 +00:00
|
|
|
Update();
|
|
|
|
}
|
|
|
|
|
2020-02-23 17:57:08 +00:00
|
|
|
u32 CodeViewWidget::AddressForRow(int row) const
|
|
|
|
{
|
|
|
|
// m_address is defined as the center row of the table, so we have rowCount/2 instructions above
|
|
|
|
// it; an instruction is 4 bytes long on GC/Wii so we increment 4 bytes per row
|
|
|
|
const u32 row_zero_address = m_address - ((rowCount() / 2) * 4);
|
|
|
|
return row_zero_address + row * 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool IsBranchInstructionWithLink(std::string_view ins)
|
|
|
|
{
|
2023-01-24 19:25:49 +00:00
|
|
|
return ins.ends_with('l') || ins.ends_with("la") || ins.ends_with("l+") || ins.ends_with("la+") ||
|
|
|
|
ins.ends_with("l-") || ins.ends_with("la-");
|
2020-02-23 17:57:08 +00:00
|
|
|
}
|
|
|
|
|
2022-03-17 19:53:38 +00:00
|
|
|
static bool IsInstructionLoadStore(std::string_view ins)
|
|
|
|
{
|
|
|
|
// Could add check for context address being near PC, because we need gprs to be correct for the
|
|
|
|
// load/store.
|
2023-01-24 19:25:49 +00:00
|
|
|
return (ins.starts_with('l') && !ins.starts_with("li")) || ins.starts_with("st") ||
|
|
|
|
ins.starts_with("psq_l") || ins.starts_with("psq_s");
|
2022-03-17 19:53:38 +00:00
|
|
|
}
|
|
|
|
|
2018-02-14 22:25:01 +00:00
|
|
|
void CodeViewWidget::Update()
|
2023-02-12 10:07:11 +00:00
|
|
|
{
|
|
|
|
if (!isVisible())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (m_updating)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (Core::GetState() == Core::State::Paused)
|
|
|
|
{
|
2023-03-28 21:52:36 +00:00
|
|
|
Core::CPUThreadGuard guard(m_system);
|
2023-02-12 10:07:11 +00:00
|
|
|
Update(&guard);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// If the core is running, blank out the view of memory instead of reading anything.
|
|
|
|
Update(nullptr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CodeViewWidget::Update(const Core::CPUThreadGuard* guard)
|
2018-02-14 22:25:01 +00:00
|
|
|
{
|
2019-07-06 08:50:11 +00:00
|
|
|
if (!isVisible())
|
|
|
|
return;
|
|
|
|
|
2018-02-14 22:25:01 +00:00
|
|
|
if (m_updating)
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_updating = true;
|
|
|
|
|
|
|
|
clearSelection();
|
|
|
|
if (rowCount() == 0)
|
|
|
|
setRowCount(1);
|
|
|
|
|
|
|
|
// Calculate (roughly) how many rows will fit in our table
|
|
|
|
int rows = std::round((height() / static_cast<float>(rowHeight(0))) - 0.25);
|
|
|
|
|
|
|
|
setRowCount(rows);
|
|
|
|
|
2019-01-12 01:25:28 +00:00
|
|
|
const QFontMetrics fm(Settings::Instance().GetDebugFont());
|
|
|
|
const int rowh = fm.height() + 1;
|
|
|
|
|
2018-02-14 22:25:01 +00:00
|
|
|
for (int i = 0; i < rows; i++)
|
2019-01-12 01:25:28 +00:00
|
|
|
setRowHeight(i, rowh);
|
2018-02-14 22:25:01 +00:00
|
|
|
|
2023-03-28 18:26:52 +00:00
|
|
|
auto& power_pc = m_system.GetPowerPC();
|
|
|
|
auto& debug_interface = power_pc.GetDebugInterface();
|
|
|
|
|
2023-03-28 21:52:36 +00:00
|
|
|
const std::optional<u32> pc =
|
2023-03-28 18:26:52 +00:00
|
|
|
guard ? std::make_optional(power_pc.GetPPCState().pc) : std::nullopt;
|
2018-02-14 22:25:01 +00:00
|
|
|
|
2018-05-16 00:24:29 +00:00
|
|
|
const bool dark_theme = qApp->palette().color(QPalette::Base).valueF() < 0.5;
|
|
|
|
|
2020-02-23 17:57:08 +00:00
|
|
|
m_branches.clear();
|
|
|
|
|
2018-02-14 22:25:01 +00:00
|
|
|
for (int i = 0; i < rowCount(); i++)
|
|
|
|
{
|
2020-02-23 17:57:08 +00:00
|
|
|
const u32 addr = AddressForRow(i);
|
2023-03-28 18:26:52 +00:00
|
|
|
const u32 color = debug_interface.GetColor(guard, addr);
|
2018-02-14 22:25:01 +00:00
|
|
|
auto* bp_item = new QTableWidgetItem;
|
|
|
|
auto* addr_item = new QTableWidgetItem(QStringLiteral("%1").arg(addr, 8, 16, QLatin1Char('0')));
|
|
|
|
|
2023-03-28 18:26:52 +00:00
|
|
|
std::string disas = debug_interface.Disassemble(guard, addr);
|
2018-02-14 22:25:01 +00:00
|
|
|
auto split = disas.find('\t');
|
|
|
|
|
|
|
|
std::string ins = (split == std::string::npos ? disas : disas.substr(0, split));
|
|
|
|
std::string param = (split == std::string::npos ? "" : disas.substr(split + 1));
|
2023-03-28 18:26:52 +00:00
|
|
|
std::string desc = debug_interface.GetDescription(addr);
|
2018-02-14 22:25:01 +00:00
|
|
|
|
2019-01-12 01:25:28 +00:00
|
|
|
// Adds whitespace and a minimum size to ins and param. Helps to prevent frequent resizing while
|
|
|
|
// scrolling.
|
|
|
|
const QString ins_formatted =
|
|
|
|
QStringLiteral("%1").arg(QString::fromStdString(ins), -7, QLatin1Char(' '));
|
|
|
|
const QString param_formatted =
|
|
|
|
QStringLiteral("%1").arg(QString::fromStdString(param), -19, QLatin1Char(' '));
|
|
|
|
const QString desc_formatted = QStringLiteral("%1 ").arg(QString::fromStdString(desc));
|
|
|
|
|
|
|
|
auto* ins_item = new QTableWidgetItem(ins_formatted);
|
|
|
|
auto* param_item = new QTableWidgetItem(param_formatted);
|
|
|
|
auto* description_item = new QTableWidgetItem(desc_formatted);
|
2020-02-23 17:57:08 +00:00
|
|
|
auto* branch_item = new QTableWidgetItem();
|
2018-02-14 22:25:01 +00:00
|
|
|
|
2020-02-23 17:57:08 +00:00
|
|
|
for (auto* item : {bp_item, addr_item, ins_item, param_item, description_item, branch_item})
|
2018-05-05 05:31:53 +00:00
|
|
|
{
|
|
|
|
item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
|
|
|
|
item->setData(Qt::UserRole, addr);
|
|
|
|
|
2018-05-16 00:24:29 +00:00
|
|
|
if (addr == pc && item != bp_item)
|
2018-05-05 05:31:53 +00:00
|
|
|
{
|
2018-05-16 00:24:29 +00:00
|
|
|
item->setBackground(QColor(Qt::green));
|
|
|
|
item->setForeground(QColor(Qt::black));
|
2018-05-05 05:31:53 +00:00
|
|
|
}
|
2018-05-16 00:24:29 +00:00
|
|
|
else if (color != 0xFFFFFF)
|
2018-05-05 05:31:53 +00:00
|
|
|
{
|
2018-05-16 00:24:29 +00:00
|
|
|
item->setBackground(dark_theme ? QColor(color).darker(240) : QColor(color));
|
2018-05-05 05:31:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-14 22:25:01 +00:00
|
|
|
// look for hex strings to decode branches
|
|
|
|
std::string hex_str;
|
|
|
|
size_t pos = param.find("0x");
|
|
|
|
if (pos != std::string::npos)
|
|
|
|
{
|
|
|
|
hex_str = param.substr(pos);
|
|
|
|
}
|
|
|
|
|
2023-02-12 10:07:11 +00:00
|
|
|
if (guard && hex_str.length() == VALID_BRANCH_LENGTH && desc != "---")
|
2018-02-14 22:25:01 +00:00
|
|
|
{
|
2023-02-12 10:07:11 +00:00
|
|
|
u32 branch_addr = GetBranchFromAddress(*guard, addr);
|
2020-02-23 17:57:08 +00:00
|
|
|
CodeViewBranch& branch = m_branches.emplace_back();
|
|
|
|
branch.src_addr = addr;
|
|
|
|
branch.dst_addr = branch_addr;
|
|
|
|
branch.is_link = IsBranchInstructionWithLink(ins);
|
|
|
|
|
2023-03-28 18:26:52 +00:00
|
|
|
description_item->setText(
|
|
|
|
tr("--> %1").arg(QString::fromStdString(debug_interface.GetDescription(branch_addr))));
|
2018-02-14 22:25:01 +00:00
|
|
|
param_item->setForeground(Qt::magenta);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ins == "blr")
|
2018-05-16 00:24:29 +00:00
|
|
|
ins_item->setForeground(dark_theme ? QColor(0xa0FFa0) : Qt::darkGreen);
|
2018-02-14 22:25:01 +00:00
|
|
|
|
2023-03-28 18:26:52 +00:00
|
|
|
if (debug_interface.IsBreakpoint(addr))
|
2018-02-14 22:25:01 +00:00
|
|
|
{
|
2021-03-04 16:33:08 +00:00
|
|
|
auto icon =
|
|
|
|
Resources::GetScaledThemeIcon("debugger_breakpoint").pixmap(QSize(rowh - 2, rowh - 2));
|
2023-03-28 18:26:52 +00:00
|
|
|
if (!m_system.GetPowerPC().GetBreakPoints().IsBreakPointEnable(addr))
|
2021-03-04 16:33:08 +00:00
|
|
|
{
|
|
|
|
QPixmap disabled_icon(icon.size());
|
|
|
|
disabled_icon.fill(Qt::transparent);
|
|
|
|
QPainter p(&disabled_icon);
|
|
|
|
p.setOpacity(0.20);
|
|
|
|
p.drawPixmap(0, 0, icon);
|
|
|
|
p.end();
|
|
|
|
icon = disabled_icon;
|
|
|
|
}
|
|
|
|
bp_item->setData(Qt::DecorationRole, icon);
|
2018-02-14 22:25:01 +00:00
|
|
|
}
|
|
|
|
|
2020-02-23 17:49:18 +00:00
|
|
|
setItem(i, CODE_VIEW_COLUMN_BREAKPOINT, bp_item);
|
|
|
|
setItem(i, CODE_VIEW_COLUMN_ADDRESS, addr_item);
|
|
|
|
setItem(i, CODE_VIEW_COLUMN_INSTRUCTION, ins_item);
|
|
|
|
setItem(i, CODE_VIEW_COLUMN_PARAMETERS, param_item);
|
|
|
|
setItem(i, CODE_VIEW_COLUMN_DESCRIPTION, description_item);
|
2020-02-23 17:57:08 +00:00
|
|
|
setItem(i, CODE_VIEW_COLUMN_BRANCH_ARROWS, branch_item);
|
2018-02-14 22:25:01 +00:00
|
|
|
|
|
|
|
if (addr == GetAddress())
|
|
|
|
{
|
2018-05-05 08:21:15 +00:00
|
|
|
selectRow(addr_item->row());
|
2018-02-14 22:25:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-26 20:33:43 +00:00
|
|
|
CalculateBranchIndentation();
|
|
|
|
|
2018-02-14 22:25:01 +00:00
|
|
|
g_symbolDB.FillInCallers();
|
|
|
|
|
|
|
|
repaint();
|
|
|
|
m_updating = false;
|
|
|
|
}
|
|
|
|
|
2020-02-26 20:33:43 +00:00
|
|
|
void CodeViewWidget::CalculateBranchIndentation()
|
|
|
|
{
|
2022-01-17 08:21:58 +00:00
|
|
|
const u32 rows = rowCount();
|
2020-02-26 20:33:43 +00:00
|
|
|
const size_t columns = m_branches.size();
|
|
|
|
if (rows < 1 || columns < 1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// process in order of how much vertical space the drawn arrow would take up
|
|
|
|
// so shorter arrows go further to the left
|
|
|
|
const auto priority = [](const CodeViewBranch& b) {
|
|
|
|
return b.is_link ? 0 : (std::max(b.src_addr, b.dst_addr) - std::min(b.src_addr, b.dst_addr));
|
|
|
|
};
|
|
|
|
std::stable_sort(m_branches.begin(), m_branches.end(),
|
|
|
|
[&priority](const CodeViewBranch& lhs, const CodeViewBranch& rhs) {
|
|
|
|
return priority(lhs) < priority(rhs);
|
|
|
|
});
|
|
|
|
|
|
|
|
// build a 2D lookup table representing the columns and rows the arrow could be drawn in
|
|
|
|
// and try to place all branch arrows in it as far left as possible
|
|
|
|
std::vector<bool> arrow_space_used(columns * rows, false);
|
2021-12-09 01:10:39 +00:00
|
|
|
const auto index = [&](u32 column, u32 row) {
|
|
|
|
ASSERT(row <= rows);
|
|
|
|
ASSERT(column <= columns);
|
|
|
|
return column * rows + row;
|
|
|
|
};
|
|
|
|
|
|
|
|
const auto add_branch_arrow = [&](CodeViewBranch& branch, u32 first_addr, u32 first_row,
|
|
|
|
u32 last_addr) {
|
2020-02-26 20:33:43 +00:00
|
|
|
const u32 arrow_src_addr = branch.src_addr;
|
|
|
|
const u32 arrow_dst_addr = branch.is_link ? branch.src_addr : branch.dst_addr;
|
2021-12-09 01:10:39 +00:00
|
|
|
const auto [arrow_addr_lower, arrow_addr_higher] = std::minmax(arrow_src_addr, arrow_dst_addr);
|
|
|
|
|
2020-02-26 20:33:43 +00:00
|
|
|
const bool is_visible =
|
2021-12-09 01:10:39 +00:00
|
|
|
std::max(arrow_addr_lower, first_addr) <= std::min(arrow_addr_higher, last_addr);
|
2020-02-26 20:33:43 +00:00
|
|
|
if (!is_visible)
|
2021-12-09 01:10:39 +00:00
|
|
|
return;
|
2020-02-26 20:33:43 +00:00
|
|
|
|
2021-12-09 01:10:39 +00:00
|
|
|
const u32 arrow_first_visible_addr = std::clamp(arrow_addr_lower, first_addr, last_addr);
|
|
|
|
const u32 arrow_last_visible_addr = std::clamp(arrow_addr_higher, first_addr, last_addr);
|
|
|
|
const u32 arrow_first_visible_row = (arrow_first_visible_addr - first_addr) / 4 + first_row;
|
|
|
|
const u32 arrow_last_visible_row = (arrow_last_visible_addr - first_addr) / 4 + first_row;
|
2020-02-26 20:33:43 +00:00
|
|
|
|
|
|
|
const auto free_column = [&]() -> std::optional<u32> {
|
|
|
|
for (u32 column = 0; column < columns; ++column)
|
|
|
|
{
|
|
|
|
const bool column_is_free = [&] {
|
|
|
|
for (u32 row = arrow_first_visible_row; row <= arrow_last_visible_row; ++row)
|
|
|
|
{
|
|
|
|
if (arrow_space_used[index(column, row)])
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}();
|
|
|
|
if (column_is_free)
|
|
|
|
return column;
|
|
|
|
}
|
|
|
|
return std::nullopt;
|
|
|
|
}();
|
|
|
|
|
|
|
|
if (!free_column)
|
2021-12-09 01:10:39 +00:00
|
|
|
return;
|
2020-02-26 20:33:43 +00:00
|
|
|
|
|
|
|
branch.indentation = *free_column;
|
|
|
|
for (u32 row = arrow_first_visible_row; row <= arrow_last_visible_row; ++row)
|
|
|
|
arrow_space_used[index(*free_column, row)] = true;
|
2021-12-09 01:10:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const u32 first_visible_addr = AddressForRow(0);
|
2022-01-17 08:21:58 +00:00
|
|
|
const u32 last_visible_addr = AddressForRow(rows - 1);
|
2021-12-09 01:10:39 +00:00
|
|
|
|
|
|
|
if (first_visible_addr <= last_visible_addr)
|
|
|
|
{
|
|
|
|
for (CodeViewBranch& branch : m_branches)
|
|
|
|
add_branch_arrow(branch, first_visible_addr, 0, last_visible_addr);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Scrolling defaults to being centered around address 00000000, which means addresses before
|
|
|
|
// the start are visible (e.g. ffffffa8 - 00000050). We need to do this in two parts, one for
|
|
|
|
// first_visible_addr to fffffffc, and the second for 00000000 to last_visible_addr.
|
|
|
|
// That means we need to find the row corresponding to 00000000.
|
|
|
|
int addr_zero_row = -1;
|
2022-01-17 08:21:58 +00:00
|
|
|
for (u32 row = 0; row < rows; row++)
|
2021-12-09 01:10:39 +00:00
|
|
|
{
|
|
|
|
if (AddressForRow(row) == 0)
|
|
|
|
{
|
|
|
|
addr_zero_row = row;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ASSERT(addr_zero_row != -1);
|
|
|
|
|
|
|
|
for (CodeViewBranch& branch : m_branches)
|
|
|
|
{
|
|
|
|
add_branch_arrow(branch, first_visible_addr, 0, 0xfffffffc);
|
|
|
|
add_branch_arrow(branch, 0x00000000, addr_zero_row, last_visible_addr);
|
|
|
|
}
|
2020-02-26 20:33:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-14 22:25:01 +00:00
|
|
|
u32 CodeViewWidget::GetAddress() const
|
|
|
|
{
|
|
|
|
return m_address;
|
|
|
|
}
|
|
|
|
|
2018-05-05 22:17:06 +00:00
|
|
|
void CodeViewWidget::SetAddress(u32 address, SetAddressUpdate update)
|
2018-02-14 22:25:01 +00:00
|
|
|
{
|
|
|
|
if (m_address == address)
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_address = address;
|
2021-02-14 12:01:32 +00:00
|
|
|
switch (update)
|
|
|
|
{
|
|
|
|
case SetAddressUpdate::WithoutUpdate:
|
|
|
|
return;
|
|
|
|
case SetAddressUpdate::WithUpdate:
|
|
|
|
// Update the CodeViewWidget
|
2018-05-05 22:17:06 +00:00
|
|
|
Update();
|
2021-02-14 12:01:32 +00:00
|
|
|
break;
|
|
|
|
case SetAddressUpdate::WithDetailedUpdate:
|
|
|
|
// Update the CodeWidget's views (code view, function calls/callers, ...)
|
|
|
|
emit UpdateCodeWidget();
|
|
|
|
break;
|
|
|
|
}
|
2018-02-14 22:25:01 +00:00
|
|
|
}
|
|
|
|
|
2018-05-13 22:24:30 +00:00
|
|
|
void CodeViewWidget::ReplaceAddress(u32 address, ReplaceWith replace)
|
2018-02-14 22:25:01 +00:00
|
|
|
{
|
2023-03-28 21:52:36 +00:00
|
|
|
Core::CPUThreadGuard guard(m_system);
|
2023-02-12 10:07:11 +00:00
|
|
|
|
2023-03-28 18:26:52 +00:00
|
|
|
m_system.GetPowerPC().GetDebugInterface().SetPatch(
|
|
|
|
guard, address, replace == ReplaceWith::BLR ? 0x4e800020 : 0x60000000);
|
2023-02-12 10:07:11 +00:00
|
|
|
|
|
|
|
Update(&guard);
|
2018-02-14 22:25:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CodeViewWidget::OnContextMenu()
|
|
|
|
{
|
|
|
|
QMenu* menu = new QMenu(this);
|
|
|
|
|
2023-02-12 10:07:11 +00:00
|
|
|
const bool running = Core::GetState() != Core::State::Uninitialized;
|
|
|
|
const bool paused = Core::GetState() == Core::State::Paused;
|
2018-02-14 22:25:01 +00:00
|
|
|
|
|
|
|
const u32 addr = GetContextAddress();
|
|
|
|
|
|
|
|
bool has_symbol = g_symbolDB.GetSymbolFromAddr(addr);
|
|
|
|
|
|
|
|
auto* follow_branch_action =
|
2018-07-09 08:02:10 +00:00
|
|
|
menu->addAction(tr("Follow &branch"), this, &CodeViewWidget::OnFollowBranch);
|
2018-02-14 22:25:01 +00:00
|
|
|
|
|
|
|
menu->addSeparator();
|
|
|
|
|
2018-07-09 08:02:10 +00:00
|
|
|
menu->addAction(tr("&Copy address"), this, &CodeViewWidget::OnCopyAddress);
|
2018-02-14 22:25:01 +00:00
|
|
|
auto* copy_address_action =
|
2018-07-09 08:02:10 +00:00
|
|
|
menu->addAction(tr("Copy &function"), this, &CodeViewWidget::OnCopyFunction);
|
2018-02-14 22:25:01 +00:00
|
|
|
auto* copy_line_action =
|
2018-07-09 08:02:10 +00:00
|
|
|
menu->addAction(tr("Copy code &line"), this, &CodeViewWidget::OnCopyCode);
|
|
|
|
auto* copy_hex_action = menu->addAction(tr("Copy &hex"), this, &CodeViewWidget::OnCopyHex);
|
2018-12-28 18:12:30 +00:00
|
|
|
|
|
|
|
menu->addAction(tr("Show in &memory"), this, &CodeViewWidget::OnShowInMemory);
|
2022-03-17 19:53:38 +00:00
|
|
|
auto* show_target_memory =
|
|
|
|
menu->addAction(tr("Show target in memor&y"), this, &CodeViewWidget::OnShowTargetInMemory);
|
|
|
|
auto* copy_target_memory =
|
|
|
|
menu->addAction(tr("Copy tar&get address"), this, &CodeViewWidget::OnCopyTargetAddress);
|
2018-02-14 22:25:01 +00:00
|
|
|
menu->addSeparator();
|
|
|
|
|
|
|
|
auto* symbol_rename_action =
|
2018-07-09 08:02:10 +00:00
|
|
|
menu->addAction(tr("&Rename symbol"), this, &CodeViewWidget::OnRenameSymbol);
|
2018-02-14 22:25:01 +00:00
|
|
|
auto* symbol_size_action =
|
2018-07-09 08:02:10 +00:00
|
|
|
menu->addAction(tr("Set symbol &size"), this, &CodeViewWidget::OnSetSymbolSize);
|
2018-02-14 22:25:01 +00:00
|
|
|
auto* symbol_end_action =
|
2018-07-09 08:02:10 +00:00
|
|
|
menu->addAction(tr("Set symbol &end address"), this, &CodeViewWidget::OnSetSymbolEndAddress);
|
2018-02-14 22:25:01 +00:00
|
|
|
menu->addSeparator();
|
|
|
|
|
2018-07-09 08:02:10 +00:00
|
|
|
menu->addAction(tr("Run &To Here"), this, &CodeViewWidget::OnRunToHere);
|
2018-02-14 22:25:01 +00:00
|
|
|
auto* function_action =
|
2018-07-09 08:02:10 +00:00
|
|
|
menu->addAction(tr("&Add function"), this, &CodeViewWidget::OnAddFunction);
|
|
|
|
auto* ppc_action = menu->addAction(tr("PPC vs Host"), this, &CodeViewWidget::OnPPCComparison);
|
|
|
|
auto* insert_blr_action = menu->addAction(tr("&Insert blr"), this, &CodeViewWidget::OnInsertBLR);
|
|
|
|
auto* insert_nop_action = menu->addAction(tr("Insert &nop"), this, &CodeViewWidget::OnInsertNOP);
|
2018-02-14 22:25:01 +00:00
|
|
|
auto* replace_action =
|
2018-07-09 08:02:10 +00:00
|
|
|
menu->addAction(tr("Re&place instruction"), this, &CodeViewWidget::OnReplaceInstruction);
|
2018-05-21 14:46:03 +00:00
|
|
|
auto* restore_action =
|
2018-07-09 08:02:10 +00:00
|
|
|
menu->addAction(tr("Restore instruction"), this, &CodeViewWidget::OnRestoreInstruction);
|
2018-02-14 22:25:01 +00:00
|
|
|
|
2022-03-26 21:48:25 +00:00
|
|
|
QString target;
|
2023-02-12 10:07:11 +00:00
|
|
|
bool valid_load_store = false;
|
|
|
|
bool follow_branch_enabled = false;
|
|
|
|
if (paused)
|
2022-03-26 21:48:25 +00:00
|
|
|
{
|
2023-03-28 21:52:36 +00:00
|
|
|
Core::CPUThreadGuard guard(m_system);
|
|
|
|
const u32 pc = m_system.GetPPCState().pc;
|
2023-03-28 18:26:52 +00:00
|
|
|
const std::string disasm = m_system.GetPowerPC().GetDebugInterface().Disassemble(&guard, pc);
|
2023-02-12 10:07:11 +00:00
|
|
|
|
2023-03-28 21:52:36 +00:00
|
|
|
if (addr == pc)
|
2023-02-12 10:07:11 +00:00
|
|
|
{
|
|
|
|
const auto target_it = std::find(disasm.begin(), disasm.end(), '\t');
|
|
|
|
const auto target_end = std::find(target_it, disasm.end(), ',');
|
2022-03-26 21:48:25 +00:00
|
|
|
|
2023-02-12 10:07:11 +00:00
|
|
|
if (target_it != disasm.end() && target_end != disasm.end())
|
|
|
|
target = QString::fromStdString(std::string{target_it + 1, target_end});
|
|
|
|
}
|
|
|
|
|
|
|
|
valid_load_store = IsInstructionLoadStore(disasm);
|
|
|
|
|
|
|
|
follow_branch_enabled = GetBranchFromAddress(guard, addr);
|
2022-03-26 21:48:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
auto* run_until_menu = menu->addMenu(tr("Run until (ignoring breakpoints)"));
|
2022-11-26 21:58:46 +00:00
|
|
|
// i18n: One of the options shown below "Run until (ignoring breakpoints)"
|
2022-03-26 21:48:25 +00:00
|
|
|
run_until_menu->addAction(tr("%1's value is hit").arg(target), this,
|
|
|
|
[this] { AutoStep(CodeTrace::AutoStop::Always); });
|
2022-11-26 21:58:46 +00:00
|
|
|
// i18n: One of the options shown below "Run until (ignoring breakpoints)"
|
2022-03-26 21:48:25 +00:00
|
|
|
run_until_menu->addAction(tr("%1's value is used").arg(target), this,
|
|
|
|
[this] { AutoStep(CodeTrace::AutoStop::Used); });
|
2022-11-26 21:58:46 +00:00
|
|
|
// i18n: One of the options shown below "Run until (ignoring breakpoints)"
|
2022-03-26 21:48:25 +00:00
|
|
|
run_until_menu->addAction(tr("%1's value is changed").arg(target),
|
|
|
|
[this] { AutoStep(CodeTrace::AutoStop::Changed); });
|
|
|
|
|
|
|
|
run_until_menu->setEnabled(!target.isEmpty());
|
2023-02-12 10:07:11 +00:00
|
|
|
follow_branch_action->setEnabled(follow_branch_enabled);
|
2018-02-14 22:25:01 +00:00
|
|
|
|
|
|
|
for (auto* action : {copy_address_action, copy_line_action, copy_hex_action, function_action,
|
|
|
|
ppc_action, insert_blr_action, insert_nop_action, replace_action})
|
2023-02-12 10:07:11 +00:00
|
|
|
{
|
2018-02-14 22:25:01 +00:00
|
|
|
action->setEnabled(running);
|
2023-02-12 10:07:11 +00:00
|
|
|
}
|
2018-02-14 22:25:01 +00:00
|
|
|
|
|
|
|
for (auto* action : {symbol_rename_action, symbol_size_action, symbol_end_action})
|
|
|
|
action->setEnabled(has_symbol);
|
|
|
|
|
2022-03-17 19:53:38 +00:00
|
|
|
for (auto* action : {copy_target_memory, show_target_memory})
|
|
|
|
{
|
|
|
|
action->setEnabled(valid_load_store);
|
|
|
|
}
|
|
|
|
|
2023-03-28 18:26:52 +00:00
|
|
|
restore_action->setEnabled(running &&
|
|
|
|
m_system.GetPowerPC().GetDebugInterface().HasEnabledPatch(addr));
|
2018-05-21 14:46:03 +00:00
|
|
|
|
2018-02-14 22:25:01 +00:00
|
|
|
menu->exec(QCursor::pos());
|
|
|
|
Update();
|
|
|
|
}
|
|
|
|
|
2022-03-26 21:48:25 +00:00
|
|
|
void CodeViewWidget::AutoStep(CodeTrace::AutoStop option)
|
|
|
|
{
|
|
|
|
// Autosteps and follows value in the target (left-most) register. The Used and Changed options
|
|
|
|
// silently follows target through reshuffles in memory and registers and stops on use or update.
|
|
|
|
|
2023-03-28 21:52:36 +00:00
|
|
|
Core::CPUThreadGuard guard(m_system);
|
2023-02-12 10:07:11 +00:00
|
|
|
|
2022-03-26 21:48:25 +00:00
|
|
|
CodeTrace code_trace;
|
|
|
|
bool repeat = false;
|
|
|
|
|
|
|
|
QMessageBox msgbox(QMessageBox::NoIcon, tr("Run until"), {}, QMessageBox::Cancel);
|
|
|
|
QPushButton* run_button = msgbox.addButton(tr("Keep Running"), QMessageBox::AcceptRole);
|
|
|
|
// Not sure if we want default to be cancel. Spacebar can let you quickly continue autostepping if
|
|
|
|
// Yes.
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
// Run autostep then update codeview
|
2023-02-12 10:07:11 +00:00
|
|
|
const AutoStepResults results = code_trace.AutoStepping(guard, repeat, option);
|
2022-03-26 21:48:25 +00:00
|
|
|
emit Host::GetInstance()->UpdateDisasmDialog();
|
|
|
|
repeat = true;
|
|
|
|
|
|
|
|
// Invalid instruction, 0 means no step executed.
|
|
|
|
if (results.count == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Status report
|
|
|
|
if (results.reg_tracked.empty() && results.mem_tracked.empty())
|
|
|
|
{
|
|
|
|
QMessageBox::warning(
|
|
|
|
this, tr("Overwritten"),
|
|
|
|
tr("Target value was overwritten by current instruction.\nInstructions executed: %1")
|
|
|
|
.arg(QString::number(results.count)),
|
|
|
|
QMessageBox::Cancel);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if (results.timed_out)
|
|
|
|
{
|
|
|
|
// Can keep running and try again after a time out.
|
|
|
|
msgbox.setText(
|
|
|
|
tr("<font color='#ff0000'>AutoStepping timed out. Current instruction is irrelevant."));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
msgbox.setText(tr("Value tracked to current instruction."));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Mem_tracked needs to track each byte individually, so a tracked word-sized value would have
|
|
|
|
// four entries. The displayed memory list needs to be shortened so it's not a huge list of
|
|
|
|
// bytes. Assumes adjacent bytes represent a word or half-word and removes the redundant bytes.
|
|
|
|
std::set<u32> mem_out;
|
|
|
|
auto iter = results.mem_tracked.begin();
|
|
|
|
|
|
|
|
while (iter != results.mem_tracked.end())
|
|
|
|
{
|
|
|
|
const u32 address = *iter;
|
|
|
|
mem_out.insert(address);
|
|
|
|
|
|
|
|
for (u32 i = 1; i <= 3; i++)
|
|
|
|
{
|
|
|
|
if (results.mem_tracked.count(address + i))
|
|
|
|
iter++;
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
iter++;
|
|
|
|
}
|
|
|
|
|
|
|
|
const QString msgtext =
|
|
|
|
tr("Instructions executed: %1\nValue contained in:\nRegisters: %2\nMemory: %3")
|
|
|
|
.arg(QString::number(results.count))
|
|
|
|
.arg(QString::fromStdString(fmt::format("{}", fmt::join(results.reg_tracked, ", "))))
|
|
|
|
.arg(QString::fromStdString(fmt::format("{:#x}", fmt::join(mem_out, ", "))));
|
|
|
|
|
|
|
|
msgbox.setInformativeText(msgtext);
|
|
|
|
msgbox.exec();
|
|
|
|
|
|
|
|
} while (msgbox.clickedButton() == (QAbstractButton*)run_button);
|
|
|
|
}
|
|
|
|
|
2018-02-14 22:25:01 +00:00
|
|
|
void CodeViewWidget::OnCopyAddress()
|
|
|
|
{
|
|
|
|
const u32 addr = GetContextAddress();
|
|
|
|
|
|
|
|
QApplication::clipboard()->setText(QStringLiteral("%1").arg(addr, 8, 16, QLatin1Char('0')));
|
|
|
|
}
|
|
|
|
|
2022-03-17 19:53:38 +00:00
|
|
|
void CodeViewWidget::OnCopyTargetAddress()
|
|
|
|
{
|
|
|
|
if (Core::GetState() != Core::State::Paused)
|
|
|
|
return;
|
|
|
|
|
2023-02-12 10:07:11 +00:00
|
|
|
const u32 addr = GetContextAddress();
|
|
|
|
|
2023-03-28 21:52:36 +00:00
|
|
|
const std::string code_line = [this, addr] {
|
|
|
|
Core::CPUThreadGuard guard(m_system);
|
2023-03-28 18:26:52 +00:00
|
|
|
return m_system.GetPowerPC().GetDebugInterface().Disassemble(&guard, addr);
|
2023-02-12 10:07:11 +00:00
|
|
|
}();
|
2022-03-17 19:53:38 +00:00
|
|
|
|
|
|
|
if (!IsInstructionLoadStore(code_line))
|
|
|
|
return;
|
|
|
|
|
2023-02-12 10:07:11 +00:00
|
|
|
const std::optional<u32> target_addr =
|
2023-03-28 18:26:52 +00:00
|
|
|
m_system.GetPowerPC().GetDebugInterface().GetMemoryAddressFromInstruction(code_line);
|
2022-03-17 19:53:38 +00:00
|
|
|
|
2023-02-14 17:44:16 +00:00
|
|
|
if (target_addr)
|
2023-02-12 10:07:11 +00:00
|
|
|
{
|
|
|
|
QApplication::clipboard()->setText(
|
|
|
|
QStringLiteral("%1").arg(*target_addr, 8, 16, QLatin1Char('0')));
|
|
|
|
}
|
2022-03-17 19:53:38 +00:00
|
|
|
}
|
|
|
|
|
2018-12-28 18:12:30 +00:00
|
|
|
void CodeViewWidget::OnShowInMemory()
|
|
|
|
{
|
|
|
|
emit ShowMemory(GetContextAddress());
|
|
|
|
}
|
|
|
|
|
2022-03-17 19:53:38 +00:00
|
|
|
void CodeViewWidget::OnShowTargetInMemory()
|
|
|
|
{
|
|
|
|
if (Core::GetState() != Core::State::Paused)
|
|
|
|
return;
|
|
|
|
|
2023-02-12 10:07:11 +00:00
|
|
|
const u32 addr = GetContextAddress();
|
|
|
|
|
2023-03-28 21:52:36 +00:00
|
|
|
const std::string code_line = [this, addr] {
|
|
|
|
Core::CPUThreadGuard guard(m_system);
|
2023-03-28 18:26:52 +00:00
|
|
|
return m_system.GetPowerPC().GetDebugInterface().Disassemble(&guard, addr);
|
2023-02-12 10:07:11 +00:00
|
|
|
}();
|
2022-03-17 19:53:38 +00:00
|
|
|
|
|
|
|
if (!IsInstructionLoadStore(code_line))
|
|
|
|
return;
|
|
|
|
|
2023-02-12 10:07:11 +00:00
|
|
|
const std::optional<u32> target_addr =
|
2023-03-28 18:26:52 +00:00
|
|
|
m_system.GetPowerPC().GetDebugInterface().GetMemoryAddressFromInstruction(code_line);
|
2022-03-17 19:53:38 +00:00
|
|
|
|
2023-02-14 17:44:16 +00:00
|
|
|
if (target_addr)
|
2023-02-12 10:07:11 +00:00
|
|
|
emit ShowMemory(*target_addr);
|
2022-03-17 19:53:38 +00:00
|
|
|
}
|
|
|
|
|
2018-02-14 22:25:01 +00:00
|
|
|
void CodeViewWidget::OnCopyCode()
|
|
|
|
{
|
|
|
|
const u32 addr = GetContextAddress();
|
|
|
|
|
2023-03-28 21:52:36 +00:00
|
|
|
const std::string text = [this, addr] {
|
|
|
|
Core::CPUThreadGuard guard(m_system);
|
2023-03-28 18:26:52 +00:00
|
|
|
return m_system.GetPowerPC().GetDebugInterface().Disassemble(&guard, addr);
|
2023-02-12 10:07:11 +00:00
|
|
|
}();
|
|
|
|
|
|
|
|
QApplication::clipboard()->setText(QString::fromStdString(text));
|
2018-02-14 22:25:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CodeViewWidget::OnCopyFunction()
|
|
|
|
{
|
|
|
|
const u32 address = GetContextAddress();
|
|
|
|
|
2018-05-27 21:37:52 +00:00
|
|
|
const Common::Symbol* symbol = g_symbolDB.GetSymbolFromAddr(address);
|
2018-02-14 22:25:01 +00:00
|
|
|
if (!symbol)
|
|
|
|
return;
|
|
|
|
|
|
|
|
std::string text = symbol->name + "\r\n";
|
2023-02-12 10:07:11 +00:00
|
|
|
|
2018-02-14 22:25:01 +00:00
|
|
|
{
|
2023-03-28 21:52:36 +00:00
|
|
|
Core::CPUThreadGuard guard(m_system);
|
2023-02-12 10:07:11 +00:00
|
|
|
|
|
|
|
// we got a function
|
|
|
|
const u32 start = symbol->address;
|
|
|
|
const u32 end = start + symbol->size;
|
|
|
|
for (u32 addr = start; addr != end; addr += 4)
|
|
|
|
{
|
2023-03-28 18:26:52 +00:00
|
|
|
const std::string disasm =
|
|
|
|
m_system.GetPowerPC().GetDebugInterface().Disassemble(&guard, addr);
|
2023-02-12 10:07:11 +00:00
|
|
|
fmt::format_to(std::back_inserter(text), "{:08x}: {}\r\n", addr, disasm);
|
|
|
|
}
|
2018-02-14 22:25:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QApplication::clipboard()->setText(QString::fromStdString(text));
|
|
|
|
}
|
|
|
|
|
|
|
|
void CodeViewWidget::OnCopyHex()
|
|
|
|
{
|
|
|
|
const u32 addr = GetContextAddress();
|
2023-02-12 10:07:11 +00:00
|
|
|
|
2023-03-28 21:52:36 +00:00
|
|
|
const u32 instruction = [this, addr] {
|
|
|
|
Core::CPUThreadGuard guard(m_system);
|
2023-03-28 18:26:52 +00:00
|
|
|
return m_system.GetPowerPC().GetDebugInterface().ReadInstruction(guard, addr);
|
2023-02-12 10:07:11 +00:00
|
|
|
}();
|
2018-02-14 22:25:01 +00:00
|
|
|
|
|
|
|
QApplication::clipboard()->setText(
|
|
|
|
QStringLiteral("%1").arg(instruction, 8, 16, QLatin1Char('0')));
|
|
|
|
}
|
|
|
|
|
|
|
|
void CodeViewWidget::OnRunToHere()
|
|
|
|
{
|
|
|
|
const u32 addr = GetContextAddress();
|
|
|
|
|
2023-03-28 18:26:52 +00:00
|
|
|
m_system.GetPowerPC().GetDebugInterface().SetBreakpoint(addr);
|
|
|
|
m_system.GetPowerPC().GetDebugInterface().RunToBreakpoint();
|
2018-02-14 22:25:01 +00:00
|
|
|
Update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CodeViewWidget::OnPPCComparison()
|
|
|
|
{
|
|
|
|
const u32 addr = GetContextAddress();
|
|
|
|
|
|
|
|
emit RequestPPCComparison(addr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CodeViewWidget::OnAddFunction()
|
|
|
|
{
|
|
|
|
const u32 addr = GetContextAddress();
|
|
|
|
|
2023-03-28 21:52:36 +00:00
|
|
|
Core::CPUThreadGuard guard(m_system);
|
2023-02-12 10:07:11 +00:00
|
|
|
|
|
|
|
g_symbolDB.AddFunction(guard, addr);
|
2018-02-14 22:25:01 +00:00
|
|
|
emit SymbolsChanged();
|
2023-02-12 10:07:11 +00:00
|
|
|
Update(&guard);
|
2018-02-14 22:25:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CodeViewWidget::OnInsertBLR()
|
|
|
|
{
|
|
|
|
const u32 addr = GetContextAddress();
|
|
|
|
|
2018-05-13 22:24:30 +00:00
|
|
|
ReplaceAddress(addr, ReplaceWith::BLR);
|
2018-02-14 22:25:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CodeViewWidget::OnInsertNOP()
|
|
|
|
{
|
|
|
|
const u32 addr = GetContextAddress();
|
|
|
|
|
2018-05-13 22:24:30 +00:00
|
|
|
ReplaceAddress(addr, ReplaceWith::NOP);
|
2018-02-14 22:25:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CodeViewWidget::OnFollowBranch()
|
|
|
|
{
|
|
|
|
const u32 addr = GetContextAddress();
|
|
|
|
|
2023-03-28 21:52:36 +00:00
|
|
|
const u32 branch_addr = [this, addr] {
|
|
|
|
Core::CPUThreadGuard guard(m_system);
|
2023-02-12 10:07:11 +00:00
|
|
|
return GetBranchFromAddress(guard, addr);
|
|
|
|
}();
|
2018-02-14 22:25:01 +00:00
|
|
|
|
|
|
|
if (!branch_addr)
|
|
|
|
return;
|
|
|
|
|
2021-02-14 12:01:32 +00:00
|
|
|
SetAddress(branch_addr, SetAddressUpdate::WithDetailedUpdate);
|
2018-02-14 22:25:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CodeViewWidget::OnRenameSymbol()
|
|
|
|
{
|
|
|
|
const u32 addr = GetContextAddress();
|
|
|
|
|
2021-08-21 17:35:21 +00:00
|
|
|
Common::Symbol* const symbol = g_symbolDB.GetSymbolFromAddr(addr);
|
2018-02-14 22:25:01 +00:00
|
|
|
|
|
|
|
if (!symbol)
|
|
|
|
return;
|
|
|
|
|
|
|
|
bool good;
|
2021-08-21 17:35:21 +00:00
|
|
|
const QString name =
|
2018-02-14 22:25:01 +00:00
|
|
|
QInputDialog::getText(this, tr("Rename symbol"), tr("Symbol name:"), QLineEdit::Normal,
|
2021-08-21 17:35:21 +00:00
|
|
|
QString::fromStdString(symbol->name), &good, Qt::WindowCloseButtonHint);
|
2018-02-14 22:25:01 +00:00
|
|
|
|
|
|
|
if (good && !name.isEmpty())
|
|
|
|
{
|
|
|
|
symbol->Rename(name.toStdString());
|
|
|
|
emit SymbolsChanged();
|
|
|
|
Update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-05 08:21:15 +00:00
|
|
|
void CodeViewWidget::OnSelectionChanged()
|
|
|
|
{
|
2023-03-28 21:52:36 +00:00
|
|
|
if (m_address == m_system.GetPPCState().pc)
|
2018-05-05 08:21:15 +00:00
|
|
|
{
|
2018-05-13 22:11:06 +00:00
|
|
|
setStyleSheet(
|
|
|
|
QStringLiteral("QTableView::item:selected {background-color: #00FF00; color: #000000;}"));
|
2018-05-05 08:21:15 +00:00
|
|
|
}
|
|
|
|
else if (!styleSheet().isEmpty())
|
|
|
|
{
|
2019-07-30 11:57:06 +00:00
|
|
|
setStyleSheet(QString{});
|
2018-05-05 08:21:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-14 22:25:01 +00:00
|
|
|
void CodeViewWidget::OnSetSymbolSize()
|
|
|
|
{
|
|
|
|
const u32 addr = GetContextAddress();
|
|
|
|
|
2021-08-21 17:35:21 +00:00
|
|
|
Common::Symbol* const symbol = g_symbolDB.GetSymbolFromAddr(addr);
|
2018-02-14 22:25:01 +00:00
|
|
|
|
|
|
|
if (!symbol)
|
|
|
|
return;
|
|
|
|
|
|
|
|
bool good;
|
2021-08-21 17:35:21 +00:00
|
|
|
const int size =
|
2018-02-14 22:25:01 +00:00
|
|
|
QInputDialog::getInt(this, tr("Rename symbol"),
|
|
|
|
tr("Set symbol size (%1):").arg(QString::fromStdString(symbol->name)),
|
2021-08-21 17:35:21 +00:00
|
|
|
symbol->size, 1, 0xFFFF, 1, &good, Qt::WindowCloseButtonHint);
|
2018-02-14 22:25:01 +00:00
|
|
|
|
|
|
|
if (!good)
|
|
|
|
return;
|
|
|
|
|
2023-03-28 21:52:36 +00:00
|
|
|
Core::CPUThreadGuard guard(m_system);
|
2023-02-12 10:07:11 +00:00
|
|
|
|
|
|
|
PPCAnalyst::ReanalyzeFunction(guard, symbol->address, *symbol, size);
|
2018-02-14 22:25:01 +00:00
|
|
|
emit SymbolsChanged();
|
2023-02-12 10:07:11 +00:00
|
|
|
Update(&guard);
|
2018-02-14 22:25:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CodeViewWidget::OnSetSymbolEndAddress()
|
|
|
|
{
|
|
|
|
const u32 addr = GetContextAddress();
|
|
|
|
|
2021-08-21 17:35:21 +00:00
|
|
|
Common::Symbol* const symbol = g_symbolDB.GetSymbolFromAddr(addr);
|
2018-02-14 22:25:01 +00:00
|
|
|
|
|
|
|
if (!symbol)
|
|
|
|
return;
|
|
|
|
|
|
|
|
bool good;
|
2021-08-21 17:35:21 +00:00
|
|
|
const QString name = QInputDialog::getText(
|
2018-02-14 22:25:01 +00:00
|
|
|
this, tr("Set symbol end address"),
|
|
|
|
tr("Symbol (%1) end address:").arg(QString::fromStdString(symbol->name)), QLineEdit::Normal,
|
2021-08-21 17:35:21 +00:00
|
|
|
QStringLiteral("%1").arg(addr + symbol->size, 8, 16, QLatin1Char('0')), &good,
|
|
|
|
Qt::WindowCloseButtonHint);
|
2018-02-14 22:25:01 +00:00
|
|
|
|
2021-08-21 17:35:21 +00:00
|
|
|
const u32 address = name.toUInt(&good, 16);
|
2018-02-14 22:25:01 +00:00
|
|
|
|
|
|
|
if (!good)
|
|
|
|
return;
|
|
|
|
|
2023-03-28 21:52:36 +00:00
|
|
|
Core::CPUThreadGuard guard(m_system);
|
2023-02-12 10:07:11 +00:00
|
|
|
|
|
|
|
PPCAnalyst::ReanalyzeFunction(guard, symbol->address, *symbol, address - symbol->address);
|
2018-02-14 22:25:01 +00:00
|
|
|
emit SymbolsChanged();
|
2023-02-12 10:07:11 +00:00
|
|
|
Update(&guard);
|
2018-02-14 22:25:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CodeViewWidget::OnReplaceInstruction()
|
|
|
|
{
|
2023-03-28 21:52:36 +00:00
|
|
|
Core::CPUThreadGuard guard(m_system);
|
2023-02-12 10:07:11 +00:00
|
|
|
|
2018-02-14 22:25:01 +00:00
|
|
|
const u32 addr = GetContextAddress();
|
|
|
|
|
2023-03-12 19:31:10 +00:00
|
|
|
if (!PowerPC::MMU::HostIsInstructionRAMAddress(guard, addr))
|
2018-02-14 22:25:01 +00:00
|
|
|
return;
|
|
|
|
|
2023-03-12 19:31:10 +00:00
|
|
|
const PowerPC::TryReadInstResult read_result =
|
|
|
|
guard.GetSystem().GetMMU().TryReadInstruction(addr);
|
2018-02-14 22:25:01 +00:00
|
|
|
if (!read_result.valid)
|
|
|
|
return;
|
|
|
|
|
2023-03-28 18:26:52 +00:00
|
|
|
auto& debug_interface = m_system.GetPowerPC().GetDebugInterface();
|
|
|
|
PatchInstructionDialog dialog(this, addr, debug_interface.ReadInstruction(guard, addr));
|
2018-02-14 22:25:01 +00:00
|
|
|
|
2019-04-23 19:42:37 +00:00
|
|
|
if (dialog.exec() == QDialog::Accepted)
|
2018-02-14 22:25:01 +00:00
|
|
|
{
|
2023-03-28 18:26:52 +00:00
|
|
|
debug_interface.SetPatch(guard, addr, dialog.GetCode());
|
2023-02-12 10:07:11 +00:00
|
|
|
Update(&guard);
|
2018-02-14 22:25:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-21 14:46:03 +00:00
|
|
|
void CodeViewWidget::OnRestoreInstruction()
|
|
|
|
{
|
2023-03-28 21:52:36 +00:00
|
|
|
Core::CPUThreadGuard guard(m_system);
|
2023-02-12 10:07:11 +00:00
|
|
|
|
2018-05-21 14:46:03 +00:00
|
|
|
const u32 addr = GetContextAddress();
|
|
|
|
|
2023-03-28 18:26:52 +00:00
|
|
|
m_system.GetPowerPC().GetDebugInterface().UnsetPatch(guard, addr);
|
2023-02-12 10:07:11 +00:00
|
|
|
Update(&guard);
|
2018-05-21 14:46:03 +00:00
|
|
|
}
|
|
|
|
|
2018-02-14 22:25:01 +00:00
|
|
|
void CodeViewWidget::resizeEvent(QResizeEvent*)
|
|
|
|
{
|
|
|
|
Update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CodeViewWidget::keyPressEvent(QKeyEvent* event)
|
|
|
|
{
|
|
|
|
switch (event->key())
|
|
|
|
{
|
|
|
|
case Qt::Key_Up:
|
2018-08-19 11:29:52 +00:00
|
|
|
m_address -= sizeof(u32);
|
2018-02-14 22:25:01 +00:00
|
|
|
Update();
|
|
|
|
return;
|
|
|
|
case Qt::Key_Down:
|
2018-08-19 11:29:52 +00:00
|
|
|
m_address += sizeof(u32);
|
2018-02-14 22:25:01 +00:00
|
|
|
Update();
|
|
|
|
return;
|
|
|
|
case Qt::Key_PageUp:
|
|
|
|
m_address -= rowCount() * sizeof(u32);
|
|
|
|
Update();
|
|
|
|
return;
|
|
|
|
case Qt::Key_PageDown:
|
|
|
|
m_address += rowCount() * sizeof(u32);
|
|
|
|
Update();
|
|
|
|
return;
|
|
|
|
default:
|
|
|
|
QWidget::keyPressEvent(event);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CodeViewWidget::wheelEvent(QWheelEvent* event)
|
|
|
|
{
|
2018-08-19 11:29:52 +00:00
|
|
|
auto delta =
|
|
|
|
-static_cast<int>(std::round((event->angleDelta().y() / (SCROLL_FRACTION_DEGREES * 8))));
|
|
|
|
|
|
|
|
if (delta == 0)
|
|
|
|
return;
|
2018-02-14 22:25:01 +00:00
|
|
|
|
2018-08-19 11:29:52 +00:00
|
|
|
m_address += delta * sizeof(u32);
|
2018-02-14 22:25:01 +00:00
|
|
|
Update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CodeViewWidget::mousePressEvent(QMouseEvent* event)
|
|
|
|
{
|
|
|
|
auto* item = itemAt(event->pos());
|
|
|
|
if (item == nullptr)
|
|
|
|
return;
|
|
|
|
|
|
|
|
const u32 addr = item->data(Qt::UserRole).toUInt();
|
|
|
|
|
|
|
|
m_context_address = addr;
|
|
|
|
|
|
|
|
switch (event->button())
|
|
|
|
{
|
|
|
|
case Qt::LeftButton:
|
2020-02-23 17:49:18 +00:00
|
|
|
if (column(item) == CODE_VIEW_COLUMN_BREAKPOINT)
|
2018-02-14 22:25:01 +00:00
|
|
|
ToggleBreakpoint();
|
|
|
|
else
|
2021-02-14 12:01:32 +00:00
|
|
|
SetAddress(addr, SetAddressUpdate::WithDetailedUpdate);
|
2018-02-14 22:25:01 +00:00
|
|
|
|
|
|
|
Update();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-06 08:50:11 +00:00
|
|
|
void CodeViewWidget::showEvent(QShowEvent* event)
|
|
|
|
{
|
|
|
|
Update();
|
|
|
|
}
|
|
|
|
|
2018-02-14 22:25:01 +00:00
|
|
|
void CodeViewWidget::ToggleBreakpoint()
|
|
|
|
{
|
2023-03-28 18:26:52 +00:00
|
|
|
auto& power_pc = m_system.GetPowerPC();
|
|
|
|
if (power_pc.GetDebugInterface().IsBreakpoint(GetContextAddress()))
|
|
|
|
power_pc.GetBreakPoints().Remove(GetContextAddress());
|
2018-02-14 22:25:01 +00:00
|
|
|
else
|
2023-03-28 18:26:52 +00:00
|
|
|
power_pc.GetBreakPoints().Add(GetContextAddress());
|
2018-02-14 22:25:01 +00:00
|
|
|
|
|
|
|
emit BreakpointsChanged();
|
|
|
|
Update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CodeViewWidget::AddBreakpoint()
|
|
|
|
{
|
2023-03-28 18:26:52 +00:00
|
|
|
m_system.GetPowerPC().GetBreakPoints().Add(GetContextAddress());
|
2018-02-14 22:25:01 +00:00
|
|
|
|
|
|
|
emit BreakpointsChanged();
|
|
|
|
Update();
|
|
|
|
}
|
|
|
|
|
|
|
|
u32 CodeViewWidget::GetContextAddress() const
|
|
|
|
{
|
|
|
|
return m_context_address;
|
|
|
|
}
|