DEBUG 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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 calls
  10. to print error messages during program execution. This will not
  11. 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 and
  15. FT_TRACE. This also includes the variants FT_TRACE0, FT_TRACE1,
  16. 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 will dump memory statistics,
  26. including the list of leaked memory blocks with the source
  27. locations where these were allocated. It is always a very good
  28. idea to define this in development builds. This works with _any_
  29. program linked to FreeType, but requires a big deal of memory (the
  30. debugging memory manager never frees the blocks to the heap in
  31. 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. II. Debugging macros
  35. --------------------
  36. Several macros can be used within the FreeType sources to help
  37. debugging its code:
  38. 1. FT_ERROR(( ... ))
  39. This macro is used to send debug messages that indicate relatively
  40. serious errors (like broken font files), but will not stop the
  41. execution of the running program. Its code is compiled only when
  42. either FT_DEBUG_LEVEL_ERROR or FT_DEBUG_LEVEL_TRACE are defined in
  43. `ftoption.h'.
  44. Note that you have to use a printf-like signature, but with double
  45. parentheses, like in
  46. FT_ERROR(( "your %s is not %s\n", "foo", "bar" ));
  47. 2. FT_ASSERT( condition )
  48. This macro is used to check strong assertions at runtime. If its
  49. condition isn't TRUE, the program will abort with a panic message.
  50. Its code is compiled when either FT_DEBUG_LEVEL_ERROR or
  51. FT_DEBUG_LEVEL_TRACE are defined. You don't need double
  52. parentheses here. For example
  53. FT_ASSERT( ptr != NULL );
  54. 3. FT_TRACE( level, (message...) )
  55. The FT_TRACE macro is used to send general-purpose debugging
  56. messages during program execution. This macro uses an *implicit*
  57. macro named FT_COMPONENT used to name the current FreeType
  58. component being run.
  59. The developer should always define FT_COMPONENT as appropriate,
  60. for example as in
  61. #undef FT_COMPONENT
  62. #define FT_COMPONENT trace_io
  63. The value of the FT_COMPONENT macro is an enumeration named
  64. `trace_XXXX' where `XXXX' is one of the component names defined in
  65. the internal file `internal/fttrace.h'. If you modify FreeType
  66. source and insert new `trace_XXXX' macro, you must register it in
  67. `fttrace.h'. If you insert or remove many trace macros, you can
  68. check the undefined or the unused trace macro by
  69. `src/tools/chktrcmp.py'.
  70. Each such component is assigned a `debug level', ranging from 0 to
  71. 7, through the use of the FT2_DEBUG environment variable
  72. (described below) when a program linked with FreeType starts.
  73. When FT_TRACE is called, its level is compared to the one of the
  74. corresponding component. Messages with trace levels *higher* than
  75. the corresponding component level are filtered and never printed.
  76. This means that trace messages with level 0 are always printed,
  77. those with level 2 are only printed when the component level is
  78. *at least* 2.
  79. The second parameter to FT_TRACE must contain parentheses and
  80. correspond to a printf-like call, as in
  81. FT_TRACE( 2, ( "your %s is not %s\n", "foo", "bar" ) )
  82. The shortcut macros FT_TRACE0, FT_TRACE1, FT_TRACE2, ...,
  83. FT_TRACE7 can be used with constant level indices, and are much
  84. cleaner to use, as in
  85. FT_TRACE2(( "your %s is not %s\n", "foo", "bar" ));
  86. III. Environment variables
  87. --------------------------
  88. The following environment variables control debugging output and
  89. behaviour of FreeType at runtime.
  90. FT2_DEBUG
  91. This variable is only used when FreeType is built with
  92. FT_DEBUG_LEVEL_TRACE defined. It contains a list of component
  93. level definitions, following this format:
  94. component1:level1 component2:level2 component3:level3 ...
  95. where `componentX' is the name of a tracing component, as defined
  96. in `fttrace.h', but without the `trace_' prefix. `levelX' is the
  97. corresponding level to use at runtime.
  98. `any' is a special component name that will be interpreted as
  99. `any/all components'. For example, the following definitions
  100. set FT2_DEBUG=any:2 memory:5 io:4 (on Windows)
  101. export FT2_DEBUG="any:2 memory:5 io:4" (on Linux with bash)
  102. both stipulate that all components should have level 2, except for
  103. the memory and io components which will be set to trace levels 5
  104. and 4, respectively.
  105. FT2_DEBUG_MEMORY
  106. This environment variable, when defined, tells FreeType to use a
  107. debugging memory manager that will track leaking memory blocks as
  108. well as other common errors like double frees. It is also capable
  109. of reporting _where_ the leaking blocks were allocated, which
  110. considerably saves time when debugging new additions to the
  111. library.
  112. This code is only compiled when FreeType is built with the
  113. FT_DEBUG_MEMORY macro #defined in `ftoption.h' though, it will be
  114. ignored in other builds.
  115. FT2_ALLOC_TOTAL_MAX
  116. This variable is ignored if FT2_DEBUG_MEMORY is not defined. It
  117. allows you to specify a maximum heap size for all memory
  118. allocations performed by FreeType. This is very useful to test
  119. the robustness of the font engine and programs that use it in
  120. tight memory conditions.
  121. If it is undefined, or if its value is not strictly positive, then
  122. no allocation bounds are checked at runtime.
  123. FT2_ALLOC_COUNT_MAX
  124. This variable is ignored if FT2_DEBUG_MEMORY is not defined. It
  125. allows you to specify a maximum number of memory allocations
  126. performed by FreeType before returning the error
  127. FT_Err_Out_Of_Memory. This is useful for debugging and testing
  128. the engine's robustness.
  129. If it is undefined, or if its value is not strictly positive, then
  130. no allocation bounds are checked at runtime.
  131. ------------------------------------------------------------------------
  132. Copyright 2002-2017 by
  133. David Turner, Robert Wilhelm, and Werner Lemberg.
  134. This file is part of the FreeType project, and may only be used,
  135. modified, and distributed under the terms of the FreeType project
  136. license, LICENSE.TXT. By continuing to use, modify, or distribute this
  137. file you indicate that you have read the license and understand and
  138. accept it fully.
  139. --- end of DEBUG ---