Skip to content

[Debugger] Memory View search box improvements #13470

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 45 additions & 6 deletions Source/Core/DolphinQt/Debugger/MemoryWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
#include "Core/ConfigManager.h"
#include "Core/Core.h"
#include "Core/HW/AddressSpace.h"
#include "Core/PowerPC/BreakPoints.h"
#include "Core/PowerPC/PowerPC.h"
#include "Core/System.h"
#include "DolphinQt/Debugger/MemoryViewWidget.h"
#include "DolphinQt/Host.h"
Expand Down Expand Up @@ -73,6 +75,7 @@ MemoryWidget::MemoryWidget(Core::System& system, QWidget* parent)
else
RemoveAfterFrameEventCallback();
});

LoadSettings();

ConnectWidgets();
Expand Down Expand Up @@ -156,10 +159,26 @@ void MemoryWidget::CreateWidgets()

m_find_next = new QPushButton(tr("Find &Next"));
m_find_previous = new QPushButton(tr("Find &Previous"));
m_find_align = new QComboBox;
m_find_align->addItem(tr("No alignment"), 0);
m_find_align->addItem(tr("2 Bytes"), 2);
m_find_align->addItem(tr("4 Bytes"), 4);
m_find_align->addItem(tr("8 Bytes"), 8);
m_find_align->addItem(tr("16 Bytes"), 16);
m_result_label = new QLabel;

auto* search_bp_group = new QHBoxLayout;
auto* auto_bp_label = new QLabel(tr("Auto BP"));
m_find_auto_mem_bp = new QCheckBox(tr("Mem"));
m_find_auto_code_bp = new QCheckBox(tr("Code"));
search_bp_group->addWidget(auto_bp_label);
search_bp_group->addWidget(m_find_auto_mem_bp);
search_bp_group->addWidget(m_find_auto_code_bp);

search_layout->addWidget(m_find_next);
search_layout->addWidget(m_find_previous);
search_layout->addWidget(m_find_align);
search_layout->addLayout(search_bp_group);
search_layout->addWidget(m_result_label);
search_layout->setSpacing(1);

Expand Down Expand Up @@ -849,28 +868,28 @@ MemoryWidget::TargetAddress MemoryWidget::GetTargetAddress() const
return target;
}

void MemoryWidget::FindValue(bool next)
bool MemoryWidget::FindValue(bool next)
{
auto target_addr = GetTargetAddress();

if (!target_addr.is_good_address)
{
m_result_label->setText(tr("Bad address provided."));
return;
return false;
}

if (!target_addr.is_good_offset)
{
m_result_label->setText(tr("Bad offset provided."));
return;
return false;
}

const QByteArray search_for = GetInputData();

if (search_for.isEmpty())
{
m_result_label->setText(tr("Bad Value Given"));
return;
return false;
}

if (!m_search_address->currentText().isEmpty())
Expand Down Expand Up @@ -900,15 +919,35 @@ void MemoryWidget::FindValue(bool next)

m_memory_view->SetAddress(offset);

return;
return true;
}

m_result_label->setText(tr("No Match"));
return false;
}

void MemoryWidget::OnFindNextValue()
{
FindValue(true);
int alignment = m_find_align->currentData().toInt();
bool set_mem_bp = m_find_auto_mem_bp->isChecked();
bool set_code_bp = m_find_auto_code_bp->isChecked();

while (FindValue(true))
{
if ((alignment == 0) || ((GetTargetAddress().address & (alignment - 1)) == 0))
{
if (set_mem_bp)
{
m_memory_view->ToggleBreakpoint(GetTargetAddress().address, false);
}
if (set_code_bp && (4 <= alignment))
{
m_system.GetPowerPC().GetBreakPoints().ToggleBreakPoint(GetTargetAddress().address);
emit Host::GetInstance()->PPCBreakpointsChanged();
}
break;
}
}
}

void MemoryWidget::OnFindPreviousValue()
Expand Down
5 changes: 4 additions & 1 deletion Source/Core/DolphinQt/Debugger/MemoryWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class MemoryWidget : public QDockWidget
void ValidateAndPreviewInputValue();
QByteArray GetInputData() const;
TargetAddress GetTargetAddress() const;
void FindValue(bool next);
bool FindValue(bool next);

void closeEvent(QCloseEvent*) override;
void hideEvent(QHideEvent* event) override;
Expand All @@ -101,6 +101,9 @@ class MemoryWidget : public QDockWidget
// Search
QPushButton* m_find_next;
QPushButton* m_find_previous;
QComboBox* m_find_align;
QCheckBox* m_find_auto_mem_bp;
QCheckBox* m_find_auto_code_bp;
QComboBox* m_input_combo;
QLabel* m_result_label;

Expand Down