DEBUG 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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 `ftoptions.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 locations
  27. where these were allocated. It is always a very good idea to define
  28. this in development builds. This works with _any_ program linked to
  29. FreeType, but requires a big deal of memory (the debugging memory
  30. manager never frees the blocks to the heap in order to detect double
  31. frees).
  32. When FT2_DEBUG_MEMORY isn't defined at runtime, the debugging memory
  33. manager is ignored, and performance is unaffected.
  34. II. Debugging macros
  35. --------------------
  36. Several macros can be used within the FreeType sources to help debugging
  37. 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 parentheses
  52. 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 component
  58. being run.
  59. The developer should always define FT_COMPONENT as appropriate, for
  60. 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 the
  65. internal file `freetype/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 check
  68. the undefined or the unused trace macro by src/tools/chktrcmp.py.
  69. Each such component is assigned a `debug level', ranging from 0
  70. to 7, through the use of the FT2_DEBUG environment variable
  71. (described below) when a program linked with FreeType starts.
  72. When FT_TRACE is called, its level is compared to the one of the
  73. corresponding component. Messages with trace levels *higher* than
  74. the corresponding component level are filtered and never printed.
  75. This means that trace messages with level 0 are always printed,
  76. those with level 2 are only printed when the component level is *at
  77. least* 2.
  78. The second parameter to FT_TRACE must contain parentheses and
  79. correspond to a printf-like call, as in
  80. FT_TRACE( 2, ( "your %s is not %s\n", "foo", "bar" ) )
  81. The shortcut macros FT_TRACE0, FT_TRACE1, FT_TRACE2, ..., FT_TRACE7
  82. can be used with constant level indices, and are much cleaner to
  83. use, as in
  84. FT_TRACE2(( "your %s is not %s\n", "foo", "bar" ));
  85. III. Environment variables
  86. --------------------------
  87. The following environment variables control debugging output and
  88. behaviour of FreeType at runtime.
  89. FT2_DEBUG
  90. This variable is only used when FreeType is built with
  91. FT_DEBUG_LEVEL_TRACE defined. It contains a list of component level
  92. definitions, following this format:
  93. component1:level1 component2:level2 component3:level3 ...
  94. where `componentX' is the name of a tracing component, as defined in
  95. `fttrace.h', but without the `trace_' prefix. `levelX' is the
  96. corresponding level to use at runtime.
  97. `any' is a special component name that will be interpreted as
  98. `any/all components'. For example, the following definitions
  99. set FT2_DEBUG=any:2 memory:5 io:4 (on Windows)
  100. export FT2_DEBUG="any:2 memory:5 io:4" (on Linux with bash)
  101. both stipulate that all components should have level 2, except for
  102. the memory and io components which will be set to trace levels 5 and
  103. 4, respectively.
  104. FT2_DEBUG_MEMORY
  105. This environment variable, when defined, tells FreeType to use a
  106. debugging memory manager that will track leaking memory blocks as
  107. well as other common errors like double frees. It is also capable
  108. of reporting _where_ the leaking blocks were allocated, which
  109. considerably saves time when debugging new additions to the library.
  110. This code is only compiled when FreeType is built with the
  111. FT_DEBUG_MEMORY macro #defined in `ftoption.h' though, it will be
  112. ignored in other builds.
  113. FT2_ALLOC_TOTAL_MAX
  114. This variable is ignored if FT2_DEBUG_MEMORY is not defined. It
  115. allows you to specify a maximum heap size for all memory allocations
  116. performed by FreeType. This is very useful to test the robustness
  117. of the font engine and programs that use it in tight memory
  118. conditions.
  119. If it is undefined, or if its value is not strictly positive, then
  120. no allocation bounds are checked at runtime.
  121. FT2_ALLOC_COUNT_MAX
  122. This variable is ignored if FT2_DEBUG_MEMORY is not defined. It
  123. allows you to specify a maximum number of memory allocations
  124. performed by FreeType before returning the error
  125. FT_Err_Out_Of_Memory. This is useful for debugging and testing the
  126. engine's robustness.
  127. If it is undefined, or if its value is not strictly positive, then
  128. no allocation bounds are checked at runtime.
  129. ------------------------------------------------------------------------
  130. Copyright 2002, 2003, 2004, 2005, 2009 by
  131. David Turner, Robert Wilhelm, and Werner Lemberg.
  132. This file is part of the FreeType project, and may only be used,
  133. modified, and distributed under the terms of the FreeType project
  134. license, LICENSE.TXT. By continuing to use, modify, or distribute this
  135. file you indicate that you have read the license and understand and
  136. accept it fully.
  137. --- end of DEBUG ---