jpayne@69: // © 2016 and later: Unicode, Inc. and others. jpayne@69: // License & terms of use: http://www.unicode.org/copyright.html jpayne@69: /* jpayne@69: ******************************************************************************* jpayne@69: * jpayne@69: * Copyright (C) 2003-2013, International Business Machines jpayne@69: * Corporation and others. All Rights Reserved. jpayne@69: * jpayne@69: ******************************************************************************* jpayne@69: * file name: utrace.h jpayne@69: * encoding: UTF-8 jpayne@69: * tab size: 8 (not used) jpayne@69: * indentation:4 jpayne@69: * jpayne@69: * created on: 2003aug06 jpayne@69: * created by: Markus W. Scherer jpayne@69: * jpayne@69: * Definitions for ICU tracing/logging. jpayne@69: * jpayne@69: */ jpayne@69: jpayne@69: #ifndef __UTRACE_H__ jpayne@69: #define __UTRACE_H__ jpayne@69: jpayne@69: #include jpayne@69: #include "unicode/utypes.h" jpayne@69: jpayne@69: /** jpayne@69: * \file jpayne@69: * \brief C API: Definitions for ICU tracing/logging. jpayne@69: * jpayne@69: * This provides API for debugging the internals of ICU without the use of jpayne@69: * a traditional debugger. jpayne@69: * jpayne@69: * By default, tracing is disabled in ICU. If you need to debug ICU with jpayne@69: * tracing, please compile ICU with the --enable-tracing configure option. jpayne@69: */ jpayne@69: jpayne@69: U_CDECL_BEGIN jpayne@69: jpayne@69: /** jpayne@69: * Trace severity levels. Higher levels increase the verbosity of the trace output. jpayne@69: * @see utrace_setLevel jpayne@69: * @stable ICU 2.8 jpayne@69: */ jpayne@69: typedef enum UTraceLevel { jpayne@69: /** Disable all tracing @stable ICU 2.8*/ jpayne@69: UTRACE_OFF=-1, jpayne@69: /** Trace error conditions only @stable ICU 2.8*/ jpayne@69: UTRACE_ERROR=0, jpayne@69: /** Trace errors and warnings @stable ICU 2.8*/ jpayne@69: UTRACE_WARNING=3, jpayne@69: /** Trace opens and closes of ICU services @stable ICU 2.8*/ jpayne@69: UTRACE_OPEN_CLOSE=5, jpayne@69: /** Trace an intermediate number of ICU operations @stable ICU 2.8*/ jpayne@69: UTRACE_INFO=7, jpayne@69: /** Trace the maximum number of ICU operations @stable ICU 2.8*/ jpayne@69: UTRACE_VERBOSE=9 jpayne@69: } UTraceLevel; jpayne@69: jpayne@69: /** jpayne@69: * These are the ICU functions that will be traced when tracing is enabled. jpayne@69: * @stable ICU 2.8 jpayne@69: */ jpayne@69: typedef enum UTraceFunctionNumber { jpayne@69: UTRACE_FUNCTION_START=0, jpayne@69: UTRACE_U_INIT=UTRACE_FUNCTION_START, jpayne@69: UTRACE_U_CLEANUP, jpayne@69: jpayne@69: #ifndef U_HIDE_DEPRECATED_API jpayne@69: /** jpayne@69: * One more than the highest normal collation trace location. jpayne@69: * @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420. jpayne@69: */ jpayne@69: UTRACE_FUNCTION_LIMIT, jpayne@69: #endif // U_HIDE_DEPRECATED_API jpayne@69: jpayne@69: UTRACE_CONVERSION_START=0x1000, jpayne@69: UTRACE_UCNV_OPEN=UTRACE_CONVERSION_START, jpayne@69: UTRACE_UCNV_OPEN_PACKAGE, jpayne@69: UTRACE_UCNV_OPEN_ALGORITHMIC, jpayne@69: UTRACE_UCNV_CLONE, jpayne@69: UTRACE_UCNV_CLOSE, jpayne@69: UTRACE_UCNV_FLUSH_CACHE, jpayne@69: UTRACE_UCNV_LOAD, jpayne@69: UTRACE_UCNV_UNLOAD, jpayne@69: jpayne@69: #ifndef U_HIDE_DEPRECATED_API jpayne@69: /** jpayne@69: * One more than the highest normal collation trace location. jpayne@69: * @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420. jpayne@69: */ jpayne@69: UTRACE_CONVERSION_LIMIT, jpayne@69: #endif // U_HIDE_DEPRECATED_API jpayne@69: jpayne@69: UTRACE_COLLATION_START=0x2000, jpayne@69: UTRACE_UCOL_OPEN=UTRACE_COLLATION_START, jpayne@69: UTRACE_UCOL_CLOSE, jpayne@69: UTRACE_UCOL_STRCOLL, jpayne@69: UTRACE_UCOL_GET_SORTKEY, jpayne@69: UTRACE_UCOL_GETLOCALE, jpayne@69: UTRACE_UCOL_NEXTSORTKEYPART, jpayne@69: UTRACE_UCOL_STRCOLLITER, jpayne@69: UTRACE_UCOL_OPEN_FROM_SHORT_STRING, jpayne@69: UTRACE_UCOL_STRCOLLUTF8, /**< @stable ICU 50 */ jpayne@69: jpayne@69: #ifndef U_HIDE_DEPRECATED_API jpayne@69: /** jpayne@69: * One more than the highest normal collation trace location. jpayne@69: * @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420. jpayne@69: */ jpayne@69: UTRACE_COLLATION_LIMIT, jpayne@69: #endif // U_HIDE_DEPRECATED_API jpayne@69: jpayne@69: #ifndef U_HIDE_DRAFT_API jpayne@69: jpayne@69: /** jpayne@69: * The lowest resource/data location. jpayne@69: * @draft ICU 65 jpayne@69: */ jpayne@69: UTRACE_UDATA_START=0x3000, jpayne@69: jpayne@69: /** jpayne@69: * Indicates that a value was read from a resource bundle. Provides three jpayne@69: * C-style strings to UTraceData: type, file name, and resource path. The jpayne@69: * possible types are: jpayne@69: * jpayne@69: * - "string" (a string value was accessed) jpayne@69: * - "binary" (a binary value was accessed) jpayne@69: * - "intvector" (a integer vector value was accessed) jpayne@69: * - "int" (a signed integer value was accessed) jpayne@69: * - "uint" (a unsigned integer value was accessed) jpayne@69: * - "get" (a path was loaded, but the value was not accessed) jpayne@69: * - "getalias" (a path was loaded, and an alias was resolved) jpayne@69: * jpayne@69: * @draft ICU 65 jpayne@69: */ jpayne@69: UTRACE_UDATA_RESOURCE=UTRACE_UDATA_START, jpayne@69: jpayne@69: /** jpayne@69: * Indicates that a resource bundle was opened. jpayne@69: * jpayne@69: * Provides one C-style string to UTraceData: file name. jpayne@69: * @draft ICU 65 jpayne@69: */ jpayne@69: UTRACE_UDATA_BUNDLE, jpayne@69: jpayne@69: /** jpayne@69: * Indicates that a data file was opened, but not *.res files. jpayne@69: * jpayne@69: * Provides one C-style string to UTraceData: file name. jpayne@69: * jpayne@69: * @draft ICU 65 jpayne@69: */ jpayne@69: UTRACE_UDATA_DATA_FILE, jpayne@69: jpayne@69: /** jpayne@69: * Indicates that a *.res file was opened. jpayne@69: * jpayne@69: * This differs from UTRACE_UDATA_BUNDLE because a res file is typically jpayne@69: * opened only once per application runtime, but the bundle corresponding jpayne@69: * to that res file may be opened many times. jpayne@69: * jpayne@69: * Provides one C-style string to UTraceData: file name. jpayne@69: * jpayne@69: * @draft ICU 65 jpayne@69: */ jpayne@69: UTRACE_UDATA_RES_FILE, jpayne@69: jpayne@69: #endif // U_HIDE_DRAFT_API jpayne@69: jpayne@69: #ifndef U_HIDE_INTERNAL_API jpayne@69: /** jpayne@69: * One more than the highest normal resource/data trace location. jpayne@69: * @internal The numeric value may change over time, see ICU ticket #12420. jpayne@69: */ jpayne@69: UTRACE_RES_DATA_LIMIT, jpayne@69: #endif // U_HIDE_INTERNAL_API jpayne@69: jpayne@69: #ifndef U_HIDE_DRAFT_API jpayne@69: /** jpayne@69: * The lowest break iterator location. jpayne@69: * @draft ICU 67 jpayne@69: */ jpayne@69: UTRACE_UBRK_START=0x4000, jpayne@69: jpayne@69: /** jpayne@69: * Indicates that a character instance of break iterator was created. jpayne@69: * jpayne@69: * @draft ICU 67 jpayne@69: */ jpayne@69: UTRACE_UBRK_CREATE_CHARACTER = UTRACE_UBRK_START, jpayne@69: jpayne@69: /** jpayne@69: * Indicates that a word instance of break iterator was created. jpayne@69: * jpayne@69: * @draft ICU 67 jpayne@69: */ jpayne@69: UTRACE_UBRK_CREATE_WORD, jpayne@69: jpayne@69: /** jpayne@69: * Indicates that a line instance of break iterator was created. jpayne@69: * jpayne@69: * Provides one C-style string to UTraceData: the lb value ("", jpayne@69: * "loose", "strict", or "normal"). jpayne@69: * jpayne@69: * @draft ICU 67 jpayne@69: */ jpayne@69: UTRACE_UBRK_CREATE_LINE, jpayne@69: jpayne@69: /** jpayne@69: * Indicates that a sentence instance of break iterator was created. jpayne@69: * jpayne@69: * @draft ICU 67 jpayne@69: */ jpayne@69: UTRACE_UBRK_CREATE_SENTENCE, jpayne@69: jpayne@69: /** jpayne@69: * Indicates that a title instance of break iterator was created. jpayne@69: * jpayne@69: * @draft ICU 67 jpayne@69: */ jpayne@69: UTRACE_UBRK_CREATE_TITLE, jpayne@69: jpayne@69: /** jpayne@69: * Indicates that an internal dictionary break engine was created. jpayne@69: * jpayne@69: * Provides one C-style string to UTraceData: the script code of what jpayne@69: * the break engine cover ("Hani", "Khmr", "Laoo", "Mymr", or "Thai"). jpayne@69: * jpayne@69: * @draft ICU 67 jpayne@69: */ jpayne@69: UTRACE_UBRK_CREATE_BREAK_ENGINE, jpayne@69: jpayne@69: #endif // U_HIDE_DRAFT_API jpayne@69: jpayne@69: #ifndef U_HIDE_INTERNAL_API jpayne@69: /** jpayne@69: * One more than the highest normal break iterator trace location. jpayne@69: * @internal The numeric value may change over time, see ICU ticket #12420. jpayne@69: */ jpayne@69: UTRACE_UBRK_LIMIT, jpayne@69: #endif // U_HIDE_INTERNAL_API jpayne@69: jpayne@69: } UTraceFunctionNumber; jpayne@69: jpayne@69: /** jpayne@69: * Setter for the trace level. jpayne@69: * @param traceLevel A UTraceLevel value. jpayne@69: * @stable ICU 2.8 jpayne@69: */ jpayne@69: U_STABLE void U_EXPORT2 jpayne@69: utrace_setLevel(int32_t traceLevel); jpayne@69: jpayne@69: /** jpayne@69: * Getter for the trace level. jpayne@69: * @return The UTraceLevel value being used by ICU. jpayne@69: * @stable ICU 2.8 jpayne@69: */ jpayne@69: U_STABLE int32_t U_EXPORT2 jpayne@69: utrace_getLevel(void); jpayne@69: jpayne@69: /* Trace function pointers types ----------------------------- */ jpayne@69: jpayne@69: /** jpayne@69: * Type signature for the trace function to be called when entering a function. jpayne@69: * @param context value supplied at the time the trace functions are set. jpayne@69: * @param fnNumber Enum value indicating the ICU function being entered. jpayne@69: * @stable ICU 2.8 jpayne@69: */ jpayne@69: typedef void U_CALLCONV jpayne@69: UTraceEntry(const void *context, int32_t fnNumber); jpayne@69: jpayne@69: /** jpayne@69: * Type signature for the trace function to be called when exiting from a function. jpayne@69: * @param context value supplied at the time the trace functions are set. jpayne@69: * @param fnNumber Enum value indicating the ICU function being exited. jpayne@69: * @param fmt A formatting string that describes the number and types jpayne@69: * of arguments included with the variable args. The fmt jpayne@69: * string has the same form as the utrace_vformat format jpayne@69: * string. jpayne@69: * @param args A variable arguments list. Contents are described by jpayne@69: * the fmt parameter. jpayne@69: * @see utrace_vformat jpayne@69: * @stable ICU 2.8 jpayne@69: */ jpayne@69: typedef void U_CALLCONV jpayne@69: UTraceExit(const void *context, int32_t fnNumber, jpayne@69: const char *fmt, va_list args); jpayne@69: jpayne@69: /** jpayne@69: * Type signature for the trace function to be called from within an ICU function jpayne@69: * to display data or messages. jpayne@69: * @param context value supplied at the time the trace functions are set. jpayne@69: * @param fnNumber Enum value indicating the ICU function being exited. jpayne@69: * @param level The current tracing level jpayne@69: * @param fmt A format string describing the tracing data that is supplied jpayne@69: * as variable args jpayne@69: * @param args The data being traced, passed as variable args. jpayne@69: * @stable ICU 2.8 jpayne@69: */ jpayne@69: typedef void U_CALLCONV jpayne@69: UTraceData(const void *context, int32_t fnNumber, int32_t level, jpayne@69: const char *fmt, va_list args); jpayne@69: jpayne@69: /** jpayne@69: * Set ICU Tracing functions. Installs application-provided tracing jpayne@69: * functions into ICU. After doing this, subsequent ICU operations jpayne@69: * will call back to the installed functions, providing a trace jpayne@69: * of the use of ICU. Passing a NULL pointer for a tracing function jpayne@69: * is allowed, and inhibits tracing action at points where that function jpayne@69: * would be called. jpayne@69: *

jpayne@69: * Tracing and Threads: Tracing functions are global to a process, and jpayne@69: * will be called in response to ICU operations performed by any jpayne@69: * thread. If tracing of an individual thread is desired, the jpayne@69: * tracing functions must themselves filter by checking that the jpayne@69: * current thread is the desired thread. jpayne@69: * jpayne@69: * @param context an uninterpreted pointer. Whatever is passed in jpayne@69: * here will in turn be passed to each of the tracing jpayne@69: * functions UTraceEntry, UTraceExit and UTraceData. jpayne@69: * ICU does not use or alter this pointer. jpayne@69: * @param e Callback function to be called on entry to a jpayne@69: * a traced ICU function. jpayne@69: * @param x Callback function to be called on exit from a jpayne@69: * traced ICU function. jpayne@69: * @param d Callback function to be called from within a jpayne@69: * traced ICU function, for the purpose of providing jpayne@69: * data to the trace. jpayne@69: * jpayne@69: * @stable ICU 2.8 jpayne@69: */ jpayne@69: U_STABLE void U_EXPORT2 jpayne@69: utrace_setFunctions(const void *context, jpayne@69: UTraceEntry *e, UTraceExit *x, UTraceData *d); jpayne@69: jpayne@69: /** jpayne@69: * Get the currently installed ICU tracing functions. Note that a null function jpayne@69: * pointer will be returned if no trace function has been set. jpayne@69: * jpayne@69: * @param context The currently installed tracing context. jpayne@69: * @param e The currently installed UTraceEntry function. jpayne@69: * @param x The currently installed UTraceExit function. jpayne@69: * @param d The currently installed UTraceData function. jpayne@69: * @stable ICU 2.8 jpayne@69: */ jpayne@69: U_STABLE void U_EXPORT2 jpayne@69: utrace_getFunctions(const void **context, jpayne@69: UTraceEntry **e, UTraceExit **x, UTraceData **d); jpayne@69: jpayne@69: jpayne@69: jpayne@69: /* jpayne@69: * jpayne@69: * ICU trace format string syntax jpayne@69: * jpayne@69: * Format Strings are passed to UTraceData functions, and define the jpayne@69: * number and types of the trace data being passed on each call. jpayne@69: * jpayne@69: * The UTraceData function, which is supplied by the application, jpayne@69: * not by ICU, can either forward the trace data (passed via jpayne@69: * varargs) and the format string back to ICU for formatting into jpayne@69: * a displayable string, or it can interpret the format itself, jpayne@69: * and do as it wishes with the trace data. jpayne@69: * jpayne@69: * jpayne@69: * Goals for the format string jpayne@69: * - basic data output jpayne@69: * - easy to use for trace programmer jpayne@69: * - sufficient provision for data types for trace output readability jpayne@69: * - well-defined types and binary portable APIs jpayne@69: * jpayne@69: * Non-goals jpayne@69: * - printf compatibility jpayne@69: * - fancy formatting jpayne@69: * - argument reordering and other internationalization features jpayne@69: * jpayne@69: * ICU trace format strings contain plain text with argument inserts, jpayne@69: * much like standard printf format strings. jpayne@69: * Each insert begins with a '%', then optionally contains a 'v', jpayne@69: * then exactly one type character. jpayne@69: * Two '%' in a row represent a '%' instead of an insert. jpayne@69: * The trace format strings need not have \n at the end. jpayne@69: * jpayne@69: * jpayne@69: * Types jpayne@69: * ----- jpayne@69: * jpayne@69: * Type characters: jpayne@69: * - c A char character in the default codepage. jpayne@69: * - s A NUL-terminated char * string in the default codepage. jpayne@69: * - S A UChar * string. Requires two params, (ptr, length). Length=-1 for nul term. jpayne@69: * - b A byte (8-bit integer). jpayne@69: * - h A 16-bit integer. Also a 16 bit Unicode code unit. jpayne@69: * - d A 32-bit integer. Also a 20 bit Unicode code point value. jpayne@69: * - l A 64-bit integer. jpayne@69: * - p A data pointer. jpayne@69: * jpayne@69: * Vectors jpayne@69: * ------- jpayne@69: * jpayne@69: * If the 'v' is not specified, then one item of the specified type jpayne@69: * is passed in. jpayne@69: * If the 'v' (for "vector") is specified, then a vector of items of the jpayne@69: * specified type is passed in, via a pointer to the first item jpayne@69: * and an int32_t value for the length of the vector. jpayne@69: * Length==-1 means zero or NUL termination. Works for vectors of all types. jpayne@69: * jpayne@69: * Note: %vS is a vector of (UChar *) strings. The strings must jpayne@69: * be nul terminated as there is no way to provide a jpayne@69: * separate length parameter for each string. The length jpayne@69: * parameter (required for all vectors) is the number of jpayne@69: * strings, not the length of the strings. jpayne@69: * jpayne@69: * Examples jpayne@69: * -------- jpayne@69: * jpayne@69: * These examples show the parameters that will be passed to an application's jpayne@69: * UTraceData() function for various formats. jpayne@69: * jpayne@69: * - the precise formatting is up to the application! jpayne@69: * - the examples use type casts for arguments only to _show_ the types of jpayne@69: * arguments without needing variable declarations in the examples; jpayne@69: * the type casts will not be necessary in actual code jpayne@69: * jpayne@69: * UTraceDataFunc(context, fnNumber, level, jpayne@69: * "There is a character %c in the string %s.", // Format String jpayne@69: * (char)c, (const char *)s); // varargs parameters jpayne@69: * -> There is a character 0x42 'B' in the string "Bravo". jpayne@69: * jpayne@69: * UTraceDataFunc(context, fnNumber, level, jpayne@69: * "Vector of bytes %vb vector of chars %vc", jpayne@69: * (const uint8_t *)bytes, (int32_t)bytesLength, jpayne@69: * (const char *)chars, (int32_t)charsLength); jpayne@69: * -> Vector of bytes jpayne@69: * 42 63 64 3f [4] jpayne@69: * vector of chars jpayne@69: * "Bcd?"[4] jpayne@69: * jpayne@69: * UTraceDataFunc(context, fnNumber, level, jpayne@69: * "An int32_t %d and a whole bunch of them %vd", jpayne@69: * (int32_t)-5, (const int32_t *)ints, (int32_t)intsLength); jpayne@69: * -> An int32_t 0xfffffffb and a whole bunch of them jpayne@69: * fffffffb 00000005 0000010a [3] jpayne@69: * jpayne@69: */ jpayne@69: jpayne@69: jpayne@69: jpayne@69: /** jpayne@69: * Trace output Formatter. An application's UTraceData tracing functions may call jpayne@69: * back to this function to format the trace output in a jpayne@69: * human readable form. Note that a UTraceData function may choose jpayne@69: * to not format the data; it could, for example, save it in jpayne@69: * in the raw form it was received (more compact), leaving jpayne@69: * formatting for a later trace analysis tool. jpayne@69: * @param outBuf pointer to a buffer to receive the formatted output. Output jpayne@69: * will be nul terminated if there is space in the buffer - jpayne@69: * if the length of the requested output < the output buffer size. jpayne@69: * @param capacity Length of the output buffer. jpayne@69: * @param indent Number of spaces to indent the output. Intended to allow jpayne@69: * data displayed from nested functions to be indented for readability. jpayne@69: * @param fmt Format specification for the data to output jpayne@69: * @param args Data to be formatted. jpayne@69: * @return Length of formatted output, including the terminating NUL. jpayne@69: * If buffer capacity is insufficient, the required capacity is returned. jpayne@69: * @stable ICU 2.8 jpayne@69: */ jpayne@69: U_STABLE int32_t U_EXPORT2 jpayne@69: utrace_vformat(char *outBuf, int32_t capacity, jpayne@69: int32_t indent, const char *fmt, va_list args); jpayne@69: jpayne@69: /** jpayne@69: * Trace output Formatter. An application's UTraceData tracing functions may call jpayne@69: * this function to format any additional trace data, beyond that jpayne@69: * provided by default, in human readable form with the same jpayne@69: * formatting conventions used by utrace_vformat(). jpayne@69: * @param outBuf pointer to a buffer to receive the formatted output. Output jpayne@69: * will be nul terminated if there is space in the buffer - jpayne@69: * if the length of the requested output < the output buffer size. jpayne@69: * @param capacity Length of the output buffer. jpayne@69: * @param indent Number of spaces to indent the output. Intended to allow jpayne@69: * data displayed from nested functions to be indented for readability. jpayne@69: * @param fmt Format specification for the data to output jpayne@69: * @param ... Data to be formatted. jpayne@69: * @return Length of formatted output, including the terminating NUL. jpayne@69: * If buffer capacity is insufficient, the required capacity is returned. jpayne@69: * @stable ICU 2.8 jpayne@69: */ jpayne@69: U_STABLE int32_t U_EXPORT2 jpayne@69: utrace_format(char *outBuf, int32_t capacity, jpayne@69: int32_t indent, const char *fmt, ...); jpayne@69: jpayne@69: jpayne@69: jpayne@69: /* Trace function numbers --------------------------------------------------- */ jpayne@69: jpayne@69: /** jpayne@69: * Get the name of a function from its trace function number. jpayne@69: * jpayne@69: * @param fnNumber The trace number for an ICU function. jpayne@69: * @return The name string for the function. jpayne@69: * jpayne@69: * @see UTraceFunctionNumber jpayne@69: * @stable ICU 2.8 jpayne@69: */ jpayne@69: U_STABLE const char * U_EXPORT2 jpayne@69: utrace_functionName(int32_t fnNumber); jpayne@69: jpayne@69: U_CDECL_END jpayne@69: jpayne@69: #endif