diff --git a/icu4c/source/common/unicode/platform.h.in b/icu4c/source/common/unicode/platform.h.in index eff00568c7..c9a1f8be7e 100644 --- a/icu4c/source/common/unicode/platform.h.in +++ b/icu4c/source/common/unicode/platform.h.in @@ -112,6 +112,11 @@ #define U_HAVE_PLACEMENT_NEW @U_HAVE_PLACEMENT_NEW@ #endif +/* Determine whether to enable tracing. */ +#ifndef U_ENABLE_TRACING +#define U_ENABLE_TRACING @U_ENABLE_TRACING@ +#endif + /* Define the library suffix in a C syntax. */ #define U_HAVE_LIB_SUFFIX @U_HAVE_LIB_SUFFIX@ #define U_LIB_SUFFIX_C_NAME @ICULIBSUFFIXCNAME@ diff --git a/icu4c/source/common/unicode/pos400.h b/icu4c/source/common/unicode/pos400.h index 5f61af79ab..4bb4db06a1 100644 --- a/icu4c/source/common/unicode/pos400.h +++ b/icu4c/source/common/unicode/pos400.h @@ -68,6 +68,11 @@ #define U_OVERRIDE_CXX_ALLOCATION 1 #endif +/* Determine whether to enable tracing. */ +#ifndef U_ENABLE_TRACING +#define U_ENABLE_TRACING 1 +#endif + /*===========================================================================*/ /* Generic data types */ /*===========================================================================*/ diff --git a/icu4c/source/common/unicode/pwin32.h b/icu4c/source/common/unicode/pwin32.h index 28c2be7db1..3c2afd104c 100644 --- a/icu4c/source/common/unicode/pwin32.h +++ b/icu4c/source/common/unicode/pwin32.h @@ -87,6 +87,11 @@ #define U_HAVE_PLACEMENT_NEW 1 #endif +/* Determine whether to enable tracing. */ +#ifndef U_ENABLE_TRACING +#define U_ENABLE_TRACING 1 +#endif + /*===========================================================================*/ /* Generic data types */ /*===========================================================================*/ diff --git a/icu4c/source/common/utracimp.h b/icu4c/source/common/utracimp.h index 119d9df619..9899b810db 100644 --- a/icu4c/source/common/utracimp.h +++ b/icu4c/source/common/utracimp.h @@ -40,13 +40,11 @@ #ifndef __UTRACIMP_H__ #define __UTRACIMP_H__ -#include #include "unicode/utrace.h" -#include "unicode/utypes.h" +#include U_CDECL_BEGIN - /** * \var utrace_level * Trace level variable. Negative for "off". @@ -63,6 +61,68 @@ U_CFUNC U_IMPORT int32_t utrace_level; +/** + * Traced Function Exit return types. + * Flags indicating the number and types of varargs included in a call + * to a UTraceExit function. + * Bits 0-3: The function return type. First variable param. + * Bit 4: Flag for presence of U_ErrorCode status param. + * @internal + */ +typedef enum UTraceExitVal { + /** The traced function returns no value @internal */ + UTRACE_EXITV_NONE = 0, + /** The traced function returns an int32_t, or compatible, type. @internal */ + UTRACE_EXITV_I32 = 1, + /** The traced function returns a pointer @internal */ + UTRACE_EXITV_PTR = 2, + /** The traced function returns a UBool @internal */ + UTRACE_EXITV_BOOL = 3, + /** Mask to extract the return type values from a UTraceExitVal @internal */ + UTRACE_EXITV_MASK = 0xf, + /** Bit indicating that the traced function includes a UErrorCode parameter @internal */ + UTRACE_EXITV_STATUS = 0x10 +} UTraceExitVal; + +/** + * Trace function for the entry point of a function. + * Do not use directly, use UTRACE_ENTRY instead. + * @param fnNumber The UTraceFunctionNumber for the current function. + * @internal + */ +U_CAPI void U_EXPORT2 +utrace_entry(int32_t fnNumber); + +/** + * Trace function for each exit point of a function. + * Do not use directly, use UTRACE_EXIT* instead. + * @param fnNumber The UTraceFunctionNumber for the current function. + * @param returnType The type of the value returned by the function. + * @param errorCode The UErrorCode value at function exit. See UTRACE_EXIT. + * @internal + */ +U_CAPI void U_EXPORT2 +utrace_exit(int32_t fnNumber, int32_t returnType, ...); + + +/** + * Trace function used inside functions that have a UTRACE_ENTRY() statement. + * Do not use directly, use UTRACE_DATAX() macros instead. + * + * @param utraceFnNumber The number of the current function, from the local + * variable of the same name. + * @param level The trace level for this message. + * @param fmt The trace format string. + * + * @internal + */ +U_CAPI void U_EXPORT2 +utrace_data(int32_t utraceFnNumber, int32_t level, const char *fmt, ...); + +U_CDECL_END + +#if U_ENABLE_TRACING + /** * Boolean expression to see if ICU tracing is turned on * to at least the specified level. @@ -121,32 +181,6 @@ utrace_level; utraceFnNumber |= UTRACE_TRACED_ENTRY; \ } - -/** - * Traced Function Exit return types. - * Flags indicating the number and types of varargs included in a call - * to a UTraceExit function. - * Bits 0-3: The function return type. First variable param. - * Bit 4: Flag for presence of U_ErrorCode status param. - * @internal - */ -typedef enum UTraceExitVal { - /** The traced function returns no value @internal */ - UTRACE_EXITV_NONE = 0, - /** The traced function returns an int32_t, or compatible, type. @internal */ - UTRACE_EXITV_I32 = 1, - /** The traced function returns a pointer @internal */ - UTRACE_EXITV_PTR = 2, - /** The traced function returns a UBool @internal */ - UTRACE_EXITV_BOOL = 3, - /** Mask to extract the return type values from a UTraceExitVal @internal */ - UTRACE_EXITV_MASK = 0xf, - /** Bit indicating that the traced function includes a UErrorCode parameter @internal */ - UTRACE_EXITV_STATUS = 0x10 -} UTraceExitVal; - - - /** * Trace statement for each exit point of a function that has a UTRACE_ENTRY() * statement. @@ -192,41 +226,6 @@ typedef enum UTraceExitVal { utrace_exit(utraceFnNumber & ~UTRACE_TRACED_ENTRY, (UTRACE_EXITV_PTR | UTRACE_EXITV_STATUS), ptr, status); \ }} -/** - * Trace function for the entry point of a function. - * Do not use directly, use UTRACE_ENTRY instead. - * @param fnNumber The UTraceFunctionNumber for the current function. - * @internal - */ -U_CAPI void U_EXPORT2 -utrace_entry(int32_t fnNumber); - -/** - * Trace function for each exit point of a function. - * Do not use directly, use UTRACE_EXIT* instead. - * @param fnNumber The UTraceFunctionNumber for the current function. - * @param returnType The type of the value returned by the function. - * @param errorCode The UErrorCode value at function exit. See UTRACE_EXIT. - * @internal - */ -U_CAPI void U_EXPORT2 -utrace_exit(int32_t fnNumber, int32_t returnType, ...); - - -/** - * Trace function used inside functions that have a UTRACE_ENTRY() statement. - * Do not use directly, use UTRACE_DATAX() macros instead. - * - * @param utraceFnNumber The number of the current function, from the local - * variable of the same name. - * @param level The trace level for this message. - * @param fmt The trace format string. - * - * @internal - */ -U_CAPI void U_EXPORT2 -utrace_data(int32_t utraceFnNumber, int32_t level, const char *fmt, ...); - /** * Trace statement used inside functions that have a UTRACE_ENTRY() statement. * Takes no data arguments. @@ -357,6 +356,31 @@ utrace_data(int32_t utraceFnNumber, int32_t level, const char *fmt, ...); utrace_data(utraceFnNumber, (level), (fmt), (a), (b), (c), (d), (e), (f), (g), (h), (i)); \ } -U_CDECL_END +#else + +/* + * When tracing is disabled, the following macros become empty + */ + +#define UTRACE_LEVEL(level) 0 +#define UTRACE_ENTRY(fnNumber) +#define UTRACE_ENTRY_OC(fnNumber) +#define UTRACE_EXIT() +#define UTRACE_EXIT_VALUE(val) +#define UTRACE_EXIT_STATUS(status) +#define UTRACE_EXIT_VALUE_STATUS(val, status) +#define UTRACE_EXIT_PTR_STATUS(ptr, status) +#define UTRACE_DATA0(level, fmt) +#define UTRACE_DATA1(level, fmt, a) +#define UTRACE_DATA2(level, fmt, a, b) +#define UTRACE_DATA3(level, fmt, a, b, c) +#define UTRACE_DATA4(level, fmt, a, b, c, d) +#define UTRACE_DATA5(level, fmt, a, b, c, d, e) +#define UTRACE_DATA6(level, fmt, a, b, c, d, e, f) +#define UTRACE_DATA7(level, fmt, a, b, c, d, e, f, g) +#define UTRACE_DATA8(level, fmt, a, b, c, d, e, f, g, h) +#define UTRACE_DATA9(level, fmt, a, b, c, d, e, f, g, h, i) + +#endif #endif diff --git a/icu4c/source/test/cintltst/tracetst.c b/icu4c/source/test/cintltst/tracetst.c index 58ebc11c8d..def1d32b15 100644 --- a/icu4c/source/test/cintltst/tracetst.c +++ b/icu4c/source/test/cintltst/tracetst.c @@ -11,7 +11,6 @@ #include "unicode/utypes.h" #include "unicode/utrace.h" -#include "utracimp.h" #include "unicode/uclean.h" #include "unicode/uchar.h" #include "unicode/ures.h" @@ -19,6 +18,7 @@ #include "cintltst.h" #include #include +#include "utracimp.h" static void TestTraceAPI(void); @@ -188,9 +188,13 @@ static void TestTraceAPI() { cnv = ucnv_open(NULL, &status); TEST_ASSERT(U_SUCCESS(status)); ucnv_close(cnv); +#if U_ENABLE_TRACING TEST_ASSERT(gTraceEntryCount > 0); TEST_ASSERT(gTraceExitCount > 0); TEST_ASSERT(gTraceDataCount > 0); +#else + log_info("Tracing has been disabled. Testing of this feature has been skipped.\n"); +#endif }