Aegis  4.25.D505
/home/archives/aegis/branch.4/branch.25/delta28933.505/common/trace.h
Go to the documentation of this file.
00001 //
00002 //      aegis - project change supervisor
00003 //      Copyright (C) 1991-1994, 1999, 2002, 2005, 2006, 2008, 2012 Peter Miller
00004 //
00005 //      This program is free software; you can redistribute it and/or modify
00006 //      it under the terms of the GNU General Public License as published by
00007 //      the Free Software Foundation; either version 3 of the License, or
00008 //      (at your option) any later version.
00009 //
00010 //      This program is distributed in the hope that it will be useful,
00011 //      but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 //      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 //      GNU General Public License for more details.
00014 //
00015 //      You should have received a copy of the GNU General Public License
00016 //      along with this program. If not, see
00017 //      <http://www.gnu.org/licenses/>.
00018 //
00019 
00020 #ifndef TRACE_H
00021 #define TRACE_H
00022 
00023 #include <common/ac/stddef.h>
00024 
00025 #include <common/gcc-attribute.h>
00026 #include <common/debug.h>
00027 
00028 struct string_ty; // forward
00029 
00036 #ifdef DEBUG
00037 #define trace_pretest_ \
00038         (                                                       \
00039                 (                                               \
00040                         trace_pretest_result                    \
00041                 ?                                               \
00042                         trace_pretest_result                    \
00043                 :                                               \
00044                         trace_pretest(__FILE__, &trace_pretest_result) \
00045                 )                                               \
00046         &                                                       \
00047                 1                                               \
00048         )
00049 #define trace_where_ trace_where(__FILE__, __LINE__)
00050 #define trace(x) (void)(trace_pretest_ && (trace_where_, trace_printf x, 0))
00051 #define trace_if() (trace_pretest_ && (trace_where_, 1))
00052 #else
00053 #define trace(x)
00054 #define trace_if() 0
00055 #endif
00056 
00057 //
00058 // This variable is static to each file which
00059 // includes the "trace.h" file.
00060 // Tracing is file-by-file, but need only test this once.
00061 // Files will fail to trace if a trace call is executed in them
00062 // prior to a call to trace_enable turning it on.
00063 //
00064 #ifdef DEBUG
00065 static int trace_pretest_result;
00066 #endif
00067 
00068 int trace_pretest(const char *file, int *result);
00069 void trace_where(const char *file, int line);
00070 void trace_printf(const char *, ...) ATTR_PRINTF(1, 2);
00071 const char * trace_args();
00072 void trace_enable(const char *);
00073 void trace_indent_reset(void);
00074 
00075 
00076 #if defined(__STDC__) || defined(__stdc__)
00077 #define trace_stringize(x) #x
00078 #else
00079 #define trace_stringize(x) "x"
00080 #endif
00081 
00082 void trace_bool_real(const char *name, const bool &value);
00083 void trace_char_real(const char *, const char *);
00084 void trace_char_unsigned_real(const char *, const unsigned char *);
00085 void trace_int_real(const char *, const int *);
00086 void trace_int_unsigned_real(const char *, const unsigned *);
00087 void trace_long_real(const char *, const long *);
00088 void trace_long_unsigned_real(const char *, const unsigned long *);
00089 void trace_pointer_real(const char *, const void *);
00090 void trace_short_real(const char *, const short *);
00091 void trace_short_unsigned_real(const char *, const unsigned short *);
00092 class nstring; // forward
00093 void trace_string_real(const char *, const nstring &);
00094 void trace_string_real(const char *, const string_ty *);
00095 void trace_string_real(const char *, const char *);
00096 void trace_time_real(const char *, long);
00097 void trace_double_real(const char *, const double &);
00098 
00099 #ifdef DEBUG
00100 
00101 #define trace_bool(x)                                           \
00102     (void)                                                      \
00103     (                                                           \
00104         trace_pretest_                                          \
00105     &&                                                          \
00106         (                                                       \
00107             trace_where_,                                       \
00108             trace_bool_real(trace_stringize(x), (x)),           \
00109             0                                                   \
00110         )                                                       \
00111     )
00112 
00113 #define trace_char(x)                                           \
00114     (void)                                                      \
00115     (                                                           \
00116         trace_pretest_                                          \
00117     &&                                                          \
00118         (                                                       \
00119             trace_where_,                                       \
00120             trace_char_real(trace_stringize(x), &(x)),          \
00121             0                                                   \
00122         )                                                       \
00123     )
00124 
00125 #define trace_char_unsigned(x)                                  \
00126     (void)                                                      \
00127     (                                                           \
00128         trace_pretest_                                          \
00129     &&                                                          \
00130         (                                                       \
00131             trace_where_,                                       \
00132             trace_char_unsigned_real(trace_stringize(x), &(x)), \
00133             0                                                   \
00134         )                                                       \
00135     )
00136 
00137 #define trace_int(x)                                            \
00138     (void)                                                      \
00139     (                                                           \
00140         trace_pretest_                                          \
00141     &&                                                          \
00142         (                                                       \
00143             trace_where_,                                       \
00144             trace_int_real(trace_stringize(x), &(x)),           \
00145             0                                                   \
00146         )                                                       \
00147     )
00148 
00149 #define trace_int_unsigned(x)                                   \
00150     (void)                                                      \
00151     (                                                           \
00152         trace_pretest_                                          \
00153     &&                                                          \
00154         (                                                       \
00155             trace_where_,                                       \
00156             trace_int_unsigned_real(trace_stringize(x), &(x)),  \
00157             0                                                   \
00158         )                                                       \
00159     )
00160 
00161 #define trace_long(x)                                           \
00162     (void)                                                      \
00163     (                                                           \
00164         trace_pretest_                                          \
00165     &&                                                          \
00166         (                                                       \
00167             trace_where_,                                       \
00168             trace_long_real(trace_stringize(x), &(x)),          \
00169             0                                                   \
00170         )                                                       \
00171     )
00172 
00173 #define trace_long_unsigned(x)                                  \
00174     (void)                                                      \
00175     (                                                           \
00176         trace_pretest_                                          \
00177     &&                                                          \
00178         (                                                       \
00179             trace_where_,                                       \
00180             trace_long_unsigned_real(trace_stringize(x), &(x)), \
00181             0                                                   \
00182         )                                                       \
00183     )
00184 
00185 #define trace_pointer(x)                                        \
00186     (void)                                                      \
00187     (                                                           \
00188         trace_pretest_                                          \
00189     &&                                                          \
00190         (                                                       \
00191             trace_where_,                                       \
00192             trace_pointer_real(trace_stringize(x), &(x)),       \
00193             0                                                   \
00194         )                                                       \
00195     )
00196 
00197 #define trace_short(x)                                          \
00198     (void)                                                      \
00199     (                                                           \
00200         trace_pretest_                                          \
00201     &&                                                          \
00202         (                                                       \
00203             trace_where_,                                       \
00204             trace_short_real(trace_stringize(x), &(x)),         \
00205             0                                                   \
00206         )                                                       \
00207     )
00208 
00209 #define trace_short_unsigned(x)                                 \
00210     (void)                                                      \
00211     (                                                           \
00212         trace_pretest_                                          \
00213     &&                                                          \
00214         (                                                       \
00215             trace_where_,                                       \
00216             trace_short_unsigned_real(trace_stringize(x), &(x)), \
00217             0                                                   \
00218         )                                                       \
00219     )
00220 
00221 #define trace_string(x)                                         \
00222     (void)                                                      \
00223     (                                                           \
00224         trace_pretest_                                          \
00225     &&                                                          \
00226         (                                                       \
00227             trace_where_,                                       \
00228             trace_string_real(trace_stringize(x), (x)),         \
00229             0                                                   \
00230         )                                                       \
00231     )
00232 
00233 #define trace_nstring(x)                                        \
00234     (void)                                                      \
00235     (                                                           \
00236         trace_pretest_                                          \
00237     &&                                                          \
00238         (                                                       \
00239             trace_where_,                                       \
00240             trace_string_real(trace_stringize(x), (x).c_str()), \
00241             0                                                   \
00242         )                                                       \
00243     )
00244 
00245 #define trace_time(x)                                           \
00246     (void)                                                      \
00247     (                                                           \
00248         trace_pretest_                                          \
00249     &&                                                          \
00250         (                                                       \
00251             trace_where_,                                       \
00252             trace_time_real(trace_stringize(x), (long)(x)),     \
00253             0                                                   \
00254         )                                                       \
00255     )
00256 
00257 #define trace_double(x)                                         \
00258     (void)                                                      \
00259     (                                                           \
00260         trace_pretest_                                          \
00261     &&                                                          \
00262         (                                                       \
00263             trace_where_,                                       \
00264             trace_time_real(trace_stringize(x), (x)),           \
00265             0                                                   \
00266         )                                                       \
00267     )
00268 
00269 #else
00270 
00271 #define trace_bool(x)
00272 #define trace_char(x)
00273 #define trace_char_unsigned(x)
00274 #define trace_int(x)
00275 #define trace_int_unsigned(x)
00276 #define trace_long(x)
00277 #define trace_long_unsigned(x)
00278 #define trace_pointer(x)
00279 #define trace_short(x)
00280 #define trace_short_unsigned(x)
00281 #define trace_string(x)
00282 #define trace_nstring(x)
00283 #define trace_time(x)
00284 #define trace_double(x)
00285 
00286 #endif
00287 
00292 const char *unctrl(int);
00293 
00295 #endif // TRACE_H
00296 // vim: set ts=8 sw=4 et :