revert between 56095 -> 55830 in arch
[AROS.git] / workbench / classes / zune / texteditor / mcc / Debug.h
blobddffecef61a9d04ec00132139f5f7bbd0ce5c2d7
1 /***************************************************************************
3 TextEditor.mcc - Textediting MUI Custom Class
4 Copyright (C) 1997-2000 Allan Odgaard
5 Copyright (C) 2005-2014 TextEditor.mcc Open Source Team
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or (at your option) any later version.
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
17 TextEditor class Support Site: http://www.sf.net/projects/texteditor-mcc
19 $Id$
21 ***************************************************************************/
23 #ifndef DEBUG_H
24 #define DEBUG_H
26 // first we make sure all previously defined symbols are undefined now so
27 // that no other debug system interferes with ours.
28 #undef ENTER
29 #undef LEAVE
30 #undef RETURN
31 #undef SHOWVALUE
32 #undef SHOWPOINTER
33 #undef SHOWSTRING
34 #undef SHOWMSG
35 #undef STARTCLOCK
36 #undef STOPCLOCK
37 #undef MEMTRACK
38 #undef UNMEMTRACK
39 #undef D
40 #undef E
41 #undef W
42 #undef ASSERT
44 #if defined(DEBUG)
46 #include <string.h>
47 #include <stdarg.h>
48 #include <stddef.h>
49 #include <assert.h>
51 // debug classes
52 #define DBC_CTRACE (1<<0) // call tracing (ENTER/LEAVE etc.)
53 #define DBC_REPORT (1<<1) // reports (SHOWVALUE/SHOWSTRING etc.)
54 #define DBC_ASSERT (1<<2) // asserts (ASSERT)
55 #define DBC_TIMEVAL (1<<3) // time evaluations (STARTCLOCK/STOPCLOCK)
56 #define DBC_DEBUG (1<<4) // debugging output D()
57 #define DBC_ERROR (1<<5) // error output E()
58 #define DBC_WARNING (1<<6) // warning output W()
59 #define DBC_MTRACK (1<<7) // memory tracking MEMTRACK/UNMEMTRACK()
60 #define DBC_ALL 0xffffffff
62 // debug flags
63 #define DBF_ALWAYS (1<<0)
64 #define DBF_STARTUP (1<<1) // for startup/shutdown events
65 #define DBF_INPUT (1<<2) // HandleInput.c
66 #define DBF_REXX (1<<3) // HandleARexx.c
67 #define DBF_CLIPBOARD (1<<4) // EditorStuff.c, BlockOperators.c
68 #define DBF_UNDO (1<<5) // UndoFunctions.c
69 #define DBF_DUMP (1<<6)
70 #define DBF_STYLE (1<<7) // styles and colors
71 #define DBF_SPELL (1<<8) // SpellChecker.c
72 #define DBF_BLOCK (1<<9) // BlockOperators.c
73 #define DBF_IMPORT (1<<10) // ImportHook.c
74 #define DBF_EXPORT (1<<10) // ExportHook.c
75 #define DBF_ALL 0xffffffff
77 void SetupDebug(void);
78 void CleanupDebug(void);
79 void DumpDbgMalloc(void);
81 void _ENTER(unsigned long dclass, const char *file, int line, const char *function);
82 void _LEAVE(unsigned long dclass, const char *file, int line, const char *function);
83 void _RETURN(unsigned long dclass, const char *file, int line, const char *function, unsigned long result);
84 void _SHOWVALUE(unsigned long dclass, unsigned long dflags, unsigned long value, int size, const char *name, const char *file, int line);
85 void _SHOWPOINTER(unsigned long dclass, unsigned long dflags, const void *p, const char *name, const char *file, int line);
86 void _SHOWSTRING(unsigned long dclass, unsigned long dflags, const char *string, const char *name, const char *file, int line);
87 void _SHOWMSG(unsigned long dclass, unsigned long dflags, const char *msg, const char *file, int line);
88 void _DPRINTF(unsigned long dclass, unsigned long dflags, const char *file, unsigned long line, const char *format, ...);
89 void _VDPRINTF(unsigned long dclass, unsigned long dflags, const char *file, unsigned long line, const char *format, va_list args);
90 void _MEMTRACK(const char *file, const int line, const char *func, void *ptr, size_t size);
91 void _UNMEMTRACK(const char *file, const int line, const char *func, const void *ptr);
93 // Core class information class messages
94 #define ENTER() _ENTER(DBC_CTRACE, __FILE__, __LINE__, __FUNCTION__)
95 #define LEAVE() _LEAVE(DBC_CTRACE, __FILE__, __LINE__, __FUNCTION__)
96 #define RETURN(r) _RETURN(DBC_CTRACE, __FILE__, __LINE__, __FUNCTION__, (long)r)
97 #define SHOWVALUE(f, v) _SHOWVALUE(DBC_REPORT, f, (long)v, sizeof(v), #v, __FILE__, __LINE__)
98 #define SHOWPOINTER(f, p) _SHOWPOINTER(DBC_REPORT, f, p, #p, __FILE__, __LINE__)
99 #define SHOWSTRING(f, s) _SHOWSTRING(DBC_REPORT, f, s, #s, __FILE__, __LINE__)
100 #define SHOWMSG(f, m) _SHOWMSG(DBC_REPORT, f, m, __FILE__, __LINE__)
101 #define MEMTRACK(f, p, s) _MEMTRACK(__FILE__, __LINE__, f, p, s)
102 #define UNMEMTRACK(f, p) _UNMEMTRACK(__FILE__, __LINE__, f, p)
103 #define D(f, ...) _DPRINTF(DBC_DEBUG, f, __FILE__, __LINE__, __VA_ARGS__)
104 #define E(f, ...) _DPRINTF(DBC_ERROR, f, __FILE__, __LINE__, __VA_ARGS__)
105 #define W(f, ...) _DPRINTF(DBC_WARNING, f, __FILE__, __LINE__, __VA_ARGS__)
106 #define ASSERT(expression) \
107 ((void) \
108 ((expression) ? 0 : \
110 _DPRINTF(DBC_ASSERT, \
111 DBF_ALWAYS, \
112 __FILE__, \
113 __LINE__, \
114 "failed assertion '%s'", \
115 #expression), \
116 assert(#expression), \
122 #if !defined(DEBUG_USE_MALLOC_REDEFINE) && !defined(__SASC) && !defined(__VBCC__)
124 // standard C-library memory functions
125 #define malloc(s) ({void *P = malloc(s); _MEMTRACK(__FILE__, __LINE__, "malloc", P, s); P;})
126 #define calloc(n, s) ({void *P = calloc(n, s); _MEMTRACK(__FILE__, __LINE__, "calloc", P, s); P;})
127 #define realloc(p, s) ({void *P; _UNMEMTRACK(__FILE__, __LINE__, "malloc|calloc|strdup|memdup|asprintf", p); P = realloc(p, s); _MEMTRACK(__FILE__, __LINE__, "realloc", P, s); P;})
128 #define strdup(s) ({char *P = strdup(s); _MEMTRACK(__FILE__, __LINE__, "strdup", P, strlen(s)+1); P;})
129 #define memdup(p, s) ({void *P = memdup(p, s); _MEMTRACK(__FILE__, __LINE__, "memdup", P, s); P;})
130 #define asprintf(p, f, ...) ({int P = asprintf(p, f, __VA_ARGS__); _MEMTRACK(__FILE__, __LINE__, "asprintf", *(p), 1); P;})
131 #define free(p) ({_UNMEMTRACK(__FILE__, __LINE__, "malloc|calloc|strdup|memdup|asprintf", p); free(p);})
133 // standard C-library IO functions
134 #define fopen(f, m) ({FILE *P = fopen(f, m); _MEMTRACK(__FILE__, __LINE__, "fopen", P, 1); P;})
135 #define fclose(p) ({int P; _UNMEMTRACK(__FILE__, __LINE__, "fopen", p); P = fclose(p); P;})
137 #include <proto/dos.h>
138 #include <proto/exec.h>
139 #include <proto/graphics.h>
141 // memory tracking of internal AmigaOS functions
142 #if !defined(__AROS__)
143 #undef AllocPooled
144 #undef FreePooled
145 #undef AllocVecPooled
146 #undef FreeVecPooled
147 #undef AllocDosObject
148 #undef AllocDosObjectTags
149 #undef FreeDosObject
150 #undef AllocSysObject
151 #undef AllocSysObjectTags
152 #undef FreeSysObject
153 #undef ExamineObject
154 #undef ExamineObjectTags
155 #undef AllocBitMap
156 #undef FreeBitMap
157 #undef ObtainDirContext
158 #undef ObtainDirContextTags
159 #undef ReleaseDirContext
160 #undef AllocSignal
161 #undef FreeSignal
162 #undef StartNotify
163 #undef EndNotify
164 #undef Remove
165 #undef RemHead
166 #undef RemTail
167 #endif
169 #if defined(__amigaos4__)
171 #define AllocPooled(p, s) ({APTR P = IExec->AllocPooled(p, s); _MEMTRACK(__FILE__, __LINE__, "AllocPooled", P, s); P;})
172 #define FreePooled(p, m, s) ({_UNMEMTRACK(__FILE__, __LINE__, "AllocPooled", m); IExec->FreePooled(p, m, s);})
173 #define AllocVecPooled(p, s) ({APTR P = IExec->AllocVecPooled(p, s); _MEMTRACK(__FILE__, __LINE__, "AllocVecPooled", P, s); P;})
174 #define FreeVecPooled(p, m) ({_UNMEMTRACK(__FILE__, __LINE__, "AllocVecPooled", m); IExec->FreeVecPooled(p, m);})
175 #define AllocDosObject(t, p) ({APTR P = IDOS->AllocDosObject(t, p); _MEMTRACK(__FILE__, __LINE__, "AllocDosObject", P, t+1); P;})
176 #define AllocDosObjectTags(t, ...) ({APTR P = IDOS->AllocDosObjectTags(t, __VA_ARGS__); _MEMTRACK(__FILE__, __LINE__, "AllocDosObjectTags", P, t+1); P;})
177 #define ExamineObject(t) ({APTR P = IDOS->ExamineObject(t); _MEMTRACK(__FILE__, __LINE__, "ExamineObject", P, 1); P;})
178 #define ExamineObjectTags(t, ...) ({APTR P = IDOS->ExamineObjectTags(t, __VA_ARGS__); _MEMTRACK(__FILE__, __LINE__, "ExamineObjectTags", P, 1); P;})
179 #define FreeDosObject(t, p) ({_UNMEMTRACK(__FILE__, __LINE__, "AllocDosObject|AllocDosObjectTags|ExamineObject|ExamineObjectTags", p); IDOS->FreeDosObject(t, p);})
180 #define AllocSysObject(t, p) ({APTR P = IExec->AllocSysObject(t, p); _MEMTRACK(__FILE__, __LINE__, "AllocSysObject", P, t+1); P;})
181 #define AllocSysObjectTags(t, ...) ({APTR P = IExec->AllocSysObjectTags(t, __VA_ARGS__); _MEMTRACK(__FILE__, __LINE__, "AllocSysObjectTags", P, t+1); P;})
182 #define FreeSysObject(t, p) ({_UNMEMTRACK(__FILE__, __LINE__, "AllocSysObject|AllocSysObjectTags", p); IExec->FreeSysObject(t, p);})
183 #define AllocBitMap(sx, sy, d, f, bm) ({APTR P = IGraphics->AllocBitMap(sx, sy, d, f, bm); _MEMTRACK(__FILE__, __LINE__, "AllocBitMap", P, sx); P;})
184 #define FreeBitMap(p) ({_UNMEMTRACK(__FILE__, __LINE__, "AllocBitMap", p); IGraphics->FreeBitMap(p);})
185 #define ObtainDirContext(t) ({APTR P = IDOS->ObtainDirContext(t); _MEMTRACK(__FILE__, __LINE__, "ObtainDirContextTags", P, 1); P;})
186 #define ObtainDirContextTags(...) ({APTR P = IDOS->ObtainDirContextTags(__VA_ARGS__); _MEMTRACK(__FILE__, __LINE__, "ObtainDirContextTags", P, 1); P;})
187 #define ReleaseDirContext(p) ({_UNMEMTRACK(__FILE__, __LINE__, "ObtainDirContext|ObtainDirContextTags", p); IDOS->ReleaseDirContext(p);})
188 #define AllocSignal(s) ({BYTE P = IExec->AllocSignal(s); _MEMTRACK(__FILE__, __LINE__, "AllocSignal", (APTR)(LONG)P, (size_t)s); P;})
189 #define FreeSignal(s) ({_UNMEMTRACK(__FILE__, __LINE__, "AllocSignal", (APTR)s); IExec->FreeSignal(s);})
190 #define StartNotify(p) ({LONG P = IDOS->StartNotify(p); _MEMTRACK(__FILE__, __LINE__, "StartNotify", p, (size_t)p); P;})
191 #define EndNotify(p) ({_UNMEMTRACK(__FILE__, __LINE__, "StartNotify", p); IDOS->EndNotify(p);})
192 #define Remove(n) ({struct Node *P = (struct Node *)(n); IExec->Remove(P); P->ln_Pred = P->ln_Succ = (struct Node *)0xcccccccc;})
193 #define RemHead(l) ({struct Node *P = IExec->RemHead(l); if(P != NULL) P->ln_Pred = P->ln_Succ = (struct Node *)0xcccccccc; P;})
194 #define RemTail(l) ({struct Node *P = IExec->RemTail(l); if(P != NULL) P->ln_Pred = P->ln_Succ = (struct Node *)0xcccccccc; P;})
196 #elif defined(__MORPHOS__)
198 #define AllocPooled(__p0, __p1) ({ \
199 APTR P = LP2(708, APTR , AllocPooled, \
200 APTR , __p0, a0, \
201 ULONG , __p1, d0, \
202 , EXEC_BASE_NAME, 0, 0, 0, 0, 0, 0); \
203 _MEMTRACK(__FILE__, __LINE__, "AllocPooled", P, __p1); \
204 P; \
207 #define FreePooled(__p0, __p1, __p2) ({ \
208 _UNMEMTRACK(__FILE__, __LINE__, "AllocPooled", __p1); \
209 LP3NR(714, FreePooled, \
210 APTR , __p0, a0, \
211 APTR , __p1, a1, \
212 ULONG , __p2, d0, \
213 , EXEC_BASE_NAME, 0, 0, 0, 0, 0, 0); \
216 #define AllocVecPooled(__p0, __p1) ({ \
217 APTR P = LP2(894, APTR , AllocVecPooled, \
218 APTR , __p0, a0, \
219 ULONG , __p1, d0, \
220 , EXEC_BASE_NAME, 0, 0, 0, 0, 0, 0); \
221 _MEMTRACK(__FILE__, __LINE__, "AllocVecPooled", P, __p1); \
222 P; \
225 #define FreeVecPooled(__p0, __p1) ({ \
226 _UNMEMTRACK(__FILE__, __LINE__, "AllocVecPooled", __p1); \
227 LP2NR(900, FreeVecPooled, \
228 APTR , __p0, a0, \
229 APTR , __p1, a1, \
230 , EXEC_BASE_NAME, 0, 0, 0, 0, 0, 0); \
233 #define AllocDosObject(__p0, __p1) ({ \
234 APTR P = LP2(228, APTR , AllocDosObject, \
235 ULONG , __p0, d1, \
236 CONST struct TagItem *, __p1, d2, \
237 , DOS_BASE_NAME, 0, 0, 0, 0, 0, 0); \
238 _MEMTRACK(__FILE__, __LINE__, "AllocDosObject", P, __p0); \
239 P; \
242 #define FreeDosObject(__p0, __p1) ({ \
243 _UNMEMTRACK(__FILE__, __LINE__, "AllocDosObject|AllocDosObjectTags", __p1); \
244 LP2NR(234, FreeDosObject, \
245 ULONG , __p0, d1, \
246 APTR , __p1, d2, \
247 , DOS_BASE_NAME, 0, 0, 0, 0, 0, 0); \
250 #define AllocSysObject(t, p) ({APTR P = AllocSysObject(t, p); _MEMTRACK(__FILE__, __LINE__, "AllocSysObject", P, t+1); P;})
252 #define AllocSysObjectTags(t, ...) ({ \
253 ULONG _tags[] = { __VA_ARGS__ }; \
254 APTR P = AllocSysObject(t, (struct TagItem *)_tags); \
255 _MEMTRACK(__FILE__, __LINE__, "AllocSysObjectTags", P, t+1); \
256 P; \
259 #define FreeSysObject(t, p) ({_UNMEMTRACK(__FILE__, __LINE__, "AllocSysObject|AllocSysObjectTags", p); FreeSysObject(t, p);})
261 #define AllocBitMap(__p0, __p1, __p2, __p3, __p4) ({ \
262 APTR P = LP5(918, struct BitMap *, AllocBitMap, \
263 ULONG , __p0, d0, \
264 ULONG , __p1, d1, \
265 ULONG , __p2, d2, \
266 ULONG , __p3, d3, \
267 CONST struct BitMap *, __p4, a0, \
268 , GRAPHICS_BASE_NAME, 0, 0, 0, 0, 0, 0); \
269 _MEMTRACK(__FILE__, __LINE__, "AllocBitMap", P, __p0); \
270 P; \
273 #define FreeBitMap(__p0) ({ \
274 _UNMEMTRACK(__FILE__, __LINE__, "AllocBitMap", __p0); \
275 LP1NR(924, FreeBitMap, \
276 struct BitMap *, __p0, a0, \
277 , GRAPHICS_BASE_NAME, 0, 0, 0, 0, 0, 0); \
280 #define ObtainDirContext(t) ({APTR P = ObtainDirContext(t); _MEMTRACK(__FILE__, __LINE__, "ObtainDirContextTags", P, 1); P;})
282 #define ObtainDirContextTags(...) ({ \
283 ULONG _tags[] = { __VA_ARGS__ }; \
284 APTR P = ObtainDirContext((struct TagItem *)_tags); \
285 _MEMTRACK(__FILE__, __LINE__, "ObtainDirContextTags", P, 1); \
286 P; \
289 #define ReleaseDirContext(p) ({_UNMEMTRACK(__FILE__, __LINE__, "ObtainDirContext|ObtainDirContextTags", p); ReleaseDirContext(p);})
291 #define AllocSignal(__p0) ({ \
292 BYTE P = LP1(330, BYTE , AllocSignal, \
293 LONG , __p0, d0, \
294 , EXEC_BASE_NAME, 0, 0, 0, 0, 0, 0); \
295 _MEMTRACK(__FILE__, __LINE__, "AllocSignal", (APTR)(LONG)P, (size_t)__p0); \
296 P; \
299 #define FreeSignal(__p0) ({ \
300 _UNMEMTRACK(__FILE__, __LINE__, "AllocSignal", (APTR)__p0); \
301 LP1NR(336, FreeSignal, \
302 LONG , __p0, d0, \
303 , EXEC_BASE_NAME, 0, 0, 0, 0, 0, 0); \
306 #define StartNotify(__p0) ({ \
307 BOOL P = LP1(888, BOOL , StartNotify, \
308 struct NotifyRequest *, __p0, d1, \
309 , DOS_BASE_NAME, 0, 0, 0, 0, 0, 0); \
310 _MEMTRACK(__FILE__, __LINE__, "StartNotify", __p0, (size_t)__p0); \
311 P; \
314 #define EndNotify(__p0) ({ \
315 _UNMEMTRACK(__FILE__, __LINE__, "StartNotify", __p0); \
316 LP1NR(894, EndNotify, \
317 struct NotifyRequest *, __p0, d1, \
318 , DOS_BASE_NAME, 0, 0, 0, 0, 0, 0); \
321 #define Remove(__p0) ({ \
322 struct Node *P = (struct Node *)(__p0); \
323 LP1NR(252, Remove, \
324 struct Node *, __p0, a1, \
325 , EXEC_BASE_NAME, 0, 0, 0, 0, 0, 0); \
326 P->ln_Pred = P->ln_Succ = (struct Node *)0xcccccccc; \
329 #define RemHead(__p0) ({ \
330 struct Node *P = LP1(258, struct Node *, RemHead, \
331 struct List *, __p0, a0, \
332 , EXEC_BASE_NAME, 0, 0, 0, 0, 0, 0); \
333 if(P != NULL) P->ln_Pred = P->ln_Succ = (struct Node *)0xcccccccc; \
334 P; \
337 #define RemTail(__p0) ({ \
338 struct Node *P = LP1(264, struct Node *, RemTail, \
339 struct List *, __p0, a0, \
340 , EXEC_BASE_NAME, 0, 0, 0, 0, 0, 0); \
341 if(P != NULL) P->ln_Pred = P->ln_Succ = (struct Node *)0xcccccccc; \
342 P; \
345 #elif !defined(__AROS__) // AmigaOS 3
347 #define AllocPooled(poolHeader, memSize) ({ \
348 APTR _AllocPooled_poolHeader = (poolHeader); \
349 ULONG _AllocPooled_memSize = (memSize); \
350 APTR _AllocPooled__re = \
351 ({ \
352 register struct ExecBase * const __AllocPooled__bn __asm("a6") = (struct ExecBase *) (EXEC_BASE_NAME);\
353 register APTR __AllocPooled__re __asm("d0"); \
354 register APTR __AllocPooled_poolHeader __asm("a0") = (_AllocPooled_poolHeader); \
355 register ULONG __AllocPooled_memSize __asm("d0") = (_AllocPooled_memSize); \
356 __asm volatile ("jsr a6@(-708:W)" \
357 : "=r"(__AllocPooled__re) \
358 : "r"(__AllocPooled__bn), "r"(__AllocPooled_poolHeader), "r"(__AllocPooled_memSize) \
359 : "d1", "a0", "a1", "fp0", "fp1", "cc", "memory"); \
360 __AllocPooled__re; \
361 }); \
362 _MEMTRACK(__FILE__, __LINE__, "AllocPooled", _AllocPooled__re, memSize); \
363 _AllocPooled__re; \
366 #define FreePooled(poolHeader, memory, memSize) ({ \
367 _UNMEMTRACK(__FILE__, __LINE__, "AllocPooled", memory); { \
368 APTR _FreePooled_poolHeader = (poolHeader); \
369 APTR _FreePooled_memory = (memory); \
370 ULONG _FreePooled_memSize = (memSize); \
372 register struct ExecBase * const __FreePooled__bn __asm("a6") = (struct ExecBase *) (EXEC_BASE_NAME);\
373 register APTR __FreePooled_poolHeader __asm("a0") = (_FreePooled_poolHeader); \
374 register APTR __FreePooled_memory __asm("a1") = (_FreePooled_memory); \
375 register ULONG __FreePooled_memSize __asm("d0") = (_FreePooled_memSize); \
376 __asm volatile ("jsr a6@(-714:W)" \
378 : "r"(__FreePooled__bn), "r"(__FreePooled_poolHeader), "r"(__FreePooled_memory), "r"(__FreePooled_memSize) \
379 : "d0", "d1", "a0", "a1", "fp0", "fp1", "cc", "memory"); \
383 #define AllocVecPooled(p, s) ({APTR P = AllocVecPooled(p, s); _MEMTRACK(__FILE__, __LINE__, "AllocVecPooled", P, s); P;})
384 #define FreeVecPooled(p, m) ({_UNMEMTRACK(__FILE__, __LINE__, "AllocVecPooled", m); FreeVecPooled(p, m);})
386 #define AllocDosObject(type, tags) ({ \
387 ULONG _AllocDosObject_type = (type); \
388 const struct TagItem * _AllocDosObject_tags = (tags); \
389 APTR _AllocDosObject__re = \
390 ({ \
391 register struct DosLibrary * const __AllocDosObject__bn __asm("a6") = (struct DosLibrary *) (DOS_BASE_NAME);\
392 register APTR __AllocDosObject__re __asm("d0"); \
393 register ULONG __AllocDosObject_type __asm("d1") = (_AllocDosObject_type); \
394 register const struct TagItem * __AllocDosObject_tags __asm("d2") = (_AllocDosObject_tags); \
395 __asm volatile ("jsr a6@(-228:W)" \
396 : "=r"(__AllocDosObject__re) \
397 : "r"(__AllocDosObject__bn), "r"(__AllocDosObject_type), "r"(__AllocDosObject_tags) \
398 : "d1", "a0", "a1", "fp0", "fp1", "cc", "memory"); \
399 __AllocDosObject__re; \
400 }); \
401 _MEMTRACK(__FILE__, __LINE__, "AllocDosObject", _AllocDosObject__re, type); \
402 _AllocDosObject__re; \
405 #define FreeDosObject(type, ptr) ({ _UNMEMTRACK(__FILE__, __LINE__, "AllocDosObject|AllocDosObjectTags", ptr); { \
406 ULONG _FreeDosObject_type = (type); \
407 APTR _FreeDosObject_ptr = (ptr); \
409 register struct DosLibrary * const __FreeDosObject__bn __asm("a6") = (struct DosLibrary *) (DOS_BASE_NAME);\
410 register ULONG __FreeDosObject_type __asm("d1") = (_FreeDosObject_type); \
411 register APTR __FreeDosObject_ptr __asm("d2") = (_FreeDosObject_ptr); \
412 __asm volatile ("jsr a6@(-234:W)" \
414 : "r"(__FreeDosObject__bn), "r"(__FreeDosObject_type), "r"(__FreeDosObject_ptr) \
415 : "d0", "d1", "a0", "a1", "fp0", "fp1", "cc", "memory"); \
419 #define AllocSysObject(t, p) ({APTR P = AllocSysObject(t, p); _MEMTRACK(__FILE__, __LINE__, "AllocSysObject", P, t+1); P;})
421 #define AllocSysObjectTags(t, ...) ({APTR P = AllocSysObjectTags(t, __VA_ARGS__); _MEMTRACK(__FILE__, __LINE__, "AllocSysObjectTags", P, t+1); P;})
423 #define FreeSysObject(t, p) ({_UNMEMTRACK(__FILE__, __LINE__, "AllocSysObject|AllocSysObjectTags", p); FreeSysObject(t, p);})
425 #define AllocBitMap(sizex, sizey, depth, flags, friend_bitmap) ({ \
426 ULONG _AllocBitMap_sizex = (sizex); \
427 ULONG _AllocBitMap_sizey = (sizey); \
428 ULONG _AllocBitMap_depth = (depth); \
429 ULONG _AllocBitMap_flags = (flags); \
430 CONST struct BitMap * _AllocBitMap_friend_bitmap = (friend_bitmap); \
431 struct BitMap * _AllocBitMap__re = \
432 ({ \
433 register struct GfxBase * const __AllocBitMap__bn __asm("a6") = (struct GfxBase *) (GRAPHICS_BASE_NAME);\
434 register struct BitMap * __AllocBitMap__re __asm("d0"); \
435 register ULONG __AllocBitMap_sizex __asm("d0") = (_AllocBitMap_sizex); \
436 register ULONG __AllocBitMap_sizey __asm("d1") = (_AllocBitMap_sizey); \
437 register ULONG __AllocBitMap_depth __asm("d2") = (_AllocBitMap_depth); \
438 register ULONG __AllocBitMap_flags __asm("d3") = (_AllocBitMap_flags); \
439 register CONST struct BitMap * __AllocBitMap_friend_bitmap __asm("a0") = (_AllocBitMap_friend_bitmap); \
440 __asm volatile ("jsr a6@(-918:W)" \
441 : "=r"(__AllocBitMap__re) \
442 : "r"(__AllocBitMap__bn), "r"(__AllocBitMap_sizex), "r"(__AllocBitMap_sizey), "r"(__AllocBitMap_depth), "r"(__AllocBitMap_flags), "r"(__AllocBitMap_friend_bitmap) \
443 : "d1", "a0", "a1", "fp0", "fp1", "cc", "memory"); \
444 __AllocBitMap__re; \
445 }); \
446 _MEMTRACK(__FILE__, __LINE__, "AllocBitMap", _AllocBitMap__re, sizex); \
447 _AllocBitMap__re; \
450 #define FreeBitMap(bm) ({ _UNMEMTRACK(__FILE__, __LINE__, "AllocBitMap", bm); { \
451 struct BitMap * _FreeBitMap_bm = (bm); \
453 register struct GfxBase * const __FreeBitMap__bn __asm("a6") = (struct GfxBase *) (GRAPHICS_BASE_NAME);\
454 register struct BitMap * __FreeBitMap_bm __asm("a0") = (_FreeBitMap_bm); \
455 __asm volatile ("jsr a6@(-924:W)" \
457 : "r"(__FreeBitMap__bn), "r"(__FreeBitMap_bm) \
458 : "d0", "d1", "a0", "a1", "fp0", "fp1", "cc", "memory"); \
462 #define ObtainDirContext(t) ({APTR P = ObtainDirContext(t); _MEMTRACK(__FILE__, __LINE__, "ObtainDirContextTags", P, 1); P;})
463 #define ObtainDirContextTags(...) ({APTR P = ObtainDirContextTags(__VA_ARGS__); _MEMTRACK(__FILE__, __LINE__, "ObtainDirContextTags", P, 1); P;})
464 #define ReleaseDirContext(p) ({_UNMEMTRACK(__FILE__, __LINE__, "ObtainDirContext|ObtainDirContextTags", p); ReleaseDirContext(p);})
466 #define AllocSignal(signalNum) ({ \
467 LONG _AllocSignal_signalNum = (signalNum); \
468 BYTE _AllocSignal__re = \
469 ({ \
470 register struct ExecBase * const __AllocSignal__bn __asm("a6") = (struct ExecBase *) (EXEC_BASE_NAME);\
471 register BYTE __AllocSignal__re __asm("d0"); \
472 register LONG __AllocSignal_signalNum __asm("d0") = (_AllocSignal_signalNum); \
473 __asm volatile ("jsr a6@(-330:W)" \
474 : "=r"(__AllocSignal__re) \
475 : "r"(__AllocSignal__bn), "r"(__AllocSignal_signalNum) \
476 : "d1", "a0", "a1", "fp0", "fp1", "cc", "memory"); \
477 __AllocSignal__re; \
478 }); \
479 _MEMTRACK(__FILE__, __LINE__, "AllocSignal", (APTR)(LONG)_AllocSignal__re, (size_t)signalNum); \
480 _AllocSignal__re; \
483 #define FreeSignal(signalNum) ({ _UNMEMTRACK(__FILE__, __LINE__, "AllocSignal", (APTR)signalNum); { \
484 LONG _FreeSignal_signalNum = (signalNum); \
486 register struct ExecBase * const __FreeSignal__bn __asm("a6") = (struct ExecBase *) (EXEC_BASE_NAME);\
487 register LONG __FreeSignal_signalNum __asm("d0") = (_FreeSignal_signalNum); \
488 __asm volatile ("jsr a6@(-336:W)" \
490 : "r"(__FreeSignal__bn), "r"(__FreeSignal_signalNum) \
491 : "d0", "d1", "a0", "a1", "fp0", "fp1", "cc", "memory"); \
495 #define StartNotify(notify) ({ \
496 struct NotifyRequest * _StartNotify_notify = (notify); \
497 BOOL _StartNotify__re = \
498 ({ \
499 register struct DosLibrary * const __StartNotify__bn __asm("a6") = (struct DosLibrary *) (DOS_BASE_NAME);\
500 register BOOL __StartNotify__re __asm("d0"); \
501 register struct NotifyRequest * __StartNotify_notify __asm("d1") = (_StartNotify_notify); \
502 __asm volatile ("jsr a6@(-888:W)" \
503 : "=r"(__StartNotify__re) \
504 : "r"(__StartNotify__bn), "r"(__StartNotify_notify) \
505 : "d1", "a0", "a1", "fp0", "fp1", "cc", "memory"); \
506 __StartNotify__re; \
507 }); \
508 _MEMTRACK(__FILE__, __LINE__, "StartNotify", _StartNotify_notify, (size_t)_StartNotify_notify); \
509 _StartNotify__re; \
512 #define EndNotify(notify) ({ _UNMEMTRACK(__FILE__, __LINE__, "StartNotify", notify); { \
513 struct NotifyRequest * _EndNotify_notify = (notify); \
515 register struct DosLibrary * const __EndNotify__bn __asm("a6") = (struct DosLibrary *) (DOS_BASE_NAME);\
516 register struct NotifyRequest * __EndNotify_notify __asm("d1") = (_EndNotify_notify); \
517 __asm volatile ("jsr a6@(-894:W)" \
519 : "r"(__EndNotify__bn), "r"(__EndNotify_notify) \
520 : "d0", "d1", "a0", "a1", "fp0", "fp1", "cc", "memory"); \
524 #define Remove(node) ({ \
525 struct Node * _Remove_node = (node); \
527 register struct ExecBase * const __Remove__bn __asm("a6") = (struct ExecBase *) (EXEC_BASE_NAME);\
528 register struct Node * __Remove_node __asm("a1") = (_Remove_node); \
529 __asm volatile ("jsr a6@(-252:W)" \
531 : "r"(__Remove__bn), "r"(__Remove_node) \
532 : "d0", "d1", "a0", "a1", "fp0", "fp1", "cc", "memory"); \
534 _Remove_node->ln_Pred = _Remove_node->ln_Succ = (struct Node *)0xcccccccc; \
537 #define RemHead(list) ({ \
538 struct List *_RemHead_list = (list); \
539 struct Node *_RemHead__re = \
540 ({ \
541 register struct ExecBase * const __RemHead__bn __asm("a6") = (struct ExecBase *) (EXEC_BASE_NAME);\
542 register struct Node *__RemHead__re __asm("d0"); \
543 register struct List *__RemHead__list __asm("a0") = (_RemHead_list); \
544 __asm volatile ("jsr a6@(-258:W)" \
545 : "=r"(__RemHead__re) \
546 : "r"(__RemHead__bn), "r"(__RemHead__list) \
547 : "d1", "a0", "a1", "fp0", "fp1", "cc", "memory"); \
548 __RemHead__re; \
549 }); \
550 if(_RemHead__re != NULL) _RemHead__re->ln_Pred = _RemHead__re->ln_Succ = (struct Node *)0xcccccccc; \
551 _RemHead__re; \
554 #define RemTail(list) ({ \
555 struct List *_RemTail_list = (list); \
556 struct Node *_RemTail__re = \
557 ({ \
558 register struct ExecBase * const __RemTail__bn __asm("a6") = (struct ExecBase *) (EXEC_BASE_NAME);\
559 register struct Node *__RemTail__re __asm("d0"); \
560 register struct List *__RemTail__list __asm("a0") = (_RemTail_list); \
561 __asm volatile ("jsr a6@(-264:W)" \
562 : "=r"(__RemTail__re) \
563 : "r"(__RemTail__bn), "r"(__RemTail__list) \
564 : "d1", "a0", "a1", "fp0", "fp1", "cc", "memory"); \
565 __RemTail__re; \
566 }); \
567 if(_RemTail__re != NULL) _RemTail__re->ln_Pred = _RemTail__re->ln_Succ = (struct Node *)0xcccccccc; \
568 _RemTail__re; \
571 #endif // amigaos4
573 #endif // !DEBUG_USE_MALLOC_REDEFINE
575 #else // DEBUG
577 // to replace with NOPs is important here!
578 #define ENTER() ((void)0)
579 #define LEAVE() ((void)0)
580 #define RETURN(r) ((void)0)
581 #define SHOWVALUE(f, v) ((void)(v)) /* Ensure side effects occur! */
582 #define SHOWPOINTER(f, p) ((void)(p)) /* Ensure side effects occur! */
583 #define SHOWSTRING(f, s) ((void)(s)) /* Ensure side effects occur! */
584 #define SHOWMSG(f, m) ((void)(m)) /* Ensure side effects occur! */
585 #define MEMTRACK(f, p, s) ((void)0)
586 #define UNMEMTRACK(f, p) ((void)0)
587 #define D(f, ...) ((void)0)
588 #define E(f, ...) ((void)0)
589 #define W(f, ...) ((void)0)
590 #define ASSERT(expression) ((void)0)
592 #define DumpDbgMalloc() ((void)0)
594 #endif // DEBUG
596 #endif // DEBUG_H