1 /* 2 Unix SMB/CIFS implementation. 3 Samba debug defines 4 Copyright (C) Andrew Tridgell 2003 5 6 This program is free software; you can redistribute it and/or modify 7 it under the terms of the GNU General Public License as published by 8 the Free Software Foundation; either version 2 of the License, or 9 (at your option) any later version. 10 11 This program is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU General Public License for more details. 15 16 You should have received a copy of the GNU General Public License 17 along with this program; if not, write to the Free Software 18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 */ 20 21 /** 22 * @file 23 * @brief Debugging macros 24 */ 25 26 /* the debug operations structure - contains function pointers to 27 various debug implementations of each operation */ 28 struct debug_ops { 29 /* function to log (using DEBUG) suspicious usage of data structure */ 30 void (*log_suspicious_usage)(const char* from, const char* info); 31 32 /* function to log (using printf) suspicious usage of data structure. 33 * To be used in circumstances when using DEBUG would cause loop. */ 34 void (*print_suspicious_usage)(const char* from, const char* info); 35 36 /* function to return process/thread id */ 37 uint32_t (*get_task_id)(void); 38 39 /* function to log process/thread id */ 40 void (*log_task_id)(int fd); 41 }; 42 43 extern int DEBUGLEVEL; 44 #define DEBUGLVL(level) ((level) <= DEBUGLEVEL) 45 #define _DEBUG(level, body, header) do { \ 46 if (DEBUGLVL(level)) { \ 47 if (header) { \ 48 do_debug_header(level, __location__, __FUNCTION__); \ 49 } \ 50 do_debug body; \ 51 } \ 52 } while (0) 53 /** 54 * Write to the debug log. 55 */ 56 #define DEBUG(level, body) _DEBUG(level, body, True) 57 /** 58 * Add data to an existing debug log entry. 59 */ 60 #define DEBUGADD(level, body) _DEBUG(level, body, False) 61 62 /** 63 * Obtain indentation string for the debug log. 64 * 65 * Level specified by n. 66 */ 67 #define DEBUGTAB(n) do_debug_tab(n) 68 69 #define DEBUG_FN_ENTER DEBUG(9,("ENTER function %s\n", __FUNCTION__)) 70 #define DEBUG_FN_ENTER_MSG(_msg) DEBUG(9,("ENTER function %s (%s)\n", __FUNCTION__, _msg)) 71 #define DEBUG_FN_EXIT DEBUG(9,("EXIT function %s (PASS)\n", __FUNCTION__)) 72 #define DEBUG_FN_EXIT_MSG(_msg) DEBUG(9,("EXIT function %s (PASS) (%s)\n", __FUNCTION__, _msg)) 73 #define DEBUG_FN_FAIL(_msg) DEBUG(9,("exit function %s (FAIL) (%s)\n", __FUNCTION__, _msg)) 74 75 /** Possible destinations for the debug log */ 76 enum debug_logtype {DEBUG_STDOUT = 0, DEBUG_FILE = 1, DEBUG_STDERR = 2}; 77