*** empty log message ***
[wmaker-crm.git] / src / DL.h
blobadd754ede3c7debb9fe8ed513d3c6e7904da0566
1 /*
2 * DL.h - support for logging (printf...) style debugging using gdb.
4 * Copyright (c) 1997 Phil Maker
5 * All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
28 * Id: DL.h,v 1.1.1.1 1997/11/23 11:45:50 pjm Exp
31 #ifndef _DL_h_
32 #define _DL_h_ 1
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
38 #ifndef WITHOUT_NANA
41 * nana-config.h - the system wide configuration file; we put the ifndef
42 * around it to avoid the file 5 million times during a compile.
45 #ifndef _nana_config_h_
46 #include <nana-config.h>
47 #endif
50 * DL_MAKE_VALID_BREAKPOINT() - used to make sure that we can put a
51 * breakpoint at this location. We default to a portable C expression
52 * which simply does an assignment. The configure script may override
53 * this (on an architecture basis) and replace it with something
54 * like asm("nop");
57 #ifndef DL_MAKE_VALID_BREAKPOINT
58 static volatile int _dl_target;
60 #define DL_MAKE_VALID_BREAKPOINT() _dl_target = 0
61 #endif
63 /*
64 * DL_LEVEL sets the level of logging analogously to NDEBUG in assert.h
66 * DL_LEVEL == 2: always print.
67 * DL_LEVEL == 1: print iff the guard is true.
68 * DL_LEVEL == 0: never print.
71 #ifndef DL_LEVEL /* define DEFAULT for DL_LEVEL */
72 #define DL_LEVEL 1
73 #endif
75 /*
76 * DL_DEFAULT_HANDLER - the default print handler; by default we just
77 * the debugger printf.
79 * @@call (void) printf(f)@@
82 #ifndef DL_DEFAULT_HANDLER /* define default handler */
83 #define DL_DEFAULT_HANDLER(g,h,p,f...) @@printf f@@
84 #endif /* DL_DEFAULT_HANDLER */
87 * DL_DEFAULT_GUARD - the default guard expression; a message is printed
88 * iff the guard is true. By default its always true.
91 #ifndef DL_DEFAULT_GUARD
92 #define DL_DEFAULT_GUARD (1)
93 #endif
96 * DL_DEFAULT_PARAMS - the default value to be passed as the second argument
97 * to the handler macro when an invariant fails.
101 #ifndef DL_DEFAULT_PARAMS
102 #define DL_DEFAULT_PARAMS stderr
103 #endif
106 * DL_SHOW_TIME - if its defined then each message gets a timestamp in front.
109 #ifdef DL_SHOW_TIME
111 unsigned long _L_gettime(void); /* returns the current time */
113 #define _DL_SHOWTIME(h,p) @@call (void) h (p, "%-8ld ", _L_gettime())@@
114 #else
116 #define _DL_SHOWTIME(h,p) /* nothing */
118 #endif /* DL_SHOWTIME */
121 * DLGHP(g,h,p,f...) - print a log message.
123 * g - the guard; print the message iff this is true
124 * h - the handler function that does the actual printing
125 * p - a parameter for the handler function; e.g. a file descriptor.
126 * f - the format and the data...
129 #if DL_LEVEL == 2 /* always log the message */
130 #ifdef _NANA_FILTER_
131 #define DLGHP(g,h,p,f...) \
132 do { \
133 @@break @__FILE__:__LINE__@@ \
134 @@command $bpnum@@ \
135 @@silent@@ \
136 _DL_SHOWTIME(h,p); \
137 DL_DEFAULT_HANDLER(g,h,p,##f); \
138 @@cont@@ \
139 @@end@@ \
140 } while(0)
141 #else
142 #define DLGHP(g,h,p,f...) DL_MAKE_VALID_BREAKPOINT()
143 #endif
145 #elif DL_LEVEL == 1 /* log it iff the guard is true */
147 #ifdef _NANA_FILTER_
148 #define DLGHP(g,h,p,f...) \
149 do { \
150 if(g) { \
151 @@break @__FILE__:__LINE__@@ \
152 @@condition $bpnum g@@ \
153 @@command $bpnum@@ \
154 @@silent@@ \
155 _DL_SHOWTIME(h,p); \
156 DL_DEFAULT_HANDLER(g,h,p,##f); \
157 @@cont@@ \
158 @@end@@ \
160 } while(0)
161 #else
162 #define DLGHP(g,h,p,f...) DL_MAKE_VALID_BREAKPOINT()
163 #endif
165 #elif DL_LEVEL == 0 /* no logging so ignore them */
166 #define DLGHP(g,h,p,f...) /* nothing */
167 #endif /* DL_LEVEL */
170 * And the user routines.
173 #define DL(f...) \
174 DLGHP(DL_DEFAULT_GUARD,DL_DEFAULT_HANDLER,DL_DEFAULT_PARAMS,##f)
175 #define DLG(g,f...) \
176 DLGHP(g,DL_DEFAULT_HANDLER,DL_DEFAULT_PARAMS,##f)
177 #define DLH(h,f...) \
178 DLGHP(DL_DEFAULT_GUARD,h,DL_DEFAULT_PARAMS,##f)
179 #define DLP(p,f...) \
180 DLGHP(DL_DEFAULT_GUARD,DL_DEFAULT_HANDLER,p,##f)
181 #define DLGP(g,p,f...) \
182 DLGHP(g,DL_DEFAULT_HANDLER,p,##f)
183 #define DLHP(h,p,f...) \
184 DLGHP(DL_DEFAULT_GUARD,h,p,##f)
188 * V* - since the DL* macros take a variable numbers of arguments we
189 * have problems compiling calls to L with C preprocessors other
190 * than GNU cccp. The V* macros are called using a bracketed arglist, e.g.
191 * VDL((s,x,y))
193 * if we are compiling with GNU C then they simply call the normal
194 * varargs macros. if we are not using GNU C then they map to empty.
197 #define VDL(a) DL a
198 #define VDLG(a) DLG a
199 #define VDLH(a) DLH a
200 #define VDLP(a) DLP a
201 #define VDLGP(a) DLGP a
202 #define VDLHP(a) DLHP a
203 #define VDLGHP(a) DLGHP a
205 #else /* defined(WITHOUT_NANA) */
207 #define VDL(a) /* empty */
208 #define VDLG(a) /* empty */
209 #define VDLH(a) /* empty */
210 #define VDLP(a) /* empty */
211 #define VDLGP(a) /* empty */
212 #define VDLHP(a) /* empty */
213 #define VDLGHP(a) /* empty */
215 #endif /* !defined(WITHOUT_NANA) */
218 #ifdef __cplusplus
220 #endif
222 #endif /* _DL_h_ */