1 /**************************************************************************** 2 * 3 * ftdebug.h 4 * 5 * Debugging and logging component (specification). 6 * 7 * Copyright 1996-2018 by 8 * David Turner, Robert Wilhelm, and Werner Lemberg. 9 * 10 * This file is part of the FreeType project, and may only be used, 11 * modified, and distributed under the terms of the FreeType project 12 * license, LICENSE.TXT. By continuing to use, modify, or distribute 13 * this file you indicate that you have read the license and 14 * understand and accept it fully. 15 * 16 * 17 * IMPORTANT: A description of FreeType's debugging support can be 18 * found in `docs/DEBUG.TXT'. Read it if you need to use or 19 * understand this code. 20 * 21 */ 22 23 24 #ifndef FTDEBUG_H_ 25 #define FTDEBUG_H_ 26 27 28 #include <ft2build.h> 29 #include FT_CONFIG_CONFIG_H 30 #include FT_FREETYPE_H 31 32 33 FT_BEGIN_HEADER 34 35 36 /* force the definition of FT_DEBUG_LEVEL_ERROR if FT_DEBUG_LEVEL_TRACE */ 37 /* is already defined; this simplifies the following #ifdefs */ 38 /* */ 39 #ifdef FT_DEBUG_LEVEL_TRACE 40 #undef FT_DEBUG_LEVEL_ERROR 41 #define FT_DEBUG_LEVEL_ERROR 42 #endif 43 44 45 /************************************************************************** 46 * 47 * Define the trace enums as well as the trace levels array when they 48 * are needed. 49 * 50 */ 51 52 #ifdef FT_DEBUG_LEVEL_TRACE 53 54 #define FT_TRACE_DEF( x ) trace_ ## x , 55 56 /* defining the enumeration */ 57 typedef enum FT_Trace_ 58 { 59 #include FT_INTERNAL_TRACE_H 60 trace_count 61 62 } FT_Trace; 63 64 65 /* a pointer to the array of trace levels, */ 66 /* provided by `src/base/ftdebug.c' */ 67 extern int* ft_trace_levels; 68 69 #undef FT_TRACE_DEF 70 71 #endif /* FT_DEBUG_LEVEL_TRACE */ 72 73 74 /************************************************************************** 75 * 76 * Define the FT_TRACE macro 77 * 78 * IMPORTANT! 79 * 80 * Each component must define the macro FT_COMPONENT to a valid FT_Trace 81 * value before using any TRACE macro. 82 * 83 */ 84 85 #ifdef FT_DEBUG_LEVEL_TRACE 86 87 #define FT_TRACE( level, varformat ) \ 88 do \ 89 { \ 90 if ( ft_trace_levels[FT_COMPONENT] >= level ) \ 91 FT_Message varformat; \ 92 } while ( 0 ) 93 94 #else /* !FT_DEBUG_LEVEL_TRACE */ 95 96 #define FT_TRACE( level, varformat ) do { } while ( 0 ) /* nothing */ 97 98 #endif /* !FT_DEBUG_LEVEL_TRACE */ 99 100 101 /************************************************************************** 102 * 103 * @function: 104 * FT_Trace_Get_Count 105 * 106 * @description: 107 * Return the number of available trace components. 108 * 109 * @return: 110 * The number of trace components. 0 if FreeType 2 is not built with 111 * FT_DEBUG_LEVEL_TRACE definition. 112 * 113 * @note: 114 * This function may be useful if you want to access elements of 115 * the internal trace levels array by an index. 116 */ 117 FT_BASE( FT_Int ) 118 FT_Trace_Get_Count( void ); 119 120 121 /************************************************************************** 122 * 123 * @function: 124 * FT_Trace_Get_Name 125 * 126 * @description: 127 * Return the name of a trace component. 128 * 129 * @input: 130 * The index of the trace component. 131 * 132 * @return: 133 * The name of the trace component. This is a statically allocated 134 * C~string, so do not free it after use. NULL if FreeType is not built 135 * with FT_DEBUG_LEVEL_TRACE definition. 136 * 137 * @note: 138 * Use @FT_Trace_Get_Count to get the number of available trace 139 * components. 140 */ 141 FT_BASE( const char* ) 142 FT_Trace_Get_Name( FT_Int idx ); 143 144 145 /************************************************************************** 146 * 147 * @function: 148 * FT_Trace_Disable 149 * 150 * @description: 151 * Switch off tracing temporarily. It can be activated again with 152 * @FT_Trace_Enable. 153 */ 154 FT_BASE( void ) 155 FT_Trace_Disable( void ); 156 157 158 /************************************************************************** 159 * 160 * @function: 161 * FT_Trace_Enable 162 * 163 * @description: 164 * Activate tracing. Use it after tracing has been switched off with 165 * @FT_Trace_Disable. 166 */ 167 FT_BASE( void ) 168 FT_Trace_Enable( void ); 169 170 171 /************************************************************************** 172 * 173 * You need two opening and closing parentheses! 174 * 175 * Example: FT_TRACE0(( "Value is %i", foo )) 176 * 177 * Output of the FT_TRACEX macros is sent to stderr. 178 * 179 */ 180 181 #define FT_TRACE0( varformat ) FT_TRACE( 0, varformat ) 182 #define FT_TRACE1( varformat ) FT_TRACE( 1, varformat ) 183 #define FT_TRACE2( varformat ) FT_TRACE( 2, varformat ) 184 #define FT_TRACE3( varformat ) FT_TRACE( 3, varformat ) 185 #define FT_TRACE4( varformat ) FT_TRACE( 4, varformat ) 186 #define FT_TRACE5( varformat ) FT_TRACE( 5, varformat ) 187 #define FT_TRACE6( varformat ) FT_TRACE( 6, varformat ) 188 #define FT_TRACE7( varformat ) FT_TRACE( 7, varformat ) 189 190 191 /************************************************************************** 192 * 193 * Define the FT_ERROR macro. 194 * 195 * Output of this macro is sent to stderr. 196 * 197 */ 198 199 #ifdef FT_DEBUG_LEVEL_ERROR 200 201 #define FT_ERROR( varformat ) FT_Message varformat 202 203 #else /* !FT_DEBUG_LEVEL_ERROR */ 204 205 #define FT_ERROR( varformat ) do { } while ( 0 ) /* nothing */ 206 207 #endif /* !FT_DEBUG_LEVEL_ERROR */ 208 209 210 /************************************************************************** 211 * 212 * Define the FT_ASSERT and FT_THROW macros. The call to `FT_Throw' 213 * makes it possible to easily set a breakpoint at this function. 214 * 215 */ 216 217 #ifdef FT_DEBUG_LEVEL_ERROR 218 219 #define FT_ASSERT( condition ) \ 220 do \ 221 { \ 222 if ( !( condition ) ) \ 223 FT_Panic( "assertion failed on line %d of file %s\n", \ 224 __LINE__, __FILE__ ); \ 225 } while ( 0 ) 226 227 #define FT_THROW( e ) \ 228 ( FT_Throw( FT_ERR_CAT( FT_ERR_PREFIX, e ), \ 229 __LINE__, \ 230 __FILE__ ) | \ 231 FT_ERR_CAT( FT_ERR_PREFIX, e ) ) 232 233 #else /* !FT_DEBUG_LEVEL_ERROR */ 234 235 #define FT_ASSERT( condition ) do { } while ( 0 ) 236 237 #define FT_THROW( e ) FT_ERR_CAT( FT_ERR_PREFIX, e ) 238 239 #endif /* !FT_DEBUG_LEVEL_ERROR */ 240 241 242 /************************************************************************** 243 * 244 * Define `FT_Message' and `FT_Panic' when needed. 245 * 246 */ 247 248 #ifdef FT_DEBUG_LEVEL_ERROR 249 250 #include "stdio.h" /* for vfprintf() */ 251 252 /* print a message */ 253 FT_BASE( void ) 254 FT_Message( const char* fmt, 255 ... ); 256 257 /* print a message and exit */ 258 FT_BASE( void ) 259 FT_Panic( const char* fmt, 260 ... ); 261 262 /* report file name and line number of an error */ 263 FT_BASE( int ) 264 FT_Throw( FT_Error error, 265 int line, 266 const char* file ); 267 268 #endif /* FT_DEBUG_LEVEL_ERROR */ 269 270 271 FT_BASE( void ) 272 ft_debug_init( void ); 273 274 FT_END_HEADER 275 276 #endif /* FTDEBUG_H_ */ 277 278 279 /* END */ 280