2003-08-13 01:53:07 +00:00
/*
Unix SMB / CIFS implementation .
Samba debug defines
Copyright ( C ) Andrew Tridgell 2003
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
2007-07-10 02:07:03 +00:00
the Free Software Foundation ; either version 3 of the License , or
2003-08-13 01:53:07 +00:00
( 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
2007-07-10 02:07:03 +00:00
along with this program . If not , see < http : //www.gnu.org/licenses/>.
2003-08-13 01:53:07 +00:00
*/
2006-03-06 00:24:51 +00:00
/**
* @ file
* @ brief Debugging macros
*/
2003-08-13 01:53:07 +00:00
/* the debug operations structure - contains function pointers to
various debug implementations of each operation */
struct debug_ops {
/* function to log (using DEBUG) suspicious usage of data structure */
void ( * log_suspicious_usage ) ( const char * from , const char * info ) ;
/* function to log (using printf) suspicious usage of data structure.
* To be used in circumstances when using DEBUG would cause loop . */
void ( * print_suspicious_usage ) ( const char * from , const char * info ) ;
/* function to return process/thread id */
2004-05-25 16:24:13 +00:00
uint32_t ( * get_task_id ) ( void ) ;
2003-12-04 09:52:14 +00:00
/* function to log process/thread id */
void ( * log_task_id ) ( int fd ) ;
2003-08-13 01:53:07 +00:00
} ;
2008-10-11 20:44:19 +02:00
# define DEBUGLEVEL *debug_level
2003-08-13 01:53:07 +00:00
extern int DEBUGLEVEL ;
2008-02-01 16:19:36 +00:00
# define debug_ctx() (_debug_ctx?_debug_ctx:(_debug_ctx=talloc_new(NULL)))
2003-08-13 01:53:07 +00:00
# define DEBUGLVL(level) ((level) <= DEBUGLEVEL)
2006-01-09 18:25:06 +00:00
# define _DEBUG(level, body, header) do { \
if ( DEBUGLVL ( level ) ) { \
2008-02-01 16:19:36 +00:00
void * _debug_ctx = NULL ; \
2006-01-09 18:25:06 +00:00
if ( header ) { \
2008-10-11 20:44:19 +02:00
dbghdr ( level , __location__ , __FUNCTION__ ) ; \
2006-01-09 18:25:06 +00:00
} \
2008-10-11 20:44:19 +02:00
dbgtext body ; \
2008-02-01 16:19:36 +00:00
talloc_free ( _debug_ctx ) ; \
2006-01-09 18:25:06 +00:00
} \
} while ( 0 )
2006-03-06 00:24:51 +00:00
/**
* Write to the debug log .
*/
2007-08-27 17:21:16 +00:00
# define DEBUG(level, body) _DEBUG(level, body, true)
2006-03-06 00:24:51 +00:00
/**
* Add data to an existing debug log entry .
*/
2007-08-27 17:21:16 +00:00
# define DEBUGADD(level, body) _DEBUG(level, body, false)
2006-03-06 00:24:51 +00:00
/**
* Obtain indentation string for the debug log .
*
* Level specified by n .
*/
2003-08-13 01:53:07 +00:00
# define DEBUGTAB(n) do_debug_tab(n)
2006-03-06 00:24:51 +00:00
/** Possible destinations for the debug log */
2005-06-13 08:12:39 +00:00
enum debug_logtype { DEBUG_STDOUT = 0 , DEBUG_FILE = 1 , DEBUG_STDERR = 2 } ;
2007-10-14 12:52:32 +02:00
/**
the backend for debug messages . Note that the DEBUG ( ) macro has already
ensured that the log level has been met before this is called
*/
2008-10-11 20:44:19 +02:00
_PUBLIC_ void dbghdr ( int level , const char * location , const char * func ) ;
2007-10-14 12:52:32 +02:00
/**
reopen the log file ( usually called because the log file name might have changed )
*/
_PUBLIC_ void reopen_logs ( void ) ;
/**
* this global variable determines what messages are printed
*/
_PUBLIC_ void debug_schedule_reopen_logs ( void ) ;
/**
control the name of the logfile and whether logging will be to stdout , stderr
or a file
*/
_PUBLIC_ void setup_logging ( const char * prog_name , enum debug_logtype new_logtype ) ;
/**
return a string constant containing n tabs
no more than 10 tabs are returned
*/
_PUBLIC_ const char * do_debug_tab ( int n ) ;
/**
log suspicious usage - print comments and backtrace
*/
_PUBLIC_ void log_suspicious_usage ( const char * from , const char * info ) ;
/**
print suspicious usage - print comments and backtrace
*/
_PUBLIC_ void print_suspicious_usage ( const char * from , const char * info ) ;
_PUBLIC_ uint32_t get_task_id ( void ) ;
_PUBLIC_ void log_task_id ( void ) ;
/**
register a set of debug handlers .
*/
_PUBLIC_ void register_debug_handlers ( const char * name , struct debug_ops * ops ) ;
/**
the backend for debug messages . Note that the DEBUG ( ) macro has already
ensured that the log level has been met before this is called
@ note You should never have to call this function directly . Call the DEBUG ( )
macro instead .
*/
2008-10-11 20:44:19 +02:00
_PUBLIC_ void dbgtext ( const char * format , . . . ) PRINTF_ATTRIBUTE ( 1 , 2 ) ;