utrace.h 17 KB

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