Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* |
michael@0 | 2 | ******************************************************************************* |
michael@0 | 3 | * |
michael@0 | 4 | * Copyright (C) 2003-2013, International Business Machines |
michael@0 | 5 | * Corporation and others. All Rights Reserved. |
michael@0 | 6 | * |
michael@0 | 7 | ******************************************************************************* |
michael@0 | 8 | * file name: utrace.h |
michael@0 | 9 | * encoding: US-ASCII |
michael@0 | 10 | * tab size: 8 (not used) |
michael@0 | 11 | * indentation:4 |
michael@0 | 12 | * |
michael@0 | 13 | * created on: 2003aug06 |
michael@0 | 14 | * created by: Markus W. Scherer |
michael@0 | 15 | * |
michael@0 | 16 | * Definitions for ICU tracing/logging. |
michael@0 | 17 | * |
michael@0 | 18 | */ |
michael@0 | 19 | |
michael@0 | 20 | #ifndef __UTRACE_H__ |
michael@0 | 21 | #define __UTRACE_H__ |
michael@0 | 22 | |
michael@0 | 23 | #include <stdarg.h> |
michael@0 | 24 | #include "unicode/utypes.h" |
michael@0 | 25 | |
michael@0 | 26 | /** |
michael@0 | 27 | * \file |
michael@0 | 28 | * \brief C API: Definitions for ICU tracing/logging. |
michael@0 | 29 | * |
michael@0 | 30 | * This provides API for debugging the internals of ICU without the use of |
michael@0 | 31 | * a traditional debugger. |
michael@0 | 32 | * |
michael@0 | 33 | * By default, tracing is disabled in ICU. If you need to debug ICU with |
michael@0 | 34 | * tracing, please compile ICU with the --enable-tracing configure option. |
michael@0 | 35 | */ |
michael@0 | 36 | |
michael@0 | 37 | U_CDECL_BEGIN |
michael@0 | 38 | |
michael@0 | 39 | /** |
michael@0 | 40 | * Trace severity levels. Higher levels increase the verbosity of the trace output. |
michael@0 | 41 | * @see utrace_setLevel |
michael@0 | 42 | * @stable ICU 2.8 |
michael@0 | 43 | */ |
michael@0 | 44 | typedef enum UTraceLevel { |
michael@0 | 45 | /** Disable all tracing @stable ICU 2.8*/ |
michael@0 | 46 | UTRACE_OFF=-1, |
michael@0 | 47 | /** Trace error conditions only @stable ICU 2.8*/ |
michael@0 | 48 | UTRACE_ERROR=0, |
michael@0 | 49 | /** Trace errors and warnings @stable ICU 2.8*/ |
michael@0 | 50 | UTRACE_WARNING=3, |
michael@0 | 51 | /** Trace opens and closes of ICU services @stable ICU 2.8*/ |
michael@0 | 52 | UTRACE_OPEN_CLOSE=5, |
michael@0 | 53 | /** Trace an intermediate number of ICU operations @stable ICU 2.8*/ |
michael@0 | 54 | UTRACE_INFO=7, |
michael@0 | 55 | /** Trace the maximum number of ICU operations @stable ICU 2.8*/ |
michael@0 | 56 | UTRACE_VERBOSE=9 |
michael@0 | 57 | } UTraceLevel; |
michael@0 | 58 | |
michael@0 | 59 | /** |
michael@0 | 60 | * These are the ICU functions that will be traced when tracing is enabled. |
michael@0 | 61 | * @stable ICU 2.8 |
michael@0 | 62 | */ |
michael@0 | 63 | typedef enum UTraceFunctionNumber { |
michael@0 | 64 | UTRACE_FUNCTION_START=0, |
michael@0 | 65 | UTRACE_U_INIT=UTRACE_FUNCTION_START, |
michael@0 | 66 | UTRACE_U_CLEANUP, |
michael@0 | 67 | UTRACE_FUNCTION_LIMIT, |
michael@0 | 68 | |
michael@0 | 69 | UTRACE_CONVERSION_START=0x1000, |
michael@0 | 70 | UTRACE_UCNV_OPEN=UTRACE_CONVERSION_START, |
michael@0 | 71 | UTRACE_UCNV_OPEN_PACKAGE, |
michael@0 | 72 | UTRACE_UCNV_OPEN_ALGORITHMIC, |
michael@0 | 73 | UTRACE_UCNV_CLONE, |
michael@0 | 74 | UTRACE_UCNV_CLOSE, |
michael@0 | 75 | UTRACE_UCNV_FLUSH_CACHE, |
michael@0 | 76 | UTRACE_UCNV_LOAD, |
michael@0 | 77 | UTRACE_UCNV_UNLOAD, |
michael@0 | 78 | UTRACE_CONVERSION_LIMIT, |
michael@0 | 79 | |
michael@0 | 80 | UTRACE_COLLATION_START=0x2000, |
michael@0 | 81 | UTRACE_UCOL_OPEN=UTRACE_COLLATION_START, |
michael@0 | 82 | UTRACE_UCOL_CLOSE, |
michael@0 | 83 | UTRACE_UCOL_STRCOLL, |
michael@0 | 84 | UTRACE_UCOL_GET_SORTKEY, |
michael@0 | 85 | UTRACE_UCOL_GETLOCALE, |
michael@0 | 86 | UTRACE_UCOL_NEXTSORTKEYPART, |
michael@0 | 87 | UTRACE_UCOL_STRCOLLITER, |
michael@0 | 88 | UTRACE_UCOL_OPEN_FROM_SHORT_STRING, |
michael@0 | 89 | UTRACE_UCOL_STRCOLLUTF8, /**< @stable ICU 50 */ |
michael@0 | 90 | UTRACE_COLLATION_LIMIT |
michael@0 | 91 | } UTraceFunctionNumber; |
michael@0 | 92 | |
michael@0 | 93 | /** |
michael@0 | 94 | * Setter for the trace level. |
michael@0 | 95 | * @param traceLevel A UTraceLevel value. |
michael@0 | 96 | * @stable ICU 2.8 |
michael@0 | 97 | */ |
michael@0 | 98 | U_STABLE void U_EXPORT2 |
michael@0 | 99 | utrace_setLevel(int32_t traceLevel); |
michael@0 | 100 | |
michael@0 | 101 | /** |
michael@0 | 102 | * Getter for the trace level. |
michael@0 | 103 | * @return The UTraceLevel value being used by ICU. |
michael@0 | 104 | * @stable ICU 2.8 |
michael@0 | 105 | */ |
michael@0 | 106 | U_STABLE int32_t U_EXPORT2 |
michael@0 | 107 | utrace_getLevel(void); |
michael@0 | 108 | |
michael@0 | 109 | /* Trace function pointers types ----------------------------- */ |
michael@0 | 110 | |
michael@0 | 111 | /** |
michael@0 | 112 | * Type signature for the trace function to be called when entering a function. |
michael@0 | 113 | * @param context value supplied at the time the trace functions are set. |
michael@0 | 114 | * @param fnNumber Enum value indicating the ICU function being entered. |
michael@0 | 115 | * @stable ICU 2.8 |
michael@0 | 116 | */ |
michael@0 | 117 | typedef void U_CALLCONV |
michael@0 | 118 | UTraceEntry(const void *context, int32_t fnNumber); |
michael@0 | 119 | |
michael@0 | 120 | /** |
michael@0 | 121 | * Type signature for the trace function to be called when exiting from a function. |
michael@0 | 122 | * @param context value supplied at the time the trace functions are set. |
michael@0 | 123 | * @param fnNumber Enum value indicating the ICU function being exited. |
michael@0 | 124 | * @param fmt A formatting string that describes the number and types |
michael@0 | 125 | * of arguments included with the variable args. The fmt |
michael@0 | 126 | * string has the same form as the utrace_vformat format |
michael@0 | 127 | * string. |
michael@0 | 128 | * @param args A variable arguments list. Contents are described by |
michael@0 | 129 | * the fmt parameter. |
michael@0 | 130 | * @see utrace_vformat |
michael@0 | 131 | * @stable ICU 2.8 |
michael@0 | 132 | */ |
michael@0 | 133 | typedef void U_CALLCONV |
michael@0 | 134 | UTraceExit(const void *context, int32_t fnNumber, |
michael@0 | 135 | const char *fmt, va_list args); |
michael@0 | 136 | |
michael@0 | 137 | /** |
michael@0 | 138 | * Type signature for the trace function to be called from within an ICU function |
michael@0 | 139 | * to display data or messages. |
michael@0 | 140 | * @param context value supplied at the time the trace functions are set. |
michael@0 | 141 | * @param fnNumber Enum value indicating the ICU function being exited. |
michael@0 | 142 | * @param level The current tracing level |
michael@0 | 143 | * @param fmt A format string describing the tracing data that is supplied |
michael@0 | 144 | * as variable args |
michael@0 | 145 | * @param args The data being traced, passed as variable args. |
michael@0 | 146 | * @stable ICU 2.8 |
michael@0 | 147 | */ |
michael@0 | 148 | typedef void U_CALLCONV |
michael@0 | 149 | UTraceData(const void *context, int32_t fnNumber, int32_t level, |
michael@0 | 150 | const char *fmt, va_list args); |
michael@0 | 151 | |
michael@0 | 152 | /** |
michael@0 | 153 | * Set ICU Tracing functions. Installs application-provided tracing |
michael@0 | 154 | * functions into ICU. After doing this, subsequent ICU operations |
michael@0 | 155 | * will call back to the installed functions, providing a trace |
michael@0 | 156 | * of the use of ICU. Passing a NULL pointer for a tracing function |
michael@0 | 157 | * is allowed, and inhibits tracing action at points where that function |
michael@0 | 158 | * would be called. |
michael@0 | 159 | * <p> |
michael@0 | 160 | * Tracing and Threads: Tracing functions are global to a process, and |
michael@0 | 161 | * will be called in response to ICU operations performed by any |
michael@0 | 162 | * thread. If tracing of an individual thread is desired, the |
michael@0 | 163 | * tracing functions must themselves filter by checking that the |
michael@0 | 164 | * current thread is the desired thread. |
michael@0 | 165 | * |
michael@0 | 166 | * @param context an uninterpretted pointer. Whatever is passed in |
michael@0 | 167 | * here will in turn be passed to each of the tracing |
michael@0 | 168 | * functions UTraceEntry, UTraceExit and UTraceData. |
michael@0 | 169 | * ICU does not use or alter this pointer. |
michael@0 | 170 | * @param e Callback function to be called on entry to a |
michael@0 | 171 | * a traced ICU function. |
michael@0 | 172 | * @param x Callback function to be called on exit from a |
michael@0 | 173 | * traced ICU function. |
michael@0 | 174 | * @param d Callback function to be called from within a |
michael@0 | 175 | * traced ICU function, for the purpose of providing |
michael@0 | 176 | * data to the trace. |
michael@0 | 177 | * |
michael@0 | 178 | * @stable ICU 2.8 |
michael@0 | 179 | */ |
michael@0 | 180 | U_STABLE void U_EXPORT2 |
michael@0 | 181 | utrace_setFunctions(const void *context, |
michael@0 | 182 | UTraceEntry *e, UTraceExit *x, UTraceData *d); |
michael@0 | 183 | |
michael@0 | 184 | /** |
michael@0 | 185 | * Get the currently installed ICU tracing functions. Note that a null function |
michael@0 | 186 | * pointer will be returned if no trace function has been set. |
michael@0 | 187 | * |
michael@0 | 188 | * @param context The currently installed tracing context. |
michael@0 | 189 | * @param e The currently installed UTraceEntry function. |
michael@0 | 190 | * @param x The currently installed UTraceExit function. |
michael@0 | 191 | * @param d The currently installed UTraceData function. |
michael@0 | 192 | * @stable ICU 2.8 |
michael@0 | 193 | */ |
michael@0 | 194 | U_STABLE void U_EXPORT2 |
michael@0 | 195 | utrace_getFunctions(const void **context, |
michael@0 | 196 | UTraceEntry **e, UTraceExit **x, UTraceData **d); |
michael@0 | 197 | |
michael@0 | 198 | |
michael@0 | 199 | |
michael@0 | 200 | /* |
michael@0 | 201 | * |
michael@0 | 202 | * ICU trace format string syntax |
michael@0 | 203 | * |
michael@0 | 204 | * Format Strings are passed to UTraceData functions, and define the |
michael@0 | 205 | * number and types of the trace data being passed on each call. |
michael@0 | 206 | * |
michael@0 | 207 | * The UTraceData function, which is supplied by the application, |
michael@0 | 208 | * not by ICU, can either forward the trace data (passed via |
michael@0 | 209 | * varargs) and the format string back to ICU for formatting into |
michael@0 | 210 | * a displayable string, or it can interpret the format itself, |
michael@0 | 211 | * and do as it wishes with the trace data. |
michael@0 | 212 | * |
michael@0 | 213 | * |
michael@0 | 214 | * Goals for the format string |
michael@0 | 215 | * - basic data output |
michael@0 | 216 | * - easy to use for trace programmer |
michael@0 | 217 | * - sufficient provision for data types for trace output readability |
michael@0 | 218 | * - well-defined types and binary portable APIs |
michael@0 | 219 | * |
michael@0 | 220 | * Non-goals |
michael@0 | 221 | * - printf compatibility |
michael@0 | 222 | * - fancy formatting |
michael@0 | 223 | * - argument reordering and other internationalization features |
michael@0 | 224 | * |
michael@0 | 225 | * ICU trace format strings contain plain text with argument inserts, |
michael@0 | 226 | * much like standard printf format strings. |
michael@0 | 227 | * Each insert begins with a '%', then optionally contains a 'v', |
michael@0 | 228 | * then exactly one type character. |
michael@0 | 229 | * Two '%' in a row represent a '%' instead of an insert. |
michael@0 | 230 | * The trace format strings need not have \n at the end. |
michael@0 | 231 | * |
michael@0 | 232 | * |
michael@0 | 233 | * Types |
michael@0 | 234 | * ----- |
michael@0 | 235 | * |
michael@0 | 236 | * Type characters: |
michael@0 | 237 | * - c A char character in the default codepage. |
michael@0 | 238 | * - s A NUL-terminated char * string in the default codepage. |
michael@0 | 239 | * - S A UChar * string. Requires two params, (ptr, length). Length=-1 for nul term. |
michael@0 | 240 | * - b A byte (8-bit integer). |
michael@0 | 241 | * - h A 16-bit integer. Also a 16 bit Unicode code unit. |
michael@0 | 242 | * - d A 32-bit integer. Also a 20 bit Unicode code point value. |
michael@0 | 243 | * - l A 64-bit integer. |
michael@0 | 244 | * - p A data pointer. |
michael@0 | 245 | * |
michael@0 | 246 | * Vectors |
michael@0 | 247 | * ------- |
michael@0 | 248 | * |
michael@0 | 249 | * If the 'v' is not specified, then one item of the specified type |
michael@0 | 250 | * is passed in. |
michael@0 | 251 | * If the 'v' (for "vector") is specified, then a vector of items of the |
michael@0 | 252 | * specified type is passed in, via a pointer to the first item |
michael@0 | 253 | * and an int32_t value for the length of the vector. |
michael@0 | 254 | * Length==-1 means zero or NUL termination. Works for vectors of all types. |
michael@0 | 255 | * |
michael@0 | 256 | * Note: %vS is a vector of (UChar *) strings. The strings must |
michael@0 | 257 | * be nul terminated as there is no way to provide a |
michael@0 | 258 | * separate length parameter for each string. The length |
michael@0 | 259 | * parameter (required for all vectors) is the number of |
michael@0 | 260 | * strings, not the length of the strings. |
michael@0 | 261 | * |
michael@0 | 262 | * Examples |
michael@0 | 263 | * -------- |
michael@0 | 264 | * |
michael@0 | 265 | * These examples show the parameters that will be passed to an application's |
michael@0 | 266 | * UTraceData() function for various formats. |
michael@0 | 267 | * |
michael@0 | 268 | * - the precise formatting is up to the application! |
michael@0 | 269 | * - the examples use type casts for arguments only to _show_ the types of |
michael@0 | 270 | * arguments without needing variable declarations in the examples; |
michael@0 | 271 | * the type casts will not be necessary in actual code |
michael@0 | 272 | * |
michael@0 | 273 | * UTraceDataFunc(context, fnNumber, level, |
michael@0 | 274 | * "There is a character %c in the string %s.", // Format String |
michael@0 | 275 | * (char)c, (const char *)s); // varargs parameters |
michael@0 | 276 | * -> There is a character 0x42 'B' in the string "Bravo". |
michael@0 | 277 | * |
michael@0 | 278 | * UTraceDataFunc(context, fnNumber, level, |
michael@0 | 279 | * "Vector of bytes %vb vector of chars %vc", |
michael@0 | 280 | * (const uint8_t *)bytes, (int32_t)bytesLength, |
michael@0 | 281 | * (const char *)chars, (int32_t)charsLength); |
michael@0 | 282 | * -> Vector of bytes |
michael@0 | 283 | * 42 63 64 3f [4] |
michael@0 | 284 | * vector of chars |
michael@0 | 285 | * "Bcd?"[4] |
michael@0 | 286 | * |
michael@0 | 287 | * UTraceDataFunc(context, fnNumber, level, |
michael@0 | 288 | * "An int32_t %d and a whole bunch of them %vd", |
michael@0 | 289 | * (int32_t)-5, (const int32_t *)ints, (int32_t)intsLength); |
michael@0 | 290 | * -> An int32_t 0xfffffffb and a whole bunch of them |
michael@0 | 291 | * fffffffb 00000005 0000010a [3] |
michael@0 | 292 | * |
michael@0 | 293 | */ |
michael@0 | 294 | |
michael@0 | 295 | |
michael@0 | 296 | |
michael@0 | 297 | /** |
michael@0 | 298 | * Trace output Formatter. An application's UTraceData tracing functions may call |
michael@0 | 299 | * back to this function to format the trace output in a |
michael@0 | 300 | * human readable form. Note that a UTraceData function may choose |
michael@0 | 301 | * to not format the data; it could, for example, save it in |
michael@0 | 302 | * in the raw form it was received (more compact), leaving |
michael@0 | 303 | * formatting for a later trace analyis tool. |
michael@0 | 304 | * @param outBuf pointer to a buffer to receive the formatted output. Output |
michael@0 | 305 | * will be nul terminated if there is space in the buffer - |
michael@0 | 306 | * if the length of the requested output < the output buffer size. |
michael@0 | 307 | * @param capacity Length of the output buffer. |
michael@0 | 308 | * @param indent Number of spaces to indent the output. Intended to allow |
michael@0 | 309 | * data displayed from nested functions to be indented for readability. |
michael@0 | 310 | * @param fmt Format specification for the data to output |
michael@0 | 311 | * @param args Data to be formatted. |
michael@0 | 312 | * @return Length of formatted output, including the terminating NUL. |
michael@0 | 313 | * If buffer capacity is insufficient, the required capacity is returned. |
michael@0 | 314 | * @stable ICU 2.8 |
michael@0 | 315 | */ |
michael@0 | 316 | U_STABLE int32_t U_EXPORT2 |
michael@0 | 317 | utrace_vformat(char *outBuf, int32_t capacity, |
michael@0 | 318 | int32_t indent, const char *fmt, va_list args); |
michael@0 | 319 | |
michael@0 | 320 | /** |
michael@0 | 321 | * Trace output Formatter. An application's UTraceData tracing functions may call |
michael@0 | 322 | * this function to format any additional trace data, beyond that |
michael@0 | 323 | * provided by default, in human readable form with the same |
michael@0 | 324 | * formatting conventions used by utrace_vformat(). |
michael@0 | 325 | * @param outBuf pointer to a buffer to receive the formatted output. Output |
michael@0 | 326 | * will be nul terminated if there is space in the buffer - |
michael@0 | 327 | * if the length of the requested output < the output buffer size. |
michael@0 | 328 | * @param capacity Length of the output buffer. |
michael@0 | 329 | * @param indent Number of spaces to indent the output. Intended to allow |
michael@0 | 330 | * data displayed from nested functions to be indented for readability. |
michael@0 | 331 | * @param fmt Format specification for the data to output |
michael@0 | 332 | * @param ... Data to be formatted. |
michael@0 | 333 | * @return Length of formatted output, including the terminating NUL. |
michael@0 | 334 | * If buffer capacity is insufficient, the required capacity is returned. |
michael@0 | 335 | * @stable ICU 2.8 |
michael@0 | 336 | */ |
michael@0 | 337 | U_STABLE int32_t U_EXPORT2 |
michael@0 | 338 | utrace_format(char *outBuf, int32_t capacity, |
michael@0 | 339 | int32_t indent, const char *fmt, ...); |
michael@0 | 340 | |
michael@0 | 341 | |
michael@0 | 342 | |
michael@0 | 343 | /* Trace function numbers --------------------------------------------------- */ |
michael@0 | 344 | |
michael@0 | 345 | /** |
michael@0 | 346 | * Get the name of a function from its trace function number. |
michael@0 | 347 | * |
michael@0 | 348 | * @param fnNumber The trace number for an ICU function. |
michael@0 | 349 | * @return The name string for the function. |
michael@0 | 350 | * |
michael@0 | 351 | * @see UTraceFunctionNumber |
michael@0 | 352 | * @stable ICU 2.8 |
michael@0 | 353 | */ |
michael@0 | 354 | U_STABLE const char * U_EXPORT2 |
michael@0 | 355 | utrace_functionName(int32_t fnNumber); |
michael@0 | 356 | |
michael@0 | 357 | U_CDECL_END |
michael@0 | 358 | |
michael@0 | 359 | #endif |