4 ** $Id: DebugMacros.h,v 1.3 2000/01/12 20:30:24 bernie Exp $
6 ** Copyright (C) 1995,96,97,98,99 Bernardo Innocenti <bernardo.innocenti@usa.net>
7 ** All rights reserved.
9 ** Use 4 chars wide TABs to read this file
11 ** Some handy debug macros which are automatically excluded when the
12 ** _DEBUG preprocessor symbol isn't defined. To make debug executables,
13 ** you must link with debug.lib or any module containing the kprintf()
16 ** Here is a short description of the macros defined below:
19 ** Output an inline "ILLEGAL" 68K opcode, which will
20 ** be interpreted as a breakpoint by most debuggers.
24 ** Output a formatted string to the debug console. This
25 ** macro uses the debug.lib/kprintf() function by default.
28 ** Do nothing if the expression <x> evalutates to a
29 ** non-zero value, output a debug message otherwise.
31 ** ASSERT_VALID_PTR(x)
32 ** Checks if the expression <x> points to a valid
33 ** memory location, and outputs a debug message
34 ** otherwise. A NULL pointer is considered VALID.
36 ** ASSERT_VALID_PTR_OR_NULL(x)
37 ** Checks if the expression <x> points to a valid
38 ** memory location, and outputs a debug message
39 ** otherwise. A NULL pointer is considered INVALID.
43 ** Compile the expression <x> when making a debug
44 ** executable, otherwise omit it.
47 ** DB verbosity level 1. Compile the expression <x> when the
48 ** preprocessor symbol DEBUG is defined to a number greater or
52 ** DB verbosity level 2. Compile the expression <x> when the
53 ** preprocessor symbol _DEBUG is defined to a number greater or
57 /* Accept DEBUG as well as _DEBUG */
68 /* Needed for TypeOfMem() */
70 #include <proto/exec.h>
71 #endif /* PROTO_EXEC_H */
75 extern void __builtin_emit (int);
76 // #define ILLEGAL __builtin_emit(0x4AFC)
78 STDARGS extern void kprintf (const char *, ...);
80 #elif defined(__GNUC__)
82 /* GCC doesn't accept asm statements in the middle of an
83 * expression such as `a ? b : asm("something")'.
85 #define ILLEGAL illegal()
86 static __inline__ int illegal(void) { asm("illegal"); return 0; }
87 extern void STDARGS FORMATCALL(printf,1,2) kprintf(const char *, ...);
90 #error Please add compiler specific definitions for your compiler
94 /* common definitions for ASSERT and DB macros */
96 #define DBPRINTF kprintf
99 /* The trick with THIS_FILE is meant to avoid multiple allocations of
100 * the filename string for each occurrence of these macros. To reduce
101 * debug executable size, each module should cooperate by undefinining
102 * the THIS_FILE macro and declaring a static global symbol with the
105 #define THIS_FILE __FILE__
107 #define ASSERT(x) ( (x) ? 0 : \
108 ( DBPRINTF("\x07%s:%ld: assertion failed: %s\n", \
109 THIS_FILE, __LINE__, #x) , ILLEGAL ) );
111 #define ASSERT_VALID_PTR_OR_NULL(x) ( ((((APTR)(x)) == NULL) || \
112 (((LONG)(x) > 1024) && TypeOfMem((APTR)(x)))) ? 0 : \
113 ( DBPRINTF("\x07%s:%ld: bad pointer: %s = $%lx\n", \
114 THIS_FILE, __LINE__, #x, (APTR)(x)) , ILLEGAL ) );
116 #define ASSERT_VALID_PTR(x) ( (((LONG)(x) > 1024) && \
117 TypeOfMem((APTR)(x))) ? 0 : \
118 ( DBPRINTF("\x07%s, %ld: bad pointer: %s = $%lx\n", \
119 THIS_FILE, __LINE__, #x, (APTR)(x)) , ILLEGAL ) );
137 #define ASSERT_VALID_PTR(x)
138 #define ASSERT_VALID_PTR_OR_NULL(x)
147 #endif /* !DEBUGMACROS_H */