-
Notifications
You must be signed in to change notification settings - Fork 177
/
Debug.h
365 lines (287 loc) · 10.5 KB
/
Debug.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
#ifndef HX_DEBUG_H
#define HX_DEBUG_H
#include <hxcpp.h>
// Some functions used by AdvancedDebug.cpp
// Returns the thread number of the calling thread
HXCPP_EXTERN_CLASS_ATTRIBUTES
int __hxcpp_GetCurrentThreadNumber();
namespace hx
{
#ifdef HXCPP_DEBUGGER
template<typename T> struct StackVariableWrapper
{
typedef T wrapper;
};
template<> struct StackVariableWrapper<size_t>
{
#ifdef HXCPP_M64
typedef cpp::Int64 wrapper;
#else
typedef int wrapper;
#endif
};
template<typename T> struct StackVariableWrapper<T *>
{
typedef cpp::Pointer<T> wrapper;
};
class StackVariable
{
public:
const char *mHaxeName;
bool mIsArg;
StackVariable *mNext;
template<typename T>
StackVariable(StackVariable *&inHead, bool inIsArg,
const char *inHaxeName, T *inCppVar)
: mHaxeName(inHaxeName), mIsArg(inIsArg), mHead(inHead),
mCppVar((void *) inCppVar)
{
mGetOrSetFunction = GetOrSetFunction<T>;
mNext = mHead;
mHead = this;
}
StackVariable(StackVariable *&inHead, bool inIsArg,
const char *inHaxeName, hx::Object **inCppVar)
: mHaxeName(inHaxeName), mIsArg(inIsArg), mHead(inHead),
mCppVar((void *) inCppVar)
{
mGetOrSetFunction = GetOrSetFunctionHxObject;
mNext = mHead;
mHead = this;
}
// For StackThis
template<typename T>
StackVariable(StackVariable *&inHead, T *inCppVar)
: mHaxeName("this"), mIsArg(true), mHead(inHead),
mCppVar((void *) inCppVar)
{
mNext = mHead;
mHead = this;
}
~StackVariable()
{
// Stack variables are always deleted in the reverse order that they
// are created, so a simple pop_front is sufficient; no need to hunt
// for and remove the variable, it's always in the front ...
mHead = mNext;
}
operator Dynamic()
{
return mGetOrSetFunction(true, mCppVar, 0);
}
StackVariable &operator =(Dynamic &other)
{
(void) mGetOrSetFunction(false, mCppVar, &other);
return *this;
}
protected:
typedef Dynamic (*GetOrSetFunctionType)(bool, void *, Dynamic *);
GetOrSetFunctionType mGetOrSetFunction;
private:
template<typename T>
static Dynamic GetOrSetFunction(bool get, void *ptr, Dynamic *dynamic)
{
typedef typename StackVariableWrapper<T>::wrapper Wrap;
if (get) {
return Wrap(* (T *) ptr);
}
else {
* (T *) ptr = Wrap(*dynamic);
return null();
}
}
static Dynamic GetOrSetFunctionHxObject(bool get, void *ptr, Dynamic *dynamic)
{
if (get) {
return * (hx::Object **) ptr;
}
else {
* (hx::Object **)ptr = dynamic->mPtr;
return null();
}
}
StackVariable *&mHead;
void *mCppVar;
};
class StackThis : public StackVariable
{
public:
template<typename T>
StackThis(StackVariable *&inHead, T *inThis)
: StackVariable(inHead, inThis)
{
mGetOrSetFunction = GetFunction<T>;
}
template<typename T>
StackThis(StackVariable *&inHead, hx::ObjectPtr<T> &inThis)
: StackVariable(inHead, &inThis.mPtr)
{
mGetOrSetFunction = GetObjectPtr<T>;
}
template<typename T>
static Dynamic GetObjectPtr(bool get, void *ptr, Dynamic *val)
{
if (get) {
return *(hx::Object **) ptr;
}
else {
return null();
}
}
template<typename T>
static Dynamic GetFunction(bool get, void *ptr, Dynamic *val)
{
if (get) {
return (T *) ptr;
}
else {
return null();
}
}
};
class StackCatchable
{
public:
StackCatchable *mNext;
template<typename T>
StackCatchable(StackFrame &frame, T * /* dummy required by template*/)
: mFrame(frame)
{
mNext = frame.catchables;
frame.catchables = this;
mTestFunction = TestFunction<T>;
}
~StackCatchable()
{
mFrame.catchables = mNext;
}
bool Catches(Dynamic e) const
{
return mTestFunction(e);
}
private:
template<typename T>
static bool TestFunction(Dynamic e)
{
return e.IsClass<T>();
}
StackFrame &mFrame;
bool (*mTestFunction)(Dynamic e);
};
#endif // HXCPP_DEBUGGER
} // end namespace hx
void __hxcpp_dbg_getScriptableFiles( Array< ::String> ioPaths );
void __hxcpp_dbg_getScriptableFilesFullPath( Array< ::String> ioPaths );
void __hxcpp_dbg_getScriptableClasses( Array< ::String> ioClasses );
#ifdef HXCPP_DEBUGGER
namespace hx
{
// These must match the values present in cpp.vm.Debugger
enum ThreadEvent
{
THREAD_CREATED = 1,
THREAD_TERMINATED = 2,
THREAD_STARTED = 3,
THREAD_STOPPED = 4
};
enum StepType
{
STEP_NONE = 0, // Not present or needed in cpp.vm.Debugger
STEP_INTO = 1,
STEP_OVER = 2,
STEP_OUT = 3
};
} // end namespace hx
// The following functions are called directly, and only, by the haxe standard
// library's cpp.vm.Debugger.hx class
void __hxcpp_dbg_setEventNotificationHandler(Dynamic handler);
void __hxcpp_dbg_enableCurrentThreadDebugging(bool enable);
int __hxcpp_dbg_getCurrentThreadNumber();
Array< ::String> __hxcpp_dbg_getFiles();
Array< ::String> __hxcpp_dbg_getFilesFullPath();
Array< ::String> __hxcpp_dbg_getClasses();
Array<Dynamic> __hxcpp_dbg_getThreadInfos();
Dynamic __hxcpp_dbg_getThreadInfo(int threadNumber, bool unsafe);
int __hxcpp_dbg_addFileLineBreakpoint(String fileName, int lineNumber);
int __hxcpp_dbg_addClassFunctionBreakpoint(String className,
String functionName);
void __hxcpp_dbg_deleteAllBreakpoints();
void __hxcpp_dbg_deleteBreakpoint(int number);
void __hxcpp_dbg_breakNow(bool wait);
void __hxcpp_dbg_continueThreads(int threadNumber, int count);
void __hxcpp_dbg_stepThread(int threadNumber, int stepType, int stepCount);
Array<Dynamic> __hxcpp_dbg_getStackVariables(int threadNumber,
int stackFrameNumber,
bool unsafe,
Dynamic markThreadNotStopped);
Dynamic __hxcpp_dbg_getStackVariableValue(int threadNumber,
int stackFrameNumber,
String name,
bool unsafe,
Dynamic markNonexistent,
Dynamic markThreadNotStopped);
Dynamic __hxcpp_dbg_setStackVariableValue(int threadNumber,
int stackFrameNumber,
String name, Dynamic value,
bool unsafe,
Dynamic markNonexistent,
Dynamic markThreadNotStopped);
void __hxcpp_dbg_setNewParameterFunction(Dynamic function);
void __hxcpp_dbg_setNewStackFrameFunction(Dynamic function);
void __hxcpp_dbg_setNewThreadInfoFunction(Dynamic function);
void __hxcpp_dbg_setAddParameterToStackFrameFunction(Dynamic function);
void __hxcpp_dbg_setAddStackFrameToThreadInfoFunction(Dynamic function);
bool __hxcpp_dbg_fix_critical_error(String inErr);
// The following functions are called by Thread.cpp to notify of thread
// created and terminated
void __hxcpp_dbg_threadCreatedOrTerminated(int threadNumber, bool created);
// The following is called by the stack macros, but only if
// HXCPP_DEBUGGER is set
HXCPP_EXTERN_CLASS_ATTRIBUTES
Dynamic __hxcpp_dbg_checkedThrow(Dynamic toThrow);
HXCPP_EXTERN_CLASS_ATTRIBUTES
Dynamic __hxcpp_dbg_checkedRethrow(Dynamic toThrow);
#else // !HXCPP_DEBUGGER
// If no debugger, provide empty implementations of the debugging functions
inline void __hxcpp_dbg_setEventNotificationHandler(Dynamic)
{ hx::Throw("Debugging is not enabled for this program; try\n"
"rebuilding it with the -D HXCPP_DEBUGGER option"); }
inline void __hxcpp_dbg_enableCurrentThreadDebugging(bool) { }
inline int __hxcpp_dbg_getCurrentThreadNumber() { return -1; }
inline Array< ::String> __hxcpp_dbg_getFiles()
{ return Array_obj< String>::__new(); }
inline Array< ::String> __hxcpp_dbg_getFilesFullPath()
{ return Array_obj< String>::__new(); }
inline Array< ::String> __hxcpp_dbg_getClasses()
{ return Array_obj< String>::__new(); }
inline Array<Dynamic> __hxcpp_dbg_getThreadInfos()
{ return Array_obj< ::Dynamic>::__new(); }
inline Dynamic __hxcpp_dbg_getThreadInfo(int, bool) { return null(); }
inline int __hxcpp_dbg_addFileLineBreakpoint(String, int) { return -1; }
inline int __hxcpp_dbg_addClassFunctionBreakpoint(String, String)
{ return -1; }
inline void __hxcpp_dbg_deleteAllBreakpoints() { }
inline void __hxcpp_dbg_deleteBreakpoint(int) { }
inline void __hxcpp_dbg_breakNow(bool) { }
inline void __hxcpp_dbg_continueThreads(int, int) { }
inline void __hxcpp_dbg_stepThread(int, int, int) { }
inline Array<Dynamic> __hxcpp_dbg_getStackVariables(int, int, bool, Dynamic)
{ return Array_obj< String>::__new(); }
inline Dynamic __hxcpp_dbg_getStackVariableValue(int, int, String, bool,
Dynamic, Dynamic)
{ return null(); }
inline Dynamic __hxcpp_dbg_setStackVariableValue(int, int, String, Dynamic,
bool, Dynamic, Dynamic)
{ return null(); }
inline void __hxcpp_dbg_setNewParameterFunction(Dynamic) { }
inline void __hxcpp_dbg_setNewStackFrameFunction(Dynamic) { }
inline void __hxcpp_dbg_setNewThreadInfoFunction(Dynamic) { }
inline void __hxcpp_dbg_setAddParameterToStackFrameFunction(Dynamic) { }
inline void __hxcpp_dbg_setAddStackFrameToThreadInfoFunction(Dynamic) { }
// The following functions are called by Thread.cpp to notify of thread
// created and terminated
inline void __hxcpp_dbg_threadCreatedOrTerminated(int, bool) { }
inline Dynamic __hxcpp_dbg_checkedThrow(Dynamic toThrow) { return hx::Throw(toThrow); }
inline Dynamic __hxcpp_dbg_checkedRethrow(Dynamic toThrow) { return hx::Rethrow(toThrow); }
#endif // HXCPP_DEBUGGER
#endif // HX_DEBUG_H