From 9209a30d9b989e2f5601cafad9001a41a4566cf2 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 30 Jun 2013 15:35:03 -0700 Subject: [PATCH] Add skeleton for conditional breakpoints. --- Core/Debugger/Breakpoints.cpp | 33 +++++++++++++++++++++++++++++++-- Core/Debugger/Breakpoints.h | 25 +++++++++++++++++++++++-- Core/MIPS/x86/Jit.cpp | 4 ++++ 3 files changed, 58 insertions(+), 4 deletions(-) diff --git a/Core/Debugger/Breakpoints.cpp b/Core/Debugger/Breakpoints.cpp index 173bb0d404..c247f17274 100644 --- a/Core/Debugger/Breakpoints.cpp +++ b/Core/Debugger/Breakpoints.cpp @@ -157,6 +157,35 @@ void CBreakPoints::ClearTemporaryBreakPoints() Update(); } +void CBreakPoints::ChangeBreakPointAddCond(u32 addr, const BreakPointCond &cond) +{ + size_t bp = FindBreakpoint(addr); + if (bp != INVALID_BREAKPOINT) + { + breakPoints_[bp].hasCond = true; + breakPoints_[bp].cond = cond; + Update(); + } +} + +void CBreakPoints::ChangeBreakPointRemoveCond(u32 addr) +{ + size_t bp = FindBreakpoint(addr); + if (bp != INVALID_BREAKPOINT) + { + breakPoints_[bp].hasCond = false; + Update(); + } +} + +BreakPointCond *CBreakPoints::GetBreakPointCondition(u32 addr) +{ + size_t bp = FindBreakpoint(addr); + if (bp != INVALID_BREAKPOINT && breakPoints_[bp].hasCond) + return &breakPoints_[bp].cond; + return NULL; +} + void CBreakPoints::AddMemCheck(u32 start, u32 end, MemCheckCondition cond, MemCheckResult result) { size_t mc = FindMemCheck(start, end); @@ -236,12 +265,12 @@ int CBreakPoints::GetNumBreakpoints() return (int)breakPoints_.size(); } -const BreakPoint CBreakPoints::GetBreakpoint(int i) +const BreakPoint CBreakPoints::GetBreakpoint(size_t i) { return breakPoints_[i]; } -int CBreakPoints::GetBreakpointAddress(int i) +int CBreakPoints::GetBreakpointAddress(size_t i) { return breakPoints_[i].iAddress; } diff --git a/Core/Debugger/Breakpoints.h b/Core/Debugger/Breakpoints.h index 83a92ddcf0..19e7e0a09e 100644 --- a/Core/Debugger/Breakpoints.h +++ b/Core/Debugger/Breakpoints.h @@ -20,12 +20,28 @@ #include "../../Globals.h" #include +// TODO: Replace with expression or something. +struct BreakPointCond +{ + u32 todo; + + u32 Evaluate() const + { + return 1; + } +}; + struct BreakPoint { + BreakPoint() : hasCond(false) {} + u32 iAddress; bool bOn; bool bTemporary; + bool hasCond; + BreakPointCond cond; + bool operator == (const BreakPoint &other) const { return iAddress == other.iAddress; } @@ -86,6 +102,11 @@ public: static void ClearAllBreakPoints(); static void ClearTemporaryBreakPoints(); + // Makes a copy. Temporary breakpoints can't have conditions. + static void ChangeBreakPointAddCond(u32 addr, const BreakPointCond &cond); + static void ChangeBreakPointRemoveCond(u32 addr); + static BreakPointCond *GetBreakPointCondition(u32 addr); + static void AddMemCheck(u32 start, u32 end, MemCheckCondition cond, MemCheckResult result); static void RemoveMemCheck(u32 start, u32 end); static void ChangeMemCheck(u32 start, u32 end, MemCheckCondition cond, MemCheckResult result); @@ -93,8 +114,8 @@ public: static MemCheck *GetMemCheck(u32 address, int size); static int GetNumBreakpoints(); - static const BreakPoint GetBreakpoint(int i); - static int GetBreakpointAddress(int i); + static const BreakPoint GetBreakpoint(size_t i); + static int GetBreakpointAddress(size_t i); // TODO: MemChecks somehow too? static void SetSkipFirst(u32 pc) { breakSkipFirstAt_ = pc; } diff --git a/Core/MIPS/x86/Jit.cpp b/Core/MIPS/x86/Jit.cpp index 08eb5f740e..cb0a35ff4e 100644 --- a/Core/MIPS/x86/Jit.cpp +++ b/Core/MIPS/x86/Jit.cpp @@ -65,6 +65,10 @@ u32 JitBreakpoint() if (CBreakPoints::CheckSkipFirst() == currentMIPS->pc) return 0; + auto cond = CBreakPoints::GetBreakPointCondition(currentMIPS->pc); + if (cond && !cond->Evaluate()) + return 0; + Core_EnableStepping(true); host->SetDebugMode(true);