00001 /* 00002 * DL.h - support for logging (printf...) style debugging using gdb. 00003 * 00004 * Copyright (c) 1997 Phil Maker 00005 * All rights reserved. 00006 * 00007 * Redistribution and use in source and binary forms, with or without 00008 * modification, are permitted provided that the following conditions 00009 * are met: 00010 * 1. Redistributions of source code must retain the above copyright 00011 * notice, this list of conditions and the following disclaimer. 00012 * 2. Redistributions in binary form must reproduce the above copyright 00013 * notice, this list of conditions and the following disclaimer in the 00014 * documentation and/or other materials provided with the distribution. 00015 * 00016 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 00017 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00018 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00019 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 00020 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00021 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 00022 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 00023 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00024 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 00025 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 00026 * SUCH DAMAGE. 00027 * 00028 * Id: DL.h,v 1.1.1.1 1997/11/23 11:45:50 pjm Exp 00029 */ 00030 00031 #ifndef _DL_h_ 00032 #define _DL_h_ 1 00033 00034 #ifdef __cplusplus 00035 extern "C" { 00036 #endif 00037 00038 #ifndef WITHOUT_NANA 00039 00040 /* 00041 * nana-config.h - the system wide configuration file; we put the ifndef 00042 * around it to avoid the file 5 million times during a compile. 00043 */ 00044 00045 #ifndef _nana_config_h_ 00046 #include <nana-config.h> 00047 #endif 00048 00049 /* 00050 * DL_MAKE_VALID_BREAKPOINT() - used to make sure that we can put a 00051 * breakpoint at this location. We default to a portable C expression 00052 * which simply does an assignment. The configure script may override 00053 * this (on an architecture basis) and replace it with something 00054 * like asm("nop"); 00055 */ 00056 00057 #ifndef DL_MAKE_VALID_BREAKPOINT 00058 static volatile int _dl_target; 00059 00060 #define DL_MAKE_VALID_BREAKPOINT() _dl_target = 0 00061 #endif 00062 00063 /* 00064 * DL_LEVEL sets the level of logging analogously to NDEBUG in assert.h 00065 * 00066 * DL_LEVEL == 2: always print. 00067 * DL_LEVEL == 1: print iff the guard is true. 00068 * DL_LEVEL == 0: never print. 00069 */ 00070 00071 #ifndef DL_LEVEL /* define DEFAULT for DL_LEVEL */ 00072 #define DL_LEVEL 1 00073 #endif 00074 00075 /* 00076 * DL_DEFAULT_HANDLER - the default print handler; by default we just 00077 * the debugger printf. 00078 * 00079 * @@call (void) printf(f)@@ 00080 */ 00081 00082 #ifndef DL_DEFAULT_HANDLER /* define default handler */ 00083 #define DL_DEFAULT_HANDLER(g,h,p,f...) @@printf f@@ 00084 #endif /* DL_DEFAULT_HANDLER */ 00085 00086 /* 00087 * DL_DEFAULT_GUARD - the default guard expression; a message is printed 00088 * iff the guard is true. By default its always true. 00089 */ 00090 00091 #ifndef DL_DEFAULT_GUARD 00092 #define DL_DEFAULT_GUARD (1) 00093 #endif 00094 00095 /* 00096 * DL_DEFAULT_PARAMS - the default value to be passed as the second argument 00097 * to the handler macro when an invariant fails. 00098 */ 00099 00100 00101 #ifndef DL_DEFAULT_PARAMS 00102 #define DL_DEFAULT_PARAMS stderr 00103 #endif 00104 00105 /* 00106 * DL_SHOW_TIME - if its defined then each message gets a timestamp in front. 00107 */ 00108 00109 #ifdef DL_SHOW_TIME 00110 00111 unsigned long _L_gettime(void); /* returns the current time */ 00112 00113 #define _DL_SHOWTIME(h,p) @@call (void) h (p, "%-8ld ", _L_gettime())@@ 00114 #else 00115 00116 #define _DL_SHOWTIME(h,p) /* nothing */ 00117 00118 #endif /* DL_SHOWTIME */ 00119 00120 /* 00121 * DLGHP(g,h,p,f...) - print a log message. 00122 * 00123 * g - the guard; print the message iff this is true 00124 * h - the handler function that does the actual printing 00125 * p - a parameter for the handler function; e.g. a file descriptor. 00126 * f - the format and the data... 00127 */ 00128 00129 #if DL_LEVEL == 2 /* always log the message */ 00130 #ifdef _NANA_FILTER_ 00131 #define DLGHP(g,h,p,f...) \ 00132 do { \ 00133 @@break @__FILE__:__LINE__@@ \ 00134 @@command $bpnum@@ \ 00135 @@silent@@ \ 00136 _DL_SHOWTIME(h,p); \ 00137 DL_DEFAULT_HANDLER(g,h,p,##f); \ 00138 @@cont@@ \ 00139 @@end@@ \ 00140 } while(0) 00141 #else 00142 #define DLGHP(g,h,p,f...) DL_MAKE_VALID_BREAKPOINT() 00143 #endif 00144 00145 #elif DL_LEVEL == 1 /* log it iff the guard is true */ 00146 00147 #ifdef _NANA_FILTER_ 00148 #define DLGHP(g,h,p,f...) \ 00149 do { \ 00150 if(g) { \ 00151 @@break @__FILE__:__LINE__@@ \ 00152 @@condition $bpnum g@@ \ 00153 @@command $bpnum@@ \ 00154 @@silent@@ \ 00155 _DL_SHOWTIME(h,p); \ 00156 DL_DEFAULT_HANDLER(g,h,p,##f); \ 00157 @@cont@@ \ 00158 @@end@@ \ 00159 } \ 00160 } while(0) 00161 #else 00162 #define DLGHP(g,h,p,f...) DL_MAKE_VALID_BREAKPOINT() 00163 #endif 00164 00165 #elif DL_LEVEL == 0 /* no logging so ignore them */ 00166 #define DLGHP(g,h,p,f...) /* nothing */ 00167 #endif /* DL_LEVEL */ 00168 00169 /* 00170 * And the user routines. 00171 */ 00172 00173 #define DL(f...) \ 00174 DLGHP(DL_DEFAULT_GUARD,DL_DEFAULT_HANDLER,DL_DEFAULT_PARAMS,##f) 00175 #define DLG(g,f...) \ 00176 DLGHP(g,DL_DEFAULT_HANDLER,DL_DEFAULT_PARAMS,##f) 00177 #define DLH(h,f...) \ 00178 DLGHP(DL_DEFAULT_GUARD,h,DL_DEFAULT_PARAMS,##f) 00179 #define DLP(p,f...) \ 00180 DLGHP(DL_DEFAULT_GUARD,DL_DEFAULT_HANDLER,p,##f) 00181 #define DLGP(g,p,f...) \ 00182 DLGHP(g,DL_DEFAULT_HANDLER,p,##f) 00183 #define DLHP(h,p,f...) \ 00184 DLGHP(DL_DEFAULT_GUARD,h,p,##f) 00185 00186 00187 /* 00188 * V* - since the DL* macros take a variable numbers of arguments we 00189 * have problems compiling calls to L with C preprocessors other 00190 * than GNU cccp. The V* macros are called using a bracketed arglist, e.g. 00191 * VDL((s,x,y)) 00192 * 00193 * if we are compiling with GNU C then they simply call the normal 00194 * varargs macros. if we are not using GNU C then they map to empty. 00195 */ 00196 00197 #define VDL(a) DL a 00198 #define VDLG(a) DLG a 00199 #define VDLH(a) DLH a 00200 #define VDLP(a) DLP a 00201 #define VDLGP(a) DLGP a 00202 #define VDLHP(a) DLHP a 00203 #define VDLGHP(a) DLGHP a 00204 00205 #else /* defined(WITHOUT_NANA) */ 00206 00207 #define VDL(a) /* empty */ 00208 #define VDLG(a) /* empty */ 00209 #define VDLH(a) /* empty */ 00210 #define VDLP(a) /* empty */ 00211 #define VDLGP(a) /* empty */ 00212 #define VDLHP(a) /* empty */ 00213 #define VDLGHP(a) /* empty */ 00214 00215 #endif /* !defined(WITHOUT_NANA) */ 00216 00217 00218 #ifdef __cplusplus 00219 } 00220 #endif 00221 00222 #endif /* _DL_h_ */ 00223 00224 00225 00226 00227
1.3.4