1 // Copyright (c) 2012- PPSSPP Project.
3 // This program is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, version 2.0 or later versions.
7 // This program is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 // GNU General Public License 2.0 for more details.
12 // A copy of the GPL 2.0 should have been included with the program.
13 // If not, see http://www.gnu.org/licenses/
15 // Official git repository and contact information can be found at
16 // https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
22 #include "Core/Debugger/DebugInterface.h"
26 DebugInterface
*debug
;
27 PostfixExpression expression
;
28 char expressionString
[128];
30 BreakPointCond() : debug(NULL
)
32 expressionString
[0] = '\0';
38 if (debug
->parseExpression(expression
,result
) == false) return 0;
45 BreakPoint() : hasCond(false) {}
54 bool operator == (const BreakPoint
&other
) const {
55 return addr
== other
.addr
;
57 bool operator < (const BreakPoint
&other
) const {
58 return addr
< other
.addr
;
62 enum MemCheckCondition
65 MEMCHECK_WRITE
= 0x02,
66 MEMCHECK_WRITE_ONCHANGE
= 0x04,
68 MEMCHECK_READWRITE
= 0x03,
73 MEMCHECK_IGNORE
= 0x00,
75 MEMCHECK_BREAK
= 0x02,
86 MemCheckCondition cond
;
87 MemCheckResult result
;
95 void Action(u32 addr
, bool write
, int size
, u32 pc
);
96 void JitBefore(u32 addr
, bool write
, int size
, u32 pc
);
99 void Log(u32 addr
, bool write
, int size
, u32 pc
);
101 bool operator == (const MemCheck
&other
) const {
102 return start
== other
.start
&& end
== other
.end
;
106 // BreakPoints cannot overlap, only one is allowed per address.
107 // MemChecks can overlap, as long as their ends are different.
108 // WARNING: MemChecks are not used in the interpreter or HLE currently.
112 static const size_t INVALID_BREAKPOINT
= -1;
113 static const size_t INVALID_MEMCHECK
= -1;
115 static bool IsAddressBreakPoint(u32 addr
);
116 static bool IsAddressBreakPoint(u32 addr
, bool* enabled
);
117 static bool IsTempBreakPoint(u32 addr
);
118 static bool RangeContainsBreakPoint(u32 addr
, u32 size
);
119 static void AddBreakPoint(u32 addr
, bool temp
= false);
120 static void RemoveBreakPoint(u32 addr
);
121 static void ChangeBreakPoint(u32 addr
, bool enable
);
122 static void ClearAllBreakPoints();
123 static void ClearTemporaryBreakPoints();
125 // Makes a copy. Temporary breakpoints can't have conditions.
126 static void ChangeBreakPointAddCond(u32 addr
, const BreakPointCond
&cond
);
127 static void ChangeBreakPointRemoveCond(u32 addr
);
128 static BreakPointCond
*GetBreakPointCondition(u32 addr
);
130 static void AddMemCheck(u32 start
, u32 end
, MemCheckCondition cond
, MemCheckResult result
);
131 static void RemoveMemCheck(u32 start
, u32 end
);
132 static void ChangeMemCheck(u32 start
, u32 end
, MemCheckCondition cond
, MemCheckResult result
);
133 static void ClearAllMemChecks();
135 static MemCheck
*GetMemCheck(u32 address
, int size
);
136 static void ExecMemCheck(u32 address
, bool write
, int size
, u32 pc
);
138 // Executes memchecks but used by the jit. Cleanup finalizes after jit is done.
139 static void ExecMemCheckJitBefore(u32 address
, bool write
, int size
, u32 pc
);
140 static void ExecMemCheckJitCleanup();
142 static void SetSkipFirst(u32 pc
);
143 static u32
CheckSkipFirst();
145 // Includes uncached addresses.
146 static const std::vector
<MemCheck
> GetMemCheckRanges();
148 static const std::vector
<MemCheck
> GetMemChecks();
149 static const std::vector
<BreakPoint
> GetBreakpoints();
151 static void Update(u32 addr
= 0);
154 static size_t FindBreakpoint(u32 addr
, bool matchTemp
= false, bool temp
= false);
155 // Finds exactly, not using a range check.
156 static size_t FindMemCheck(u32 start
, u32 end
);
158 static std::vector
<BreakPoint
> breakPoints_
;
159 static u32 breakSkipFirstAt_
;
160 static u64 breakSkipFirstTicks_
;
162 static std::vector
<MemCheck
> memChecks_
;
163 static std::vector
<MemCheck
*> cleanupMemChecks_
;