Core: Implement automatic symbol demangling

This commit is contained in:
Amber Brault
2026-05-07 09:25:28 +02:00
parent eb44b64c9e
commit 3f5460a5ff
18 changed files with 1388 additions and 7 deletions
+29 -6
View File
@@ -73,6 +73,9 @@ CodeWidget::CodeWidget(QWidget* parent)
connect(&Settings::Instance(), &Settings::EmulationStateChanged, this, &CodeWidget::Update);
connect(&Settings::Instance(), &Settings::ShowDemangledNamesChanged, this,
&CodeWidget::OnShowDemangledNamesChanged);
ConnectWidgets();
m_code_splitter->restoreState(
@@ -248,6 +251,16 @@ void CodeWidget::OnSetCodeAddress(u32 address)
SetAddress(address, CodeViewWidget::SetAddressUpdate::WithDetailedUpdate);
}
void CodeWidget::OnShowDemangledNamesChanged()
{
UpdateSymbols();
if (const Common::Symbol* symbol = m_ppc_symbol_db.GetSymbolFromAddr(m_code_view->GetAddress()))
{
UpdateFunctionCalls(symbol);
UpdateFunctionCallers(symbol);
}
}
void CodeWidget::OnPPCSymbolsChanged()
{
UpdateSymbols();
@@ -424,7 +437,7 @@ void CodeWidget::UpdateSymbols()
m_symbols_list->clear();
m_ppc_symbol_db.ForEachSymbol([&](const Common::Symbol& symbol) {
QString name = QString::fromStdString(symbol.name);
QString name = QString::fromStdString(GetSymbolDisplayName(&symbol));
// If the symbol has an object name, add it to the entry name.
if (!symbol.object_name.empty())
@@ -488,15 +501,16 @@ void CodeWidget::UpdateFunctionCalls(const Common::Symbol* symbol)
if (call_symbol)
{
QString name;
const std::string& symbol_name = GetSymbolDisplayName(call_symbol);
if (!call_symbol->object_name.empty())
{
name = QString::fromStdString(
fmt::format("< {} ({}, {:08x})", call_symbol->name, call_symbol->object_name, addr));
fmt::format("< {} ({}, {:08x})", symbol_name, call_symbol->object_name, addr));
}
else
{
name = QString::fromStdString(fmt::format("< {} ({:08x})", call_symbol->name, addr));
name = QString::fromStdString(fmt::format("< {} ({:08x})", symbol_name, addr));
}
if (!name.contains(filter, Qt::CaseInsensitive))
@@ -525,15 +539,16 @@ void CodeWidget::UpdateFunctionCallers(const Common::Symbol* symbol)
if (caller_symbol)
{
QString name;
const std::string& symbol_name = GetSymbolDisplayName(caller_symbol);
if (!caller_symbol->object_name.empty())
{
name = QString::fromStdString(fmt::format("< {} ({}, {:08x})", caller_symbol->name,
caller_symbol->object_name, addr));
name = QString::fromStdString(
fmt::format("< {} ({}, {:08x})", symbol_name, caller_symbol->object_name, addr));
}
else
{
name = QString::fromStdString(fmt::format("< {} ({:08x})", caller_symbol->name, addr));
name = QString::fromStdString(fmt::format("< {} ({:08x})", symbol_name, addr));
}
if (!name.contains(filter, Qt::CaseInsensitive))
@@ -546,6 +561,14 @@ void CodeWidget::UpdateFunctionCallers(const Common::Symbol* symbol)
}
}
// Gets the name of this symbol based on the option for whether or not to show
// demangled names.
const std::string& CodeWidget::GetSymbolDisplayName(const Common::Symbol* symbol) const
{
const bool show_demangled_names = Settings::Instance().IsShowDemangledNames();
return symbol->GetDisplayName(show_demangled_names);
}
void CodeWidget::Step()
{
auto& cpu = m_system.GetCPU();
@@ -64,6 +64,7 @@ private:
void UpdateFunctionCallers(const Common::Symbol* symbol);
void UpdateNotes();
void OnShowDemangledNamesChanged();
void OnPPCSymbolsChanged();
void OnSearchAddress();
void OnSearchSymbols();
@@ -76,6 +77,8 @@ private:
void closeEvent(QCloseEvent*) override;
void showEvent(QShowEvent* event) override;
const std::string& GetSymbolDisplayName(const Common::Symbol* symbol) const;
Core::System& m_system;
PPCSymbolDB& m_ppc_symbol_db;
+8
View File
@@ -1073,6 +1073,7 @@ void MenuBar::AddSymbolsMenu()
generate->addAction(tr("Address"), this, &MenuBar::GenerateSymbolsFromAddress);
generate->addAction(tr("Signature Database"), this, &MenuBar::GenerateSymbolsFromSignatureDB);
generate->addAction(tr("RSO Modules"), this, &MenuBar::GenerateSymbolsFromRSO);
m_debugger_show_demangled_names = m_symbols->addAction(tr("Show &Demangled Names"));
m_symbols->addSeparator();
m_symbols->addAction(tr("&Load Symbol Map"), this, &MenuBar::LoadSymbolMap);
@@ -1096,6 +1097,13 @@ void MenuBar::AddSymbolsMenu()
m_symbols->addSeparator();
m_symbols->addAction(tr("&Patch HLE Functions"), this, &MenuBar::PatchHLEFunctions);
m_debugger_show_demangled_names->setCheckable(true);
m_debugger_show_demangled_names->setChecked(Settings::Instance().IsShowDemangledNames());
connect(m_debugger_show_demangled_names, &QAction::toggled, &Settings::Instance(),
&Settings::SetShowDemangledNames);
connect(&Settings::Instance(), &Settings::ShowDemangledNamesChanged,
m_debugger_show_demangled_names, &QAction::setChecked);
}
void MenuBar::UpdateToolsMenu(const Core::State state)
+1
View File
@@ -310,6 +310,7 @@ private:
QAction* m_jit_systemregisters_off;
QAction* m_jit_branch_off;
QAction* m_jit_register_cache_off;
QAction* m_debugger_show_demangled_names;
bool m_game_selected = false;
+14
View File
@@ -871,6 +871,20 @@ QFont Settings::GetDebugFont() const
return GetQSettings().value(QStringLiteral("debugger/font"), default_font).value<QFont>();
}
void Settings::SetShowDemangledNames(bool enabled)
{
if (IsShowDemangledNames() == enabled)
return;
QSettings().setValue(QStringLiteral("debugger/showdemanglednames"), enabled);
emit ShowDemangledNamesChanged(enabled);
}
bool Settings::IsShowDemangledNames() const
{
return QSettings().value(QStringLiteral("debugger/showdemanglednames")).toBool();
}
void Settings::SetAutoUpdateTrack(const QString& mode)
{
if (mode == GetAutoUpdateTrack())
+3
View File
@@ -176,6 +176,8 @@ public:
bool IsAssemblerVisible() const;
QFont GetDebugFont() const;
void SetDebugFont(const QFont& font);
void SetShowDemangledNames(bool enabled);
bool IsShowDemangledNames() const;
// Auto-Update
QString GetAutoUpdateTrack() const;
@@ -223,6 +225,7 @@ signals:
void AssemblerVisibilityChanged(bool visible);
void DebugModeToggled(bool enabled);
void DebugFontChanged(const QFont& font);
void ShowDemangledNamesChanged(bool enabled);
void AutoUpdateTrackChanged(const QString& mode);
void FallbackRegionChanged(const DiscIO::Region& region);
void AnalyticsToggled(bool enabled);