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/CodeWidget.h"
|
2018-02-14 22:25:01 +00:00
|
|
|
|
|
|
|
#include <chrono>
|
|
|
|
|
2022-10-12 02:21:51 +00:00
|
|
|
#include <fmt/format.h>
|
|
|
|
|
2018-02-14 22:25:01 +00:00
|
|
|
#include <QGridLayout>
|
|
|
|
#include <QGroupBox>
|
2023-04-25 07:12:59 +00:00
|
|
|
#include <QGuiApplication>
|
2022-07-05 13:17:06 +00:00
|
|
|
#include <QLabel>
|
2018-02-14 22:25:01 +00:00
|
|
|
#include <QLineEdit>
|
|
|
|
#include <QListWidget>
|
2020-04-09 01:12:23 +00:00
|
|
|
#include <QPushButton>
|
2018-02-14 22:25:01 +00:00
|
|
|
#include <QSplitter>
|
2023-04-25 07:12:59 +00:00
|
|
|
#include <QStyleHints>
|
2018-02-14 22:25:01 +00:00
|
|
|
#include <QTableWidget>
|
|
|
|
#include <QWidget>
|
|
|
|
|
|
|
|
#include "Common/Event.h"
|
|
|
|
#include "Core/Core.h"
|
|
|
|
#include "Core/Debugger/Debugger_SymbolMap.h"
|
|
|
|
#include "Core/HW/CPU.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/PPCSymbolDB.h"
|
|
|
|
#include "Core/PowerPC/PowerPC.h"
|
2023-01-10 04:14:32 +00:00
|
|
|
#include "Core/System.h"
|
2023-12-07 17:36:02 +00:00
|
|
|
#include "DolphinQt/Debugger/BranchWatchDialog.h"
|
2018-07-06 22:40:15 +00:00
|
|
|
#include "DolphinQt/Host.h"
|
2023-07-30 22:42:15 +00:00
|
|
|
#include "DolphinQt/QtUtils/SetWindowDecorations.h"
|
2018-07-06 22:40:15 +00:00
|
|
|
#include "DolphinQt/Settings.h"
|
2018-02-14 22:25:01 +00:00
|
|
|
|
2023-04-25 07:12:59 +00:00
|
|
|
static const QString BOX_SPLITTER_STYLESHEET = QStringLiteral(
|
|
|
|
"QSplitter::handle { border-top: 1px dashed black; width: 1px; margin-left: 10px; "
|
|
|
|
"margin-right: 10px; }");
|
|
|
|
|
2024-03-10 18:43:12 +00:00
|
|
|
CodeWidget::CodeWidget(QWidget* parent)
|
|
|
|
: QDockWidget(parent), m_system(Core::System::GetInstance()),
|
|
|
|
m_ppc_symbol_db(m_system.GetPPCSymbolDB())
|
2018-02-14 22:25:01 +00:00
|
|
|
{
|
|
|
|
setWindowTitle(tr("Code"));
|
2018-04-19 09:32:00 +00:00
|
|
|
setObjectName(QStringLiteral("code"));
|
|
|
|
|
2019-02-28 20:19:04 +00:00
|
|
|
setHidden(!Settings::Instance().IsCodeVisible() || !Settings::Instance().IsDebugModeEnabled());
|
|
|
|
|
2018-02-14 22:25:01 +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();
|
2018-02-14 22:25:01 +00:00
|
|
|
|
|
|
|
restoreGeometry(settings.value(QStringLiteral("codewidget/geometry")).toByteArray());
|
2019-02-28 20:19:04 +00:00
|
|
|
// macOS: setHidden() needs to be evaluated before setFloating() for proper window presentation
|
|
|
|
// according to Settings
|
2018-02-14 22:25:01 +00:00
|
|
|
setFloating(settings.value(QStringLiteral("codewidget/floating")).toBool());
|
|
|
|
|
2020-09-12 22:53:17 +00:00
|
|
|
connect(&Settings::Instance(), &Settings::CodeVisibilityChanged, this,
|
2018-02-14 22:25:01 +00:00
|
|
|
[this](bool visible) { setHidden(!visible); });
|
|
|
|
|
2018-05-05 22:17:06 +00:00
|
|
|
connect(Host::GetInstance(), &Host::UpdateDisasmDialog, this, [this] {
|
2024-03-28 18:35:13 +00:00
|
|
|
if (Core::GetState(m_system) == Core::State::Paused)
|
2023-03-28 21:52:36 +00:00
|
|
|
SetAddress(m_system.GetPPCState().pc, CodeViewWidget::SetAddressUpdate::WithoutUpdate);
|
2018-05-05 22:17:06 +00:00
|
|
|
Update();
|
|
|
|
});
|
|
|
|
|
2020-09-12 22:53:17 +00:00
|
|
|
connect(&Settings::Instance(), &Settings::DebugModeToggled, this,
|
2018-02-14 22:25:01 +00:00
|
|
|
[this](bool enabled) { setHidden(!enabled || !Settings::Instance().IsCodeVisible()); });
|
|
|
|
|
|
|
|
connect(&Settings::Instance(), &Settings::EmulationStateChanged, this, &CodeWidget::Update);
|
|
|
|
|
|
|
|
ConnectWidgets();
|
|
|
|
|
|
|
|
m_code_splitter->restoreState(
|
|
|
|
settings.value(QStringLiteral("codewidget/codesplitter")).toByteArray());
|
|
|
|
m_box_splitter->restoreState(
|
|
|
|
settings.value(QStringLiteral("codewidget/boxsplitter")).toByteArray());
|
|
|
|
}
|
|
|
|
|
|
|
|
CodeWidget::~CodeWidget()
|
|
|
|
{
|
2018-03-23 11:10:53 +00:00
|
|
|
auto& settings = Settings::GetQSettings();
|
2018-02-14 22:25:01 +00:00
|
|
|
|
|
|
|
settings.setValue(QStringLiteral("codewidget/geometry"), saveGeometry());
|
|
|
|
settings.setValue(QStringLiteral("codewidget/floating"), isFloating());
|
|
|
|
settings.setValue(QStringLiteral("codewidget/codesplitter"), m_code_splitter->saveState());
|
2020-03-20 19:51:26 +00:00
|
|
|
settings.setValue(QStringLiteral("codewidget/boxsplitter"), m_box_splitter->saveState());
|
2018-02-14 22:25:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CodeWidget::closeEvent(QCloseEvent*)
|
|
|
|
{
|
|
|
|
Settings::Instance().SetCodeVisible(false);
|
|
|
|
}
|
|
|
|
|
2019-07-06 08:50:11 +00:00
|
|
|
void CodeWidget::showEvent(QShowEvent* event)
|
|
|
|
{
|
|
|
|
Update();
|
|
|
|
}
|
|
|
|
|
2018-02-14 22:25:01 +00:00
|
|
|
void CodeWidget::CreateWidgets()
|
|
|
|
{
|
|
|
|
auto* layout = new QGridLayout;
|
|
|
|
|
2018-08-02 19:50:23 +00:00
|
|
|
layout->setContentsMargins(2, 2, 2, 2);
|
|
|
|
layout->setSpacing(0);
|
|
|
|
|
2018-02-14 22:25:01 +00:00
|
|
|
m_search_address = new QLineEdit;
|
2023-12-07 17:36:02 +00:00
|
|
|
m_branch_watch = new QPushButton(tr("Branch Watch"));
|
2018-02-14 22:25:01 +00:00
|
|
|
m_code_view = new CodeViewWidget;
|
|
|
|
|
|
|
|
m_search_address->setPlaceholderText(tr("Search Address"));
|
2022-07-05 13:17:06 +00:00
|
|
|
|
|
|
|
m_box_splitter = new QSplitter(Qt::Vertical);
|
2023-04-25 07:12:59 +00:00
|
|
|
m_box_splitter->setStyleSheet(BOX_SPLITTER_STYLESHEET);
|
2022-07-05 13:17:06 +00:00
|
|
|
|
|
|
|
auto add_search_line_edit = [this](const QString& name, QListWidget* list_widget) {
|
|
|
|
auto* widget = new QWidget;
|
2023-02-03 00:12:45 +00:00
|
|
|
auto* line_layout = new QGridLayout;
|
2022-07-05 13:17:06 +00:00
|
|
|
auto* label = new QLabel(name);
|
|
|
|
auto* search_line_edit = new QLineEdit;
|
|
|
|
|
2023-02-03 00:12:45 +00:00
|
|
|
widget->setLayout(line_layout);
|
|
|
|
line_layout->addWidget(label, 0, 0);
|
|
|
|
line_layout->addWidget(search_line_edit, 0, 1);
|
|
|
|
line_layout->addWidget(list_widget, 1, 0, -1, -1);
|
2022-07-05 13:17:06 +00:00
|
|
|
m_box_splitter->addWidget(widget);
|
|
|
|
return search_line_edit;
|
|
|
|
};
|
2018-02-14 22:25:01 +00:00
|
|
|
|
|
|
|
// Callstack
|
|
|
|
m_callstack_list = new QListWidget;
|
2022-07-05 13:17:06 +00:00
|
|
|
m_search_callstack = add_search_line_edit(tr("Callstack"), m_callstack_list);
|
2018-02-14 22:25:01 +00:00
|
|
|
|
|
|
|
// Symbols
|
|
|
|
m_symbols_list = new QListWidget;
|
2022-07-05 13:17:06 +00:00
|
|
|
m_search_symbols = add_search_line_edit(tr("Symbols"), m_symbols_list);
|
2018-02-14 22:25:01 +00:00
|
|
|
|
|
|
|
// Function calls
|
|
|
|
m_function_calls_list = new QListWidget;
|
2022-07-05 13:17:06 +00:00
|
|
|
m_search_calls = add_search_line_edit(tr("Calls"), m_function_calls_list);
|
2018-02-14 22:25:01 +00:00
|
|
|
|
|
|
|
// Function callers
|
|
|
|
m_function_callers_list = new QListWidget;
|
2022-07-05 13:17:06 +00:00
|
|
|
m_search_callers = add_search_line_edit(tr("Callers"), m_function_callers_list);
|
2018-02-14 22:25:01 +00:00
|
|
|
|
|
|
|
m_code_splitter = new QSplitter(Qt::Horizontal);
|
|
|
|
|
|
|
|
m_code_splitter->addWidget(m_box_splitter);
|
|
|
|
m_code_splitter->addWidget(m_code_view);
|
|
|
|
|
|
|
|
layout->addWidget(m_search_address, 0, 0);
|
2023-12-07 17:36:02 +00:00
|
|
|
layout->addWidget(m_branch_watch, 0, 2);
|
2018-02-14 22:25:01 +00:00
|
|
|
layout->addWidget(m_code_splitter, 1, 0, -1, -1);
|
|
|
|
|
|
|
|
QWidget* widget = new QWidget(this);
|
|
|
|
widget->setLayout(layout);
|
|
|
|
setWidget(widget);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CodeWidget::ConnectWidgets()
|
|
|
|
{
|
2023-04-25 07:12:59 +00:00
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
|
|
|
|
connect(QGuiApplication::styleHints(), &QStyleHints::colorSchemeChanged, this,
|
|
|
|
[this](Qt::ColorScheme colorScheme) {
|
|
|
|
m_box_splitter->setStyleSheet(BOX_SPLITTER_STYLESHEET);
|
|
|
|
});
|
|
|
|
#endif
|
|
|
|
|
2018-02-14 22:25:01 +00:00
|
|
|
connect(m_search_address, &QLineEdit::textChanged, this, &CodeWidget::OnSearchAddress);
|
2019-10-14 19:47:27 +00:00
|
|
|
connect(m_search_address, &QLineEdit::returnPressed, this, &CodeWidget::OnSearchAddress);
|
2018-02-14 22:25:01 +00:00
|
|
|
connect(m_search_symbols, &QLineEdit::textChanged, this, &CodeWidget::OnSearchSymbols);
|
2022-07-05 13:17:06 +00:00
|
|
|
connect(m_search_calls, &QLineEdit::textChanged, this, [this]() {
|
2024-03-10 18:43:12 +00:00
|
|
|
if (const Common::Symbol* symbol = m_ppc_symbol_db.GetSymbolFromAddr(m_code_view->GetAddress()))
|
2022-07-05 13:17:06 +00:00
|
|
|
UpdateFunctionCalls(symbol);
|
|
|
|
});
|
|
|
|
connect(m_search_callers, &QLineEdit::textChanged, this, [this]() {
|
2024-03-10 18:43:12 +00:00
|
|
|
if (const Common::Symbol* symbol = m_ppc_symbol_db.GetSymbolFromAddr(m_code_view->GetAddress()))
|
2022-07-05 13:17:06 +00:00
|
|
|
UpdateFunctionCallers(symbol);
|
|
|
|
});
|
|
|
|
connect(m_search_callstack, &QLineEdit::textChanged, this, &CodeWidget::UpdateCallstack);
|
|
|
|
|
2023-12-07 17:36:02 +00:00
|
|
|
connect(m_branch_watch, &QPushButton::pressed, this, &CodeWidget::OnBranchWatchDialog);
|
2018-02-14 22:25:01 +00:00
|
|
|
|
2019-05-16 05:13:57 +00:00
|
|
|
connect(m_symbols_list, &QListWidget::itemPressed, this, &CodeWidget::OnSelectSymbol);
|
|
|
|
connect(m_callstack_list, &QListWidget::itemPressed, this, &CodeWidget::OnSelectCallstack);
|
|
|
|
connect(m_function_calls_list, &QListWidget::itemPressed, this,
|
2018-02-14 22:25:01 +00:00
|
|
|
&CodeWidget::OnSelectFunctionCalls);
|
2019-05-16 05:13:57 +00:00
|
|
|
connect(m_function_callers_list, &QListWidget::itemPressed, this,
|
2018-02-14 22:25:01 +00:00
|
|
|
&CodeWidget::OnSelectFunctionCallers);
|
|
|
|
|
2024-03-17 06:05:56 +00:00
|
|
|
connect(Host::GetInstance(), &Host::PPCSymbolsChanged, this, &CodeWidget::OnPPCSymbolsChanged);
|
2018-02-14 22:25:01 +00:00
|
|
|
connect(m_code_view, &CodeViewWidget::BreakpointsChanged, this,
|
|
|
|
[this] { emit BreakpointsChanged(); });
|
2021-02-14 12:01:32 +00:00
|
|
|
connect(m_code_view, &CodeViewWidget::UpdateCodeWidget, this, &CodeWidget::Update);
|
2018-04-09 13:31:20 +00:00
|
|
|
|
|
|
|
connect(m_code_view, &CodeViewWidget::RequestPPCComparison, this,
|
|
|
|
&CodeWidget::RequestPPCComparison);
|
2018-12-28 18:12:30 +00:00
|
|
|
connect(m_code_view, &CodeViewWidget::ShowMemory, this, &CodeWidget::ShowMemory);
|
2018-02-14 22:25:01 +00:00
|
|
|
}
|
|
|
|
|
2023-12-07 17:36:02 +00:00
|
|
|
void CodeWidget::OnBranchWatchDialog()
|
2020-04-09 01:12:23 +00:00
|
|
|
{
|
2024-03-05 22:02:45 +00:00
|
|
|
if (m_branch_watch_dialog == nullptr)
|
|
|
|
{
|
2024-03-10 18:43:12 +00:00
|
|
|
m_branch_watch_dialog = new BranchWatchDialog(m_system, m_system.GetPowerPC().GetBranchWatch(),
|
|
|
|
m_ppc_symbol_db, this, this);
|
2024-03-05 22:02:45 +00:00
|
|
|
}
|
|
|
|
m_branch_watch_dialog->show();
|
2023-12-07 17:36:02 +00:00
|
|
|
m_branch_watch_dialog->raise();
|
|
|
|
m_branch_watch_dialog->activateWindow();
|
2020-04-09 01:12:23 +00:00
|
|
|
}
|
|
|
|
|
2024-03-17 06:05:56 +00:00
|
|
|
void CodeWidget::OnPPCSymbolsChanged()
|
|
|
|
{
|
|
|
|
UpdateSymbols();
|
|
|
|
UpdateCallstack();
|
|
|
|
if (const Common::Symbol* symbol = m_ppc_symbol_db.GetSymbolFromAddr(m_code_view->GetAddress()))
|
|
|
|
{
|
|
|
|
UpdateFunctionCalls(symbol);
|
|
|
|
UpdateFunctionCallers(symbol);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-14 22:25:01 +00:00
|
|
|
void CodeWidget::OnSearchAddress()
|
|
|
|
{
|
|
|
|
bool good = true;
|
|
|
|
u32 address = m_search_address->text().toUInt(&good, 16);
|
|
|
|
|
|
|
|
QPalette palette;
|
|
|
|
QFont font;
|
|
|
|
|
|
|
|
if (!good && !m_search_address->text().isEmpty())
|
|
|
|
{
|
|
|
|
font.setBold(true);
|
|
|
|
palette.setColor(QPalette::Text, Qt::red);
|
|
|
|
}
|
|
|
|
|
|
|
|
m_search_address->setPalette(palette);
|
|
|
|
m_search_address->setFont(font);
|
|
|
|
|
|
|
|
if (good)
|
2018-05-05 22:17:06 +00:00
|
|
|
m_code_view->SetAddress(address, CodeViewWidget::SetAddressUpdate::WithUpdate);
|
2018-02-14 22:25:01 +00:00
|
|
|
|
|
|
|
Update();
|
2018-06-30 21:47:16 +00:00
|
|
|
|
|
|
|
m_search_address->setFocus();
|
2018-02-14 22:25:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CodeWidget::OnSearchSymbols()
|
|
|
|
{
|
|
|
|
m_symbol_filter = m_search_symbols->text();
|
|
|
|
UpdateSymbols();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CodeWidget::OnSelectSymbol()
|
|
|
|
{
|
|
|
|
const auto items = m_symbols_list->selectedItems();
|
|
|
|
if (items.isEmpty())
|
|
|
|
return;
|
|
|
|
|
2018-05-27 03:37:10 +00:00
|
|
|
const u32 address = items[0]->data(Qt::UserRole).toUInt();
|
2024-03-10 18:43:12 +00:00
|
|
|
const Common::Symbol* const symbol = m_ppc_symbol_db.GetSymbolFromAddr(address);
|
2018-02-14 22:25:01 +00:00
|
|
|
|
2018-05-27 03:37:10 +00:00
|
|
|
m_code_view->SetAddress(address, CodeViewWidget::SetAddressUpdate::WithUpdate);
|
2018-02-14 22:25:01 +00:00
|
|
|
UpdateCallstack();
|
|
|
|
UpdateFunctionCalls(symbol);
|
|
|
|
UpdateFunctionCallers(symbol);
|
|
|
|
|
|
|
|
m_code_view->setFocus();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CodeWidget::OnSelectCallstack()
|
|
|
|
{
|
|
|
|
const auto items = m_callstack_list->selectedItems();
|
|
|
|
if (items.isEmpty())
|
|
|
|
return;
|
|
|
|
|
2018-05-05 22:17:06 +00:00
|
|
|
m_code_view->SetAddress(items[0]->data(Qt::UserRole).toUInt(),
|
|
|
|
CodeViewWidget::SetAddressUpdate::WithUpdate);
|
2018-02-14 22:25:01 +00:00
|
|
|
Update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CodeWidget::OnSelectFunctionCalls()
|
|
|
|
{
|
|
|
|
const auto items = m_function_calls_list->selectedItems();
|
|
|
|
if (items.isEmpty())
|
|
|
|
return;
|
|
|
|
|
2018-05-05 22:17:06 +00:00
|
|
|
m_code_view->SetAddress(items[0]->data(Qt::UserRole).toUInt(),
|
|
|
|
CodeViewWidget::SetAddressUpdate::WithUpdate);
|
2018-02-14 22:25:01 +00:00
|
|
|
Update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CodeWidget::OnSelectFunctionCallers()
|
|
|
|
{
|
|
|
|
const auto items = m_function_callers_list->selectedItems();
|
|
|
|
if (items.isEmpty())
|
|
|
|
return;
|
|
|
|
|
2018-05-05 22:17:06 +00:00
|
|
|
m_code_view->SetAddress(items[0]->data(Qt::UserRole).toUInt(),
|
|
|
|
CodeViewWidget::SetAddressUpdate::WithUpdate);
|
2018-02-14 22:25:01 +00:00
|
|
|
Update();
|
|
|
|
}
|
|
|
|
|
2018-05-05 22:17:06 +00:00
|
|
|
void CodeWidget::SetAddress(u32 address, CodeViewWidget::SetAddressUpdate update)
|
|
|
|
{
|
|
|
|
m_code_view->SetAddress(address, update);
|
2018-12-28 18:12:30 +00:00
|
|
|
|
2022-12-02 00:43:41 +00:00
|
|
|
if (update == CodeViewWidget::SetAddressUpdate::WithUpdate ||
|
|
|
|
update == CodeViewWidget::SetAddressUpdate::WithDetailedUpdate)
|
2018-12-28 18:12:30 +00:00
|
|
|
{
|
2022-12-02 00:43:41 +00:00
|
|
|
Settings::Instance().SetCodeVisible(true);
|
2018-12-28 18:12:30 +00:00
|
|
|
raise();
|
|
|
|
m_code_view->setFocus();
|
|
|
|
}
|
2018-05-05 22:17:06 +00:00
|
|
|
}
|
|
|
|
|
2018-02-14 22:25:01 +00:00
|
|
|
void CodeWidget::Update()
|
|
|
|
{
|
2019-07-06 08:50:11 +00:00
|
|
|
if (!isVisible())
|
|
|
|
return;
|
|
|
|
|
2024-03-10 18:43:12 +00:00
|
|
|
const Common::Symbol* const symbol = m_ppc_symbol_db.GetSymbolFromAddr(m_code_view->GetAddress());
|
2018-02-14 22:25:01 +00:00
|
|
|
|
|
|
|
UpdateCallstack();
|
|
|
|
|
2018-05-05 22:17:06 +00:00
|
|
|
m_code_view->Update();
|
|
|
|
m_code_view->setFocus();
|
|
|
|
|
2018-02-14 22:25:01 +00:00
|
|
|
if (!symbol)
|
|
|
|
return;
|
|
|
|
|
|
|
|
UpdateFunctionCalls(symbol);
|
|
|
|
UpdateFunctionCallers(symbol);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CodeWidget::UpdateCallstack()
|
|
|
|
{
|
|
|
|
m_callstack_list->clear();
|
|
|
|
|
2024-03-28 18:35:13 +00:00
|
|
|
if (Core::GetState(m_system) != Core::State::Paused)
|
2023-02-12 11:50:28 +00:00
|
|
|
return;
|
|
|
|
|
2018-02-14 22:25:01 +00:00
|
|
|
std::vector<Dolphin_Debugger::CallstackEntry> stack;
|
2024-03-10 18:43:12 +00:00
|
|
|
if (!Dolphin_Debugger::GetCallstack(Core::CPUThreadGuard{m_system}, stack))
|
2018-02-14 22:25:01 +00:00
|
|
|
{
|
|
|
|
m_callstack_list->addItem(tr("Invalid callstack"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-07-05 13:17:06 +00:00
|
|
|
const QString filter = m_search_callstack->text();
|
|
|
|
|
2018-02-14 22:25:01 +00:00
|
|
|
for (const auto& frame : stack)
|
|
|
|
{
|
2022-07-05 13:17:06 +00:00
|
|
|
const QString name = QString::fromStdString(frame.Name.substr(0, frame.Name.length() - 1));
|
|
|
|
|
2024-02-27 20:03:38 +00:00
|
|
|
if (!name.contains(filter, Qt::CaseInsensitive))
|
2022-07-05 13:17:06 +00:00
|
|
|
continue;
|
2018-02-14 22:25:01 +00:00
|
|
|
|
2022-07-05 13:17:06 +00:00
|
|
|
auto* item = new QListWidgetItem(name);
|
|
|
|
item->setData(Qt::UserRole, frame.vAddress);
|
2018-02-14 22:25:01 +00:00
|
|
|
m_callstack_list->addItem(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CodeWidget::UpdateSymbols()
|
|
|
|
{
|
2019-07-30 11:57:06 +00:00
|
|
|
const QString selection = m_symbols_list->selectedItems().isEmpty() ?
|
|
|
|
QString{} :
|
|
|
|
m_symbols_list->selectedItems()[0]->text();
|
2018-02-14 22:25:01 +00:00
|
|
|
m_symbols_list->clear();
|
|
|
|
|
2024-03-10 18:43:12 +00:00
|
|
|
for (const auto& symbol : m_ppc_symbol_db.Symbols())
|
2018-02-14 22:25:01 +00:00
|
|
|
{
|
|
|
|
QString name = QString::fromStdString(symbol.second.name);
|
|
|
|
|
|
|
|
auto* item = new QListWidgetItem(name);
|
|
|
|
if (name == selection)
|
|
|
|
item->setSelected(true);
|
|
|
|
|
|
|
|
// Disable non-function symbols as you can't do anything with them.
|
2018-05-27 21:37:52 +00:00
|
|
|
if (symbol.second.type != Common::Symbol::Type::Function)
|
2018-02-14 22:25:01 +00:00
|
|
|
item->setFlags(Qt::NoItemFlags);
|
|
|
|
|
|
|
|
item->setData(Qt::UserRole, symbol.second.address);
|
|
|
|
|
2024-02-27 20:03:38 +00:00
|
|
|
if (name.contains(m_symbol_filter, Qt::CaseInsensitive))
|
2018-02-14 22:25:01 +00:00
|
|
|
m_symbols_list->addItem(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
m_symbols_list->sortItems();
|
|
|
|
}
|
|
|
|
|
2018-05-27 21:37:52 +00:00
|
|
|
void CodeWidget::UpdateFunctionCalls(const Common::Symbol* symbol)
|
2018-02-14 22:25:01 +00:00
|
|
|
{
|
|
|
|
m_function_calls_list->clear();
|
2022-07-05 13:17:06 +00:00
|
|
|
const QString filter = m_search_calls->text();
|
2018-02-14 22:25:01 +00:00
|
|
|
|
|
|
|
for (const auto& call : symbol->calls)
|
|
|
|
{
|
2018-05-27 03:37:10 +00:00
|
|
|
const u32 addr = call.function;
|
2024-03-10 18:43:12 +00:00
|
|
|
const Common::Symbol* const call_symbol = m_ppc_symbol_db.GetSymbolFromAddr(addr);
|
2018-02-14 22:25:01 +00:00
|
|
|
|
|
|
|
if (call_symbol)
|
|
|
|
{
|
2022-07-05 13:17:06 +00:00
|
|
|
const QString name =
|
2022-10-12 02:21:51 +00:00
|
|
|
QString::fromStdString(fmt::format("> {} ({:08x})", call_symbol->name, addr));
|
2018-02-14 22:25:01 +00:00
|
|
|
|
2024-02-27 20:03:38 +00:00
|
|
|
if (!name.contains(filter, Qt::CaseInsensitive))
|
2022-07-05 13:17:06 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
auto* item = new QListWidgetItem(name);
|
|
|
|
item->setData(Qt::UserRole, addr);
|
2018-02-14 22:25:01 +00:00
|
|
|
m_function_calls_list->addItem(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-27 21:37:52 +00:00
|
|
|
void CodeWidget::UpdateFunctionCallers(const Common::Symbol* symbol)
|
2018-02-14 22:25:01 +00:00
|
|
|
{
|
|
|
|
m_function_callers_list->clear();
|
2022-07-05 13:17:06 +00:00
|
|
|
const QString filter = m_search_callers->text();
|
2018-02-14 22:25:01 +00:00
|
|
|
|
|
|
|
for (const auto& caller : symbol->callers)
|
|
|
|
{
|
2018-05-27 21:15:20 +00:00
|
|
|
const u32 addr = caller.call_address;
|
2024-03-10 18:43:12 +00:00
|
|
|
const Common::Symbol* const caller_symbol = m_ppc_symbol_db.GetSymbolFromAddr(addr);
|
2018-02-14 22:25:01 +00:00
|
|
|
|
|
|
|
if (caller_symbol)
|
|
|
|
{
|
2022-10-12 02:21:51 +00:00
|
|
|
const QString name =
|
|
|
|
QString::fromStdString(fmt::format("< {} ({:08x})", caller_symbol->name, addr));
|
2018-02-14 22:25:01 +00:00
|
|
|
|
2024-02-27 20:03:38 +00:00
|
|
|
if (!name.contains(filter, Qt::CaseInsensitive))
|
2022-07-05 13:17:06 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
auto* item = new QListWidgetItem(name);
|
|
|
|
item->setData(Qt::UserRole, addr);
|
2018-02-14 22:25:01 +00:00
|
|
|
m_function_callers_list->addItem(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CodeWidget::Step()
|
|
|
|
{
|
2023-03-28 21:52:36 +00:00
|
|
|
auto& cpu = m_system.GetCPU();
|
2023-03-07 03:02:48 +00:00
|
|
|
|
|
|
|
if (!cpu.IsStepping())
|
2018-02-14 22:25:01 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
Common::Event sync_event;
|
|
|
|
|
2023-03-28 18:26:52 +00:00
|
|
|
auto& power_pc = m_system.GetPowerPC();
|
|
|
|
PowerPC::CoreMode old_mode = power_pc.GetMode();
|
|
|
|
power_pc.SetMode(PowerPC::CoreMode::Interpreter);
|
|
|
|
power_pc.GetBreakPoints().ClearAllTemporary();
|
2023-03-07 03:02:48 +00:00
|
|
|
cpu.StepOpcode(&sync_event);
|
2018-02-14 22:25:01 +00:00
|
|
|
sync_event.WaitFor(std::chrono::milliseconds(20));
|
2023-03-28 18:26:52 +00:00
|
|
|
power_pc.SetMode(old_mode);
|
2018-02-14 22:25:01 +00:00
|
|
|
Core::DisplayMessage(tr("Step successful!").toStdString(), 2000);
|
2018-05-05 22:17:06 +00:00
|
|
|
// Will get a UpdateDisasmDialog(), don't update the GUI here.
|
2023-12-07 17:36:02 +00:00
|
|
|
|
|
|
|
// TODO: Step doesn't cause EmulationStateChanged to be emitted, so it has to call this manually.
|
2024-03-05 22:02:45 +00:00
|
|
|
if (m_branch_watch_dialog != nullptr)
|
|
|
|
m_branch_watch_dialog->Update();
|
2018-02-14 22:25:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CodeWidget::StepOver()
|
|
|
|
{
|
2023-03-28 21:52:36 +00:00
|
|
|
auto& cpu = m_system.GetCPU();
|
2023-03-07 03:02:48 +00:00
|
|
|
|
|
|
|
if (!cpu.IsStepping())
|
2018-02-14 22:25:01 +00:00
|
|
|
return;
|
|
|
|
|
2023-03-08 00:58:05 +00:00
|
|
|
const UGeckoInstruction inst = [&] {
|
2023-03-28 21:52:36 +00:00
|
|
|
Core::CPUThreadGuard guard(m_system);
|
|
|
|
return PowerPC::MMU::HostRead_Instruction(guard, m_system.GetPPCState().pc);
|
2023-02-12 10:07:11 +00:00
|
|
|
}();
|
|
|
|
|
2018-02-14 22:25:01 +00:00
|
|
|
if (inst.LK)
|
|
|
|
{
|
2023-03-28 18:26:52 +00:00
|
|
|
auto& breakpoints = m_system.GetPowerPC().GetBreakPoints();
|
|
|
|
breakpoints.ClearAllTemporary();
|
|
|
|
breakpoints.Add(m_system.GetPPCState().pc + 4, true);
|
2023-03-07 03:02:48 +00:00
|
|
|
cpu.EnableStepping(false);
|
2018-02-14 22:25:01 +00:00
|
|
|
Core::DisplayMessage(tr("Step over in progress...").toStdString(), 2000);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Step();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns true on a rfi, blr or on a bclr that evaluates to true.
|
2023-03-28 21:52:36 +00:00
|
|
|
static bool WillInstructionReturn(Core::System& system, UGeckoInstruction inst)
|
2018-02-14 22:25:01 +00:00
|
|
|
{
|
|
|
|
// Is a rfi instruction
|
|
|
|
if (inst.hex == 0x4C000064u)
|
|
|
|
return true;
|
2023-03-28 21:52:36 +00:00
|
|
|
const auto& ppc_state = system.GetPPCState();
|
|
|
|
bool counter = (inst.BO_2 >> 2 & 1) != 0 || (CTR(ppc_state) != 0) != ((inst.BO_2 >> 1 & 1) != 0);
|
|
|
|
bool condition = inst.BO_2 >> 4 != 0 || ppc_state.cr.GetBit(inst.BI_2) == (inst.BO_2 >> 3 & 1);
|
2018-02-14 22:25:01 +00:00
|
|
|
bool isBclr = inst.OPCD_7 == 0b010011 && (inst.hex >> 1 & 0b10000) != 0;
|
|
|
|
return isBclr && counter && condition && !inst.LK_3;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CodeWidget::StepOut()
|
|
|
|
{
|
2023-03-28 21:52:36 +00:00
|
|
|
auto& cpu = m_system.GetCPU();
|
2023-03-07 03:02:48 +00:00
|
|
|
|
|
|
|
if (!cpu.IsStepping())
|
2018-02-14 22:25:01 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
// Keep stepping until the next return instruction or timeout after five seconds
|
|
|
|
using clock = std::chrono::steady_clock;
|
|
|
|
clock::time_point timeout = clock::now() + std::chrono::seconds(5);
|
|
|
|
|
2023-03-28 18:26:52 +00:00
|
|
|
auto& power_pc = m_system.GetPowerPC();
|
|
|
|
auto& ppc_state = power_pc.GetPPCState();
|
|
|
|
auto& breakpoints = power_pc.GetBreakPoints();
|
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
|
|
|
breakpoints.ClearAllTemporary();
|
2023-02-12 10:07:11 +00:00
|
|
|
|
2023-03-28 18:26:52 +00:00
|
|
|
PowerPC::CoreMode old_mode = power_pc.GetMode();
|
|
|
|
power_pc.SetMode(PowerPC::CoreMode::Interpreter);
|
2018-02-14 22:25:01 +00:00
|
|
|
|
2023-02-12 10:07:11 +00:00
|
|
|
// Loop until either the current instruction is a return instruction with no Link flag
|
|
|
|
// or a breakpoint is detected so it can step at the breakpoint. If the PC is currently
|
|
|
|
// on a breakpoint, skip it.
|
2023-03-28 21:52:36 +00:00
|
|
|
UGeckoInstruction inst = PowerPC::MMU::HostRead_Instruction(guard, ppc_state.pc);
|
2023-02-12 10:07:11 +00:00
|
|
|
do
|
2018-02-14 22:25:01 +00:00
|
|
|
{
|
2023-03-28 21:52:36 +00:00
|
|
|
if (WillInstructionReturn(m_system, inst))
|
2018-02-14 22:25:01 +00:00
|
|
|
{
|
2023-03-28 18:26:52 +00:00
|
|
|
power_pc.SingleStep();
|
2023-02-12 10:07:11 +00:00
|
|
|
break;
|
|
|
|
}
|
2018-02-14 22:25:01 +00:00
|
|
|
|
2023-02-12 10:07:11 +00:00
|
|
|
if (inst.LK)
|
|
|
|
{
|
|
|
|
// Step over branches
|
2023-03-28 21:52:36 +00:00
|
|
|
u32 next_pc = ppc_state.pc + 4;
|
2023-02-12 10:07:11 +00:00
|
|
|
do
|
|
|
|
{
|
2023-03-28 18:26:52 +00:00
|
|
|
power_pc.SingleStep();
|
2023-03-28 21:52:36 +00:00
|
|
|
} while (ppc_state.pc != next_pc && clock::now() < timeout &&
|
2023-03-28 18:26:52 +00:00
|
|
|
!breakpoints.IsAddressBreakPoint(ppc_state.pc));
|
2023-02-12 10:07:11 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-03-28 18:26:52 +00:00
|
|
|
power_pc.SingleStep();
|
2023-02-12 10:07:11 +00:00
|
|
|
}
|
2018-02-14 22:25:01 +00:00
|
|
|
|
2023-03-28 21:52:36 +00:00
|
|
|
inst = PowerPC::MMU::HostRead_Instruction(guard, ppc_state.pc);
|
2023-03-28 18:26:52 +00:00
|
|
|
} while (clock::now() < timeout && !breakpoints.IsAddressBreakPoint(ppc_state.pc));
|
2023-02-12 10:07:11 +00:00
|
|
|
|
2023-03-28 18:26:52 +00:00
|
|
|
power_pc.SetMode(old_mode);
|
2023-02-12 10:07:11 +00:00
|
|
|
}
|
2018-02-14 22:25:01 +00:00
|
|
|
|
2018-05-05 22:17:06 +00:00
|
|
|
emit Host::GetInstance()->UpdateDisasmDialog();
|
|
|
|
|
2023-03-28 18:26:52 +00:00
|
|
|
if (breakpoints.IsAddressBreakPoint(ppc_state.pc))
|
2018-02-14 22:25:01 +00:00
|
|
|
Core::DisplayMessage(tr("Breakpoint encountered! Step out aborted.").toStdString(), 2000);
|
|
|
|
else if (clock::now() >= timeout)
|
|
|
|
Core::DisplayMessage(tr("Step out timed out!").toStdString(), 2000);
|
|
|
|
else
|
|
|
|
Core::DisplayMessage(tr("Step out successful!").toStdString(), 2000);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CodeWidget::Skip()
|
|
|
|
{
|
2023-03-28 21:52:36 +00:00
|
|
|
m_system.GetPPCState().pc += 4;
|
2018-02-14 22:25:01 +00:00
|
|
|
ShowPC();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CodeWidget::ShowPC()
|
|
|
|
{
|
2023-03-28 21:52:36 +00:00
|
|
|
m_code_view->SetAddress(m_system.GetPPCState().pc, CodeViewWidget::SetAddressUpdate::WithUpdate);
|
2018-02-14 22:25:01 +00:00
|
|
|
Update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CodeWidget::SetPC()
|
|
|
|
{
|
2023-03-28 21:52:36 +00:00
|
|
|
m_system.GetPPCState().pc = m_code_view->GetAddress();
|
2018-02-14 22:25:01 +00:00
|
|
|
Update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CodeWidget::ToggleBreakpoint()
|
|
|
|
{
|
|
|
|
m_code_view->ToggleBreakpoint();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CodeWidget::AddBreakpoint()
|
|
|
|
{
|
|
|
|
m_code_view->AddBreakpoint();
|
|
|
|
}
|