1/* ***************************************************************************** 2 3libcsc: Debug Header File 4 5 ---------------------------------------------------------------- 6 7Copyright (c) 2001, Douglas R. Jerome, Peoria, AZ USA 8 9 This program is free software; you can redistribute it and/or modify 10 it under the terms of the GNU Library General Public License as 11 published by the Free Software Foundation; either version 2 of the 12 License, or (at your option) any later version. 13 14 This program is distributed in the hope that it will be useful, 15 but WITHOUT ANY WARRANTY; without even the implied warranty of 16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 GNU General Public License for more details. 18 19 You should have received a copy of the GNU Library General Public 20 License along with this program; if not, write to the Free Software 21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 22 23 ---------------------------------------------------------------- 24 25FILE NAME 26 27 $RCSfile: libcsc_debug.h,v $ 28 $Revision: 1.2 $ 29 $Date: 2002/05/04 04:50:19 $ 30 31PROGRAM INFORMATION 32 33 Developed by: libcsc project 34 Developer: Douglas R. Jerome, drj, <jerome@primenet.com> 35 36FILE DESCRIPTION 37 38 This is the libcsc debug header file. Read it carefully. 39 40CHANGE LOG 41 42 25jun01 drj File generation. 43 44***************************************************************************** */ 45 46 47/* 48 * ABSTRACT 49 * 50 * This debug resource is a compile-time configuration. Manifest constant 51 * macros (#define'd macros) are used to add debug instrumentation with 52 * compile-time enabling/disabling via the manifest constant (#define'd) 53 * word `DEBUG'. 54 * 55 * All of the libcsc assertion macros generate usefull function calls only when 56 * the manifest constant `DEBUG' is defined. The Standard C manifest constant 57 * `NDEBUG' is unused. 58 * 59 * The "secret" `x' assert functions are prototyped locally and no assumption 60 * is made about having `NULL' or any other things from headers files (like 61 * printf or stderr). Remember, we don't know, and can't assume, which headers 62 * files have been included by the code that includes this header. 63 * 64 * This header file tries to be passive to form a good debug environment, and 65 * therefore cannot include any header files. 66 * 67 * "Secret" `x' functions are used to do actual work (display of assertions, 68 * invocation of debuggers, etc.). This is the ONLY non-passive thing we can 69 * do, except possibly declare the manifest constant `ASSERT_FAIL' and define 70 * the three assertion macros: 71 * 1) ASSERT 72 * 2) ASSERT_ERRNO 73 * 3) ASSERT_RTN 74 * 75 * This header file my be included in a source code file multiple times, each 76 * time the manifest constant `DEBUG' may be define, or not. In this way, 77 * limited parts of the including source code will have the actual debug 78 * instrumentation (becuase re-including this header file with out having the 79 * manifest constant `DEBUG' defined will redefine the assertion debug macros 80 * to be empty). See this example description: 81 * 82 * #undef DEBUG 83 * #include "libcsc_debug.h" 84 * ^ 85 * | 86 * | 87 * // In this area of the code the macros `ASSERT', `ASSERT_ERRNO', and 88 * // `ASSERT_RTN' all have no affect; they are not defined to generate any 89 * // error checking. This is because DEBUG is not #define'd. 90 * | 91 * | 92 * v 93 * #define DEBUG 94 * #include "libcsc_debug.h" 95 * ^ 96 * | 97 * | 98 * // In this area of the code the macros `ASSERT', `ASSERT_ERRNO', and 99 * // `ASSERT_RTN' all have debuging affects; they ARE defined to generate 100 * // error checking. This is because DEBUG is #define'd. 101 * | 102 * | 103 * v 104 * #undef DEBUG 105 * #include "libcsc_debug.h" 106 * ^ 107 * | 108 * | 109 * // In this area of the code the macros `ASSERT', `ASSERT_ERRNO', and 110 * // `ASSERT_RTN' all have have been turned off and have no affect; they 111 * // are no longer defined to generate any error checking. This is 112 * // because DEBUG is not #define'd. 113 * | 114 * | 115 * v 116 */ 117 118 119#ifndef __libcsc_debugh 120#define __libcsc_debugh 121#endif 122 123 124#ifdef __cplusplus 125extern "C" { 126#endif 127 128 129#ifdef DEBUG 130 131 132/* ************************************************************************* */ 133/* */ 134/* H A V E D E B U G */ 135/* */ 136/* ************************************************************************* */ 137 138/* 139 * The libcsc version of `ASSERT' is parameterized by the `ASSERT_FAIL' 140 * manifest constant. If `ASSERT_FAIL' is defined as a non-zero value, then 141 * the secret assertion function `xcsc_assert_fail()' should call `abort()' 142 * or some other debug function. If `ASSERT_FAIL' is defined as zero, then 143 * the secret assertion function `xcsc_assert_fail()' should simply return. 144 */ 145 146#undef ASSERT 147#define ASSERT(exp) \ 148 ((void) ((exp) ? (void)0 : \ 149 xcsc_assert_fail(__FILE__,__LINE__,#exp,(char*)0,ASSERT_FAIL))) 150 151/* 152 * The libcsc version of `ASSERT_ERRNO' is parameterized by the `ASSERT_FAIL' 153 * manifest constant in the same way as the libcsc version of `ASSERT'. 154 */ 155#define ASSERT_ERRNO(exp) \ 156 ((void) (!(exp) ? (void)0 : \ 157 xassert_errno(__FILE__,__LINE__,(exp),ASSERT_FAIL))) 158 159/* 160 * The `ASSERT_RTN' macro is parameterized by the `ASSERT_FAIL' manifest 161 * constant in the same way as the libcsc version of `ASSERT'; however, it will 162 * execute a return instruction if the assertion function `xcsc_assert_fail()' 163 * returns, i.e. if `ASSERT_FAIL' is defined as zero. The `ASSERT_RTN' macro 164 * also accepts a user-specified string which should be printed by the secret 165 * assertion function `xcsc_assert_fail()'. 166 */ 167#define ASSERT_RTN(exp,str,ret) \ 168 {if(!(exp)) \ 169 {xcsc_assert_fail(__FILE__,__LINE__,#exp,str,ASSERT_FAIL);return(ret);}} 170 171 172/* 173 * If not defined, define the manifest constant `ASSERT_FAIL' such that the 174 * `x' assert "secret" functions harmlessly return. 175 */ 176#ifndef ASSERT_FAIL 177#define ASSERT_FAIL (0) 178#endif 179 180/* 181 * Here's a debug/trace print macro. 182 ---------- REMOVED 183#define dprint(x) cout << x; 184#define dtrace(x) {cout << __FILE__ << "(" << __LINE__<< "): "; \ 185 cout << x;} 186 ---------- end of REMOVED 187 */ 188 189/* 190 Enable debug version of miscellaneous standard str and mem functions. 191 */ 192 193#define csc_memcpy(dst,src,size) xcsc_memcpy(__FILE__,__LINE__,dst,src,size) 194#define csc_memmove(dst,src,size) xcsc_memmove(__FILE__,__LINE__,dst,src,size) 195#define csc_memset(dst,c,size) xcsc_memset(__FILE__,__LINE__,dst,c,size) 196#define csc_strcat(dst,src) xcsc_strcat(__FILE__,__LINE__,dst,src) 197#define csc_strcmp(str1,str2) xcsc_strcmp(__FILE__,__LINE__,str1,str2) 198#define csc_strncmp(str1,str2,n) xcsc_strncmp(__FILE__,__LINE__,str1,str2,n) 199#define csc_strcpy(dst,src) xcsc_strcpy(__FILE__,__LINE__,dst,src) 200#define csc_strncpy(dst,src,n) xcsc_strncpy(__FILE__,__LINE__,dst,src,n) 201#define csc_strlen(ptr) xcsc_strlen(__FILE__,__LINE__,ptr) 202#define csc_strrchr(ptr,c) xcsc_strrchr(__FILE__,__LINE__,ptr,c) 203 204extern void xcsc_assert_fail ( 205 const char* file_name, 206 unsigned int line_number, 207 const char* assert_expression, 208 const char* user_string, 209 int fail_flag 210 ); 211 212extern void xcsc_assert_errno ( 213 const char* file_name, 214 unsigned int line_number, 215 int error_number, 216 int fail_flag 217 ); 218 219extern void* xcsc_memcpy ( 220 const char* file_name, 221 unsigned int line_number, 222 void* dst, 223 const void* src, 224 size_t n 225 ); 226 227extern void* xcsc_memset ( 228 const char* file_name, 229 unsigned int line_number, 230 void* dst, 231 int c, 232 size_t n 233 ); 234 235extern char* xcsc_strcat ( 236 const char* file_name, 237 unsigned int line_number, 238 char* dst, 239 const char* src 240 ); 241 242extern int xcsc_strcmp ( 243 const char* file_name, 244 unsigned int line_number, 245 const char* str1, 246 const char* str2 247 ); 248 249extern int xcsc_strncmp ( 250 const char* file_name, 251 unsigned int line_number, 252 const char* str1, 253 const char* str2, 254 size_t n 255 ); 256 257extern char* xcsc_strcpy ( 258 const char* file_name, 259 unsigned int line_number, 260 char* dst, 261 const char* src 262 ); 263 264extern char* xcsc_strncpy ( 265 const char* file_name, 266 unsigned int line_number, 267 char* dst, 268 const char* src, 269 size_t n 270 ); 271 272extern int xcsc_strlen ( 273 const char* file_name, 274 unsigned int line_number, 275 const char* ptr 276 ); 277 278extern char* xcsc_strrchr ( 279 const char* file_name, 280 unsigned int line_number, 281 const char* ptr, 282 int c 283 ); 284 285 286#else 287 288 289/* ************************************************************************* */ 290/* */ 291/* N O D E B U G */ 292/* */ 293/* ************************************************************************* */ 294 295#undef ASSERT 296#undef ASSERT_ERRNO 297#undef ASSERT_RTN 298 299#define ASSERT(expression) ((void)0) 300#define ASSERT_ERRNO(expresssion) ((void)0) 301#define ASSERT_RTN(expression,string,return) ((void)0) 302 303#undef ASSERT_FAIL 304 305/* 306 ---------- REMOVED 307#define dprint(x) ((void)0) 308#define dtrace(x) ((void)0) 309 ---------- end of REMOVED 310*/ 311 312#define csc_memcpy memcpy 313#define csc_memmove memmove 314#define csc_memset memset 315#define csc_strcat strcat 316#define csc_strcmp strcmp 317#define csc_strncmp strncmp 318#define csc_strcpy strcpy 319#define csc_strncpy strncpy 320#define csc_strlen strlen 321#define csc_strrchr strrchr 322 323 324/* 325 * end of `#ifdef DEBUG' 326 */ 327#endif 328 329 330#ifdef __cplusplus 331} 332#endif 333 334 335#undef __libcsc_debugh 336