2000-02-03 07:47:50 +03:00
/*
Unix SMB / Netbios implementation .
Version 1.9 .
SMB debug stuff
Copyright ( C ) Andrew Tridgell 1992 - 1998
Copyright ( C ) John H Terpstra 1996 - 1998
Copyright ( C ) Luke Kenneth Casson Leighton 1996 - 1998
Copyright ( C ) Paul Ashton 1998
This program is free software ; you can redistribute it and / or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation ; either version 2 of the License , or
( at your option ) any later version .
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
You should have received a copy of the GNU General Public License
along with this program ; if not , write to the Free Software
Foundation , Inc . , 675 Mass Ave , Cambridge , MA 0213 9 , USA .
*/
# ifndef _DEBUG_H
# define _DEBUG_H
/* -------------------------------------------------------------------------- **
* Debugging code . See also debug . c
*/
/* mkproto.awk has trouble with ifdef'd function definitions (it ignores
* the # ifdef directive and will read both definitions , thus creating two
* diffferent prototype declarations ) , so we must do these by hand .
*/
/* I know the __attribute__ stuff is ugly, but it does ensure we get the
arguemnts to DEBUG ( ) right . We have got them wrong too often in the
past .
*/
2001-04-28 17:49:34 +04:00
int Debug1 ( char * , . . . ) PRINTF_ATTRIBUTE ( 1 , 2 ) ;
BOOL dbgtext ( char * , . . . ) PRINTF_ATTRIBUTE ( 1 , 2 ) ;
2000-02-03 07:47:50 +03:00
/* If we have these macros, we can add additional info to the header. */
# ifdef HAVE_FILE_MACRO
# define FILE_MACRO (__FILE__)
# else
# define FILE_MACRO ("")
# endif
# ifdef HAVE_FUNCTION_MACRO
# define FUNCTION_MACRO (__FUNCTION__)
# else
# define FUNCTION_MACRO ("")
# endif
2001-02-12 19:18:02 +03:00
/*
* Redefine DEBUGLEVEL because so we don ' t have to change every source file
* that * unnecessarily * references it . Source files neeed not extern reference
* DEBUGLEVEL , as it ' s extern in includes . h ( which all source files include ) .
* Eventually , all these references should be removed , and all references to
* DEBUGLEVEL should be references to DEBUGLEVEL_CLASS [ DBGC_ALL ] . This could
* still be through a macro still called DEBUGLEVEL . This cannot be done now
* because some references would expand incorrectly .
*/
# define DEBUGLEVEL *debug_level
/*
* Define all new debug classes here . A class is represented by an entry in
* the DEBUGLEVEL_CLASS array . Index zero of this arrray is equivalent to the
* old DEBUGLEVEL . Any source file that does NOT add the following lines :
*
* # undef DBGC_CLASS
* # define DBGC_CLASS DBGC_ < your class name here >
*
* at the start of the file ( after # include " includes.h " ) will default to
* using index zero , so it will behaive just like it always has .
*/
# define DBGC_CLASS 0 /* override as shown above */
# define DBGC_ALL 0 /* index equivalent to DEBUGLEVEL */
# define DBGC_TDB 1
# define DBGC_PRINTDRIVERS 2
# define DBGC_LANMAN 3
2001-06-01 16:04:44 +04:00
# define DBGC_SMB 4
# define DBGC_RPC 5
# define DBGC_RPC_HDR 6
# define DBGC_BDC 7
2001-02-12 19:18:02 +03:00
2001-06-01 16:04:44 +04:00
# define DBGC_LAST 8 /* MUST be last class value + 1 */
2001-02-12 19:18:02 +03:00
extern int DEBUGLEVEL_CLASS [ DBGC_LAST ] ;
2001-06-01 16:04:44 +04:00
extern BOOL DEBUGLEVEL_CLASS_ISSET [ DBGC_LAST ] ;
2001-02-12 19:18:02 +03:00
2001-06-01 16:04:44 +04:00
struct debuglevel_message {
int debuglevel_class [ DBGC_LAST ] ;
BOOL debuglevel_class_isset [ DBGC_LAST ] ;
} ;
2001-02-12 19:18:02 +03:00
/* Debugging macros
*
* DEBUGLVL ( )
* If the ' file specific ' debug class level > = level OR the system - wide
* DEBUGLEVEL ( synomym for DEBUGLEVEL_CLASS [ DBGC_ALL ] ) > = level then
* generate a header using the default macros for file , line , and
* function name . Returns True if the debug level was < = DEBUGLEVEL .
*
* Example : if ( DEBUGLVL ( 2 ) ) dbgtext ( " Some text. \n " ) ;
*
* DEBUGLVLC ( )
* If the ' macro specified ' debug class level > = level OR the system - wide
* DEBUGLEVEL ( synomym for DEBUGLEVEL_CLASS [ DBGC_ALL ] ) > = level then
* generate a header using the default macros for file , line , and
* function name . Returns True if the debug level was < = DEBUGLEVEL .
*
2001-06-01 16:04:44 +04:00
* Example : if ( DEBUGLVLC ( DBGC_TDB , 2 ) ) dbgtext ( " Some text. \n " ) ;
2001-02-12 19:18:02 +03:00
*
* DEBUG ( )
* If the ' file specific ' debug class level > = level OR the system - wide
* DEBUGLEVEL ( synomym for DEBUGLEVEL_CLASS [ DBGC_ALL ] ) > = level then
* generate a header using the default macros for file , line , and
* function name . Each call to DEBUG ( ) generates a new header * unless * the
* previous debug output was unterminated ( i . e . no ' \n ' ) .
* See debug . c : dbghdr ( ) for more info .
*
2001-06-01 16:04:44 +04:00
* Example : DEBUG ( 2 , ( " Some text and a value %d. \n " , value ) ) ;
2001-02-12 19:18:02 +03:00
*
* DEBUGC ( )
* If the ' macro specified ' debug class level > = level OR the system - wide
* DEBUGLEVEL ( synomym for DEBUGLEVEL_CLASS [ DBGC_ALL ] ) > = level then
* generate a header using the default macros for file , line , and
* function name . Each call to DEBUG ( ) generates a new header * unless * the
* previous debug output was unterminated ( i . e . no ' \n ' ) .
* See debug . c : dbghdr ( ) for more info .
*
2001-06-01 16:04:44 +04:00
* Example : DEBUGC ( DBGC_TDB , 2 , ( " Some text and a value %d. \n " , value ) ) ;
2001-02-12 19:18:02 +03:00
*
* DEBUGADD ( ) , DEBUGADDC ( )
* Same as DEBUG ( ) and DEBUGC ( ) except the text is appended to the previous
* DEBUG ( ) , DEBUGC ( ) , DEBUGADD ( ) , DEBUGADDC ( ) with out another interviening
* header .
*
2001-06-01 16:04:44 +04:00
* Example : DEBUGADD ( 2 , ( " Some text and a value %d. \n " , value ) ) ;
* DEBUGADDC ( DBGC_TDB , 2 , ( " Some text and a value %d. \n " , value ) ) ;
2001-02-12 19:18:02 +03:00
*
* Note : If the debug class has not be redeined ( see above ) then the optimizer
* will remove the extra conditional test .
2000-02-03 07:47:50 +03:00
*/
2001-02-12 19:18:02 +03:00
2000-02-03 07:47:50 +03:00
# define DEBUGLVL( level ) \
2001-02-12 19:18:02 +03:00
( ( ( DEBUGLEVEL_CLASS [ DBGC_CLASS ] > = ( level ) ) | | \
2001-06-01 16:04:44 +04:00
( ! DEBUGLEVEL_CLASS [ DBGC_CLASS ] & & \
DEBUGLEVEL_CLASS [ DBGC_ALL ] > = ( level ) ) ) \
2001-02-12 19:18:02 +03:00
& & dbghdr ( level , FILE_MACRO , FUNCTION_MACRO , ( __LINE__ ) ) )
# define DEBUGLVLC( dbgc_class, level ) \
( ( ( DEBUGLEVEL_CLASS [ dbgc_class ] > = ( level ) ) | | \
2001-06-01 16:04:44 +04:00
( ! DEBUGLEVEL_CLASS_ISSET [ dbgc_class ] & & \
DEBUGLEVEL_CLASS [ DBGC_ALL ] > = ( level ) ) ) \
2000-02-03 07:47:50 +03:00
& & dbghdr ( level , FILE_MACRO , FUNCTION_MACRO , ( __LINE__ ) ) )
2001-02-12 19:18:02 +03:00
2000-02-03 07:47:50 +03:00
# define DEBUG( level, body ) \
2001-02-12 19:18:02 +03:00
( void ) ( ( ( DEBUGLEVEL_CLASS [ DBGC_CLASS ] > = ( level ) ) | | \
2001-06-01 16:04:44 +04:00
( ! DEBUGLEVEL_CLASS_ISSET [ DBGC_CLASS ] & & \
DEBUGLEVEL_CLASS [ DBGC_ALL ] > = ( level ) ) ) \
2001-02-12 19:18:02 +03:00
& & ( dbghdr ( level , FILE_MACRO , FUNCTION_MACRO , ( __LINE__ ) ) ) \
& & ( dbgtext body ) )
# define DEBUGC( dbgc_class, level, body ) \
( void ) ( ( ( DEBUGLEVEL_CLASS [ dbgc_class ] > = ( level ) ) | | \
2001-06-01 16:04:44 +04:00
( ! DEBUGLEVEL_CLASS_ISSET [ dbgc_class ] & & \
DEBUGLEVEL_CLASS [ DBGC_ALL ] > = ( level ) ) ) \
2000-02-03 07:47:50 +03:00
& & ( dbghdr ( level , FILE_MACRO , FUNCTION_MACRO , ( __LINE__ ) ) ) \
& & ( dbgtext body ) )
# define DEBUGADD( level, body ) \
2001-02-12 19:18:02 +03:00
( void ) ( ( ( DEBUGLEVEL_CLASS [ DBGC_CLASS ] > = ( level ) ) | | \
2001-06-01 16:04:44 +04:00
( ! DEBUGLEVEL_CLASS_ISSET [ DBGC_CLASS ] & & \
DEBUGLEVEL_CLASS [ DBGC_ALL ] > = ( level ) ) ) \
2001-02-12 19:18:02 +03:00
& & ( dbgtext body ) )
2000-02-03 07:47:50 +03:00
2001-02-12 19:18:02 +03:00
# define DEBUGADDC( dbgc_class, level, body ) \
( void ) ( ( ( DEBUGLEVEL_CLASS [ dbgc_class ] > = ( level ) ) | | \
2001-06-01 16:04:44 +04:00
( ! DEBUGLEVEL_CLASS_ISSET [ dbgc_class ] & & \
DEBUGLEVEL_CLASS [ DBGC_ALL ] > = ( level ) ) ) \
2001-02-12 19:18:02 +03:00
& & ( dbgtext body ) )
2000-02-03 07:47:50 +03:00
# endif