]> git.saurik.com Git - apple/security.git/blob - OSX/libsecurity_apple_csp/lib/cspdebugging.h
Security-57740.51.3.tar.gz
[apple/security.git] / OSX / libsecurity_apple_csp / lib / cspdebugging.h
1 /*
2 * Copyright (c) 2000-2001,2011,2013-2014 Apple 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
25 Copyright (c) 1998,2011,2013-2014 Apple Inc. All Rights Reserved.
26
27 Change History (most recent first):
28
29 06/02/98 dpm Added DEBUG_THREAD_YIELD.
30 03/10/98 dpm Created.
31
32 */
33
34 #ifndef _CSPDEBUGGING_H_
35 #define _CSPDEBUGGING_H_
36
37 #ifdef NDEBUG
38 #define DEBUG_ENABLE 0
39 #define ERROR_LOG_ENABLE 0
40 #else
41 #define DEBUG_ENABLE 1
42 #define ERROR_LOG_ENABLE 1
43 #endif
44
45 /* any other way? */
46 #define LOG_VIA_PRINTF 1
47
48 #if DEBUG_ENABLE || ERROR_LOG_ENABLE
49
50 #include <stdio.h>
51 #include <stdlib.h>
52
53 #if !LOG_VIA_PRINTF
54
55 #error Hey, figure out a debug mechanism
56
57 #include <string.h>
58 #include <TextUtils.h>
59
60 /* common log macros */
61
62 /* remaining ones can take constant strings */
63
64 #ifdef __cplusplus
65 extern "C" {
66 #endif
67
68 extern void dblog0(char *str);
69 extern void dblog1(char *str, void * arg1);
70 extern void dblog2(char *str, void * arg1, void * arg2);
71 extern void dblog3(char *str, void * arg1, void * arg2, void * arg3);
72 extern void dblog4(char *str, void * arg1, void * arg2, void * arg3, void * arg4);
73
74 #ifdef __cplusplus
75 }
76 #endif
77
78
79 #else /* LOG_VIA_PRINTF */
80
81 #define dblog0(str) printf(str)
82 #define dblog1(str, arg1) printf(str, arg1)
83 #define dblog2(str, arg1, arg2) printf(str, arg1, arg2)
84 #define dblog3(str, arg1, arg2, arg3) printf(str, arg1, arg2, arg3)
85 #define dblog4(str, arg1, arg2, arg3, arg4) printf(str, arg1, arg2, arg3, arg4)
86
87 #endif /* LOG_VIA_PRINTF */
88
89 #else /* log macros disabled */
90
91 #define dblog0(str)
92 #define dblog1(str, arg1)
93 #define dblog2(str, arg1, arg2)
94 #define dblog3(str, arg1, arg2, arg3)
95 #define dblog4(str, arg1, arg2, arg3, arg4)
96
97 #endif /* DEBUG_ENABLE || ERROR_LOG_ENABLE */
98
99 #if DEBUG_ENABLE
100
101 #define dprintf0(str) dblog0(str)
102 #define dprintf1(str, arg1) dblog1(str, arg1)
103 #define dprintf2(str, arg1, arg2) dblog2(str, arg1, arg2)
104 #define dprintf3(str, arg1, arg2, arg3) dblog3(str, arg1, arg2, arg3)
105 #define dprintf4(str, arg1, arg2, arg3, arg4) dblog4(str, arg1, arg2, arg3, arg4)
106
107 #ifdef __cplusplus
108 extern "C" {
109 #endif
110
111 #include <CrashReporterClient.h>
112
113 static inline void _panic(const char *str)
114 {
115 printf("%s\n", str);
116 CRSetCrashLogMessage(str);
117 abort();
118 }
119
120 #ifdef __cplusplus
121 }
122 #endif
123
124 #define CASSERT(expression) \
125 ((expression) ? (void)0 : \
126 (dprintf1 ("Assertion failed: " #expression \
127 ", file " __FILE__ ", line %d.\n", __LINE__), \
128 _panic("Assertion Failure")))
129
130 #else /* DEBUG_ENABLE */
131
132 #define dprintf0(str)
133 #define dprintf1(str, arg1)
134 #define dprintf2(str, arg1, arg2)
135 #define dprintf3(str, arg1, arg2, arg3)
136 #define dprintf4(str, arg1, arg2, arg3, arg4)
137
138 #define CASSERT(expression)
139
140 #endif /* DEBUG_ENABLE */
141
142 /*
143 * Error logging. This may well be platform dependent.
144 */
145 #if ERROR_LOG_ENABLE
146 #define errorLog0(str) dblog0(str);
147 #define errorLog1(str, arg1) dblog1(str, arg1)
148 #define errorLog2(str, arg1, arg2) dblog2(str, arg1, arg2)
149 #define errorLog3(str, arg1, arg2, arg3) dblog3(str, arg1, arg2, arg3)
150 #define errorLog4(str, arg1, arg2, arg3, arg4) dblog4(str, arg1, arg2, arg3, arg4)
151
152 #else /* ERROR_LOG_ENABLE */
153
154 #define errorLog0(str)
155 #define errorLog1(str, arg1)
156 #define errorLog2(str, arg1, arg2)
157 #define errorLog3(str, arg1, arg2, arg3)
158 #define errorLog4(str, arg1, arg2, arg3, arg4)
159
160 #endif /* ERROR_LOG_ENABLE */
161
162 #endif /* _CSPDEBUGGING_H_ */