blob: ef7faa19ec32f8b988d0454660ddab1c0f99293c [file] [log] [blame]
David Turner02c3aed2002-07-08 23:02:32 +00001Debugging within the FreeType sources:
2======================================
3
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
9located 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
15 used to print error messages during program execution. This will
16 not stop the program, but is very useful to spot invalid fonts
17 during development and code wordarounds 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 Lemberg7f74a522002-07-26 09:09:10 +000021 #define this macro if you want to compile both the FT_ERROR macro
22 and the FT_TRACE one. This also includes the variants FT_TRACE0,
23 FT_TRACE1, FT_TRACE2, ..., FT_TRACE6.
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
26 appropriate "debug level" is configured at runtime through the
27 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 Lemberg7f74a522002-07-26 09:09:10 +000031 If this macro is #defined, the FreeType engines is linked with a
32 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
38 where these were allocated. It's always a very good idea to define
39 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
45 manager is ignored, and performance is un-affected.
46
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 Lemberg7f74a522002-07-26 09:09:10 +000054 1. FT_ERROR(( ... ))
David Turner02c3aed2002-07-08 23:02:32 +000055
Werner Lemberg7f74a522002-07-26 09:09:10 +000056 This macro is used to send debug messages that indicate relatively
57 serious errors (like broken font files), but will not stop the
58 execution of the running program. Its code is compiled only when
59 either FT_DEBUG_LEVEL_ERROR or FT_DEBUG_LEVEL_TRACE are defined in
60 "ftoption.h".
David Turner02c3aed2002-07-08 23:02:32 +000061
Werner Lemberg7f74a522002-07-26 09:09:10 +000062 Note that you must use with a printf-like signature, but with double
63 parentheses, like in:
David Turner02c3aed2002-07-08 23:02:32 +000064
Werner Lemberg7f74a522002-07-26 09:09:10 +000065 FT_ERROR(( "your %s is not %s\n", "foo", "bar" ));
David Turner02c3aed2002-07-08 23:02:32 +000066
67
Werner Lemberg7f74a522002-07-26 09:09:10 +000068 2. FT_ASSERT( condition )
David Turner02c3aed2002-07-08 23:02:32 +000069
Werner Lemberg7f74a522002-07-26 09:09:10 +000070 This macro is used to check strong assertions at runtime. If its
71 condition isn't TRUE, the program will abort with a panic message.
72 Its code is compiled when either FT_DEBUG_LEVEL_ERROR or
73 FT_DEBUG_LEVEL_TRACE are defined. You don't need double-parentheses
74 here. For example:
David Turner02c3aed2002-07-08 23:02:32 +000075
Werner Lemberg7f74a522002-07-26 09:09:10 +000076 FT_ASSERT( ptr != NULL );
David Turner02c3aed2002-07-08 23:02:32 +000077
78
Werner Lemberg7f74a522002-07-26 09:09:10 +000079 3. FT_TRACE( level, (message...) )
David Turner02c3aed2002-07-08 23:02:32 +000080
Werner Lemberg7f74a522002-07-26 09:09:10 +000081 The FT_TRACE macro is used to send general-purpose debugging
82 messages during program execution. This macro uses an *implicit*
83 macro named FT_COMPONENT used to name the current FreeType component
84 being run.
David Turner02c3aed2002-07-08 23:02:32 +000085
Werner Lemberg7f74a522002-07-26 09:09:10 +000086 The developer should always define FT_COMPONENT as appropriate, for
87 example as in:
David Turner02c3aed2002-07-08 23:02:32 +000088
Werner Lemberg7f74a522002-07-26 09:09:10 +000089 #undef FT_COMPONENT
90 #define FT_COMPONENT trace_io
David Turner02c3aed2002-07-08 23:02:32 +000091
Werner Lemberg7f74a522002-07-26 09:09:10 +000092 The value of the FT_COMPONENT macro is an enumeration named
93 trace_XXXX where XXXX is one of the component names defined in the
94 internal file <freetype/internal/fttrace.h>.
David Turner02c3aed2002-07-08 23:02:32 +000095
Werner Lemberg7f74a522002-07-26 09:09:10 +000096 Each such component is assigned a "debug level", ranging from 0 to 6
97 when a program linked with FreeType starts, through the use of the
98 FT2_DEBUG environment variable, described later.
David Turner02c3aed2002-07-08 23:02:32 +000099
Werner Lemberg7f74a522002-07-26 09:09:10 +0000100 When FT_TRACE is called, its level is compared to the one of the
101 corresponding component. Messages with trace levels *higher* than
102 the corresponding component level are filtered and never printed.
David Turner02c3aed2002-07-08 23:02:32 +0000103
Werner Lemberg7f74a522002-07-26 09:09:10 +0000104 This means that trace messages with level 0 are always printed,
105 those with level 2 are only printed when the component level is *at
106 least* 2.
David Turner02c3aed2002-07-08 23:02:32 +0000107
Werner Lemberg7f74a522002-07-26 09:09:10 +0000108 The second parameter to FT_TRACE must contain parentheses and
109 correspond to a print-like call, as in:
David Turner02c3aed2002-07-08 23:02:32 +0000110
Werner Lemberg7f74a522002-07-26 09:09:10 +0000111 FT_TRACE( 2, ( "your %s is not %s\n", "foo", "bar" ) )
David Turner02c3aed2002-07-08 23:02:32 +0000112
Werner Lemberg7f74a522002-07-26 09:09:10 +0000113 The shortcut macros FT_TRACE0, FT_TRACE1, FT_TRACE2_, ... FT_TRACE6
114 can be used with constant level indices, and are much cleaner to
115 use, as in
David Turner02c3aed2002-07-08 23:02:32 +0000116
117 FT_TRACE2(( "your %s is not %s\n", "foo", "bar" ));
118
119
Werner Lemberg7f74a522002-07-26 09:09:10 +0000120III. Environment variables
121--------------------------
David Turner02c3aed2002-07-08 23:02:32 +0000122
Werner Lemberg7f74a522002-07-26 09:09:10 +0000123The following environment variables control debugging output and
124behaviour of FreeType at runtime:
David Turner02c3aed2002-07-08 23:02:32 +0000125
126
127 FT2_DEBUG
David Turner02c3aed2002-07-08 23:02:32 +0000128
Werner Lemberg7f74a522002-07-26 09:09:10 +0000129 This variable is only used when FreeType is built with
130 FT_DEBUG_LEVEL_TRACE defined. It contains a list of component level
131 definitions, following this format:
132
133 component1:level1 component2:level2 component3:level3 ...
David Turner02c3aed2002-07-08 23:02:32 +0000134
135 where "componentX" is the name of a tracing component, as defined in
Werner Lemberg7f74a522002-07-26 09:09:10 +0000136 "fttrace.h", but without the "trace_" prefix, and "levelX" is the
David Turner02c3aed2002-07-08 23:02:32 +0000137 corresponding level to use at runtime.
138
Werner Lemberg7f74a522002-07-26 09:09:10 +0000139 "any" is a special component name that will be interpreted as
140 "any/all components". For example, the following definitions
David Turner02c3aed2002-07-08 23:02:32 +0000141
142 set FT2_DEBUG=any:2 memory:5 io:4 (on Windows)
143 export FT2_DEBUG="any:2 memory:5 io:4" (on Linux)
144
Werner Lemberg7f74a522002-07-26 09:09:10 +0000145 both stipulate that all components should have level 2, except for
146 the memory and io components which will be set to trace levels 5 and
147 4 respectively.
David Turner02c3aed2002-07-08 23:02:32 +0000148
149 FT2_DEBUG_MEMORY
David Turner02c3aed2002-07-08 23:02:32 +0000150
Werner Lemberg7f74a522002-07-26 09:09:10 +0000151 This environment variable, when defined, tells FreeType to use a
152 debugging memory manager that will track leaked memory blocks as
153 well as other common errors like double frees. It is also capable
154 of reporting _where_ the leaked blocks were allocated, which
155 considerably saves time when debugging new additions to the library.
156
157 This code is only compiled when FreeType is built with the
158 FT_DEBUG_MEMORY macro #defined in "ftoption.h" though, it will be
159 ignored in other builds.
David Turner02c3aed2002-07-08 23:02:32 +0000160
161
Werner Lemberg7f74a522002-07-26 09:09:10 +0000162End of file