blob: 4b0501afff8ead08e4bce8836bbfbfaf5b127e1f [file] [log] [blame]
Werner Lemberga16c4a72003-04-21 13:30:27 +00001Debugging within the FreeType sources
2=====================================
David Turner02c3aed2002-07-08 23:02:32 +00003
Werner Lemberg7f74a522002-07-26 09:09:10 +00004I. Configuration macros
5-----------------------
David Turner02c3aed2002-07-08 23:02:32 +00006
Werner Lemberg7f74a522002-07-26 09:09:10 +00007There are several ways to enable debugging features in a FreeType 2
8builds. This is controlled through the definition of special macros
Werner Lemberga7235262005-08-30 00:22:46 +00009located in the file `ftoptions.h'. The macros are:
David Turner02c3aed2002-07-08 23:02:32 +000010
11
Werner Lemberg7f74a522002-07-26 09:09:10 +000012 FT_DEBUG_LEVEL_ERROR
David Turner02c3aed2002-07-08 23:02:32 +000013
Werner Lemberg7f74a522002-07-26 09:09:10 +000014 #define this macro if you want to compile the FT_ERROR macro calls
Werner Lemberga16c4a72003-04-21 13:30:27 +000015 to print error messages during program execution. This will not
16 stop the program. Very useful to spot invalid fonts during
17 development and to code workarounds for them.
David Turner02c3aed2002-07-08 23:02:32 +000018
Werner Lemberg7f74a522002-07-26 09:09:10 +000019 FT_DEBUG_LEVEL_TRACE
David Turner02c3aed2002-07-08 23:02:32 +000020
Werner Lemberga16c4a72003-04-21 13:30:27 +000021 #define this macro if you want to compile both macros FT_ERROR and
22 FT_TRACE. This also includes the variants FT_TRACE0, FT_TRACE1,
Werner Lemberg1357c192004-09-04 06:55:32 +000023 FT_TRACE2, ..., FT_TRACE7.
David Turner02c3aed2002-07-08 23:02:32 +000024
Werner Lemberg7f74a522002-07-26 09:09:10 +000025 The trace macros are used to send debugging messages when an
Werner Lemberga7235262005-08-30 00:22:46 +000026 appropriate `debug level' is configured at runtime through the
Werner Lemberg7f74a522002-07-26 09:09:10 +000027 FT2_DEBUG environment variable (more on this later).
David Turner02c3aed2002-07-08 23:02:32 +000028
Werner Lemberg7f74a522002-07-26 09:09:10 +000029 FT_DEBUG_MEMORY
David Turner02c3aed2002-07-08 23:02:32 +000030
Werner Lemberga16c4a72003-04-21 13:30:27 +000031 If this macro is #defined, the FreeType engine is linked with a
Werner Lemberg7f74a522002-07-26 09:09:10 +000032 small but effective debugging memory manager that tracks all
33 allocations and frees that are performed within the font engine.
David Turner02c3aed2002-07-08 23:02:32 +000034
Werner Lemberg7f74a522002-07-26 09:09:10 +000035 When the FT2_DEBUG_MEMORY environment variable is defined at
36 runtime, a call to FT_Done_FreeType will dump memory statistics,
37 including the list of leaked memory blocks with the source locations
Werner Lemberga16c4a72003-04-21 13:30:27 +000038 where these were allocated. It is always a very good idea to define
Werner Lemberg7f74a522002-07-26 09:09:10 +000039 this in development builds. This works with _any_ program linked to
40 FreeType, but requires a big deal of memory (the debugging memory
41 manager never frees the blocks to the heap in order to detect double
42 frees).
David Turner02c3aed2002-07-08 23:02:32 +000043
44 When FT2_DEBUG_MEMORY isn't defined at runtime, the debugging memory
Werner Lemberga16c4a72003-04-21 13:30:27 +000045 manager is ignored, and performance is unaffected.
David Turner02c3aed2002-07-08 23:02:32 +000046
47
Werner Lemberg7f74a522002-07-26 09:09:10 +000048II. Debugging macros
49--------------------
David Turner02c3aed2002-07-08 23:02:32 +000050
Werner Lemberg7f74a522002-07-26 09:09:10 +000051Several macros can be used within the FreeType sources to help debugging
52its code:
David Turner02c3aed2002-07-08 23:02:32 +000053
Werner Lemberga7235262005-08-30 00:22:46 +000054
Werner Lemberg7f74a522002-07-26 09:09:10 +000055 1. FT_ERROR(( ... ))
David Turner02c3aed2002-07-08 23:02:32 +000056
Werner Lemberg7f74a522002-07-26 09:09:10 +000057 This macro is used to send debug messages that indicate relatively
58 serious errors (like broken font files), but will not stop the
59 execution of the running program. Its code is compiled only when
60 either FT_DEBUG_LEVEL_ERROR or FT_DEBUG_LEVEL_TRACE are defined in
Werner Lemberga7235262005-08-30 00:22:46 +000061 `ftoption.h'.
David Turner02c3aed2002-07-08 23:02:32 +000062
Werner Lemberga16c4a72003-04-21 13:30:27 +000063 Note that you have to use a printf-like signature, but with double
Werner Lemberga7235262005-08-30 00:22:46 +000064 parentheses, like in
David Turner02c3aed2002-07-08 23:02:32 +000065
Werner Lemberg7f74a522002-07-26 09:09:10 +000066 FT_ERROR(( "your %s is not %s\n", "foo", "bar" ));
David Turner02c3aed2002-07-08 23:02:32 +000067
68
Werner Lemberg7f74a522002-07-26 09:09:10 +000069 2. FT_ASSERT( condition )
David Turner02c3aed2002-07-08 23:02:32 +000070
Werner Lemberg7f74a522002-07-26 09:09:10 +000071 This macro is used to check strong assertions at runtime. If its
72 condition isn't TRUE, the program will abort with a panic message.
73 Its code is compiled when either FT_DEBUG_LEVEL_ERROR or
Werner Lemberga7235262005-08-30 00:22:46 +000074 FT_DEBUG_LEVEL_TRACE are defined. You don't need double parentheses
75 here. For example
David Turner02c3aed2002-07-08 23:02:32 +000076
Werner Lemberg7f74a522002-07-26 09:09:10 +000077 FT_ASSERT( ptr != NULL );
David Turner02c3aed2002-07-08 23:02:32 +000078
79
Werner Lemberg7f74a522002-07-26 09:09:10 +000080 3. FT_TRACE( level, (message...) )
Werner Lemberga7235262005-08-30 00:22:46 +000081
Werner Lemberg7f74a522002-07-26 09:09:10 +000082 The FT_TRACE macro is used to send general-purpose debugging
83 messages during program execution. This macro uses an *implicit*
84 macro named FT_COMPONENT used to name the current FreeType component
85 being run.
David Turner02c3aed2002-07-08 23:02:32 +000086
Werner Lemberg7f74a522002-07-26 09:09:10 +000087 The developer should always define FT_COMPONENT as appropriate, for
Werner Lemberga7235262005-08-30 00:22:46 +000088 example as in
David Turner02c3aed2002-07-08 23:02:32 +000089
Werner Lemberg7f74a522002-07-26 09:09:10 +000090 #undef FT_COMPONENT
91 #define FT_COMPONENT trace_io
David Turner02c3aed2002-07-08 23:02:32 +000092
Werner Lemberg7f74a522002-07-26 09:09:10 +000093 The value of the FT_COMPONENT macro is an enumeration named
94 trace_XXXX where XXXX is one of the component names defined in the
Werner Lemberga7235262005-08-30 00:22:46 +000095 internal file `freetype/internal/fttrace.h'.
David Turner02c3aed2002-07-08 23:02:32 +000096
Werner Lemberga7235262005-08-30 00:22:46 +000097 Each such component is assigned a `debug level', ranging from 0
98 to 7, through the use of the FT2_DEBUG environment variable
Werner Lemberga16c4a72003-04-21 13:30:27 +000099 (described below) when a program linked with FreeType starts.
David Turner02c3aed2002-07-08 23:02:32 +0000100
Werner Lemberg7f74a522002-07-26 09:09:10 +0000101 When FT_TRACE is called, its level is compared to the one of the
102 corresponding component. Messages with trace levels *higher* than
103 the corresponding component level are filtered and never printed.
David Turner02c3aed2002-07-08 23:02:32 +0000104
Werner Lemberg7f74a522002-07-26 09:09:10 +0000105 This means that trace messages with level 0 are always printed,
106 those with level 2 are only printed when the component level is *at
107 least* 2.
David Turner02c3aed2002-07-08 23:02:32 +0000108
Werner Lemberg7f74a522002-07-26 09:09:10 +0000109 The second parameter to FT_TRACE must contain parentheses and
Werner Lemberga7235262005-08-30 00:22:46 +0000110 correspond to a printf-like call, as in
David Turner02c3aed2002-07-08 23:02:32 +0000111
Werner Lemberg7f74a522002-07-26 09:09:10 +0000112 FT_TRACE( 2, ( "your %s is not %s\n", "foo", "bar" ) )
David Turner02c3aed2002-07-08 23:02:32 +0000113
Werner Lemberga7235262005-08-30 00:22:46 +0000114 The shortcut macros FT_TRACE0, FT_TRACE1, FT_TRACE2, ..., FT_TRACE7
Werner Lemberg7f74a522002-07-26 09:09:10 +0000115 can be used with constant level indices, and are much cleaner to
116 use, as in
David Turner02c3aed2002-07-08 23:02:32 +0000117
118 FT_TRACE2(( "your %s is not %s\n", "foo", "bar" ));
119
120
Werner Lemberg7f74a522002-07-26 09:09:10 +0000121III. Environment variables
122--------------------------
David Turner02c3aed2002-07-08 23:02:32 +0000123
Werner Lemberg7f74a522002-07-26 09:09:10 +0000124The following environment variables control debugging output and
Werner Lemberga7235262005-08-30 00:22:46 +0000125behaviour of FreeType at runtime.
126
David Turner02c3aed2002-07-08 23:02:32 +0000127
David Turner02c3aed2002-07-08 23:02:32 +0000128 FT2_DEBUG
David Turner02c3aed2002-07-08 23:02:32 +0000129
Werner Lemberg7f74a522002-07-26 09:09:10 +0000130 This variable is only used when FreeType is built with
131 FT_DEBUG_LEVEL_TRACE defined. It contains a list of component level
132 definitions, following this format:
133
134 component1:level1 component2:level2 component3:level3 ...
David Turner02c3aed2002-07-08 23:02:32 +0000135
Werner Lemberga7235262005-08-30 00:22:46 +0000136 where `componentX' is the name of a tracing component, as defined in
137 `fttrace.h', but without the `trace_' prefix. `levelX' is the
David Turner02c3aed2002-07-08 23:02:32 +0000138 corresponding level to use at runtime.
139
Werner Lemberga7235262005-08-30 00:22:46 +0000140 `any' is a special component name that will be interpreted as
141 `any/all components'. For example, the following definitions
David Turner02c3aed2002-07-08 23:02:32 +0000142
143 set FT2_DEBUG=any:2 memory:5 io:4 (on Windows)
Werner Lemberga16c4a72003-04-21 13:30:27 +0000144 export FT2_DEBUG="any:2 memory:5 io:4" (on Linux with bash)
David Turner02c3aed2002-07-08 23:02:32 +0000145
Werner Lemberg7f74a522002-07-26 09:09:10 +0000146 both stipulate that all components should have level 2, except for
Werner Lemberga7235262005-08-30 00:22:46 +0000147 the memory and io components which will be set to trace levels 5 and
148 4, respectively.
149
David Turner02c3aed2002-07-08 23:02:32 +0000150
151 FT2_DEBUG_MEMORY
David Turner02c3aed2002-07-08 23:02:32 +0000152
Werner Lemberg7f74a522002-07-26 09:09:10 +0000153 This environment variable, when defined, tells FreeType to use a
Werner Lemberga16c4a72003-04-21 13:30:27 +0000154 debugging memory manager that will track leaking memory blocks as
Werner Lemberg7f74a522002-07-26 09:09:10 +0000155 well as other common errors like double frees. It is also capable
Werner Lemberga16c4a72003-04-21 13:30:27 +0000156 of reporting _where_ the leaking blocks were allocated, which
Werner Lemberg7f74a522002-07-26 09:09:10 +0000157 considerably saves time when debugging new additions to the library.
158
159 This code is only compiled when FreeType is built with the
Werner Lemberga7235262005-08-30 00:22:46 +0000160 FT_DEBUG_MEMORY macro #defined in `ftoption.h' though, it will be
Werner Lemberg7f74a522002-07-26 09:09:10 +0000161 ignored in other builds.
David Turner02c3aed2002-07-08 23:02:32 +0000162
Werner Lemberga7235262005-08-30 00:22:46 +0000163
David Turnerb2805372003-03-13 21:07:51 +0000164 FT2_ALLOC_TOTAL_MAX
165
Werner Lemberga16c4a72003-04-21 13:30:27 +0000166 This variable is ignored if FT2_DEBUG_MEMORY is not defined. It
167 allows you to specify a maximum heap size for all memory allocations
168 performed by FreeType. This is very useful to test the robustness
169 of the font engine and programs that use it in tight memory
170 conditions.
David Turnerb2805372003-03-13 21:07:51 +0000171
Werner Lemberga16c4a72003-04-21 13:30:27 +0000172 If it is undefined, or if its value is not strictly positive, then
173 no allocation bounds are checked at runtime.
David Turnerb2805372003-03-13 21:07:51 +0000174
Werner Lemberga7235262005-08-30 00:22:46 +0000175
David Turnerb2805372003-03-13 21:07:51 +0000176 FT2_ALLOC_COUNT_MAX
177
Werner Lemberga16c4a72003-04-21 13:30:27 +0000178 This variable is ignored if FT2_DEBUG_MEMORY is not defined. It
179 allows you to specify a maximum number of memory allocations
180 performed by FreeType before returning the error
181 FT_Err_Out_Of_Memory. This is useful for debugging and testing the
182 engine's robustness.
David Turnerb2805372003-03-13 21:07:51 +0000183
Werner Lemberga16c4a72003-04-21 13:30:27 +0000184 If it is undefined, or if its value is not strictly positive, then
Werner Lemberga7235262005-08-30 00:22:46 +0000185 no allocation bounds are checked at runtime.
David Turnerb2805372003-03-13 21:07:51 +0000186
Werner Lemberg56c368c2005-06-04 23:00:25 +0000187------------------------------------------------------------------------
188
Werner Lemberga7235262005-08-30 00:22:46 +0000189Copyright 2002, 2003, 2004, 2005 by
Werner Lemberg56c368c2005-06-04 23:00:25 +0000190David Turner, Robert Wilhelm, and Werner Lemberg.
191
Werner Lemberga7235262005-08-30 00:22:46 +0000192This file is part of the FreeType project, and may only be used,
193modified, and distributed under the terms of the FreeType project
194license, LICENSE.TXT. By continuing to use, modify, or distribute this
195file you indicate that you have read the license and understand and
Werner Lemberg56c368c2005-06-04 23:00:25 +0000196accept it fully.
197
Werner Lemberga16c4a72003-04-21 13:30:27 +0000198
199--- end of DEBUG ---