]> git.saurik.com Git - apple/security.git/blob - SecurityServer/MacYarrow/YarrowServer/debug.h
Security-29.tar.gz
[apple/security.git] / SecurityServer / MacYarrow / YarrowServer / debug.h
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: debug.h
21
22 Contains: Debugging macros.
23
24 Written by: Doug Mitchell
25
26 Copyright: (c) 1999 by Apple Computer, Inc., all rights reserved.
27
28 Change History (most recent first):
29
30 12/07/99 dpm Created.
31
32 */
33
34 #ifndef _DEBUG_H_
35 #define _DEBUG_H_
36
37 extern void yarrowPanic(const char *errStr);
38
39 #define ERROR_LOG_ENABLE 0
40
41 #define LOG_VIA_PRINTF 1
42
43 #if DEBUG || ERROR_LOG_ENABLE
44
45 #include <stdio.h>
46
47 #if !LOG_VIA_PRINTF
48
49 #include <string.h>
50 #include <Types.h>
51 #include <TextUtils.h>
52
53 #if defined(__cplusplus)
54 extern "C" {
55 #endif
56
57 /* common log macros */
58
59 extern void dblog0(char *str);
60 extern void dblog1(char *str, void * arg1);
61 extern void dblog2(char *str, void * arg1, void * arg2);
62 extern void dblog3(char *str, void * arg1, void * arg2, void * arg3);
63 extern void dblog4(char *str, void * arg1, void * arg2, void * arg3, void * arg4);
64
65 #if defined(__cplusplus)
66 }
67 #endif
68
69 #else /* LOG_VIA_PRINTF */
70
71 #define dblog0(str) printf(str)
72 #define dblog1(str, arg1) printf(str, arg1)
73 #define dblog2(str, arg1, arg2) printf(str, arg1, arg2)
74 #define dblog3(str, arg1, arg2, arg3) printf(str, arg1, arg2, arg3)
75 #define dblog4(str, arg1, arg2, arg3, arg4) printf(str, arg1, arg2, arg3, arg4)
76
77 #endif /* LOG_VIA_PRINTF */
78
79 #else /* log macros disabled */
80
81 #define dblog0(str)
82 #define dblog1(str, arg1)
83 #define dblog2(str, arg1, arg2)
84 #define dblog3(str, arg1, arg2, arg3)
85 #define dblog4(str, arg1, arg2, arg3, arg4)
86
87 #endif /* log macros */
88
89 #if DEBUG
90
91 #define dprintf0(str) dblog0(str)
92 #define dprintf1(str, arg1) dblog1(str, (void *)arg1)
93 #define dprintf2(str, arg1, arg2) dblog2(str, (void *)arg1, (void *)arg2)
94 #define dprintf3(str, arg1, arg2, arg3) dblog3(str, (void *)arg1, (void *)arg2, (void *)arg3)
95 #define dprintf4(str, arg1, arg2, arg3, arg4) dblog4(str, (void *)arg1, (void *)arg2, (void *)arg3, (void *) arg4)
96
97 #define CASSERT(expression) \
98 ((expression) ? (void)0 : \
99 (dprintf1 ("Assertion failed: " #expression \
100 ", file " __FILE__ ", line %d.\n", __LINE__), \
101 yarrowPanic("Assertion Failure")))
102
103 #else /* DEBUG */
104
105 #define dprintf0(str)
106 #define dprintf1(str, arg1)
107 #define dprintf2(str, arg1, arg2)
108 #define dprintf3(str, arg1, arg2, arg3)
109 #define dprintf4(str, arg1, arg2, arg3, arg4)
110
111 #define CASSERT(expression)
112
113 #endif /* DEBUG */
114
115 /*
116 * Error logging. This may well be platform dependent.
117 */
118 #if ERROR_LOG_ENABLE
119 #define errorLog0(str) dblog0(str);
120 #define errorLog1(str, arg1) dblog1(str, (void *)arg1)
121 #define errorLog2(str, arg1, arg2) dblog2(str, (void *)arg1, (void *)arg2)
122 #define errorLog3(str, arg1, arg2, arg3) dblog3(str, (void *)arg1, (void *)arg2, (void *)arg3)
123 #define errorLog4(str, arg1, arg2, arg3, arg4) dblog4(str, (void *)arg1, (void *)arg2, (void *)arg3, (void *)arg4)
124
125 #else /* ERROR_LOG_ENABLE */
126
127 #define errorLog0(str)
128 #define errorLog1(str, arg1)
129 #define errorLog2(str, arg1, arg2)
130 #define errorLog3(str, arg1, arg2, arg3)
131 #define errorLog4(str, arg1, arg2, arg3, arg4)
132
133 #endif /* ERROR_LOG_ENABLE */
134
135 #endif /* _DEBUG_H_ */