michael@0: /* michael@0: ******************************************************************************* michael@0: * michael@0: * Copyright (C) 2003-2009, International Business Machines michael@0: * Corporation and others. All Rights Reserved. michael@0: * michael@0: ******************************************************************************* michael@0: * file name: utracimp.h michael@0: * encoding: US-ASCII michael@0: * tab size: 8 (not used) michael@0: * indentation:4 michael@0: * michael@0: * created on: 2003aug06 michael@0: * created by: Markus W. Scherer michael@0: * michael@0: * Internal header for ICU tracing/logging. michael@0: * michael@0: * michael@0: * Various notes: michael@0: * - using a trace level variable to only call trace functions michael@0: * when the level is sufficient michael@0: * - using the same variable for tracing on/off to never make a function michael@0: * call when off michael@0: * - the function number is put into a local variable by the entry macro michael@0: * and used implicitly to avoid copy&paste/typing mistakes by the developer michael@0: * - the application must call utrace_setFunctions() and pass in michael@0: * implementations for the trace functions michael@0: * - ICU trace macros call ICU functions that route through the function michael@0: * pointers if they have been set; michael@0: * this avoids an indirection at the call site michael@0: * (which would cost more code for another check and for the indirection) michael@0: * michael@0: * ### TODO Issues: michael@0: * - Verify that va_list is portable among compilers for the same platform. michael@0: * va_list should be portable because printf() would fail otherwise! michael@0: * - Should enum values like UTraceLevel be passed into int32_t-type arguments, michael@0: * or should enum types be used? michael@0: */ michael@0: michael@0: #ifndef __UTRACIMP_H__ michael@0: #define __UTRACIMP_H__ michael@0: michael@0: #include "unicode/utrace.h" michael@0: #include michael@0: michael@0: U_CDECL_BEGIN michael@0: michael@0: /** michael@0: * \var utrace_level michael@0: * Trace level variable. Negative for "off". michael@0: * Use only via UTRACE_ macros. michael@0: * @internal michael@0: */ michael@0: #ifdef UTRACE_IMPL michael@0: U_EXPORT int32_t michael@0: #else michael@0: U_CFUNC U_COMMON_API int32_t michael@0: #endif michael@0: utrace_level; michael@0: michael@0: michael@0: /** michael@0: * Traced Function Exit return types. michael@0: * Flags indicating the number and types of varargs included in a call michael@0: * to a UTraceExit function. michael@0: * Bits 0-3: The function return type. First variable param. michael@0: * Bit 4: Flag for presence of U_ErrorCode status param. michael@0: * @internal michael@0: */ michael@0: typedef enum UTraceExitVal { michael@0: /** The traced function returns no value @internal */ michael@0: UTRACE_EXITV_NONE = 0, michael@0: /** The traced function returns an int32_t, or compatible, type. @internal */ michael@0: UTRACE_EXITV_I32 = 1, michael@0: /** The traced function returns a pointer @internal */ michael@0: UTRACE_EXITV_PTR = 2, michael@0: /** The traced function returns a UBool @internal */ michael@0: UTRACE_EXITV_BOOL = 3, michael@0: /** Mask to extract the return type values from a UTraceExitVal @internal */ michael@0: UTRACE_EXITV_MASK = 0xf, michael@0: /** Bit indicating that the traced function includes a UErrorCode parameter @internal */ michael@0: UTRACE_EXITV_STATUS = 0x10 michael@0: } UTraceExitVal; michael@0: michael@0: /** michael@0: * Trace function for the entry point of a function. michael@0: * Do not use directly, use UTRACE_ENTRY instead. michael@0: * @param fnNumber The UTraceFunctionNumber for the current function. michael@0: * @internal michael@0: */ michael@0: U_CAPI void U_EXPORT2 michael@0: utrace_entry(int32_t fnNumber); michael@0: michael@0: /** michael@0: * Trace function for each exit point of a function. michael@0: * Do not use directly, use UTRACE_EXIT* instead. michael@0: * @param fnNumber The UTraceFunctionNumber for the current function. michael@0: * @param returnType The type of the value returned by the function. michael@0: * @param errorCode The UErrorCode value at function exit. See UTRACE_EXIT. michael@0: * @internal michael@0: */ michael@0: U_CAPI void U_EXPORT2 michael@0: utrace_exit(int32_t fnNumber, int32_t returnType, ...); michael@0: michael@0: michael@0: /** michael@0: * Trace function used inside functions that have a UTRACE_ENTRY() statement. michael@0: * Do not use directly, use UTRACE_DATAX() macros instead. michael@0: * michael@0: * @param utraceFnNumber The number of the current function, from the local michael@0: * variable of the same name. michael@0: * @param level The trace level for this message. michael@0: * @param fmt The trace format string. michael@0: * michael@0: * @internal michael@0: */ michael@0: U_CAPI void U_EXPORT2 michael@0: utrace_data(int32_t utraceFnNumber, int32_t level, const char *fmt, ...); michael@0: michael@0: U_CDECL_END michael@0: michael@0: #if U_ENABLE_TRACING michael@0: michael@0: /** michael@0: * Boolean expression to see if ICU tracing is turned on michael@0: * to at least the specified level. michael@0: * @internal michael@0: */ michael@0: #define UTRACE_LEVEL(level) (utrace_getLevel()>=(level)) michael@0: michael@0: /** michael@0: * Flag bit in utraceFnNumber, the local variable added to each function michael@0: * with tracing code to contains the function number. michael@0: * michael@0: * Set the flag if the function's entry is traced, which will cause the michael@0: * function's exit to also be traced. utraceFnNumber is uncoditionally michael@0: * set at entry, whether or not the entry is traced, so that it will michael@0: * always be available for error trace output. michael@0: * @internal michael@0: */ michael@0: #define UTRACE_TRACED_ENTRY 0x80000000 michael@0: michael@0: /** michael@0: * Trace statement for the entry point of a function. michael@0: * Stores the function number in a local variable. michael@0: * In C code, must be placed immediately after the last variable declaration. michael@0: * Must be matched with UTRACE_EXIT() at all function exit points. michael@0: * michael@0: * Tracing should start with UTRACE_ENTRY after checking for michael@0: * U_FAILURE at function entry, so that if a function returns immediately michael@0: * because of a pre-existing error condition, it does not show up in the trace, michael@0: * consistent with ICU's error handling model. michael@0: * michael@0: * @param fnNumber The UTraceFunctionNumber for the current function. michael@0: * @internal michael@0: */ michael@0: #define UTRACE_ENTRY(fnNumber) \ michael@0: int32_t utraceFnNumber=(fnNumber); \ michael@0: if(utrace_getLevel()>=UTRACE_INFO) { \ michael@0: utrace_entry(fnNumber); \ michael@0: utraceFnNumber |= UTRACE_TRACED_ENTRY; \ michael@0: } michael@0: michael@0: michael@0: /** michael@0: * Trace statement for the entry point of open and close functions. michael@0: * Produces trace output at a less verbose setting than plain UTRACE_ENTRY michael@0: * Stores the function number in a local variable. michael@0: * In C code, must be placed immediately after the last variable declaration. michael@0: * Must be matched with UTRACE_EXIT() at all function exit points. michael@0: * michael@0: * @param fnNumber The UTraceFunctionNumber for the current function. michael@0: * @internal michael@0: */ michael@0: #define UTRACE_ENTRY_OC(fnNumber) \ michael@0: int32_t utraceFnNumber=(fnNumber); \ michael@0: if(utrace_getLevel()>=UTRACE_OPEN_CLOSE) { \ michael@0: utrace_entry(fnNumber); \ michael@0: utraceFnNumber |= UTRACE_TRACED_ENTRY; \ michael@0: } michael@0: michael@0: /** michael@0: * Trace statement for each exit point of a function that has a UTRACE_ENTRY() michael@0: * statement. michael@0: * michael@0: * @param errorCode The function's ICU UErrorCode value at function exit, michael@0: * or U_ZERO_ERROR if the function does not use a UErrorCode. michael@0: * 0==U_ZERO_ERROR indicates success, michael@0: * positive values an error (see u_errorName()), michael@0: * negative values an informational status. michael@0: * michael@0: * @internal michael@0: */ michael@0: #define UTRACE_EXIT() \ michael@0: {if(utraceFnNumber & UTRACE_TRACED_ENTRY) { \ michael@0: utrace_exit(utraceFnNumber & ~UTRACE_TRACED_ENTRY, UTRACE_EXITV_NONE); \ michael@0: }} michael@0: michael@0: /** michael@0: * Trace statement for each exit point of a function that has a UTRACE_ENTRY() michael@0: * statement, and that returns a value. michael@0: * michael@0: * @param val The function's return value, int32_t or comatible type. michael@0: * michael@0: * @internal michael@0: */ michael@0: #define UTRACE_EXIT_VALUE(val) \ michael@0: {if(utraceFnNumber & UTRACE_TRACED_ENTRY) { \ michael@0: utrace_exit(utraceFnNumber & ~UTRACE_TRACED_ENTRY, UTRACE_EXITV_I32, val); \ michael@0: }} michael@0: michael@0: #define UTRACE_EXIT_STATUS(status) \ michael@0: {if(utraceFnNumber & UTRACE_TRACED_ENTRY) { \ michael@0: utrace_exit(utraceFnNumber & ~UTRACE_TRACED_ENTRY, UTRACE_EXITV_STATUS, status); \ michael@0: }} michael@0: michael@0: #define UTRACE_EXIT_VALUE_STATUS(val, status) \ michael@0: {if(utraceFnNumber & UTRACE_TRACED_ENTRY) { \ michael@0: utrace_exit(utraceFnNumber & ~UTRACE_TRACED_ENTRY, (UTRACE_EXITV_I32 | UTRACE_EXITV_STATUS), val, status); \ michael@0: }} michael@0: michael@0: #define UTRACE_EXIT_PTR_STATUS(ptr, status) \ michael@0: {if(utraceFnNumber & UTRACE_TRACED_ENTRY) { \ michael@0: utrace_exit(utraceFnNumber & ~UTRACE_TRACED_ENTRY, (UTRACE_EXITV_PTR | UTRACE_EXITV_STATUS), ptr, status); \ michael@0: }} michael@0: michael@0: /** michael@0: * Trace statement used inside functions that have a UTRACE_ENTRY() statement. michael@0: * Takes no data arguments. michael@0: * The number of arguments for this macro must match the number of inserts michael@0: * in the format string. Vector inserts count as two arguments. michael@0: * Calls utrace_data() if the level is high enough. michael@0: * @internal michael@0: */ michael@0: #define UTRACE_DATA0(level, fmt) \ michael@0: if(UTRACE_LEVEL(level)) { \ michael@0: utrace_data(utraceFnNumber & ~UTRACE_TRACED_ENTRY, (level), (fmt)); \ michael@0: } michael@0: michael@0: /** michael@0: * Trace statement used inside functions that have a UTRACE_ENTRY() statement. michael@0: * Takes one data argument. michael@0: * The number of arguments for this macro must match the number of inserts michael@0: * in the format string. Vector inserts count as two arguments. michael@0: * Calls utrace_data() if the level is high enough. michael@0: * @internal michael@0: */ michael@0: #define UTRACE_DATA1(level, fmt, a) \ michael@0: if(UTRACE_LEVEL(level)) { \ michael@0: utrace_data(utraceFnNumber & ~UTRACE_TRACED_ENTRY , (level), (fmt), (a)); \ michael@0: } michael@0: michael@0: /** michael@0: * Trace statement used inside functions that have a UTRACE_ENTRY() statement. michael@0: * Takes two data arguments. michael@0: * The number of arguments for this macro must match the number of inserts michael@0: * in the format string. Vector inserts count as two arguments. michael@0: * Calls utrace_data() if the level is high enough. michael@0: * @internal michael@0: */ michael@0: #define UTRACE_DATA2(level, fmt, a, b) \ michael@0: if(UTRACE_LEVEL(level)) { \ michael@0: utrace_data(utraceFnNumber & ~UTRACE_TRACED_ENTRY , (level), (fmt), (a), (b)); \ michael@0: } michael@0: michael@0: /** michael@0: * Trace statement used inside functions that have a UTRACE_ENTRY() statement. michael@0: * Takes three data arguments. michael@0: * The number of arguments for this macro must match the number of inserts michael@0: * in the format string. Vector inserts count as two arguments. michael@0: * Calls utrace_data() if the level is high enough. michael@0: * @internal michael@0: */ michael@0: #define UTRACE_DATA3(level, fmt, a, b, c) \ michael@0: if(UTRACE_LEVEL(level)) { \ michael@0: utrace_data(utraceFnNumber & ~UTRACE_TRACED_ENTRY, (level), (fmt), (a), (b), (c)); \ michael@0: } michael@0: michael@0: /** michael@0: * Trace statement used inside functions that have a UTRACE_ENTRY() statement. michael@0: * Takes four data arguments. michael@0: * The number of arguments for this macro must match the number of inserts michael@0: * in the format string. Vector inserts count as two arguments. michael@0: * Calls utrace_data() if the level is high enough. michael@0: * @internal michael@0: */ michael@0: #define UTRACE_DATA4(level, fmt, a, b, c, d) \ michael@0: if(UTRACE_LEVEL(level)) { \ michael@0: utrace_data(utraceFnNumber & ~UTRACE_TRACED_ENTRY, (level), (fmt), (a), (b), (c), (d)); \ michael@0: } michael@0: michael@0: /** michael@0: * Trace statement used inside functions that have a UTRACE_ENTRY() statement. michael@0: * Takes five data arguments. michael@0: * The number of arguments for this macro must match the number of inserts michael@0: * in the format string. Vector inserts count as two arguments. michael@0: * Calls utrace_data() if the level is high enough. michael@0: * @internal michael@0: */ michael@0: #define UTRACE_DATA5(level, fmt, a, b, c, d, e) \ michael@0: if(UTRACE_LEVEL(level)) { \ michael@0: utrace_data(utraceFnNumber & ~UTRACE_TRACED_ENTRY, (level), (fmt), (a), (b), (c), (d), (e)); \ michael@0: } michael@0: michael@0: /** michael@0: * Trace statement used inside functions that have a UTRACE_ENTRY() statement. michael@0: * Takes six data arguments. michael@0: * The number of arguments for this macro must match the number of inserts michael@0: * in the format string. Vector inserts count as two arguments. michael@0: * Calls utrace_data() if the level is high enough. michael@0: * @internal michael@0: */ michael@0: #define UTRACE_DATA6(level, fmt, a, b, c, d, e, f) \ michael@0: if(UTRACE_LEVEL(level)) { \ michael@0: utrace_data(utraceFnNumber & ~UTRACE_TRACED_ENTRY, (level), (fmt), (a), (b), (c), (d), (e), (f)); \ michael@0: } michael@0: michael@0: /** michael@0: * Trace statement used inside functions that have a UTRACE_ENTRY() statement. michael@0: * Takes seven data arguments. michael@0: * The number of arguments for this macro must match the number of inserts michael@0: * in the format string. Vector inserts count as two arguments. michael@0: * Calls utrace_data() if the level is high enough. michael@0: * @internal michael@0: */ michael@0: #define UTRACE_DATA7(level, fmt, a, b, c, d, e, f, g) \ michael@0: if(UTRACE_LEVEL(level)) { \ michael@0: utrace_data(utraceFnNumber & ~UTRACE_TRACED_ENTRY, (level), (fmt), (a), (b), (c), (d), (e), (f), (g)); \ michael@0: } michael@0: michael@0: /** michael@0: * Trace statement used inside functions that have a UTRACE_ENTRY() statement. michael@0: * Takes eight data arguments. michael@0: * The number of arguments for this macro must match the number of inserts michael@0: * in the format string. Vector inserts count as two arguments. michael@0: * Calls utrace_data() if the level is high enough. michael@0: * @internal michael@0: */ michael@0: #define UTRACE_DATA8(level, fmt, a, b, c, d, e, f, g, h) \ michael@0: if(UTRACE_LEVEL(level)) { \ michael@0: utrace_data(utraceFnNumber & ~UTRACE_TRACED_ENTRY, (level), (fmt), (a), (b), (c), (d), (e), (f), (g), (h)); \ michael@0: } michael@0: michael@0: /** michael@0: * Trace statement used inside functions that have a UTRACE_ENTRY() statement. michael@0: * Takes nine data arguments. michael@0: * The number of arguments for this macro must match the number of inserts michael@0: * in the format string. Vector inserts count as two arguments. michael@0: * Calls utrace_data() if the level is high enough. michael@0: * @internal michael@0: */ michael@0: #define UTRACE_DATA9(level, fmt, a, b, c, d, e, f, g, h, i) \ michael@0: if(UTRACE_LEVEL(level)) { \ michael@0: utrace_data(utraceFnNumber & ~UTRACE_TRACED_ENTRY, (level), (fmt), (a), (b), (c), (d), (e), (f), (g), (h), (i)); \ michael@0: } michael@0: michael@0: #else michael@0: michael@0: /* michael@0: * When tracing is disabled, the following macros become empty michael@0: */ michael@0: michael@0: #define UTRACE_LEVEL(level) 0 michael@0: #define UTRACE_ENTRY(fnNumber) michael@0: #define UTRACE_ENTRY_OC(fnNumber) michael@0: #define UTRACE_EXIT() michael@0: #define UTRACE_EXIT_VALUE(val) michael@0: #define UTRACE_EXIT_STATUS(status) michael@0: #define UTRACE_EXIT_VALUE_STATUS(val, status) michael@0: #define UTRACE_EXIT_PTR_STATUS(ptr, status) michael@0: #define UTRACE_DATA0(level, fmt) michael@0: #define UTRACE_DATA1(level, fmt, a) michael@0: #define UTRACE_DATA2(level, fmt, a, b) michael@0: #define UTRACE_DATA3(level, fmt, a, b, c) michael@0: #define UTRACE_DATA4(level, fmt, a, b, c, d) michael@0: #define UTRACE_DATA5(level, fmt, a, b, c, d, e) michael@0: #define UTRACE_DATA6(level, fmt, a, b, c, d, e, f) michael@0: #define UTRACE_DATA7(level, fmt, a, b, c, d, e, f, g) michael@0: #define UTRACE_DATA8(level, fmt, a, b, c, d, e, f, g, h) michael@0: #define UTRACE_DATA9(level, fmt, a, b, c, d, e, f, g, h, i) michael@0: michael@0: #endif michael@0: michael@0: #endif