Skip to content

Commit

Permalink
Merge pull request #5009 from aldelaro5/memcheck-fix
Browse files Browse the repository at this point in the history
Fix memory breakpoint when checking the middle of the data
  • Loading branch information
Helios747 committed Mar 20, 2017
2 parents 5cc55f0 + 8bf27cf commit 50faffc
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 20 deletions.
3 changes: 2 additions & 1 deletion Source/Core/Common/DebugInterface.h
Expand Up @@ -4,6 +4,7 @@

#pragma once

#include <cstddef>
#include <cstring>
#include <string>

Expand All @@ -26,7 +27,7 @@ class DebugInterface
virtual void ToggleBreakpoint(unsigned int /*address*/) {}
virtual void AddWatch(unsigned int /*address*/) {}
virtual void ClearAllMemChecks() {}
virtual bool IsMemCheck(unsigned int /*address*/) { return false; }
virtual bool IsMemCheck(unsigned int /*address*/, size_t /*size*/) { return false; }
virtual void ToggleMemCheck(unsigned int /*address*/, bool /*read*/, bool /*write*/, bool /*log*/)
{
}
Expand Down
5 changes: 3 additions & 2 deletions Source/Core/Core/Debugger/PPCDebugInterface.cpp
Expand Up @@ -4,6 +4,7 @@

#include "Core/Debugger/PPCDebugInterface.h"

#include <cstddef>
#include <string>

#include "Common/GekkoDisassembler.h"
Expand Down Expand Up @@ -129,9 +130,9 @@ void PPCDebugInterface::ClearAllMemChecks()
PowerPC::memchecks.Clear();
}

bool PPCDebugInterface::IsMemCheck(unsigned int address)
bool PPCDebugInterface::IsMemCheck(unsigned int address, size_t size)
{
return PowerPC::memchecks.GetMemCheck(address) != nullptr;
return PowerPC::memchecks.GetMemCheck(address, size) != nullptr;
}

void PPCDebugInterface::ToggleMemCheck(unsigned int address, bool read, bool write, bool log)
Expand Down
3 changes: 2 additions & 1 deletion Source/Core/Core/Debugger/PPCDebugInterface.h
Expand Up @@ -4,6 +4,7 @@

#pragma once

#include <cstddef>
#include <string>

#include "Common/DebugInterface.h"
Expand All @@ -25,7 +26,7 @@ class PPCDebugInterface final : public DebugInterface
void AddWatch(unsigned int address) override;
void ToggleBreakpoint(unsigned int address) override;
void ClearAllMemChecks() override;
bool IsMemCheck(unsigned int address) override;
bool IsMemCheck(unsigned int address, size_t size = 1) override;
void ToggleMemCheck(unsigned int address, bool read = true, bool write = true,
bool log = true) override;
unsigned int ReadMemory(unsigned int address) override;
Expand Down
3 changes: 2 additions & 1 deletion Source/Core/Core/HW/DSPLLE/DSPDebugInterface.cpp
Expand Up @@ -4,6 +4,7 @@

#include "Core/HW/DSPLLE/DSPDebugInterface.h"

#include <cstddef>
#include <string>

#include "Common/MsgHandler.h"
Expand Down Expand Up @@ -116,7 +117,7 @@ void DSPDebugInterface::ToggleBreakpoint(unsigned int address)
}
}

bool DSPDebugInterface::IsMemCheck(unsigned int address)
bool DSPDebugInterface::IsMemCheck(unsigned int address, size_t size)
{
return false;
}
Expand Down
3 changes: 2 additions & 1 deletion Source/Core/Core/HW/DSPLLE/DSPDebugInterface.h
Expand Up @@ -4,6 +4,7 @@

#pragma once

#include <cstddef>
#include <string>

#include "Common/CommonTypes.h"
Expand All @@ -27,7 +28,7 @@ class DSPDebugInterface final : public DebugInterface
void ClearAllBreakpoints() override;
void ToggleBreakpoint(unsigned int address) override;
void ClearAllMemChecks() override;
bool IsMemCheck(unsigned int address) override;
bool IsMemCheck(unsigned int address, size_t size) override;
void ToggleMemCheck(unsigned int address, bool read = true, bool write = true,
bool log = true) override;
unsigned int ReadMemory(unsigned int address) override;
Expand Down
14 changes: 5 additions & 9 deletions Source/Core/Core/PowerPC/BreakPoints.cpp
Expand Up @@ -5,6 +5,7 @@
#include "Core/PowerPC/BreakPoints.h"

#include <algorithm>
#include <cstddef>
#include <sstream>
#include <string>
#include <vector>
Expand Down Expand Up @@ -201,16 +202,11 @@ void MemChecks::Remove(u32 address)
}
}

TMemCheck* MemChecks::GetMemCheck(u32 address)
TMemCheck* MemChecks::GetMemCheck(u32 address, size_t size)
{
for (TMemCheck& mc : m_mem_checks)
{
if (mc.is_ranged)
{
if (address >= mc.start_address && address <= mc.end_address)
return &mc;
}
else if (mc.start_address == address)
if (mc.end_address >= address && address + size - 1 >= mc.start_address)
{
return &mc;
}
Expand Down Expand Up @@ -239,8 +235,8 @@ bool MemChecks::OverlapsMemcheck(u32 address, u32 length)
return false;
}

bool TMemCheck::Action(DebugInterface* debug_interface, u32 value, u32 addr, bool write, int size,
u32 pc)
bool TMemCheck::Action(DebugInterface* debug_interface, u32 value, u32 addr, bool write,
size_t size, u32 pc)
{
if ((write && is_break_on_write) || (!write && is_break_on_read))
{
Expand Down
5 changes: 3 additions & 2 deletions Source/Core/Core/PowerPC/BreakPoints.h
Expand Up @@ -4,6 +4,7 @@

#pragma once

#include <cstddef>
#include <string>
#include <vector>

Expand Down Expand Up @@ -34,7 +35,7 @@ struct TMemCheck
u32 num_hits = 0;

// returns whether to break
bool Action(DebugInterface* dbg_interface, u32 value, u32 addr, bool write, int size, u32 pc);
bool Action(DebugInterface* dbg_interface, u32 value, u32 addr, bool write, size_t size, u32 pc);
};

struct TWatch
Expand Down Expand Up @@ -86,7 +87,7 @@ class MemChecks
void Add(const TMemCheck& memory_check);

// memory breakpoint
TMemCheck* GetMemCheck(u32 address);
TMemCheck* GetMemCheck(u32 address, size_t size = 1);
bool OverlapsMemcheck(u32 address, u32 length);
void Remove(u32 address);

Expand Down
4 changes: 2 additions & 2 deletions Source/Core/Core/PowerPC/MMU.cpp
Expand Up @@ -416,11 +416,11 @@ u32 HostRead_Instruction(const u32 address)
return inst.hex;
}

static void Memcheck(u32 address, u32 var, bool write, int size)
static void Memcheck(u32 address, u32 var, bool write, size_t size)
{
if (PowerPC::memchecks.HasAny())
{
TMemCheck* mc = PowerPC::memchecks.GetMemCheck(address);
TMemCheck* mc = PowerPC::memchecks.GetMemCheck(address, size);
if (mc)
{
if (CPU::IsStepping())
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/DolphinWX/Debugger/MemoryView.cpp
Expand Up @@ -418,7 +418,7 @@ void CMemoryView::OnPaint(wxPaintEvent& event)
draw_text(StrToWxStr(desc), 2);

// Show blue memory check dot
if (debugger->IsMemCheck(address))
if (debugger->IsMemCheck(address, sizeof(u8)))
{
dc.SetPen(*wxTRANSPARENT_PEN);
dc.SetBrush(mc_brush);
Expand Down

0 comments on commit 50faffc

Please sign in to comment.