1 #ifndef XDVI_DEBUG_H_ 2 #define XDVI_DEBUG_H_ 3 4 /* 5 * Copyright (c) 2002-2013 the xdvik development team 6 * 7 * Permission is hereby granted, free of charge, to any person obtaining a copy 8 * of this software and associated documentation files (the "Software"), to 9 * deal in the Software without restriction, including without limitation the 10 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 11 * sell copies of the Software, and to permit persons to whom the Software is 12 * furnished to do so, subject to the following conditions: 13 * 14 * The above copyright notice and this permission notice shall be included in 15 * all copies or substantial portions of the Software. 16 * 17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 20 * PAUL VOJTA OR ANY OTHER AUTHOR OF THIS SOFTWARE BE LIABLE FOR ANY CLAIM, 21 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 * OTHER DEALINGS IN THE SOFTWARE. 24 * 25 */ 26 27 /* debugging flags and macros */ 28 29 #include "xdvi-config.h" 30 #include "xdvi.h" 31 #include "version.h" 32 33 #if HAVE_STRINGIZE 34 #ifdef NDEBUG 35 /* for production code, a failed ASSERT(x) just prints out a warning; 36 else it aborts and dumps core. 37 */ 38 #define ASSERT(x, y) do { \ 39 if(!(x)) { \ 40 fprintf(stderr, \ 41 "************************************************************\n" \ 42 "XDvi %s: Failed assertion:\n%s:%d: \"%s\": %s\n" \ 43 "Please report this as a bug to:\n" \ 44 "http://sourceforge.net/tracker/?group_id=23164&atid=377580\n" \ 45 "************************************************************\n", \ 46 XDVI_VERSION_INFO, __FILE__, __LINE__, #x, y); \ 47 } } while (0) 48 #else /* NDEBUG */ 49 #define ASSERT(x, y) do { \ 50 if(!(x)) { \ 51 fprintf(stderr, \ 52 "\n************************************************************\n" \ 53 "XDvi %s: Failed assertion:\n%s:%d: \"%s\": %s\n" \ 54 "Aborting now. Please report this as a bug to:\n" \ 55 "http://sourceforge.net/tracker/?group_id=23164&atid=377580\n" \ 56 "If a core dump has been produced, please invoke:\n" \ 57 "gdb %s core\nThen type \"bt\", " \ 58 "and include the resulting output in your bug report.\n" \ 59 "************************************************************\n", \ 60 XDVI_VERSION_INFO, __FILE__, __LINE__, #x, y, globals.program_name); \ 61 do_abort(); \ 62 } } while (0) 63 #endif /* NDEBUG */ 64 #else /* HAVE_STRINGIZE */ 65 #define ASSERT(x, y) /* as nothing */ 66 #endif 67 68 /* for temporary debugging statements */ 69 /* #define MYDEBUG 1 */ 70 #ifdef MYDEBUG 71 # define MYTRACE(X) do { \ 72 fprintf(stderr, "%s:%d: ", __FILE__, __LINE__); \ 73 fprintf X; \ 74 fprintf(stderr, "\n"); \ 75 } while(0) 76 #else 77 # define MYTRACE(X) 78 #endif 79 80 /* NOTE: keep these in sync with the debug_string_options array in util.c! */ 81 #define DBG_BITMAP 1 82 #define DBG_DVI 2 83 #define DBG_PK 4 84 #define DBG_BATCH 8 85 #define DBG_EVENT 16 86 #define DBG_PS 32 87 /* start of kpathsea debugging options */ 88 #define DBG_STAT 64 89 #define DBG_HASH 128 90 #define DBG_OPEN 256 91 #define DBG_PATHS 512 92 #define DBG_EXPAND 1024 93 #define DBG_SEARCH 2048 94 #define DBG_KPATHSEA 4032 /* handy abbrev */ 95 /* end of kpathsea debugging options */ 96 #define DBG_HTEX 4096 97 #define DBG_SRC_SPECIALS 8192 98 #define DBG_CLIENT 16384 99 #define DBG_FT 32768 100 #define DBG_FT_VERBOSE 65536 /* not currently used */ 101 #define DBG_GUI 131072 102 #define DBG_FIND 262144 103 #define DBG_FILES 524288 104 #define DBG_PTEXFNT 1048576 105 #define DBG_ALL (~DBG_BATCH) 106 107 /* a mapping of numerical options to descriptive strings, defined in util.c */ 108 struct debug_string_options { 109 int bitmap; 110 const char *description; 111 const char *help_formatting; 112 }; 113 114 /* 115 */ 116 117 #if 0 118 /* we don't want this defined for NDEBUG, since the tracing macros 119 are pretty useful also for users reporting bugs etc.; so we 120 enable them always. 121 */ 122 #define TRACE_HTEX(X) 123 #define TRACE_SRC(X) 124 #define TRACE_CLIENT(X) 125 #define TRACE_FT(X) 126 #define TRACE_FT_VERBOSE(X) 127 #define TRACE_GUI(X) 128 #define TRACE_EVENTS(X) 129 #define TRACE_FIND(X) 130 #define TRACE_FILES(X) 131 132 #else /* 0 */ 133 134 /* 135 * Note that the argument to these macros is always ((stderr, "...")). 136 * We could also have 137 * TRACE_SRC(("...")); 138 * and invoke a function, but then gcc (3.1) won't be able to check 139 * inconsistencies between conversion specifiers and arguments any 140 * more, and that's a real killer IMHO. 141 */ 142 143 #define TRACE_HTEX(X) \ 144 do { \ 145 if (globals.debug & DBG_HTEX) { \ 146 fprintf(stderr, "%s:%d: HTEX: ", __FILE__, __LINE__); \ 147 fprintf X; \ 148 fprintf(stderr, "\n"); \ 149 } \ 150 } while(0) 151 #define TRACE_SRC(X) \ 152 do { \ 153 if (globals.debug & DBG_SRC_SPECIALS) { \ 154 fprintf(stderr, "%s:%d: SRC: ", __FILE__, __LINE__); \ 155 fprintf X; \ 156 fprintf(stderr, "\n"); \ 157 } \ 158 } while(0) 159 #define TRACE_CLIENT(X) \ 160 do { \ 161 if (globals.debug & DBG_CLIENT) { \ 162 fprintf(stderr, "%s:%d: CLIENT: ", __FILE__, __LINE__); \ 163 fprintf X; \ 164 fprintf(stderr, "\n"); \ 165 } \ 166 } while(0) 167 #define TRACE_FT(X) \ 168 do { \ 169 if (globals.debug & DBG_FT) { \ 170 fprintf(stderr, "%s:%d: FT: ", __FILE__, __LINE__); \ 171 fprintf X; \ 172 fprintf(stderr, "\n"); \ 173 } \ 174 } while(0) 175 #define TRACE_FT_VERBOSE(X) \ 176 do { \ 177 if (globals.debug & DBG_FT_VERBOSE) { \ 178 fprintf(stderr, "%s:%d: FT_VERBOSE: ", __FILE__, __LINE__); \ 179 fprintf X; \ 180 fprintf(stderr, "\n"); \ 181 } \ 182 } while(0) 183 #define TRACE_GUI(X) \ 184 do { \ 185 if (globals.debug & DBG_GUI) { \ 186 fprintf(stderr, "%s:%d: GUI: ", __FILE__, __LINE__); \ 187 fprintf X; \ 188 fprintf(stderr, "\n"); \ 189 } \ 190 } while(0) 191 #define TRACE_EVENTS(X) \ 192 do { \ 193 if (globals.debug & DBG_EVENT) { \ 194 fprintf(stderr, "%s:%d: EVENT: ", __FILE__, __LINE__); \ 195 fprintf X; \ 196 fprintf(stderr, "\n"); \ 197 } \ 198 } while(0) 199 #define TRACE_FIND(X) \ 200 do { \ 201 if (globals.debug & DBG_FIND) { \ 202 fprintf(stderr, "%s:%d: FIND: ", __FILE__, __LINE__); \ 203 fprintf X; \ 204 fprintf(stderr, "\n"); \ 205 } \ 206 } while(0) 207 208 #define TRACE_FILES(X) \ 209 do { \ 210 if (globals.debug & DBG_FILES) { \ 211 fprintf(stderr, "%s:%d: FILES: ", __FILE__, __LINE__); \ 212 fprintf X; \ 213 fprintf(stderr, "\n"); \ 214 } \ 215 } while(0) 216 217 #endif /* 0 */ 218 219 #endif /* XDVI_DEBUG_H_ */ 220