preparing for release of alpha.0.0
[Samba.git] / source / include / debug.h
blobdf74da0b41592d68f664d5d2f1aed6073733ed57
1 /*
2 Unix SMB/Netbios implementation.
3 Version 1.9.
4 SMB debug stuff
5 Copyright (C) Andrew Tridgell 1992-1998
6 Copyright (C) John H Terpstra 1996-1998
7 Copyright (C) Luke Kenneth Casson Leighton 1996-1998
8 Copyright (C) Paul Ashton 1998
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 #ifndef _DEBUG_H
26 #define _DEBUG_H
28 /* -------------------------------------------------------------------------- **
29 * Debugging code. See also debug.c
32 /* mkproto.awk has trouble with ifdef'd function definitions (it ignores
33 * the #ifdef directive and will read both definitions, thus creating two
34 * diffferent prototype declarations), so we must do these by hand.
36 /* I know the __attribute__ stuff is ugly, but it does ensure we get the
37 arguemnts to DEBUG() right. We have got them wrong too often in the
38 past.
40 #ifdef HAVE_STDARG_H
41 int Debug1( char *, ... )
42 #ifdef __GNUC__
43 __attribute__ ((format (printf, 1, 2)))
44 #endif
46 BOOL dbgtext( char *, ... )
47 #ifdef __GNUC__
48 __attribute__ ((format (printf, 1, 2)))
49 #endif
51 #else
52 int Debug1();
53 BOOL dbgtext();
54 #endif
56 /* If we have these macros, we can add additional info to the header. */
57 #ifdef HAVE_FILE_MACRO
58 #define FILE_MACRO (__FILE__)
59 #else
60 #define FILE_MACRO ("")
61 #endif
63 #ifdef HAVE_FUNCTION_MACRO
64 #define FUNCTION_MACRO (__FUNCTION__)
65 #else
66 #define FUNCTION_MACRO ("")
67 #endif
69 /* Debugging macros.
70 * DEBUGLVL() - If level is <= the system-wide DEBUGLEVEL then generate a
71 * header using the default macros for file, line, and
72 * function name.
73 * Returns True if the debug level was <= DEBUGLEVEL.
74 * Example usage:
75 * if( DEBUGLVL( 2 ) )
76 * dbgtext( "Some text.\n" );
77 * DEGUG() - Good old DEBUG(). Each call to DEBUG() will generate a new
78 * header *unless* the previous debug output was unterminated
79 * (i.e., no '\n'). See debug.c:dbghdr() for more info.
80 * Example usage:
81 * DEBUG( 2, ("Some text.\n") );
82 * DEBUGADD() - If level <= DEBUGLEVEL, then the text is appended to the
83 * current message (i.e., no header).
84 * Usage:
85 * DEBUGADD( 2, ("Some additional text.\n") );
87 #define DEBUGLVL( level ) \
88 ( (DEBUGLEVEL >= (level)) \
89 && dbghdr( level, FILE_MACRO, FUNCTION_MACRO, (__LINE__) ) )
91 #define DEBUG( level, body ) \
92 (void)( (DEBUGLEVEL >= (level)) \
93 && (dbghdr( level, FILE_MACRO, FUNCTION_MACRO, (__LINE__) )) \
94 && (dbgtext body) )
96 #define DEBUGADD( level, body ) \
97 (void)( (DEBUGLEVEL >= (level)) && (dbgtext body) )
99 /* -------------------------------------------------------------------------- **
100 * These are the tokens returned by dbg_char2token().
103 typedef enum
105 dbg_null = 0,
106 dbg_ignore,
107 dbg_header,
108 dbg_timestamp,
109 dbg_level,
110 dbg_sourcefile,
111 dbg_function,
112 dbg_lineno,
113 dbg_message,
114 dbg_eof
115 } dbg_Token;
117 /* End Debugging code section.
118 * -------------------------------------------------------------------------- **
121 #endif