blob: 86ffbcfa5cf31227ef0650111e6fe3b715904359 [file] [log] [blame]
David Turner02c3aed2002-07-08 23:02:32 +00001Debugging within the FreeType sources:
2======================================
3
4I. Configuration macros:
5========================
6
7There are several ways to enable debugging features in a FreeType 2 builds.
8This is controled through the definition of special macros located in the
9file "ftoptions.h". The macros are:
10
11
12 FT_DEBUG_LEVEL_ERROR ::
13
14 #define this macro if you want to compile the FT_ERROR macro calls
15 used to print error messages during program execution. This will not
16 stop the program, but is very useful to spot invalid fonts during
17 development and code wordarounds for them.
18
19
20 FT_DEBUG_LEVEL_TRACE ::
21
22 #define this macro if you want to compile both the FT_ERROR macro and
23 the FT_TRACE one. This also includes the variants FT_TRACE0, FT_TRACE1,
24 FT_TRACE2, ..., FT_TRACE6.
25
26 The trace macros are used to send debugging messages when an appropriate
27 "debug level" is configured at runtime through the FT2_DEBUG environment
28 variable (more on this later)
29
30
31 FT_DEBUG_MEMORY ::
32
33 when this macro is #defined, the FreeType engines is linked with a small
34 but effective debugging memory manager that tracks all allocations and
35 frees that are performed within the font engine.
36
37 When the FT2_DEBUG_MEMORY environment variable is defined at runtime, a
38 call to FT_Done_FreeType will dump memory statistics, including the list of
39 leaked memory blocks with the source locations where these were allocated.
40 It's always a very good idea to define this in development builds. This
41 works with _any_ program linked to FreeType, but requires a big deal of
42 memory (the debugging memory manager never frees the blocks to the
43 heap in order to detect double frees).
44
45 When FT2_DEBUG_MEMORY isn't defined at runtime, the debugging memory
46 manager is ignored, and performance is un-affected.
47
48
49II. Debugging macros:
50=====================
51
52 Several macros can be used within the FreeType sources to help debugging
53 its code:
54
55 1. FT_ERROR(( .. ))
56
57 this macro is used to send debug messages that indicate relatively serious
58 errors (like broken font files), but will not stop the execution of the
59 running program. Its code is compiled only when either FT_DEBUG_LEVEL_ERROR
60 or FT_DEBUG_LEVEL_TRACE are defined in "ftoption.h"
61
62 Note that you must use with a printf-like signature, but with double
63 parentheses, like in:
64
65 FT_ERROR(( "your %s is not %s\n", "foo", "bar" ));
66
67
68 2. FT_ASSERT( condition )
69
70 this macro is used to check strong assertions at runtime. If its condition
71 isn't TRUE, the program will abort with a panic message. Its code is
72 compiled when either FT_DEBUG_LEVEL_ERROR or FT_DEBUG_LEVEL_TRACE are
73 defined. You don't need double-parentheses here. For example:
74
75 FT_ASSERT( ptr != NULL );
76
77
78 3. FT_TRACE( level, (message...) )
79
80 the FT_TRACE macro is used to send general-purpose debugging messages
81 during program execution. This macro uses an *implicit* macro named
82 FT_COMPONENT used to name the current FreeType component being run.
83
84 The developer should always define FT_COMPONENT as appropriate, for
85 example as in:
86
87 #undef FT_COMPONENT
88 #define FT_COMPONENT trace_io
89
90 the value of the FT_COMPONENT macro is an enumeration named trace_XXXX
91 where XXXX is one of the component names defined in the internal file
92 <freetype/internal/fttrace.h>
93
94 Each such component is assigned a "debug level", ranging from 0 to 6
95 when a program linked with FreeType starts, through the use of the FT2_DEBUG
96 environment variable, described later.
97
98 When FT_TRACE is called, its level is compared to the one of the
99 corresponding component. Messages with trace levels *higher* than the
100 corresponding component level are filtered and never printed.
101
102 this means that trace messages with level 0 are always printed, those
103 with level 2 are only printed when the component level is *at least* 2
104
105 The second parameter to FT_TRACE must contain parentheses and correspond
106 to a print-like call, as in:
107
108 FT_TRACE( 2, ( "your %s is not %s\n", "foo", "bar" ) )
109
110 The shortcut macros FT_TRACE0, FT_TRACE1, FT_TRACE2_, ... FT_TRACE6 can
111 be used with constant level indices, and are much cleaner to use, as in
112
113 FT_TRACE2(( "your %s is not %s\n", "foo", "bar" ));
114
115
116III. Environment variables:
117===========================
118
119 The following environment variables control debugging output and behaviour
120 of FreeType at runtime:
121
122
123 FT2_DEBUG
124 this variable is only used when FreeType is built with FT_DEBUG_LEVEL_TRACE
125 defined. It contains a list of component level definitions, following this
126 format:
127
128 component1:level1 component2:level2 component3:level3 ...
129
130 where "componentX" is the name of a tracing component, as defined in
131 "fttrace.h", but without the "trace_" prefix, and "levelX" is the
132 corresponding level to use at runtime.
133
134 "any" is a special component name that will be interpreted as
135 "any/all components". For example, the following definitions
136
137 set FT2_DEBUG=any:2 memory:5 io:4 (on Windows)
138 export FT2_DEBUG="any:2 memory:5 io:4" (on Linux)
139
140 both stipulate that all components should have level 2, except for the
141 memory and io components which will be set to trace levels 5 and 4
142 respectively.
143
144
145 FT2_DEBUG_MEMORY
146 this environment variable, when defined, tells FreeType to use a debugging
147 memory manager that will track leaked memory blocks as well as other common
148 errors like double frees. It is also capable of reporting _where_ the
149 leaked blocks were allocated, which considerably saves time when
150 debugging new additions to the library.
151
152 This code is only compiled when FreeType is built with the FT_DEBUG_MEMORY
153 macro #defined in "ftoption.h" though, it will be ignored in other builds.
154
155
156Voila,
157
158- David Turner
159
160
161
162 used like printf( format, ... ), but with double quotes. This will
163 send a message to the standard error descriptor (stderr on most systems)
164 in certain builds of the library