utrace.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506
  1. // © 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: UTF-8
  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. /**
  104. * The lowest resource/data location.
  105. * @stable ICU 65
  106. */
  107. UTRACE_UDATA_START=0x3000,
  108. /**
  109. * Indicates that a value was read from a resource bundle. Provides three
  110. * C-style strings to UTraceData: type, file name, and resource path. The
  111. * possible types are:
  112. *
  113. * - "string" (a string value was accessed)
  114. * - "binary" (a binary value was accessed)
  115. * - "intvector" (a integer vector value was accessed)
  116. * - "int" (a signed integer value was accessed)
  117. * - "uint" (a unsigned integer value was accessed)
  118. * - "get" (a path was loaded, but the value was not accessed)
  119. * - "getalias" (a path was loaded, and an alias was resolved)
  120. *
  121. * @stable ICU 65
  122. */
  123. UTRACE_UDATA_RESOURCE=UTRACE_UDATA_START,
  124. /**
  125. * Indicates that a resource bundle was opened.
  126. *
  127. * Provides one C-style string to UTraceData: file name.
  128. * @stable ICU 65
  129. */
  130. UTRACE_UDATA_BUNDLE,
  131. /**
  132. * Indicates that a data file was opened, but not *.res files.
  133. *
  134. * Provides one C-style string to UTraceData: file name.
  135. *
  136. * @stable ICU 65
  137. */
  138. UTRACE_UDATA_DATA_FILE,
  139. /**
  140. * Indicates that a *.res file was opened.
  141. *
  142. * This differs from UTRACE_UDATA_BUNDLE because a res file is typically
  143. * opened only once per application runtime, but the bundle corresponding
  144. * to that res file may be opened many times.
  145. *
  146. * Provides one C-style string to UTraceData: file name.
  147. *
  148. * @stable ICU 65
  149. */
  150. UTRACE_UDATA_RES_FILE,
  151. #ifndef U_HIDE_INTERNAL_API
  152. /**
  153. * One more than the highest normal resource/data trace location.
  154. * @internal The numeric value may change over time, see ICU ticket #12420.
  155. */
  156. UTRACE_RES_DATA_LIMIT,
  157. #endif // U_HIDE_INTERNAL_API
  158. /**
  159. * The lowest break iterator location.
  160. * @stable ICU 67
  161. */
  162. UTRACE_UBRK_START=0x4000,
  163. /**
  164. * Indicates that a character instance of break iterator was created.
  165. *
  166. * @stable ICU 67
  167. */
  168. UTRACE_UBRK_CREATE_CHARACTER = UTRACE_UBRK_START,
  169. /**
  170. * Indicates that a word instance of break iterator was created.
  171. *
  172. * @stable ICU 67
  173. */
  174. UTRACE_UBRK_CREATE_WORD,
  175. /**
  176. * Indicates that a line instance of break iterator was created.
  177. *
  178. * Provides one C-style string to UTraceData: the lb value ("",
  179. * "loose", "strict", or "normal").
  180. *
  181. * @stable ICU 67
  182. */
  183. UTRACE_UBRK_CREATE_LINE,
  184. /**
  185. * Indicates that a sentence instance of break iterator was created.
  186. *
  187. * @stable ICU 67
  188. */
  189. UTRACE_UBRK_CREATE_SENTENCE,
  190. /**
  191. * Indicates that a title instance of break iterator was created.
  192. *
  193. * @stable ICU 67
  194. */
  195. UTRACE_UBRK_CREATE_TITLE,
  196. /**
  197. * Indicates that an internal dictionary break engine was created.
  198. *
  199. * Provides one C-style string to UTraceData: the script code of what
  200. * the break engine cover ("Hani", "Khmr", "Laoo", "Mymr", or "Thai").
  201. *
  202. * @stable ICU 67
  203. */
  204. UTRACE_UBRK_CREATE_BREAK_ENGINE,
  205. #ifndef U_HIDE_INTERNAL_API
  206. /**
  207. * One more than the highest normal break iterator trace location.
  208. * @internal The numeric value may change over time, see ICU ticket #12420.
  209. */
  210. UTRACE_UBRK_LIMIT,
  211. #endif // U_HIDE_INTERNAL_API
  212. } UTraceFunctionNumber;
  213. /**
  214. * Setter for the trace level.
  215. * @param traceLevel A UTraceLevel value.
  216. * @stable ICU 2.8
  217. */
  218. U_CAPI void U_EXPORT2
  219. utrace_setLevel(int32_t traceLevel);
  220. /**
  221. * Getter for the trace level.
  222. * @return The UTraceLevel value being used by ICU.
  223. * @stable ICU 2.8
  224. */
  225. U_CAPI int32_t U_EXPORT2
  226. utrace_getLevel(void);
  227. /* Trace function pointers types ----------------------------- */
  228. /**
  229. * Type signature for the trace function to be called when entering a function.
  230. * @param context value supplied at the time the trace functions are set.
  231. * @param fnNumber Enum value indicating the ICU function being entered.
  232. * @stable ICU 2.8
  233. */
  234. typedef void U_CALLCONV
  235. UTraceEntry(const void *context, int32_t fnNumber);
  236. /**
  237. * Type signature for the trace function to be called when exiting from a function.
  238. * @param context value supplied at the time the trace functions are set.
  239. * @param fnNumber Enum value indicating the ICU function being exited.
  240. * @param fmt A formatting string that describes the number and types
  241. * of arguments included with the variable args. The fmt
  242. * string has the same form as the utrace_vformat format
  243. * string.
  244. * @param args A variable arguments list. Contents are described by
  245. * the fmt parameter.
  246. * @see utrace_vformat
  247. * @stable ICU 2.8
  248. */
  249. typedef void U_CALLCONV
  250. UTraceExit(const void *context, int32_t fnNumber,
  251. const char *fmt, va_list args);
  252. /**
  253. * Type signature for the trace function to be called from within an ICU function
  254. * to display data or messages.
  255. * @param context value supplied at the time the trace functions are set.
  256. * @param fnNumber Enum value indicating the ICU function being exited.
  257. * @param level The current tracing level
  258. * @param fmt A format string describing the tracing data that is supplied
  259. * as variable args
  260. * @param args The data being traced, passed as variable args.
  261. * @stable ICU 2.8
  262. */
  263. typedef void U_CALLCONV
  264. UTraceData(const void *context, int32_t fnNumber, int32_t level,
  265. const char *fmt, va_list args);
  266. /**
  267. * Set ICU Tracing functions. Installs application-provided tracing
  268. * functions into ICU. After doing this, subsequent ICU operations
  269. * will call back to the installed functions, providing a trace
  270. * of the use of ICU. Passing a NULL pointer for a tracing function
  271. * is allowed, and inhibits tracing action at points where that function
  272. * would be called.
  273. * <p>
  274. * Tracing and Threads: Tracing functions are global to a process, and
  275. * will be called in response to ICU operations performed by any
  276. * thread. If tracing of an individual thread is desired, the
  277. * tracing functions must themselves filter by checking that the
  278. * current thread is the desired thread.
  279. *
  280. * @param context an uninterpreted pointer. Whatever is passed in
  281. * here will in turn be passed to each of the tracing
  282. * functions UTraceEntry, UTraceExit and UTraceData.
  283. * ICU does not use or alter this pointer.
  284. * @param e Callback function to be called on entry to a
  285. * a traced ICU function.
  286. * @param x Callback function to be called on exit from a
  287. * traced ICU function.
  288. * @param d Callback function to be called from within a
  289. * traced ICU function, for the purpose of providing
  290. * data to the trace.
  291. *
  292. * @stable ICU 2.8
  293. */
  294. U_CAPI void U_EXPORT2
  295. utrace_setFunctions(const void *context,
  296. UTraceEntry *e, UTraceExit *x, UTraceData *d);
  297. /**
  298. * Get the currently installed ICU tracing functions. Note that a null function
  299. * pointer will be returned if no trace function has been set.
  300. *
  301. * @param context The currently installed tracing context.
  302. * @param e The currently installed UTraceEntry function.
  303. * @param x The currently installed UTraceExit function.
  304. * @param d The currently installed UTraceData function.
  305. * @stable ICU 2.8
  306. */
  307. U_CAPI void U_EXPORT2
  308. utrace_getFunctions(const void **context,
  309. UTraceEntry **e, UTraceExit **x, UTraceData **d);
  310. /*
  311. *
  312. * ICU trace format string syntax
  313. *
  314. * Format Strings are passed to UTraceData functions, and define the
  315. * number and types of the trace data being passed on each call.
  316. *
  317. * The UTraceData function, which is supplied by the application,
  318. * not by ICU, can either forward the trace data (passed via
  319. * varargs) and the format string back to ICU for formatting into
  320. * a displayable string, or it can interpret the format itself,
  321. * and do as it wishes with the trace data.
  322. *
  323. *
  324. * Goals for the format string
  325. * - basic data output
  326. * - easy to use for trace programmer
  327. * - sufficient provision for data types for trace output readability
  328. * - well-defined types and binary portable APIs
  329. *
  330. * Non-goals
  331. * - printf compatibility
  332. * - fancy formatting
  333. * - argument reordering and other internationalization features
  334. *
  335. * ICU trace format strings contain plain text with argument inserts,
  336. * much like standard printf format strings.
  337. * Each insert begins with a '%', then optionally contains a 'v',
  338. * then exactly one type character.
  339. * Two '%' in a row represent a '%' instead of an insert.
  340. * The trace format strings need not have \n at the end.
  341. *
  342. *
  343. * Types
  344. * -----
  345. *
  346. * Type characters:
  347. * - c A char character in the default codepage.
  348. * - s A NUL-terminated char * string in the default codepage.
  349. * - S A UChar * string. Requires two params, (ptr, length). Length=-1 for nul term.
  350. * - b A byte (8-bit integer).
  351. * - h A 16-bit integer. Also a 16 bit Unicode code unit.
  352. * - d A 32-bit integer. Also a 20 bit Unicode code point value.
  353. * - l A 64-bit integer.
  354. * - p A data pointer.
  355. *
  356. * Vectors
  357. * -------
  358. *
  359. * If the 'v' is not specified, then one item of the specified type
  360. * is passed in.
  361. * If the 'v' (for "vector") is specified, then a vector of items of the
  362. * specified type is passed in, via a pointer to the first item
  363. * and an int32_t value for the length of the vector.
  364. * Length==-1 means zero or NUL termination. Works for vectors of all types.
  365. *
  366. * Note: %vS is a vector of (UChar *) strings. The strings must
  367. * be nul terminated as there is no way to provide a
  368. * separate length parameter for each string. The length
  369. * parameter (required for all vectors) is the number of
  370. * strings, not the length of the strings.
  371. *
  372. * Examples
  373. * --------
  374. *
  375. * These examples show the parameters that will be passed to an application's
  376. * UTraceData() function for various formats.
  377. *
  378. * - the precise formatting is up to the application!
  379. * - the examples use type casts for arguments only to _show_ the types of
  380. * arguments without needing variable declarations in the examples;
  381. * the type casts will not be necessary in actual code
  382. *
  383. * UTraceDataFunc(context, fnNumber, level,
  384. * "There is a character %c in the string %s.", // Format String
  385. * (char)c, (const char *)s); // varargs parameters
  386. * -> There is a character 0x42 'B' in the string "Bravo".
  387. *
  388. * UTraceDataFunc(context, fnNumber, level,
  389. * "Vector of bytes %vb vector of chars %vc",
  390. * (const uint8_t *)bytes, (int32_t)bytesLength,
  391. * (const char *)chars, (int32_t)charsLength);
  392. * -> Vector of bytes
  393. * 42 63 64 3f [4]
  394. * vector of chars
  395. * "Bcd?"[4]
  396. *
  397. * UTraceDataFunc(context, fnNumber, level,
  398. * "An int32_t %d and a whole bunch of them %vd",
  399. * (int32_t)-5, (const int32_t *)ints, (int32_t)intsLength);
  400. * -> An int32_t 0xfffffffb and a whole bunch of them
  401. * fffffffb 00000005 0000010a [3]
  402. *
  403. */
  404. /**
  405. * Trace output Formatter. An application's UTraceData tracing functions may call
  406. * back to this function to format the trace output in a
  407. * human readable form. Note that a UTraceData function may choose
  408. * to not format the data; it could, for example, save it in
  409. * in the raw form it was received (more compact), leaving
  410. * formatting for a later trace analysis tool.
  411. * @param outBuf pointer to a buffer to receive the formatted output. Output
  412. * will be nul terminated if there is space in the buffer -
  413. * if the length of the requested output < the output buffer size.
  414. * @param capacity Length of the output buffer.
  415. * @param indent Number of spaces to indent the output. Intended to allow
  416. * data displayed from nested functions to be indented for readability.
  417. * @param fmt Format specification for the data to output
  418. * @param args Data to be formatted.
  419. * @return Length of formatted output, including the terminating NUL.
  420. * If buffer capacity is insufficient, the required capacity is returned.
  421. * @stable ICU 2.8
  422. */
  423. U_CAPI int32_t U_EXPORT2
  424. utrace_vformat(char *outBuf, int32_t capacity,
  425. int32_t indent, const char *fmt, va_list args);
  426. /**
  427. * Trace output Formatter. An application's UTraceData tracing functions may call
  428. * this function to format any additional trace data, beyond that
  429. * provided by default, in human readable form with the same
  430. * formatting conventions used by utrace_vformat().
  431. * @param outBuf pointer to a buffer to receive the formatted output. Output
  432. * will be nul terminated if there is space in the buffer -
  433. * if the length of the requested output < the output buffer size.
  434. * @param capacity Length of the output buffer.
  435. * @param indent Number of spaces to indent the output. Intended to allow
  436. * data displayed from nested functions to be indented for readability.
  437. * @param fmt Format specification for the data to output
  438. * @param ... Data to be formatted.
  439. * @return Length of formatted output, including the terminating NUL.
  440. * If buffer capacity is insufficient, the required capacity is returned.
  441. * @stable ICU 2.8
  442. */
  443. U_CAPI int32_t U_EXPORT2
  444. utrace_format(char *outBuf, int32_t capacity,
  445. int32_t indent, const char *fmt, ...);
  446. /* Trace function numbers --------------------------------------------------- */
  447. /**
  448. * Get the name of a function from its trace function number.
  449. *
  450. * @param fnNumber The trace number for an ICU function.
  451. * @return The name string for the function.
  452. *
  453. * @see UTraceFunctionNumber
  454. * @stable ICU 2.8
  455. */
  456. U_CAPI const char * U_EXPORT2
  457. utrace_functionName(int32_t fnNumber);
  458. U_CDECL_END
  459. #endif