2003-08-13 05:53:07 +04: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 06:07:03 +04:00
the Free Software Foundation ; either version 3 of the License , or
2003-08-13 05:53:07 +04: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 06:07:03 +04:00
along with this program . If not , see < http : //www.gnu.org/licenses/>.
2003-08-13 05:53:07 +04:00
*/
2008-11-01 17:21:31 +03:00
# ifndef _SAMBA_DEBUG_H_
# define _SAMBA_DEBUG_H_
2006-03-06 03:24:51 +03:00
/**
* @ file
* @ brief Debugging macros
*/
2003-08-13 05:53:07 +04: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 20:24:13 +04:00
uint32_t ( * get_task_id ) ( void ) ;
2003-12-04 12:52:14 +03:00
/* function to log process/thread id */
void ( * log_task_id ) ( int fd ) ;
2003-08-13 05:53:07 +04:00
} ;
2008-10-11 22:44:19 +04:00
# define DEBUGLEVEL *debug_level
2003-08-13 05:53:07 +04:00
extern int DEBUGLEVEL ;
# define DEBUGLVL(level) ((level) <= DEBUGLEVEL)
2006-01-09 21:25:06 +03:00
# define _DEBUG(level, body, header) do { \
if ( DEBUGLVL ( level ) ) { \
if ( header ) { \
2008-10-11 22:44:19 +04:00
dbghdr ( level , __location__ , __FUNCTION__ ) ; \
2006-01-09 21:25:06 +03:00
} \
2008-10-11 22:44:19 +04:00
dbgtext body ; \
2006-01-09 21:25:06 +03:00
} \
} while ( 0 )
2006-03-06 03:24:51 +03:00
/**
* Write to the debug log .
*/
2007-08-27 21:21:16 +04:00
# define DEBUG(level, body) _DEBUG(level, body, true)
2006-03-06 03:24:51 +03:00
/**
* Add data to an existing debug log entry .
*/
2007-08-27 21:21:16 +04:00
# define DEBUGADD(level, body) _DEBUG(level, body, false)
2006-03-06 03:24:51 +03:00
/**
* Obtain indentation string for the debug log .
*
* Level specified by n .
*/
2003-08-13 05:53:07 +04:00
# define DEBUGTAB(n) do_debug_tab(n)
2009-06-29 14:12:23 +04:00
/** Possible destinations for the debug log (in order of precedence -
* once set to DEBUG_FILE , it is not possible to reset to DEBUG_STDOUT
* for example . This makes it easy to override for debug to stderr on
* the command line , as the smb . conf cannot reset it back to
* file - based logging */
2009-06-29 13:57:57 +04:00
enum debug_logtype { DEBUG_STDOUT = 0 , DEBUG_FILE = 1 , DEBUG_STDERR = 2 } ;
2007-10-14 14:52:32 +04: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 22:44:19 +04:00
_PUBLIC_ void dbghdr ( int level , const char * location , const char * func ) ;
2007-10-14 14:52:32 +04:00
2008-11-02 06:50:32 +03:00
_PUBLIC_ void dbghdrclass ( int level , int cls , const char * location , const char * func ) ;
2008-10-20 20:59:51 +04:00
2007-10-14 14:52:32 +04: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 ) ;
2009-06-29 14:12:23 +04:00
/**
Just run logging to stdout for this program
*/
_PUBLIC_ void setup_logging_stdout ( void ) ;
2007-10-14 14:52:32 +04:00
/**
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 22:44:19 +04:00
_PUBLIC_ void dbgtext ( const char * format , . . . ) PRINTF_ATTRIBUTE ( 1 , 2 ) ;
2008-10-20 20:59:51 +04:00
2008-12-17 13:34:41 +03:00
struct _XFILE ;
extern struct _XFILE * dbf ;
2008-11-01 17:21:31 +03:00
2010-04-02 11:19:47 +04:00
/* setup talloc logging */
void debug_setup_talloc_log ( void ) ;
2008-11-01 17:21:31 +03:00
# endif