Skip to content

Commit

Permalink
Debugger: Support 'unknown initial value' search types
Browse files Browse the repository at this point in the history
  • Loading branch information
F0bes committed Feb 5, 2025
1 parent 1f0d6f0 commit 27e6ba9
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 52 deletions.
123 changes: 71 additions & 52 deletions pcsx2-qt/Debugger/MemorySearchWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ MemorySearchWidget::MemorySearchWidget(QWidget* parent)
connect(m_ui.listSearchResults->verticalScrollBar(), &QScrollBar::valueChanged, this, &MemorySearchWidget::onSearchResultsListScroll);
connect(m_ui.listSearchResults, &QListView::customContextMenuRequested, this, &MemorySearchWidget::onListSearchResultsContextMenu);
connect(m_ui.cmbSearchType, &QComboBox::currentIndexChanged, this, &MemorySearchWidget::onSearchTypeChanged);
connect(m_ui.cmbSearchComparison, &QComboBox::currentIndexChanged, this, &MemorySearchWidget::onSearchComparisonChanged);

// Ensures we don't retrigger the load results function unintentionally
m_resultsLoadTimer.setInterval(100);
Expand Down Expand Up @@ -249,7 +250,7 @@ bool handleSearchComparison(SearchComparison searchComparison, u32 searchAddress
}
case SearchComparison::IncreasedBy:
{

const T priorValue = priorResult->getValue<T>();
const T expectedIncrease = searchValue + priorValue;
return memoryValueComparator(SearchComparison::Equals, readValue, expectedIncrease);
Expand Down Expand Up @@ -282,6 +283,10 @@ bool handleSearchComparison(SearchComparison searchComparison, u32 searchAddress
const T expectedDecrease = priorValue - searchValue;
return memoryValueComparator(SearchComparison::Equals, readValue, expectedIncrease) || memoryValueComparator(SearchComparison::Equals, readValue, expectedDecrease);
}
case SearchComparison::UnknownValue:
{
return true;
}
default:
Console.Error("Debugger: Unknown type when doing memory search!");
return false;
Expand Down Expand Up @@ -506,63 +511,66 @@ void MemorySearchWidget::onSearchButtonClicked()
const bool isFilterSearch = sender() == m_ui.btnFilterSearch;
unsigned long long value;

switch (searchType)
{
case SearchType::ByteType:
case SearchType::Int16Type:
case SearchType::Int32Type:
case SearchType::Int64Type:
value = searchValue.toULongLong(&ok, searchHex ? 16 : 10);
break;
case SearchType::FloatType:
case SearchType::DoubleType:
searchValue.toDouble(&ok);
break;
case SearchType::StringType:
ok = !searchValue.isEmpty();
break;
case SearchType::ArrayType:
ok = !searchValue.trimmed().isEmpty();
break;
}

if (!ok)
{
QMessageBox::critical(this, tr("Debugger"), tr("Invalid search value"));
return;
}

switch (searchType)
if(searchComparison != SearchComparison::UnknownValue)
{
case SearchType::ArrayType:
case SearchType::StringType:
case SearchType::DoubleType:
case SearchType::FloatType:
break;
case SearchType::Int64Type:
if (value <= std::numeric_limits<unsigned long long>::max())
switch (searchType)
{
case SearchType::ByteType:
case SearchType::Int16Type:
case SearchType::Int32Type:
case SearchType::Int64Type:
value = searchValue.toULongLong(&ok, searchHex ? 16 : 10);
break;
case SearchType::Int32Type:
if (value <= std::numeric_limits<unsigned long>::max())
case SearchType::FloatType:
case SearchType::DoubleType:
searchValue.toDouble(&ok);
break;
case SearchType::Int16Type:
if (value <= std::numeric_limits<unsigned short>::max())
case SearchType::StringType:
ok = !searchValue.isEmpty();
break;
case SearchType::ByteType:
if (value <= std::numeric_limits<unsigned char>::max())
case SearchType::ArrayType:
ok = !searchValue.trimmed().isEmpty();
break;
default:
QMessageBox::critical(this, tr("Debugger"), tr("Value is larger than type"));
}

if (!ok)
{
QMessageBox::critical(this, tr("Debugger"), tr("Invalid search value"));
return;
}

if (!isFilterSearch && (searchComparison == SearchComparison::Changed || searchComparison == SearchComparison::ChangedBy
|| searchComparison == SearchComparison::Decreased || searchComparison == SearchComparison::DecreasedBy
|| searchComparison == SearchComparison::Increased || searchComparison == SearchComparison::IncreasedBy
|| searchComparison == SearchComparison::NotChanged))
{
QMessageBox::critical(this, tr("Debugger"), tr("This search comparison can only be used with filter searches."));
return;
}

switch (searchType)
{
case SearchType::ArrayType:
case SearchType::StringType:
case SearchType::DoubleType:
case SearchType::FloatType:
break;
case SearchType::Int64Type:
if (value <= std::numeric_limits<unsigned long long>::max())
break;
case SearchType::Int32Type:
if (value <= std::numeric_limits<unsigned long>::max())
break;
case SearchType::Int16Type:
if (value <= std::numeric_limits<unsigned short>::max())
break;
case SearchType::ByteType:
if (value <= std::numeric_limits<unsigned char>::max())
break;
default:
QMessageBox::critical(this, tr("Debugger"), tr("Value is larger than type"));
return;
}

if (!isFilterSearch && (searchComparison == SearchComparison::Changed || searchComparison == SearchComparison::ChangedBy
|| searchComparison == SearchComparison::Decreased || searchComparison == SearchComparison::DecreasedBy
|| searchComparison == SearchComparison::Increased || searchComparison == SearchComparison::IncreasedBy
|| searchComparison == SearchComparison::NotChanged))
{
QMessageBox::critical(this, tr("Debugger"), tr("This search comparison can only be used with filter searches."));
return;
}
}

QFutureWatcher<std::vector<SearchResult>>* workerWatcher = new QFutureWatcher<std::vector<SearchResult>>();
Expand Down Expand Up @@ -654,6 +662,11 @@ void MemorySearchWidget::onSearchTypeChanged(int newIndex)
updateSearchComparisonSelections();
}

void MemorySearchWidget::onSearchComparisonChanged(int newValue)
{
m_ui.txtSearchValue->setEnabled(getCurrentSearchComparison() != SearchComparison::UnknownValue);
}

void MemorySearchWidget::updateSearchComparisonSelections()
{
const QString selectedComparisonLabel = m_ui.cmbSearchComparison->currentText();
Expand Down Expand Up @@ -704,5 +717,11 @@ std::vector<SearchComparison> MemorySearchWidget::getValidSearchComparisonsForSt
comparisons.push_back(SearchComparison::ChangedBy);
comparisons.push_back(SearchComparison::NotChanged);
}

if(!hasResults)
{
comparisons.push_back(SearchComparison::UnknownValue);
}

return comparisons;
}
3 changes: 3 additions & 0 deletions pcsx2-qt/Debugger/MemorySearchWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class MemorySearchWidget final : public QWidget
Changed,
ChangedBy,
NotChanged,
UnknownValue,
Invalid
};

Expand All @@ -69,6 +70,7 @@ class MemorySearchWidget final : public QWidget
insert(SearchComparison::Changed, tr("Changed"));
insert(SearchComparison::ChangedBy, tr("Changed By"));
insert(SearchComparison::NotChanged, tr("Not Changed"));
insert(SearchComparison::UnknownValue, tr("Unknown Initial Value"));
insert(SearchComparison::Invalid, "");
}
SearchComparison labelToEnum(QString comparisonLabel)
Expand Down Expand Up @@ -120,6 +122,7 @@ public slots:
void onSearchButtonClicked();
void onSearchResultsListScroll(u32 value);
void onSearchTypeChanged(int newIndex);
void onSearchComparisonChanged(int newIndex);
void loadSearchResults();
void contextSearchResultGoToDisassembly();
void contextRemoveSearchResult();
Expand Down
5 changes: 5 additions & 0 deletions pcsx2-qt/Debugger/MemorySearchWidget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,11 @@
<string>Less Than Or Equal</string>
</property>
</item>
<item>
<property name="text">
<string>Unknown Initial Value</string>
</property>
</item>
</widget>
</item>
<item row="1" column="0">
Expand Down

0 comments on commit 27e6ba9

Please sign in to comment.