1 /******************************************************************* 2 * 3 * ttdebug.h 4 * 5 * Debugging and Logging component (specification) 6 * 7 * Copyright 1996-1999 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 * This component contains various macros and functions used to 18 * ease the debugging of the FreeType engine. Its main purpose 19 * is in assertion checking, tracing, and error detection. 20 * 21 * There are now three debugging modes: 22 * 23 * - trace mode: 24 * 25 * Error and trace messages are sent to the log file 26 * (which can be the standard error output). Define 27 * DEBUG_LEVEL_TRACE to enable this mode. 28 * 29 * - error mode: 30 * 31 * Only error messages are generated. Define 32 * DEBUG_LEVEL_ERROR to enable this mode. 33 * 34 * - release mode: 35 * 36 * Error messages are neither sent nor generated. The code is 37 * free from any debugging parts. 38 * 39 ******************************************************************/ 40 41 #ifndef TTDEBUG_H 42 #define TTDEBUG_H 43 44 #include "ttconfig.h" 45 #include "tttypes.h" 46 47 48 #ifdef __cplusplus 49 extern "C" { 50 #endif 51 52 53 #if defined( DEBUG_LEVEL_TRACE ) 54 55 typedef enum Trace_Component_ 56 { 57 trace_any = 0, 58 trace_api, 59 trace_interp, 60 trace_load, 61 trace_gload, 62 trace_memory, 63 trace_file, 64 trace_mutex, 65 trace_cache, 66 trace_calc, 67 trace_cmap, 68 trace_extend, 69 trace_objs, 70 trace_raster, 71 72 trace_bitmap, 73 trace_max 74 75 } Trace_Component; 76 77 78 /* Here we define an array to hold the trace levels per component. */ 79 /* Since it is globally defined, all array members are set to 0. */ 80 /* You should set the values in this array either in your program */ 81 /* or with your debugger. */ 82 /* */ 83 /* Currently, up to eight levels (PTRACE0-PTRACE7, see below) are */ 84 /* used in some parts of the engine. */ 85 /* */ 86 /* For example, to have all tracing messages in the raster */ 87 /* component, say */ 88 /* */ 89 /* #define DEBUG_LEVEL_TRACE */ 90 /* #include "ttdebug.h" */ 91 /* */ 92 /* ... */ 93 /* set_tt_trace_levels( trace_raster, 7 ) */ 94 /* */ 95 /* in your code before initializing the FreeType engine. */ 96 /* */ 97 /* Maybe it is better to define DEBUG_LEVEL_TRACE in ttconfig.h... */ 98 99 extern char tt_trace_levels[trace_max]; 100 101 /* IMPORTANT: */ 102 /* */ 103 /* Each component must define the macro TT_COMPONENT */ 104 /* to a valid Trace_Component value before using any */ 105 /* PTRACEx macro. */ 106 /* */ 107 108 #define PTRACE( level, varformat ) \ 109 if ( tt_trace_levels[TT_COMPONENT] >= level ) TT_Message##varformat 110 111 #elif defined( DEBUG_LEVEL_ERROR ) 112 113 #define PTRACE( level, varformat ) /* nothing */ 114 115 #else /* RELEASE MODE */ 116 117 #define TT_Assert( condition, action ) /* nothing */ 118 119 #define PTRACE( level, varformat ) /* nothing */ 120 #define PERROR( varformat ) /* nothing */ 121 #define PANIC( varformat ) /* nothing */ 122 123 #endif 124 125 126 /************************************************************************/ 127 /* */ 128 /* Define macros and fuctions that are common to the debug and trace */ 129 /* modes. */ 130 /* */ 131 132 #if defined( DEBUG_LEVEL_TRACE ) || defined( DEBUG_LEVEL_ERROR ) 133 134 135 #define TT_Assert( condition, action ) if ( !(condition) ) ( action ) 136 137 void TT_Message( const String* fmt, ... ); 138 void TT_Panic ( const String* fmt, ... ); 139 /* print a message and exit */ 140 141 const String* Cur_U_Line( void* exec ); 142 143 #define PERROR( varformat ) TT_Message##varformat 144 #define PANIC( varformat ) TT_Panic##varformat 145 146 #endif 147 148 #if defined( DEBUG_LEVEL_TRACE ) 149 150 void set_tt_trace_levels( int index, char value ); 151 152 #endif 153 154 155 #define PTRACE0( varformat ) PTRACE( 0, varformat ) 156 #define PTRACE1( varformat ) PTRACE( 1, varformat ) 157 #define PTRACE2( varformat ) PTRACE( 2, varformat ) 158 #define PTRACE3( varformat ) PTRACE( 3, varformat ) 159 #define PTRACE4( varformat ) PTRACE( 4, varformat ) 160 #define PTRACE5( varformat ) PTRACE( 5, varformat ) 161 #define PTRACE6( varformat ) PTRACE( 6, varformat ) 162 #define PTRACE7( varformat ) PTRACE( 7, varformat ) 163 164 165 #ifdef __cplusplus 166 } 167 #endif 168 169 170 #endif /* TTDEBUG_H */ 171