Skip to content

Commit

Permalink
MemoryWidget: Add negative offset search support
Browse files Browse the repository at this point in the history
  • Loading branch information
sepalani committed Sep 1, 2021
1 parent 32c7524 commit 375d4f3
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 21 deletions.
69 changes: 48 additions & 21 deletions Source/Core/DolphinQt/Debugger/MemoryWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -443,26 +443,23 @@ void MemoryWidget::SetAddress(u32 address)

void MemoryWidget::OnSearchAddress()
{
bool good_addr, good_offset;
// Returns 0 if conversion fails
const u32 addr = m_search_address->text().toUInt(&good_addr, 16);
const u32 offset = m_search_offset->text().toUInt(&good_offset, 16);
bool good_address;
bool good_offset;
const u32 address = GetTargetAddress(&good_address, &good_offset);

if (good_address && good_offset)
m_memory_view->SetAddress(address);

QFont addr_font, offset_font;
QPalette addr_palette, offset_palette;

if (good_addr || m_search_address->text().isEmpty())
{
if (good_addr)
m_memory_view->SetAddress(addr + offset);
}
else
if (!good_address)
{
addr_font.setBold(true);
addr_palette.setColor(QPalette::Text, Qt::red);
}

if (!good_offset && !m_search_offset->text().isEmpty())
if (!good_offset)
{
offset_font.setBold(true);
offset_palette.setColor(QPalette::Text, Qt::red);
Expand Down Expand Up @@ -500,10 +497,9 @@ void MemoryWidget::OnSetValue()
if (!Core::IsRunning())
return;

bool good_address, good_offset;
// Returns 0 if conversion fails
u32 addr = m_search_address->text().toUInt(&good_address, 16);
addr += m_search_offset->text().toUInt(&good_offset, 16);
bool good_address;
bool good_offset;
u32 addr = GetTargetAddress(&good_address, &good_offset);

if (!good_address)
{
Expand Down Expand Up @@ -651,22 +647,53 @@ std::vector<u8> MemoryWidget::GetValueData() const
return search_for;
}

u32 MemoryWidget::GetTargetAddress(bool* good_address, bool* good_offset) const
{
// Returns 0 if conversion fails
const u32 addr = m_search_address->text().toUInt(good_address, 16);
*good_address |= m_search_address->text().isEmpty();
const s32 offset = m_search_offset->text().toInt(good_offset, 16);
*good_offset |= m_search_offset->text().isEmpty();
*good_offset &= offset >= 0 || u32(-offset) <= addr;

if (!*good_address || !*good_offset)
return 0;

if (offset < 0)
return addr - u32(-offset);
else
return addr + u32(offset);
}

void MemoryWidget::FindValue(bool next)
{
std::vector<u8> search_for = GetValueData();
bool good_address;
bool good_offset;
u32 addr = GetTargetAddress(&good_address, &good_offset);

if (search_for.empty())
if (!good_address)
{
m_result_label->setText(tr("No Value Given"));
m_result_label->setText(tr("Bad address provided."));
return;
}

if (!good_offset)
{
m_result_label->setText(tr("Bad offset provided."));
return;
}
u32 addr = 0;

if (!m_search_address->text().isEmpty())
{
// skip the quoted address so we don't potentially refind the last result
addr = m_search_address->text().toUInt(nullptr, 16) +
m_search_offset->text().toUInt(nullptr, 16) + (next ? 1 : -1);
addr += next ? 1 : -1;
}

const std::vector<u8> search_for = GetValueData();
if (search_for.empty())
{
m_result_label->setText(tr("No value provided."));
return;
}

AddressSpace::Accessors* accessors = AddressSpace::GetAccessors(m_memory_view->GetAddressSpace());
Expand Down
1 change: 1 addition & 0 deletions Source/Core/DolphinQt/Debugger/MemoryWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class MemoryWidget : public QDockWidget
void OnDumpFakeVMEM();

std::vector<u8> GetValueData() const;
u32 GetTargetAddress(bool* good_address, bool* good_offset) const;

void FindValue(bool next);

Expand Down

0 comments on commit 375d4f3

Please sign in to comment.