🛠️🐜 Antkeeper superbuild with dependencies included https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

310 lines
11 KiB

2 years ago
  1. Debugging within the FreeType sources
  2. =====================================
  3. I. Configuration macros
  4. -----------------------
  5. There are several ways to enable debugging features in a FreeType 2
  6. builds. This is controlled through the definition of special macros
  7. located in the file `ftoption.h'. The macros are:
  8. FT_DEBUG_LEVEL_ERROR
  9. #define this macro if you want to compile the `FT_ERROR' macro
  10. calls to print error messages during program execution. This does
  11. not stop the program. Very useful to spot invalid fonts during
  12. development and to code workarounds for them.
  13. FT_DEBUG_LEVEL_TRACE
  14. #define this macro if you want to compile both macros `FT_ERROR'
  15. and `FT_TRACE'. This also includes the variants `FT_TRACE0',
  16. `FT_TRACE1', `FT_TRACE2', ..., `FT_TRACE7'.
  17. The trace macros are used to send debugging messages when an
  18. appropriate `debug level' is configured at runtime through the
  19. `FT2_DEBUG' environment variable (more on this later).
  20. FT_DEBUG_MEMORY
  21. If this macro is #defined, the FreeType engine is linked with a
  22. small but effective debugging memory manager that tracks all
  23. allocations and frees that are performed within the font engine.
  24. When the `FT2_DEBUG_MEMORY' environment variable is defined at
  25. runtime, a call to `FT_Done_FreeType' dumps memory statistics,
  26. including the list of leaked memory blocks and optionally with the
  27. source locations where these were allocated. It is always a very
  28. good idea to define this in development builds. This works with
  29. _any_ program linked to FreeType, but requires a big deal of
  30. memory (the debugging memory manager never frees the blocks to the
  31. heap in order to detect double frees).
  32. When `FT2_DEBUG_MEMORY' isn't defined at runtime, the debugging
  33. memory manager is ignored, and performance is unaffected.
  34. FT_DEBUG_LOGGING
  35. #define this macro for enhanced logging support; it automatically
  36. sets `FT_DEBUG_LEVEL_TRACE' and `FT_DEBUG_LEVEL_ERROR'.
  37. If defined, `FT_TRACE' and `FT_ERROR' can send tracing and
  38. debugging messages to a file. The location of the log file has to
  39. be set with the `FT_LOGGING_FILE' environment variable (more on
  40. this later).
  41. The main enhancements are the possibility of logging the time and
  42. the name of the `FT_COMPONENT' macro together with the affected
  43. `FT_TRACE' or `FT_ERROR' calls. See below how to activate this in
  44. the `FT2_DEBUG' environment variable.
  45. II. Debugging macros
  46. --------------------
  47. Several macros can be used within the FreeType sources to help
  48. debugging its code:
  49. 1. FT_ERROR(( ... ))
  50. This macro is used to send debug messages that indicate relatively
  51. serious errors (like broken font files) without stopping the
  52. execution of the running program. Its code is compiled only when
  53. either `FT_DEBUG_LEVEL_ERROR' or `FT_DEBUG_LEVEL_TRACE' are
  54. defined in `ftoption.h'.
  55. Note that you have to use a printf-like signature, but with double
  56. parentheses, like in
  57. FT_ERROR(( "your %s is not %s\n", "foo", "bar" ));
  58. 2. FT_ASSERT( condition )
  59. This macro is used to check strong assertions at runtime. If its
  60. condition isn't TRUE, the program aborts with a panic message.
  61. Its code is compiled when either `FT_DEBUG_LEVEL_ERROR' or
  62. `FT_DEBUG_LEVEL_TRACE' are defined. You don't need double
  63. parentheses here. Example:
  64. FT_ASSERT( ptr != NULL );
  65. 3. FT_TRACE( level, (message...) )
  66. The `FT_TRACE' macro is used to send general-purpose debugging
  67. messages during program execution. This macro uses an *implicit*
  68. macro named `FT_COMPONENT', which names the current FreeType
  69. component being run.
  70. The developer should always define `FT_COMPONENT' as appropriate,
  71. for example as in
  72. #undef FT_COMPONENT
  73. #define FT_COMPONENT io
  74. The value of the `FT_COMPONENT' macro is one of the component
  75. names defined in the internal file `internal/fttrace.h'. If you
  76. modify the FreeType source code and insert a new `FT_COMPONENT'
  77. macro, you must register it in `fttrace.h'. If you insert or
  78. remove many trace macros, you can test for undefined or unused
  79. trace macros with the script `src/tools/chktrcmp.py'.
  80. Each such component is assigned a `debug level', ranging from
  81. value 0 to 7, through the use of the `FT2_DEBUG' environment
  82. variable (described below) when a program linked with FreeType
  83. starts.
  84. When `FT_TRACE' is called, its level is compared to the one of the
  85. corresponding component. Messages with trace levels *higher* than
  86. the corresponding component level are filtered out and never
  87. printed. This means that trace messages with level 0 are always
  88. printed, those with level 2 are only printed when the component
  89. level is *at least* 2, etc.
  90. The second parameter to `FT_TRACE' must contain parentheses and
  91. corresponds to a printf-like call, as in
  92. FT_TRACE( 2, ( "your %s is not %s\n", "foo", "bar" ) )
  93. The shortcut macros `FT_TRACE0', `FT_TRACE1', `FT_TRACE2', ...,
  94. `FT_TRACE7' can be used with constant level indices, and are much
  95. cleaner to use, as in
  96. FT_TRACE2(( "your %s is not %s\n", "foo", "bar" ));
  97. III. Environment variables
  98. --------------------------
  99. The following environment variables control debugging output and
  100. behaviour of FreeType at runtime.
  101. FT2_DEBUG
  102. This variable is only used when FreeType is built with
  103. `FT_DEBUG_LEVEL_TRACE' defined. It contains a list of component
  104. level definitions, following this format:
  105. component1:level1 component2:level2 component3:level3 ...
  106. where `componentX' is the name of a tracing component, as defined
  107. in `fttrace.h'. `levelX' is the corresponding level to use at
  108. runtime.
  109. `any' is a special component name that is interpreted as `any/all
  110. components'. For example, the following definitions
  111. set FT2_DEBUG=any:2 memory:5 io:4 (on Windows)
  112. export FT2_DEBUG="any:2 memory:5 io:4" (on Linux with bash)
  113. both stipulate that all components should have level 2, except for
  114. the memory and io components, which are set to the trace levels 5
  115. and 4, respectively.
  116. If `FT_DEBUG_LOGGING' is defined, two more options are available.
  117. * -v: Print also the name of FreeType's component from which the
  118. current log is produced, together with the tracing level.
  119. * -t: Print also the time.
  120. Here are some examples how the output might look like.
  121. FT2_DEBUG="any:7 memory:5 -vt"
  122. => [20:32:02:44969 ttload:2] table directory loaded
  123. FT2_DEBUG="any:7 memory:5 -t"
  124. => [20:32:02:44969] table directory loaded
  125. FT2_DEBUG="any:7 memory:5 -v"
  126. => [ttload:2] table directory loaded
  127. FT_LOGGING_FILE
  128. This variable is only used if FreeType is built with the
  129. `FT_DEBUG_LOGGING' macro defined. It contains the path to the
  130. file where the user wants to put his log file. If it is not set,
  131. FreeType uses stderr.
  132. Examples:
  133. On UNIX-like systems with bash:
  134. export FT_LOGGING_FILE="/tmp/freetype2.log"
  135. On Windows:
  136. set FT_LOGGING_FILE=C:\Users\AppData\Local\Temp\freetype2.log
  137. FT2_DEBUG_MEMORY
  138. This environment variable, when defined, tells FreeType to use a
  139. debugging memory manager that tracks leaking memory blocks as well
  140. as other common errors like double frees. It is also capable of
  141. reporting _where_ the leaking blocks were allocated, which
  142. considerably saves time when debugging new additions to the
  143. library.
  144. This code is only compiled when FreeType is built with the
  145. `FT_DEBUG_MEMORY' macro #defined in `ftoption.h' though, it is
  146. ignored in other builds.
  147. FT2_ALLOC_TOTAL_MAX
  148. This variable is ignored if `FT2_DEBUG_MEMORY' is not defined. It
  149. allows you to specify a maximum heap size for all memory
  150. allocations performed by FreeType. This is very useful to test
  151. the robustness of the font engine and programs that use it in
  152. tight memory conditions.
  153. If it is undefined, or if its value is not strictly positive, no
  154. allocation bounds are checked at runtime.
  155. FT2_ALLOC_COUNT_MAX
  156. This variable is ignored if `FT2_DEBUG_MEMORY' is not defined. It
  157. allows you to specify a maximum number of memory allocations
  158. performed by FreeType before returning the error
  159. `FT_Err_Out_Of_Memory'. This is useful for debugging and testing
  160. the engine's robustness.
  161. If it is undefined, or if its value is not strictly positive, no
  162. allocation bounds are checked at runtime.
  163. FT2_KEEP_ALIVE
  164. This variable is ignored if `FT2_DEBUG_MEMORY' is not defined.
  165. `Keep alive' means that freed blocks aren't released to the heap.
  166. This is useful to detect double-frees or weird heap corruption,
  167. reporting the source code location of the original allocation and
  168. deallocation in case of a problem. It uses large amounts of
  169. memory, however.
  170. If it is undefined, or if its value is not strictly positive,
  171. freed blocks are released at runtime.
  172. IV. Additional Capabilities with `FT_DEBUG_LOGGING'
  173. ---------------------------------------------------
  174. If `FT_DEBUG_LOGGING' is defined, four APIs are available to provide
  175. additional debugging support. Use
  176. #include <freetype/ftlogging.h>
  177. to access them.
  178. FT_Trace_Set_Level( const char* level )
  179. By default, FreeType uses the tracing levels set in the
  180. `FT2_DEBUG' environment variable. Use this function to override
  181. the value with `level'. Use value `NULL' to disable tracing.
  182. FT_Trace_Set_Default_Level():
  183. Reset the tracing levels to the default value, i.e., the value of
  184. the `FT2_DEBUG' environment variable or no tracing if not set.
  185. FT_Set_Log_Handler( ft_custom_log_handler handler ):
  186. Use `handler' as a custom handler for formatting tracing and error
  187. messages. The `ft_custom_log_handler' typedef has the following
  188. prototype.
  189. void
  190. (*ft_custom_log_handler)( const char* ft_component,
  191. const char* fmt,
  192. va_list args );
  193. `ft_component' is the current component like `ttload', `fmt' is the
  194. first argument of `FT_TRACE' or `FT_ERROR', and `args' holds the
  195. remaining arguments.
  196. FT_Set_Default_Log_Handler():
  197. Reset the log handler to the default version.
  198. ------------------------------------------------------------------------
  199. Copyright (C) 2002-2022 by
  200. David Turner, Robert Wilhelm, and Werner Lemberg.
  201. This file is part of the FreeType project, and may only be used,
  202. modified, and distributed under the terms of the FreeType project
  203. license, LICENSE.TXT. By continuing to use, modify, or distribute this
  204. file you indicate that you have read the license and understand and
  205. accept it fully.
  206. --- end of DEBUG ---