-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathrip.cpp
441 lines (346 loc) · 7.55 KB
/
rip.cpp
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
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
/////////////////////////////////////////////////////////////////////////////
// rip.cpp
/////////////////////////////////////////////////////////////////////////////
// This module contains support for communicating errors or messages to a
// developer or tester.
/////////////////////////////////////////////////////////////////////////////
#if defined(_DEBUG) || defined(DEBUG)
namespace wi {
char *gpszRipFile;
int giRipLine;
}
#if defined(WIN) && !defined(CE)
#include "windows.h"
#include "rip.h"
#ifdef USE_PALM_UNIX_HEADERS
#include <unix\unix_stdio.h>
#else
#include <stdio.h>
#endif
#define RIP_DEFINED
namespace wi {
/////////////////////////////////////////////////////////////////////////////
// DoRip
//
// Gets called to output a message to a developer or tester.
/////////////////////////////////////////////////////////////////////////////
// Turn off c++ exception handler unwind semantics not enabled warning
#pragma warning(disable : 4530)
void DoRip(TCHAR *pszTitle, TCHAR *psz, va_list va)
{
int idT;
static bool gfRipActive = FALSE;
// If gpszRipFile is not NULL, Format the string
// "File: name.cpp, Line: nnn, ..."
// Otherwise, format the string without the File/Line info.
TCHAR szT[256];
TCHAR szT1[128];
wvsprintf(szT1, psz, va);
if (gpszRipFile != NULL)
wsprintf(szT, TEXT("\n%s: File: %s, Line: %d. %s\n"), pszTitle, gpszRipFile, giRipLine, szT1);
else
wsprintf(szT, TEXT("%s: %s"), pszTitle, szT1);
// This'll break into the debugger if the debugger is present,
// otherwise it'll fall through to the message box case.
OutputDebugString(szT);
#if 0
bool fBeingDebugged = TRUE;
#if defined(WIN) && !defined(CE)
try {
DebugBreak();
} catch (...) {
fBeingDebugged = FALSE;
}
#else
DebugBreak();
#endif
// If we are not being debugged, bring up the message box
if (fBeingDebugged)
return;
#endif
// Bring up a message box with these options:
// Abort: terminate app
// Retry: break
// Ignore: keep running
// We don't want to recurse, which may happen when this message
// box comes up due to WM_ACTIVATE messages and other being
// sent back to the app
if (gfRipActive)
return;
gfRipActive = TRUE;
idT = MessageBox(NULL, szT, pszTitle,
MB_ABORTRETRYIGNORE | MB_SETFOREGROUND);
gfRipActive = FALSE;
switch (idT) {
case IDABORT:
// The process should exit now
// Terminate the process so we don't go through all that
// .dll cleanup code. This'll avoid mfc dumping heap
// allocation info to the debugger, making termination
// faster.
TerminateProcess(GetCurrentProcess(), 0);
return;
case IDRETRY:
// This'll break into the debugger or cause the just
// in time debugger to load. If neither are present, the app
// will terminate.
OutputDebugString(szT);
DebugBreak();
// Just continue and hope things get better
return;
case IDIGNORE:
// Output assertion string. Can also be used to ignore
// asserts.
OutputDebugString(szT);
return;
}
}
void DoAssertRip(int fNoAssert, TCHAR *psz, ...)
{
if (fNoAssert)
return;
va_list va;
va_start(va, psz);
DoRip(TEXT("Assertion failed!"), psz, va);
va_end(va);
}
void DoAssertRip(int fNoAssert)
{
if (fNoAssert)
return;
DoRip(TEXT("Assertion failed!"), TEXT(""), NULL);
}
void DoAssertRip(TCHAR *psz, ...)
{
va_list va;
va_start(va, psz);
DoRip(TEXT("Assert!"), psz, va);
va_end(va);
}
void dvprintf(TCHAR *psz, va_list va)
{
TCHAR szT1[2048];
wvsprintf(szT1, psz, va);
OutputDebugString(szT1);
}
void dprintf(TCHAR *psz, ...)
{
va_list va;
va_start(va, psz);
dvprintf(psz, va);
va_end(va);
}
void DoAssertRip()
{
DoAssertRip(TEXT("Unknown error"));
}
} // namespace wi
#endif // WIN
#ifdef PIL
#define RIP_DEFINED
#include <palmos.h>
#include "rip.h"
namespace wi {
#ifdef PNO
void DebugBreak()
{
}
#else
extern "C" void DebugBreak() secCode14;
#endif
void Break()
{
ErrDisplayFileLineMsg(gpszRipFile, giRipLine, "Assert!");
// DebugBreak();
}
void DoAssertRip(int fNoAssert, char *psz, ...)
{
if (fNoAssert)
return;
Break();
}
void DoAssertRip(int fNoAssert)
{
if (!fNoAssert)
Break();
}
void DoAssertRip(char *psz, ...)
{
Break();
}
void DoAssertRip()
{
Break();
}
} // namespace wi
#endif // PIL
#ifdef CE
#define RIP_DEFINED
#include "windows.h"
#include "rip.h"
namespace wi {
void Break()
{
WCHAR wszT[300];
WCHAR wszT2[300];
MultiByteToWideChar(CP_ACP, 0, gpszRipFile, -1, wszT2, sizeof(wszT) - 1);
wsprintf(wszT, TEXT("File: %s, Line: %d"), wszT2, giRipLine);
MessageBox(NULL, wszT, TEXT("Assert"), MB_OK);
DebugBreak();
}
void DoRip(char *psz, va_list va)
{
char szT[300];
sprintf(szT, "File: %s, Line: %d. ", gpszRipFile, giRipLine);
vsprintf(szT + strlen(szT), psz, va);
WCHAR wszT[300];
MultiByteToWideChar(CP_ACP, 0, szT, -1, wszT, sizeof(wszT) - 1);
MessageBox(NULL, wszT, TEXT("Assert"), MB_OK);
DebugBreak();
}
void DoAssertRip(int fNoAssert, char *psz, ...)
{
if (fNoAssert)
return;
va_list va;
va_start(va, psz);
DoRip(psz, va);
va_end(va);
}
void DoAssertRip(int fNoAssert)
{
if (fNoAssert)
return;
DoRip("", NULL);
}
void DoAssertRip(char *psz, ...)
{
va_list va;
va_start(va, psz);
DoRip(psz, va);
va_end(va);
}
void DoAssertRip()
{
Break();
}
} // namespace wi
#endif // CE
#ifdef IPHONE
#define RIP_DEFINED
#include <stdarg.h>
#include "rip.h"
#include "iphone.h"
namespace wi {
void Break()
{
IPhone::Log("Break:");
IPhone::Log("File: %s, Line: %d", gpszRipFile, giRipLine);
IPhone::Break();
}
void DoRip(char *psz, va_list va)
{
IPhone::Log("Assert:");
IPhone::Log("File: %s, Line: %d", gpszRipFile, giRipLine);
IPhone::Log(psz, va);
IPhone::Break();
}
void DoAssertRip(int fNoAssert, char *psz, ...)
{
if (fNoAssert)
return;
va_list va;
va_start(va, psz);
DoRip(psz, va);
va_end(va);
}
void DoAssertRip(int fNoAssert)
{
if (fNoAssert)
return;
DoRip("", 0);
}
void DoAssertRip(char *psz, ...)
{
va_list va;
va_start(va, psz);
DoRip(psz, va);
va_end(va);
}
void DoAssertRip()
{
Break();
}
void dprintf(const char *psz, ...)
{
va_list va;
va_start(va, psz);
vprintf(psz, va);
va_end(va);
}
} // namespace wi
#endif // IPHONE
#ifndef RIP_DEFINED
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include "inc/rip.h"
namespace wi {
void Break()
{
printf("Break:\n");
printf("File: %s, Line: %d\n", gpszRipFile, giRipLine);
abort();
}
void DoRip(char *psz, va_list va)
{
printf("Assert:\n");
printf("File: %s, Line: %d\n", gpszRipFile, giRipLine);
#ifdef __ANDROID__
printf("%s", psz);
#else
if (va == NULL) {
printf("%s", psz);
} else {
vprintf(psz, va);
}
#endif
Break();
}
void DoAssertRip(int fNoAssert, char *psz, ...)
{
if (fNoAssert)
return;
va_list va;
va_start(va, psz);
DoRip(psz, va);
va_end(va);
}
void DoAssertRip(int fNoAssert)
{
if (fNoAssert)
return;
va_list empty_va_list;
DoRip("", empty_va_list);
}
void DoAssertRip(char *psz, ...)
{
va_list va;
va_start(va, psz);
DoRip(psz, va);
va_end(va);
}
void DoAssertRip()
{
Break();
}
void dprintf(const char *psz, ...)
{
va_list va;
va_start(va, psz);
vprintf(psz, va);
va_end(va);
}
} // namespace wi
#endif // !RIP_DEFINED
#endif // defined(_DEBUG) || defined(DEBUG)