utrace.h 14 KB

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