From 3b9b9a84cd8d5afe516abcf4627b8ba0329837b6 Mon Sep 17 00:00:00 2001 From: chaoticgd <43898262+chaoticgd@users.noreply.github.com> Date: Thu, 14 Nov 2024 22:53:55 +0000 Subject: [PATCH] Debugger: Use expressions for the function scanner address range --- .../Settings/DebugAnalysisSettingsWidget.cpp | 4 +-- pcsx2/Config.h | 4 +-- pcsx2/DebugTools/SymbolImporter.cpp | 28 ++++++++++++++++--- 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/pcsx2-qt/Settings/DebugAnalysisSettingsWidget.cpp b/pcsx2-qt/Settings/DebugAnalysisSettingsWidget.cpp index f3fa4d1021..b0856068ca 100644 --- a/pcsx2-qt/Settings/DebugAnalysisSettingsWidget.cpp +++ b/pcsx2-qt/Settings/DebugAnalysisSettingsWidget.cpp @@ -37,8 +37,8 @@ DebugAnalysisSettingsWidget::DebugAnalysisSettingsWidget(QWidget* parent) } m_ui.customAddressRange->setChecked(Host::GetBoolSettingValue("Debugger/Analysis", "CustomFunctionScanRange", false)); - m_ui.addressRangeStart->setText(QString::fromStdString(Host::GetStringSettingValue("Debugger/Analysis", "FunctionScanStartAddress", "0"))); - m_ui.addressRangeEnd->setText(QString::fromStdString(Host::GetStringSettingValue("Debugger/Analysis", "FunctionScanEndAddress", "0"))); + m_ui.addressRangeStart->setText(QString::fromStdString(Host::GetStringSettingValue("Debugger/Analysis", "FunctionScanStartAddress", ""))); + m_ui.addressRangeEnd->setText(QString::fromStdString(Host::GetStringSettingValue("Debugger/Analysis", "FunctionScanEndAddress", ""))); m_ui.grayOutOverwrittenFunctions->setChecked(Host::GetBoolSettingValue("Debugger/Analysis", "GenerateFunctionHashes", true)); diff --git a/pcsx2/Config.h b/pcsx2/Config.h index ca331e9768..403900ff2c 100644 --- a/pcsx2/Config.h +++ b/pcsx2/Config.h @@ -1105,8 +1105,8 @@ struct Pcsx2Config DebugFunctionScanMode FunctionScanMode = DebugFunctionScanMode::SCAN_ELF; bool CustomFunctionScanRange = false; - std::string FunctionScanStartAddress = "0"; - std::string FunctionScanEndAddress = "0"; + std::string FunctionScanStartAddress; + std::string FunctionScanEndAddress; bool GenerateFunctionHashes = true; diff --git a/pcsx2/DebugTools/SymbolImporter.cpp b/pcsx2/DebugTools/SymbolImporter.cpp index 5c651efccf..2a964420bc 100644 --- a/pcsx2/DebugTools/SymbolImporter.cpp +++ b/pcsx2/DebugTools/SymbolImporter.cpp @@ -351,7 +351,7 @@ void SymbolImporter::ImportExtraSymbols( std::string error; if (!parseExpression(extra_symbol_file.Condition.c_str(), &expression_functions, expression_result, error)) { - Console.Error("Failed to parse condition expression '%s' while importing extra symbol file '%s': %s.", + Console.Error("Failed to evaluate condition expression '%s' while importing extra symbol file '%s': %s", extra_symbol_file.Condition.c_str(), path.c_str(), error.c_str()); } @@ -366,7 +366,7 @@ void SymbolImporter::ImportExtraSymbols( std::string error; if (!parseExpression(extra_symbol_file.BaseAddress.c_str(), &expression_functions, expression_result, error)) { - Console.Error("Failed to parse base address expression '%s' while importing extra symbol file '%s': %s.", + Console.Error("Failed to evaluate base address expression '%s' while importing extra symbol file '%s': %s", extra_symbol_file.BaseAddress.c_str(), path.c_str(), error.c_str()); } @@ -548,12 +548,32 @@ std::unique_ptr SymbolImporter::GetBuiltInType( void SymbolImporter::ScanForFunctions( ccc::SymbolDatabase& database, const ccc::ElfSymbolFile& elf, const Pcsx2Config::DebugAnalysisOptions& options) { + MipsExpressionFunctions expression_functions(&r5900Debug, &database, true); + u32 start_address = 0; u32 end_address = 0; if (options.CustomFunctionScanRange) { - start_address = static_cast(std::stoull(options.FunctionScanStartAddress.c_str(), nullptr, 16)); - end_address = static_cast(std::stoull(options.FunctionScanEndAddress.c_str(), nullptr, 16)); + u64 expression_result = 0; + std::string error; + + if (!parseExpression(options.FunctionScanStartAddress.c_str(), &expression_functions, expression_result, error)) + { + Console.Error("Failed to evaluate start address expression '%s' while scanning for functions: %s", + options.FunctionScanStartAddress.c_str(), error.c_str()); + return; + } + + start_address = static_cast(expression_result); + + if (!parseExpression(options.FunctionScanEndAddress.c_str(), &expression_functions, expression_result, error)) + { + Console.Error("Failed to evaluate end address expression '%s' while scanning for functions: %s", + options.FunctionScanEndAddress.c_str(), error.c_str()); + return; + } + + end_address = static_cast(expression_result); } else {