]>
git.saurik.com Git - apple/icu.git/blob - icuSources/common/utracimp.h
f32fe1db3948241a4847701dec0fb6690d47333c
1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
4 *******************************************************************************
6 * Copyright (C) 2003-2009, International Business Machines
7 * Corporation and others. All Rights Reserved.
9 *******************************************************************************
10 * file name: utracimp.h
12 * tab size: 8 (not used)
15 * created on: 2003aug06
16 * created by: Markus W. Scherer
18 * Internal header for ICU tracing/logging.
22 * - using a trace level variable to only call trace functions
23 * when the level is sufficient
24 * - using the same variable for tracing on/off to never make a function
26 * - the function number is put into a local variable by the entry macro
27 * and used implicitly to avoid copy&paste/typing mistakes by the developer
28 * - the application must call utrace_setFunctions() and pass in
29 * implementations for the trace functions
30 * - ICU trace macros call ICU functions that route through the function
31 * pointers if they have been set;
32 * this avoids an indirection at the call site
33 * (which would cost more code for another check and for the indirection)
36 * - Verify that va_list is portable among compilers for the same platform.
37 * va_list should be portable because printf() would fail otherwise!
38 * - Should enum values like UTraceLevel be passed into int32_t-type arguments,
39 * or should enum types be used?
42 #ifndef __UTRACIMP_H__
43 #define __UTRACIMP_H__
45 #include "unicode/utrace.h"
51 * Traced Function Exit return types.
52 * Flags indicating the number and types of varargs included in a call
53 * to a UTraceExit function.
54 * Bits 0-3: The function return type. First variable param.
55 * Bit 4: Flag for presence of U_ErrorCode status param.
58 typedef enum UTraceExitVal
{
59 /** The traced function returns no value @internal */
60 UTRACE_EXITV_NONE
= 0,
61 /** The traced function returns an int32_t, or compatible, type. @internal */
63 /** The traced function returns a pointer @internal */
65 /** The traced function returns a UBool @internal */
66 UTRACE_EXITV_BOOL
= 3,
67 /** Mask to extract the return type values from a UTraceExitVal @internal */
68 UTRACE_EXITV_MASK
= 0xf,
69 /** Bit indicating that the traced function includes a UErrorCode parameter @internal */
70 UTRACE_EXITV_STATUS
= 0x10
74 * Trace function for the entry point of a function.
75 * Do not use directly, use UTRACE_ENTRY instead.
76 * @param fnNumber The UTraceFunctionNumber for the current function.
80 utrace_entry(int32_t fnNumber
);
83 * Trace function for each exit point of a function.
84 * Do not use directly, use UTRACE_EXIT* instead.
85 * @param fnNumber The UTraceFunctionNumber for the current function.
86 * @param returnType The type of the value returned by the function.
87 * @param errorCode The UErrorCode value at function exit. See UTRACE_EXIT.
91 utrace_exit(int32_t fnNumber
, int32_t returnType
, ...);
95 * Trace function used inside functions that have a UTRACE_ENTRY() statement.
96 * Do not use directly, use UTRACE_DATAX() macros instead.
98 * @param utraceFnNumber The number of the current function, from the local
99 * variable of the same name.
100 * @param level The trace level for this message.
101 * @param fmt The trace format string.
105 U_CAPI
void U_EXPORT2
106 utrace_data(int32_t utraceFnNumber
, int32_t level
, const char *fmt
, ...);
113 * Boolean expression to see if ICU tracing is turned on
114 * to at least the specified level.
117 #define UTRACE_LEVEL(level) (utrace_getLevel()>=(level))
120 * Flag bit in utraceFnNumber, the local variable added to each function
121 * with tracing code to contains the function number.
123 * Set the flag if the function's entry is traced, which will cause the
124 * function's exit to also be traced. utraceFnNumber is uncoditionally
125 * set at entry, whether or not the entry is traced, so that it will
126 * always be available for error trace output.
129 #define UTRACE_TRACED_ENTRY 0x80000000
132 * Trace statement for the entry point of a function.
133 * Stores the function number in a local variable.
134 * In C code, must be placed immediately after the last variable declaration.
135 * Must be matched with UTRACE_EXIT() at all function exit points.
137 * Tracing should start with UTRACE_ENTRY after checking for
138 * U_FAILURE at function entry, so that if a function returns immediately
139 * because of a pre-existing error condition, it does not show up in the trace,
140 * consistent with ICU's error handling model.
142 * @param fnNumber The UTraceFunctionNumber for the current function.
145 #define UTRACE_ENTRY(fnNumber) \
146 int32_t utraceFnNumber=(fnNumber); \
147 UPRV_BLOCK_MACRO_BEGIN { \
148 if(utrace_getLevel()>=UTRACE_INFO) { \
149 utrace_entry(fnNumber); \
150 utraceFnNumber |= UTRACE_TRACED_ENTRY; \
152 } UPRV_BLOCK_MACRO_END
156 * Trace statement for the entry point of open and close functions.
157 * Produces trace output at a less verbose setting than plain UTRACE_ENTRY
158 * Stores the function number in a local variable.
159 * In C code, must be placed immediately after the last variable declaration.
160 * Must be matched with UTRACE_EXIT() at all function exit points.
162 * @param fnNumber The UTraceFunctionNumber for the current function.
165 #define UTRACE_ENTRY_OC(fnNumber) \
166 int32_t utraceFnNumber=(fnNumber); \
167 UPRV_BLOCK_MACRO_BEGIN { \
168 if(utrace_getLevel()>=UTRACE_OPEN_CLOSE) { \
169 utrace_entry(fnNumber); \
170 utraceFnNumber |= UTRACE_TRACED_ENTRY; \
172 } UPRV_BLOCK_MACRO_END
175 * Trace statement for each exit point of a function that has a UTRACE_ENTRY()
178 * @param errorCode The function's ICU UErrorCode value at function exit,
179 * or U_ZERO_ERROR if the function does not use a UErrorCode.
180 * 0==U_ZERO_ERROR indicates success,
181 * positive values an error (see u_errorName()),
182 * negative values an informational status.
186 #define UTRACE_EXIT() UPRV_BLOCK_MACRO_BEGIN { \
187 if(utraceFnNumber & UTRACE_TRACED_ENTRY) { \
188 utrace_exit(utraceFnNumber & ~UTRACE_TRACED_ENTRY, UTRACE_EXITV_NONE); \
190 } UPRV_BLOCK_MACRO_END
193 * Trace statement for each exit point of a function that has a UTRACE_ENTRY()
194 * statement, and that returns a value.
196 * @param val The function's return value, int32_t or comatible type.
200 #define UTRACE_EXIT_VALUE(val) UPRV_BLOCK_MACRO_BEGIN { \
201 if(utraceFnNumber & UTRACE_TRACED_ENTRY) { \
202 utrace_exit(utraceFnNumber & ~UTRACE_TRACED_ENTRY, UTRACE_EXITV_I32, val); \
204 } UPRV_BLOCK_MACRO_END
206 #define UTRACE_EXIT_STATUS(status) UPRV_BLOCK_MACRO_BEGIN { \
207 if(utraceFnNumber & UTRACE_TRACED_ENTRY) { \
208 utrace_exit(utraceFnNumber & ~UTRACE_TRACED_ENTRY, UTRACE_EXITV_STATUS, status); \
210 } UPRV_BLOCK_MACRO_END
212 #define UTRACE_EXIT_VALUE_STATUS(val, status) UPRV_BLOCK_MACRO_BEGIN { \
213 if(utraceFnNumber & UTRACE_TRACED_ENTRY) { \
214 utrace_exit(utraceFnNumber & ~UTRACE_TRACED_ENTRY, (UTRACE_EXITV_I32 | UTRACE_EXITV_STATUS), val, status); \
216 } UPRV_BLOCK_MACRO_END
218 #define UTRACE_EXIT_PTR_STATUS(ptr, status) UPRV_BLOCK_MACRO_BEGIN { \
219 if(utraceFnNumber & UTRACE_TRACED_ENTRY) { \
220 utrace_exit(utraceFnNumber & ~UTRACE_TRACED_ENTRY, (UTRACE_EXITV_PTR | UTRACE_EXITV_STATUS), ptr, status); \
222 } UPRV_BLOCK_MACRO_END
225 * Trace statement used inside functions that have a UTRACE_ENTRY() statement.
226 * Takes no data arguments.
227 * The number of arguments for this macro must match the number of inserts
228 * in the format string. Vector inserts count as two arguments.
229 * Calls utrace_data() if the level is high enough.
232 #define UTRACE_DATA0(level, fmt) UPRV_BLOCK_MACRO_BEGIN { \
233 if(UTRACE_LEVEL(level)) { \
234 utrace_data(utraceFnNumber & ~UTRACE_TRACED_ENTRY, (level), (fmt)); \
236 } UPRV_BLOCK_MACRO_END
239 * Trace statement used inside functions that have a UTRACE_ENTRY() statement.
240 * Takes one data argument.
241 * The number of arguments for this macro must match the number of inserts
242 * in the format string. Vector inserts count as two arguments.
243 * Calls utrace_data() if the level is high enough.
246 #define UTRACE_DATA1(level, fmt, a) UPRV_BLOCK_MACRO_BEGIN { \
247 if(UTRACE_LEVEL(level)) { \
248 utrace_data(utraceFnNumber & ~UTRACE_TRACED_ENTRY , (level), (fmt), (a)); \
250 } UPRV_BLOCK_MACRO_END
253 * Trace statement used inside functions that have a UTRACE_ENTRY() statement.
254 * Takes two data arguments.
255 * The number of arguments for this macro must match the number of inserts
256 * in the format string. Vector inserts count as two arguments.
257 * Calls utrace_data() if the level is high enough.
260 #define UTRACE_DATA2(level, fmt, a, b) UPRV_BLOCK_MACRO_BEGIN { \
261 if(UTRACE_LEVEL(level)) { \
262 utrace_data(utraceFnNumber & ~UTRACE_TRACED_ENTRY , (level), (fmt), (a), (b)); \
264 } UPRV_BLOCK_MACRO_END
267 * Trace statement used inside functions that have a UTRACE_ENTRY() statement.
268 * Takes three data arguments.
269 * The number of arguments for this macro must match the number of inserts
270 * in the format string. Vector inserts count as two arguments.
271 * Calls utrace_data() if the level is high enough.
274 #define UTRACE_DATA3(level, fmt, a, b, c) UPRV_BLOCK_MACRO_BEGIN { \
275 if(UTRACE_LEVEL(level)) { \
276 utrace_data(utraceFnNumber & ~UTRACE_TRACED_ENTRY, (level), (fmt), (a), (b), (c)); \
278 } UPRV_BLOCK_MACRO_END
281 * Trace statement used inside functions that have a UTRACE_ENTRY() statement.
282 * Takes four data arguments.
283 * The number of arguments for this macro must match the number of inserts
284 * in the format string. Vector inserts count as two arguments.
285 * Calls utrace_data() if the level is high enough.
288 #define UTRACE_DATA4(level, fmt, a, b, c, d) UPRV_BLOCK_MACRO_BEGIN { \
289 if(UTRACE_LEVEL(level)) { \
290 utrace_data(utraceFnNumber & ~UTRACE_TRACED_ENTRY, (level), (fmt), (a), (b), (c), (d)); \
292 } UPRV_BLOCK_MACRO_END
295 * Trace statement used inside functions that have a UTRACE_ENTRY() statement.
296 * Takes five data arguments.
297 * The number of arguments for this macro must match the number of inserts
298 * in the format string. Vector inserts count as two arguments.
299 * Calls utrace_data() if the level is high enough.
302 #define UTRACE_DATA5(level, fmt, a, b, c, d, e) UPRV_BLOCK_MACRO_BEGIN { \
303 if(UTRACE_LEVEL(level)) { \
304 utrace_data(utraceFnNumber & ~UTRACE_TRACED_ENTRY, (level), (fmt), (a), (b), (c), (d), (e)); \
306 } UPRV_BLOCK_MACRO_END
309 * Trace statement used inside functions that have a UTRACE_ENTRY() statement.
310 * Takes six data arguments.
311 * The number of arguments for this macro must match the number of inserts
312 * in the format string. Vector inserts count as two arguments.
313 * Calls utrace_data() if the level is high enough.
316 #define UTRACE_DATA6(level, fmt, a, b, c, d, e, f) UPRV_BLOCK_MACRO_BEGIN { \
317 if(UTRACE_LEVEL(level)) { \
318 utrace_data(utraceFnNumber & ~UTRACE_TRACED_ENTRY, (level), (fmt), (a), (b), (c), (d), (e), (f)); \
320 } UPRV_BLOCK_MACRO_END
323 * Trace statement used inside functions that have a UTRACE_ENTRY() statement.
324 * Takes seven data arguments.
325 * The number of arguments for this macro must match the number of inserts
326 * in the format string. Vector inserts count as two arguments.
327 * Calls utrace_data() if the level is high enough.
330 #define UTRACE_DATA7(level, fmt, a, b, c, d, e, f, g) UPRV_BLOCK_MACRO_BEGIN { \
331 if(UTRACE_LEVEL(level)) { \
332 utrace_data(utraceFnNumber & ~UTRACE_TRACED_ENTRY, (level), (fmt), (a), (b), (c), (d), (e), (f), (g)); \
334 } UPRV_BLOCK_MACRO_END
337 * Trace statement used inside functions that have a UTRACE_ENTRY() statement.
338 * Takes eight data arguments.
339 * The number of arguments for this macro must match the number of inserts
340 * in the format string. Vector inserts count as two arguments.
341 * Calls utrace_data() if the level is high enough.
344 #define UTRACE_DATA8(level, fmt, a, b, c, d, e, f, g, h) UPRV_BLOCK_MACRO_BEGIN { \
345 if(UTRACE_LEVEL(level)) { \
346 utrace_data(utraceFnNumber & ~UTRACE_TRACED_ENTRY, (level), (fmt), (a), (b), (c), (d), (e), (f), (g), (h)); \
348 } UPRV_BLOCK_MACRO_END
351 * Trace statement used inside functions that have a UTRACE_ENTRY() statement.
352 * Takes nine data arguments.
353 * The number of arguments for this macro must match the number of inserts
354 * in the format string. Vector inserts count as two arguments.
355 * Calls utrace_data() if the level is high enough.
358 #define UTRACE_DATA9(level, fmt, a, b, c, d, e, f, g, h, i) UPRV_BLOCK_MACRO_BEGIN { \
359 if(UTRACE_LEVEL(level)) { \
360 utrace_data(utraceFnNumber & ~UTRACE_TRACED_ENTRY, (level), (fmt), (a), (b), (c), (d), (e), (f), (g), (h), (i)); \
362 } UPRV_BLOCK_MACRO_END
367 * When tracing is disabled, the following macros become empty
370 #define UTRACE_LEVEL(level) 0
371 #define UTRACE_ENTRY(fnNumber)
372 #define UTRACE_ENTRY_OC(fnNumber)
373 #define UTRACE_EXIT()
374 #define UTRACE_EXIT_VALUE(val)
375 #define UTRACE_EXIT_STATUS(status)
376 #define UTRACE_EXIT_VALUE_STATUS(val, status)
377 #define UTRACE_EXIT_PTR_STATUS(ptr, status)
378 #define UTRACE_DATA0(level, fmt)
379 #define UTRACE_DATA1(level, fmt, a)
380 #define UTRACE_DATA2(level, fmt, a, b)
381 #define UTRACE_DATA3(level, fmt, a, b, c)
382 #define UTRACE_DATA4(level, fmt, a, b, c, d)
383 #define UTRACE_DATA5(level, fmt, a, b, c, d, e)
384 #define UTRACE_DATA6(level, fmt, a, b, c, d, e, f)
385 #define UTRACE_DATA7(level, fmt, a, b, c, d, e, f, g)
386 #define UTRACE_DATA8(level, fmt, a, b, c, d, e, f, g, h)
387 #define UTRACE_DATA9(level, fmt, a, b, c, d, e, f, g, h, i)