Skip to content

Commit

Permalink
CodeViewWidget: Get rid of magic values in OnInsertBLR() and OnInsert…
Browse files Browse the repository at this point in the history
…NOP()

A call like ReplaceAddress(address, 0) is pretty ambiguous; so is
ReplaceAddress(address, false), so use an enum class that tells people
straight-up what the replacer is.

This also gets rid of the really weird naming, where if 'blr' is true,
we'd be replacing the address with a NOP, rather than an actual BLR
instruction, so we invert that so it actually makes sense. There's no
actual bug fixed here though, considering the OnInsert functions
specified the correct values; it's literally just weird naming.
  • Loading branch information
lioncash committed May 13, 2018
1 parent bbc0aee commit d7a3ce2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
10 changes: 5 additions & 5 deletions Source/Core/DolphinQt2/Debugger/CodeViewWidget.cpp
Expand Up @@ -195,14 +195,14 @@ void CodeViewWidget::SetAddress(u32 address, SetAddressUpdate update)
Update();
}

void CodeViewWidget::ReplaceAddress(u32 address, bool blr)
void CodeViewWidget::ReplaceAddress(u32 address, ReplaceWith replace)
{
auto found = std::find_if(m_repl_list.begin(), m_repl_list.end(),
[address](ReplStruct r) { return r.address == address; });

if (found != m_repl_list.end())
{
PowerPC::debug_interface.WriteExtraMemory(0, (*found).old_value, address);
PowerPC::debug_interface.WriteExtraMemory(0, found->old_value, address);
m_repl_list.erase(found);
}
else
Expand All @@ -214,7 +214,7 @@ void CodeViewWidget::ReplaceAddress(u32 address, bool blr)

m_repl_list.push_back(repl);

PowerPC::debug_interface.Patch(address, blr ? 0x60000000 : 0x4e800020);
PowerPC::debug_interface.Patch(address, replace == ReplaceWith::BLR ? 0x4e800020 : 0x60000000);
}

Update();
Expand Down Expand Up @@ -347,14 +347,14 @@ void CodeViewWidget::OnInsertBLR()
{
const u32 addr = GetContextAddress();

ReplaceAddress(addr, 0);
ReplaceAddress(addr, ReplaceWith::BLR);
}

void CodeViewWidget::OnInsertNOP()
{
const u32 addr = GetContextAddress();

ReplaceAddress(addr, 1);
ReplaceAddress(addr, ReplaceWith::NOP);
}

void CodeViewWidget::OnFollowBranch()
Expand Down
8 changes: 7 additions & 1 deletion Source/Core/DolphinQt2/Debugger/CodeViewWidget.h
Expand Up @@ -40,7 +40,13 @@ class CodeViewWidget : public QTableWidget
void BreakpointsChanged();

private:
void ReplaceAddress(u32 address, bool blr);
enum class ReplaceWith
{
BLR,
NOP
};

void ReplaceAddress(u32 address, ReplaceWith replace);

void resizeEvent(QResizeEvent*) override;
void keyPressEvent(QKeyEvent* event) override;
Expand Down

0 comments on commit d7a3ce2

Please sign in to comment.