]>
Commit | Line | Data |
---|---|---|
b1ab9ed8 A |
1 | /* |
2 | * Copyright (c) 2000-2001 Apple Computer, Inc. All Rights Reserved. | |
3 | * | |
4 | * The contents of this file constitute Original Code as defined in and are | |
5 | * subject to the Apple Public Source License Version 1.2 (the 'License'). | |
6 | * You may not use this file except in compliance with the License. Please obtain | |
7 | * a copy of the License at http://www.apple.com/publicsource and read it before | |
8 | * using this file. | |
9 | * | |
10 | * This Original Code and all software distributed under the License are | |
11 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS | |
12 | * OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, INCLUDING WITHOUT | |
13 | * LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR | |
14 | * PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please see the License for the | |
15 | * specific language governing rights and limitations under the License. | |
16 | */ | |
17 | ||
18 | ||
19 | /* | |
20 | File: cspdebugging.h | |
21 | ||
22 | Contains: Debugging macros. | |
23 | ||
24 | Written by: Doug Mitchell | |
25 | ||
26 | Copyright: (c) 1998 by Apple Computer, Inc., all rights reserved. | |
27 | ||
28 | Change History (most recent first): | |
29 | ||
30 | 06/02/98 dpm Added DEBUG_THREAD_YIELD. | |
31 | 03/10/98 dpm Created. | |
32 | ||
33 | */ | |
34 | ||
35 | #ifndef _CSPDEBUGGING_H_ | |
36 | #define _CSPDEBUGGING_H_ | |
37 | ||
38 | #ifdef NDEBUG | |
39 | #define DEBUG_ENABLE 0 | |
40 | #define ERROR_LOG_ENABLE 0 | |
41 | #else | |
42 | #define DEBUG_ENABLE 1 | |
43 | #define ERROR_LOG_ENABLE 1 | |
44 | #endif | |
45 | ||
46 | /* any other way? */ | |
47 | #define LOG_VIA_PRINTF 1 | |
48 | ||
49 | #if DEBUG_ENABLE || ERROR_LOG_ENABLE | |
50 | ||
51 | #include <stdio.h> | |
52 | #include <stdlib.h> | |
53 | ||
54 | #if !LOG_VIA_PRINTF | |
55 | ||
56 | #error Hey, figure out a debug mechanism | |
57 | ||
58 | #include <string.h> | |
59 | #include <CoreServices/../Frameworks/CarbonCore.framework/Headers/MacTypes.h> | |
60 | #include <TextUtils.h> | |
61 | ||
62 | /* common log macros */ | |
63 | ||
64 | /* remaining ones can take constant strings */ | |
65 | ||
66 | #ifdef __cplusplus | |
67 | extern "C" { | |
68 | #endif | |
69 | ||
70 | extern void dblog0(char *str); | |
71 | extern void dblog1(char *str, void * arg1); | |
72 | extern void dblog2(char *str, void * arg1, void * arg2); | |
73 | extern void dblog3(char *str, void * arg1, void * arg2, void * arg3); | |
74 | extern void dblog4(char *str, void * arg1, void * arg2, void * arg3, void * arg4); | |
75 | ||
76 | #ifdef __cplusplus | |
77 | } | |
78 | #endif | |
79 | ||
80 | ||
81 | #else /* LOG_VIA_PRINTF */ | |
82 | ||
83 | #define dblog0(str) printf(str) | |
84 | #define dblog1(str, arg1) printf(str, arg1) | |
85 | #define dblog2(str, arg1, arg2) printf(str, arg1, arg2) | |
86 | #define dblog3(str, arg1, arg2, arg3) printf(str, arg1, arg2, arg3) | |
87 | #define dblog4(str, arg1, arg2, arg3, arg4) printf(str, arg1, arg2, arg3, arg4) | |
88 | ||
89 | #endif /* LOG_VIA_PRINTF */ | |
90 | ||
91 | #else /* log macros disabled */ | |
92 | ||
93 | #define dblog0(str) | |
94 | #define dblog1(str, arg1) | |
95 | #define dblog2(str, arg1, arg2) | |
96 | #define dblog3(str, arg1, arg2, arg3) | |
97 | #define dblog4(str, arg1, arg2, arg3, arg4) | |
98 | ||
99 | #endif /* DEBUG_ENABLE || ERROR_LOG_ENABLE */ | |
100 | ||
101 | #if DEBUG_ENABLE | |
102 | ||
103 | #define dprintf0(str) dblog0(str) | |
104 | #define dprintf1(str, arg1) dblog1(str, arg1) | |
105 | #define dprintf2(str, arg1, arg2) dblog2(str, arg1, arg2) | |
106 | #define dprintf3(str, arg1, arg2, arg3) dblog3(str, arg1, arg2, arg3) | |
107 | #define dprintf4(str, arg1, arg2, arg3, arg4) dblog4(str, arg1, arg2, arg3, arg4) | |
108 | ||
109 | #ifdef __cplusplus | |
110 | extern "C" { | |
111 | #endif | |
112 | ||
113 | static inline void _panic(const char *str) | |
114 | { | |
115 | printf("%s\n", str); | |
116 | exit(1); | |
117 | } | |
118 | ||
119 | #ifdef __cplusplus | |
120 | } | |
121 | #endif | |
122 | ||
123 | #define CASSERT(expression) \ | |
124 | ((expression) ? (void)0 : \ | |
125 | (dprintf1 ("Assertion failed: " #expression \ | |
126 | ", file " __FILE__ ", line %d.\n", __LINE__), \ | |
127 | _panic("Assertion Failure"))) | |
128 | ||
129 | #else /* DEBUG_ENABLE */ | |
130 | ||
131 | #define dprintf0(str) | |
132 | #define dprintf1(str, arg1) | |
133 | #define dprintf2(str, arg1, arg2) | |
134 | #define dprintf3(str, arg1, arg2, arg3) | |
135 | #define dprintf4(str, arg1, arg2, arg3, arg4) | |
136 | ||
137 | #define CASSERT(expression) | |
138 | ||
139 | #endif /* DEBUG_ENABLE */ | |
140 | ||
141 | /* | |
142 | * Error logging. This may well be platform dependent. | |
143 | */ | |
144 | #if ERROR_LOG_ENABLE | |
145 | #define errorLog0(str) dblog0(str); | |
146 | #define errorLog1(str, arg1) dblog1(str, arg1) | |
147 | #define errorLog2(str, arg1, arg2) dblog2(str, arg1, arg2) | |
148 | #define errorLog3(str, arg1, arg2, arg3) dblog3(str, arg1, arg2, arg3) | |
149 | #define errorLog4(str, arg1, arg2, arg3, arg4) dblog4(str, arg1, arg2, arg3, arg4) | |
150 | ||
151 | #else /* ERROR_LOG_ENABLE */ | |
152 | ||
153 | #define errorLog0(str) | |
154 | #define errorLog1(str, arg1) | |
155 | #define errorLog2(str, arg1, arg2) | |
156 | #define errorLog3(str, arg1, arg2, arg3) | |
157 | #define errorLog4(str, arg1, arg2, arg3, arg4) | |
158 | ||
159 | #endif /* ERROR_LOG_ENABLE */ | |
160 | ||
161 | #endif /* _CSPDEBUGGING_H_ */ |