Merge pull request #12630 from mitaclaw/ppc-symbols-global

PPCSymbolDB: Move instance to PowerPCManager
This commit is contained in:
Admiral H. Curtiss 2024-03-17 06:03:05 +01:00 committed by GitHub
commit 1ee923fd3d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
41 changed files with 201 additions and 160 deletions

View file

@ -194,25 +194,26 @@ void BranchWatchProxyModel::SetInspected(const QModelIndex& index)
}
BranchWatchDialog::BranchWatchDialog(Core::System& system, Core::BranchWatch& branch_watch,
CodeWidget* code_widget, QWidget* parent)
PPCSymbolDB& ppc_symbol_db, CodeWidget* code_widget,
QWidget* parent)
: QDialog(parent), m_system(system), m_branch_watch(branch_watch), m_code_widget(code_widget)
{
setWindowTitle(tr("Branch Watch Tool"));
setWindowFlags((windowFlags() | Qt::WindowMinMaxButtonsHint) & ~Qt::WindowContextHelpButtonHint);
SetQWidgetWindowDecorations(this);
setLayout([this]() {
setLayout([this, &ppc_symbol_db]() {
auto* main_layout = new QVBoxLayout;
// Controls Toolbar (widgets are added later)
main_layout->addWidget(m_control_toolbar = new QToolBar);
// Branch Watch Table
main_layout->addWidget(m_table_view = [this]() {
main_layout->addWidget(m_table_view = [this, &ppc_symbol_db]() {
const auto& ui_settings = Settings::Instance();
m_table_proxy = new BranchWatchProxyModel(m_branch_watch);
m_table_proxy->setSourceModel(m_table_model =
new BranchWatchTableModel(m_system, m_branch_watch));
m_table_proxy->setSourceModel(
m_table_model = new BranchWatchTableModel(m_system, m_branch_watch, ppc_symbol_db));
m_table_proxy->setSortRole(UserRole::SortRole);
m_table_model->setFont(ui_settings.GetDebugFont());

View file

@ -17,6 +17,8 @@ class BranchWatch;
class CPUThreadGuard;
class System;
} // namespace Core
class PPCSymbolDB;
class BranchWatchProxyModel;
class BranchWatchTableModel;
class CodeWidget;
@ -48,7 +50,8 @@ class BranchWatchDialog : public QDialog
public:
explicit BranchWatchDialog(Core::System& system, Core::BranchWatch& branch_watch,
CodeWidget* code_widget, QWidget* parent = nullptr);
PPCSymbolDB& ppc_symbol_db, CodeWidget* code_widget,
QWidget* parent = nullptr);
~BranchWatchDialog() override;
protected:

View file

@ -285,8 +285,8 @@ void BranchWatchTableModel::PrefetchSymbols()
for (const Core::BranchWatch::Selection::value_type& value : selection)
{
const Core::BranchWatch::Collection::value_type* const kv = value.collection_ptr;
m_symbol_list.emplace_back(g_symbolDB.GetSymbolFromAddr(kv->first.origin_addr),
g_symbolDB.GetSymbolFromAddr(kv->first.destin_addr));
m_symbol_list.emplace_back(m_ppc_symbol_db.GetSymbolFromAddr(kv->first.origin_addr),
m_ppc_symbol_db.GetSymbolFromAddr(kv->first.destin_addr));
}
}

View file

@ -18,6 +18,7 @@ class BranchWatch;
class CPUThreadGuard;
class System;
} // namespace Core
class PPCSymbolDB;
namespace BranchWatchTableModelColumn
{
@ -69,8 +70,9 @@ public:
using SymbolList = QList<SymbolListValueType>;
explicit BranchWatchTableModel(Core::System& system, Core::BranchWatch& branch_watch,
QObject* parent = nullptr)
: QAbstractTableModel(parent), m_system(system), m_branch_watch(branch_watch)
PPCSymbolDB& ppc_symbol_db, QObject* parent = nullptr)
: QAbstractTableModel(parent), m_system(system), m_branch_watch(branch_watch),
m_ppc_symbol_db(ppc_symbol_db)
{
}
QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
@ -113,6 +115,7 @@ private:
Core::System& m_system;
Core::BranchWatch& m_branch_watch;
PPCSymbolDB& m_ppc_symbol_db;
SymbolList m_symbol_list;
mutable QFont m_font;

View file

@ -178,6 +178,7 @@ void BreakpointWidget::Update()
auto& power_pc = m_system.GetPowerPC();
auto& breakpoints = power_pc.GetBreakPoints();
auto& memchecks = power_pc.GetMemChecks();
auto& ppc_symbol_db = power_pc.GetSymbolDB();
// Breakpoints
for (const auto& bp : breakpoints.GetBreakPoints())
@ -192,10 +193,10 @@ void BreakpointWidget::Update()
m_table->setItem(i, 0, active);
m_table->setItem(i, 1, create_item(QStringLiteral("BP")));
if (g_symbolDB.GetSymbolFromAddr(bp.address))
if (ppc_symbol_db.GetSymbolFromAddr(bp.address))
{
m_table->setItem(i, 2,
create_item(QString::fromStdString(g_symbolDB.GetDescription(bp.address))));
m_table->setItem(
i, 2, create_item(QString::fromStdString(ppc_symbol_db.GetDescription(bp.address))));
}
m_table->setItem(i, 3,
@ -233,10 +234,11 @@ void BreakpointWidget::Update()
m_table->setItem(i, 0, active);
m_table->setItem(i, 1, create_item(QStringLiteral("MBP")));
if (g_symbolDB.GetSymbolFromAddr(mbp.start_address))
if (ppc_symbol_db.GetSymbolFromAddr(mbp.start_address))
{
m_table->setItem(
i, 2, create_item(QString::fromStdString(g_symbolDB.GetDescription(mbp.start_address))));
i, 2,
create_item(QString::fromStdString(ppc_symbol_db.GetDescription(mbp.start_address))));
}
if (mbp.is_ranged)

View file

@ -138,7 +138,8 @@ constexpr int CODE_VIEW_COLUMN_DESCRIPTION = 4;
constexpr int CODE_VIEW_COLUMN_BRANCH_ARROWS = 5;
constexpr int CODE_VIEW_COLUMNCOUNT = 6;
CodeViewWidget::CodeViewWidget() : m_system(Core::System::GetInstance())
CodeViewWidget::CodeViewWidget()
: m_system(Core::System::GetInstance()), m_ppc_symbol_db(m_system.GetPPCSymbolDB())
{
setColumnCount(CODE_VIEW_COLUMNCOUNT);
setShowGrid(false);
@ -382,7 +383,7 @@ void CodeViewWidget::Update(const Core::CPUThreadGuard* guard)
if (debug_interface.IsBreakpoint(addr))
{
auto icon = Resources::GetThemeIcon("debugger_breakpoint").pixmap(QSize(rowh - 2, rowh - 2));
if (!m_system.GetPowerPC().GetBreakPoints().IsBreakPointEnable(addr))
if (!power_pc.GetBreakPoints().IsBreakPointEnable(addr))
{
QPixmap disabled_icon(icon.size());
disabled_icon.fill(Qt::transparent);
@ -410,7 +411,7 @@ void CodeViewWidget::Update(const Core::CPUThreadGuard* guard)
CalculateBranchIndentation();
g_symbolDB.FillInCallers();
m_ppc_symbol_db.FillInCallers();
repaint();
m_updating = false;
@ -561,7 +562,7 @@ void CodeViewWidget::OnContextMenu()
const u32 addr = GetContextAddress();
bool has_symbol = g_symbolDB.GetSymbolFromAddr(addr);
const bool has_symbol = m_ppc_symbol_db.GetSymbolFromAddr(addr);
auto* follow_branch_action =
menu->addAction(tr("Follow &branch"), this, &CodeViewWidget::OnFollowBranch);
@ -819,7 +820,7 @@ void CodeViewWidget::OnCopyFunction()
{
const u32 address = GetContextAddress();
const Common::Symbol* symbol = g_symbolDB.GetSymbolFromAddr(address);
const Common::Symbol* const symbol = m_ppc_symbol_db.GetSymbolFromAddr(address);
if (!symbol)
return;
@ -877,7 +878,7 @@ void CodeViewWidget::OnAddFunction()
Core::CPUThreadGuard guard(m_system);
g_symbolDB.AddFunction(guard, addr);
m_ppc_symbol_db.AddFunction(guard, addr);
emit SymbolsChanged();
Update(&guard);
}
@ -915,7 +916,7 @@ void CodeViewWidget::OnRenameSymbol()
{
const u32 addr = GetContextAddress();
Common::Symbol* const symbol = g_symbolDB.GetSymbolFromAddr(addr);
Common::Symbol* const symbol = m_ppc_symbol_db.GetSymbolFromAddr(addr);
if (!symbol)
return;
@ -950,7 +951,7 @@ void CodeViewWidget::OnSetSymbolSize()
{
const u32 addr = GetContextAddress();
Common::Symbol* const symbol = g_symbolDB.GetSymbolFromAddr(addr);
Common::Symbol* const symbol = m_ppc_symbol_db.GetSymbolFromAddr(addr);
if (!symbol)
return;
@ -975,7 +976,7 @@ void CodeViewWidget::OnSetSymbolEndAddress()
{
const u32 addr = GetContextAddress();
Common::Symbol* const symbol = g_symbolDB.GetSymbolFromAddr(addr);
Common::Symbol* const symbol = m_ppc_symbol_db.GetSymbolFromAddr(addr);
if (!symbol)
return;

View file

@ -23,6 +23,7 @@ class System;
struct CodeViewBranch;
class BranchDisplayDelegate;
class PPCSymbolDB;
class CodeViewWidget : public QTableWidget
{
@ -102,6 +103,7 @@ private:
void CalculateBranchIndentation();
Core::System& m_system;
PPCSymbolDB& m_ppc_symbol_db;
bool m_updating = false;

View file

@ -36,7 +36,9 @@ static const QString BOX_SPLITTER_STYLESHEET = QStringLiteral(
"QSplitter::handle { border-top: 1px dashed black; width: 1px; margin-left: 10px; "
"margin-right: 10px; }");
CodeWidget::CodeWidget(QWidget* parent) : QDockWidget(parent), m_system(Core::System::GetInstance())
CodeWidget::CodeWidget(QWidget* parent)
: QDockWidget(parent), m_system(Core::System::GetInstance()),
m_ppc_symbol_db(m_system.GetPPCSymbolDB())
{
setWindowTitle(tr("Code"));
setObjectName(QStringLiteral("code"));
@ -171,13 +173,11 @@ void CodeWidget::ConnectWidgets()
connect(m_search_address, &QLineEdit::returnPressed, this, &CodeWidget::OnSearchAddress);
connect(m_search_symbols, &QLineEdit::textChanged, this, &CodeWidget::OnSearchSymbols);
connect(m_search_calls, &QLineEdit::textChanged, this, [this]() {
const Common::Symbol* symbol = g_symbolDB.GetSymbolFromAddr(m_code_view->GetAddress());
if (symbol)
if (const Common::Symbol* symbol = m_ppc_symbol_db.GetSymbolFromAddr(m_code_view->GetAddress()))
UpdateFunctionCalls(symbol);
});
connect(m_search_callers, &QLineEdit::textChanged, this, [this]() {
const Common::Symbol* symbol = g_symbolDB.GetSymbolFromAddr(m_code_view->GetAddress());
if (symbol)
if (const Common::Symbol* symbol = m_ppc_symbol_db.GetSymbolFromAddr(m_code_view->GetAddress()))
UpdateFunctionCallers(symbol);
});
connect(m_search_callstack, &QLineEdit::textChanged, this, &CodeWidget::UpdateCallstack);
@ -194,8 +194,7 @@ void CodeWidget::ConnectWidgets()
connect(m_code_view, &CodeViewWidget::SymbolsChanged, this, [this]() {
UpdateCallstack();
UpdateSymbols();
const Common::Symbol* symbol = g_symbolDB.GetSymbolFromAddr(m_code_view->GetAddress());
if (symbol)
if (const Common::Symbol* symbol = m_ppc_symbol_db.GetSymbolFromAddr(m_code_view->GetAddress()))
{
UpdateFunctionCalls(symbol);
UpdateFunctionCallers(symbol);
@ -214,8 +213,8 @@ void CodeWidget::OnBranchWatchDialog()
{
if (m_branch_watch_dialog == nullptr)
{
m_branch_watch_dialog =
new BranchWatchDialog(m_system, m_system.GetPowerPC().GetBranchWatch(), this, this);
m_branch_watch_dialog = new BranchWatchDialog(m_system, m_system.GetPowerPC().GetBranchWatch(),
m_ppc_symbol_db, this, this);
}
m_branch_watch_dialog->show();
m_branch_watch_dialog->raise();
@ -260,7 +259,7 @@ void CodeWidget::OnSelectSymbol()
return;
const u32 address = items[0]->data(Qt::UserRole).toUInt();
const Common::Symbol* symbol = g_symbolDB.GetSymbolFromAddr(address);
const Common::Symbol* const symbol = m_ppc_symbol_db.GetSymbolFromAddr(address);
m_code_view->SetAddress(address, CodeViewWidget::SetAddressUpdate::WithUpdate);
UpdateCallstack();
@ -321,7 +320,7 @@ void CodeWidget::Update()
if (!isVisible())
return;
const Common::Symbol* symbol = g_symbolDB.GetSymbolFromAddr(m_code_view->GetAddress());
const Common::Symbol* const symbol = m_ppc_symbol_db.GetSymbolFromAddr(m_code_view->GetAddress());
UpdateCallstack();
@ -343,13 +342,7 @@ void CodeWidget::UpdateCallstack()
return;
std::vector<Dolphin_Debugger::CallstackEntry> stack;
const bool success = [this, &stack] {
Core::CPUThreadGuard guard(m_system);
return Dolphin_Debugger::GetCallstack(guard, stack);
}();
if (!success)
if (!Dolphin_Debugger::GetCallstack(Core::CPUThreadGuard{m_system}, stack))
{
m_callstack_list->addItem(tr("Invalid callstack"));
return;
@ -377,7 +370,7 @@ void CodeWidget::UpdateSymbols()
m_symbols_list->selectedItems()[0]->text();
m_symbols_list->clear();
for (const auto& symbol : g_symbolDB.Symbols())
for (const auto& symbol : m_ppc_symbol_db.Symbols())
{
QString name = QString::fromStdString(symbol.second.name);
@ -411,7 +404,7 @@ void CodeWidget::UpdateFunctionCalls(const Common::Symbol* symbol)
for (const auto& call : symbol->calls)
{
const u32 addr = call.function;
const Common::Symbol* call_symbol = g_symbolDB.GetSymbolFromAddr(addr);
const Common::Symbol* const call_symbol = m_ppc_symbol_db.GetSymbolFromAddr(addr);
if (call_symbol)
{
@ -436,7 +429,7 @@ void CodeWidget::UpdateFunctionCallers(const Common::Symbol* symbol)
for (const auto& caller : symbol->callers)
{
const u32 addr = caller.call_address;
const Common::Symbol* caller_symbol = g_symbolDB.GetSymbolFromAddr(addr);
const Common::Symbol* const caller_symbol = m_ppc_symbol_db.GetSymbolFromAddr(addr);
if (caller_symbol)
{

View file

@ -26,6 +26,7 @@ namespace Core
{
class System;
}
class PPCSymbolDB;
class CodeWidget : public QDockWidget
{
@ -71,6 +72,7 @@ private:
void showEvent(QShowEvent* event) override;
Core::System& m_system;
PPCSymbolDB& m_ppc_symbol_db;
BranchWatchDialog* m_branch_watch_dialog = nullptr;
QLineEdit* m_search_address;

View file

@ -1261,35 +1261,37 @@ void MenuBar::ClearSymbols()
if (result == QMessageBox::Cancel)
return;
g_symbolDB.Clear();
Core::System::GetInstance().GetPPCSymbolDB().Clear();
emit NotifySymbolsUpdated();
}
void MenuBar::GenerateSymbolsFromAddress()
{
Core::CPUThreadGuard guard(Core::System::GetInstance());
auto& system = Core::System::GetInstance();
auto& memory = system.GetMemory();
auto& ppc_symbol_db = system.GetPPCSymbolDB();
const Core::CPUThreadGuard guard(system);
PPCAnalyst::FindFunctions(guard, Memory::MEM1_BASE_ADDR,
Memory::MEM1_BASE_ADDR + memory.GetRamSizeReal(), &g_symbolDB);
Memory::MEM1_BASE_ADDR + memory.GetRamSizeReal(), &ppc_symbol_db);
emit NotifySymbolsUpdated();
}
void MenuBar::GenerateSymbolsFromSignatureDB()
{
Core::CPUThreadGuard guard(Core::System::GetInstance());
auto& system = Core::System::GetInstance();
auto& memory = system.GetMemory();
auto& ppc_symbol_db = system.GetPPCSymbolDB();
const Core::CPUThreadGuard guard(system);
PPCAnalyst::FindFunctions(guard, Memory::MEM1_BASE_ADDR,
Memory::MEM1_BASE_ADDR + memory.GetRamSizeReal(), &g_symbolDB);
Memory::MEM1_BASE_ADDR + memory.GetRamSizeReal(), &ppc_symbol_db);
SignatureDB db(SignatureDB::HandlerType::DSY);
if (db.Load(File::GetSysDirectory() + TOTALDB))
{
db.Apply(guard, &g_symbolDB);
db.Apply(guard, &ppc_symbol_db);
ModalMessageBox::information(
this, tr("Information"),
tr("Generated symbol names from '%1'").arg(QString::fromStdString(TOTALDB)));
@ -1325,12 +1327,13 @@ void MenuBar::GenerateSymbolsFromRSO()
return;
}
Core::CPUThreadGuard guard(Core::System::GetInstance());
auto& system = Core::System::GetInstance();
const Core::CPUThreadGuard guard(system);
RSOChainView rso_chain;
if (rso_chain.Load(guard, static_cast<u32>(address)))
{
rso_chain.Apply(guard, &g_symbolDB);
rso_chain.Apply(guard, &system.GetPPCSymbolDB());
emit NotifySymbolsUpdated();
}
else
@ -1382,11 +1385,12 @@ void MenuBar::GenerateSymbolsFromRSOAuto()
RSOChainView rso_chain;
const u32 address = item.mid(0, item.indexOf(QLatin1Char(' '))).toUInt(nullptr, 16);
Core::CPUThreadGuard guard(Core::System::GetInstance());
auto& system = Core::System::GetInstance();
const Core::CPUThreadGuard guard(system);
if (rso_chain.Load(guard, address))
{
rso_chain.Apply(guard, &g_symbolDB);
rso_chain.Apply(guard, &system.GetPPCSymbolDB());
emit NotifySymbolsUpdated();
}
else
@ -1502,22 +1506,23 @@ void MenuBar::LoadSymbolMap()
{
auto& system = Core::System::GetInstance();
auto& memory = system.GetMemory();
auto& ppc_symbol_db = system.GetPPCSymbolDB();
std::string existing_map_file, writable_map_file;
bool map_exists = CBoot::FindMapFile(&existing_map_file, &writable_map_file);
if (!map_exists)
{
g_symbolDB.Clear();
ppc_symbol_db.Clear();
{
Core::CPUThreadGuard guard(Core::System::GetInstance());
const Core::CPUThreadGuard guard(system);
PPCAnalyst::FindFunctions(guard, Memory::MEM1_BASE_ADDR + 0x1300000,
Memory::MEM1_BASE_ADDR + memory.GetRamSizeReal(), &g_symbolDB);
Memory::MEM1_BASE_ADDR + memory.GetRamSizeReal(), &ppc_symbol_db);
SignatureDB db(SignatureDB::HandlerType::DSY);
if (db.Load(File::GetSysDirectory() + TOTALDB))
db.Apply(guard, &g_symbolDB);
db.Apply(guard, &ppc_symbol_db);
}
ModalMessageBox::warning(this, tr("Warning"),
@ -1603,13 +1608,8 @@ void MenuBar::SaveCode()
const std::string path =
writable_map_file.substr(0, writable_map_file.find_last_of('.')) + "_code.map";
bool success;
{
Core::CPUThreadGuard guard(Core::System::GetInstance());
success = g_symbolDB.SaveCodeMap(guard, path);
}
if (!success)
auto& system = Core::System::GetInstance();
if (!system.GetPPCSymbolDB().SaveCodeMap(Core::CPUThreadGuard{system}, path))
{
ModalMessageBox::warning(
this, tr("Error"),
@ -1619,9 +1619,10 @@ void MenuBar::SaveCode()
bool MenuBar::TryLoadMapFile(const QString& path, const bool bad)
{
Core::CPUThreadGuard guard(Core::System::GetInstance());
auto& system = Core::System::GetInstance();
auto& ppc_symbol_db = system.GetPPCSymbolDB();
if (!g_symbolDB.LoadMap(guard, path.toStdString(), bad))
if (!ppc_symbol_db.LoadMap(Core::CPUThreadGuard{system}, path.toStdString(), bad))
{
ModalMessageBox::warning(this, tr("Error"), tr("Failed to load map file '%1'").arg(path));
return false;
@ -1632,7 +1633,7 @@ bool MenuBar::TryLoadMapFile(const QString& path, const bool bad)
void MenuBar::TrySaveSymbolMap(const QString& path)
{
if (g_symbolDB.SaveSymbolMap(path.toStdString()))
if (Core::System::GetInstance().GetPPCSymbolDB().SaveSymbolMap(path.toStdString()))
return;
ModalMessageBox::warning(this, tr("Error"),
@ -1653,7 +1654,7 @@ void MenuBar::CreateSignatureFile()
const std::string prefix = text.toStdString();
const std::string save_path = file.toStdString();
SignatureDB db(save_path);
db.Populate(&g_symbolDB, prefix);
db.Populate(&Core::System::GetInstance().GetPPCSymbolDB(), prefix);
if (!db.Save(save_path))
{
@ -1678,7 +1679,7 @@ void MenuBar::AppendSignatureFile()
const std::string prefix = text.toStdString();
const std::string signature_path = file.toStdString();
SignatureDB db(signature_path);
db.Populate(&g_symbolDB, prefix);
db.Populate(&Core::System::GetInstance().GetPPCSymbolDB(), prefix);
db.List();
db.Load(signature_path);
if (!db.Save(signature_path))
@ -1699,15 +1700,13 @@ void MenuBar::ApplySignatureFile()
if (file.isEmpty())
return;
auto& system = Core::System::GetInstance();
const std::string load_path = file.toStdString();
SignatureDB db(load_path);
db.Load(load_path);
{
Core::CPUThreadGuard guard(Core::System::GetInstance());
db.Apply(guard, &g_symbolDB);
}
db.Apply(Core::CPUThreadGuard{system}, &system.GetPPCSymbolDB());
db.List();
auto& system = Core::System::GetInstance();
HLE::PatchFunctions(system);
emit NotifySymbolsUpdated();
}