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;