Skip to content

Commit

Permalink
DebugInterface: Add original_value to MemoryPatch
Browse files Browse the repository at this point in the history
  • Loading branch information
sepalani committed Feb 27, 2021
1 parent e89df4c commit 9282782
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 14 deletions.
11 changes: 6 additions & 5 deletions Source/Core/Common/Debug/MemoryPatches.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@

namespace Common::Debug
{
MemoryPatch::MemoryPatch(u32 address_, std::vector<u8> value_)
: address(address_), value(std::move(value_))
MemoryPatch::MemoryPatch(u32 address_, std::vector<u8> value)
: address(address_), patch_value(std::move(value)), original_value()
{
}

MemoryPatch::MemoryPatch(u32 address_, u32 value_)
: MemoryPatch(address_, {static_cast<u8>(value_ >> 24), static_cast<u8>(value_ >> 16),
static_cast<u8>(value_ >> 8), static_cast<u8>(value_)})
MemoryPatch::MemoryPatch(u32 address_, u32 value)
: MemoryPatch(address_, {static_cast<u8>(value >> 24), static_cast<u8>(value >> 16),
static_cast<u8>(value >> 8), static_cast<u8>(value)})
{
}

Expand Down Expand Up @@ -80,6 +80,7 @@ void MemoryPatches::DisablePatch(std::size_t index)
return;
m_patches[index].is_enabled = MemoryPatch::State::Disabled;
Patch(index);
m_patches[index].original_value.clear();
}

bool MemoryPatches::HasEnabledPatch(u32 address) const
Expand Down
3 changes: 2 additions & 1 deletion Source/Core/Common/Debug/MemoryPatches.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ struct MemoryPatch
MemoryPatch(u32 address_, u32 value_);

u32 address;
std::vector<u8> value;
std::vector<u8> patch_value;
std::vector<u8> original_value;
State is_enabled = State::Enabled;
};

Expand Down
18 changes: 13 additions & 5 deletions Source/Core/Core/Debugger/PPCDebugInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,27 @@
void PPCPatches::Patch(std::size_t index)
{
auto& patch = m_patches[index];
if (patch.value.empty())
if (patch.patch_value.empty())
return;

const u32 address = patch.address;
const std::size_t size = patch.value.size();
const std::size_t size = patch.patch_value.size();
if (!PowerPC::HostIsRAMAddress(address))
return;

const bool is_enabled = patch.is_enabled == Common::Debug::MemoryPatch::State::Enabled;
for (u32 offset = 0; offset < size; ++offset)
{
const u8 value = PowerPC::HostRead_U8(address + offset);
PowerPC::HostWrite_U8(patch.value[offset], address + offset);
patch.value[offset] = value;
if (is_enabled)
{
const u8 original_value = PowerPC::HostRead_U8(address + offset);
PowerPC::HostWrite_U8(patch.patch_value[offset], address + offset);
patch.original_value.push_back(original_value);
}
else
{
PowerPC::HostWrite_U8(patch.original_value[offset], address + offset);
}

if (((address + offset) % 4) == 3)
PowerPC::ScheduleInvalidateCacheThreadSafe(Common::AlignDown(address + offset, 4));
Expand Down
13 changes: 10 additions & 3 deletions Source/Core/DolphinQt/Debugger/MemoryPatchWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@ void MemoryPatchWidget::CreateWidgets()
m_toolbar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);

m_table = new QTableWidget;
m_table->setColumnCount(3);
m_table->setSelectionMode(QAbstractItemView::SingleSelection);
m_table->setSelectionBehavior(QAbstractItemView::SelectRows);
m_table->setEditTriggers(QAbstractItemView::NoEditTriggers);

const QStringList header{{tr("Active"), tr("Address"), tr("Value")}};
const QStringList header{{tr("Active"), tr("Address"), tr("Patch value"), tr("Original value")}};
m_table->setColumnCount(header.size());
m_table->setHorizontalHeaderLabels(header);
m_table->verticalHeader()->hide();

Expand Down Expand Up @@ -139,12 +139,19 @@ void MemoryPatchWidget::Update()

std::ostringstream oss;
oss << std::hex << std::setfill('0');
for (u8 b : patch.value)
for (u8 b : patch.patch_value)
{
oss << std::setw(2) << static_cast<u32>(b);
}
m_table->setItem(patch_id, 2, create_item(QString::fromStdString(oss.str())));

oss.str("");
for (u8 b : patch.original_value)
{
oss << std::setw(2) << static_cast<u32>(b);
}
m_table->setItem(patch_id, 3, create_item(QString::fromStdString(oss.str())));

patch_id += 1;
}
}
Expand Down

0 comments on commit 9282782

Please sign in to comment.