debug Explain the behaviour of setup_logging() more clearly
[sfrench/samba-autobuild/.git] / source3 / include / debug.h
index f69c213eb700c32c12779969233d485850622f7f..92fa6e61453bbd972180f02eb33eb28e51024abc 100644 (file)
@@ -5,20 +5,19 @@
    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
+   the Free Software Foundation; either version 3 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 02139, USA.
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
 #ifndef _DEBUG_H
  * Debugging code.  See also debug.c
  */
 
+/* the maximum debug level to compile into the code. This assumes a good
+   optimising compiler that can remove unused code
+   for embedded or low-memory systems set this to a value like 2 to get
+   only important messages. This gives *much* smaller binaries
+*/
+#ifndef MAX_DEBUG_LEVEL
+#define MAX_DEBUG_LEVEL 1000
+#endif
+
 /* 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.
 /* PRINTFLIKE1 */
 int  Debug1( const char *, ... ) PRINTF_ATTRIBUTE(1,2);
 /* PRINTFLIKE1 */
-BOOL dbgtext( const char *, ... ) PRINTF_ATTRIBUTE(1,2);
-BOOL dbghdr( int level, const char *file, const char *func, int line );
+bool dbgtext( const char *, ... ) PRINTF_ATTRIBUTE(1,2);
+bool dbghdrclass( int level, int cls, const char *location, const char *func);
+bool dbghdr( int level, const char *location, const char *func);
 
-extern XFILE *dbf;
-extern pstring debugf;
+#if defined(sgi) && (_COMPILER_VERSION >= 730)
+#pragma mips_frequency_hint NEVER Debug1
+#pragma mips_frequency_hint NEVER dbgtext
+#pragma mips_frequency_hint NEVER dbghdrclass
+#pragma mips_frequency_hint NEVER dbghdr
+#endif
 
 /* If we have these macros, we can add additional info to the header. */
 
@@ -94,9 +107,10 @@ extern int DEBUGLEVEL;
 #define DBGC_IDMAP             13
 #define DBGC_QUOTA             14
 #define DBGC_ACLS              15
-#define DBGC_PRINTERDB         16
-#define DBGC_LOCKING           17
-#define DBGC_MSDFS             18
+#define DBGC_LOCKING           16
+#define DBGC_MSDFS             17
+#define DBGC_DMAPI             18
+#define DBGC_REGISTRY          19
 
 /* So you can define DBGC_CLASS before including debug.h */
 #ifndef DBGC_CLASS
@@ -104,7 +118,7 @@ extern int DEBUGLEVEL;
 #endif
 
 extern int  *DEBUGLEVEL_CLASS;
-extern BOOL *DEBUGLEVEL_CLASS_ISSET;
+extern bool *DEBUGLEVEL_CLASS_ISSET;
 
 /* Debugging macros
  *
@@ -156,50 +170,110 @@ extern BOOL *DEBUGLEVEL_CLASS_ISSET;
  * will remove the extra conditional test.
  */
 
-#define DEBUGLVL( level ) \
+/*
+ * From talloc.c:
+ */
+
+/* these macros gain us a few percent of speed on gcc */
+#if (__GNUC__ >= 3)
+/* the strange !! is to ensure that __builtin_expect() takes either 0 or 1
+   as its first argument */
+#ifndef likely
+#define likely(x)   __builtin_expect(!!(x), 1)
+#endif
+#ifndef unlikely
+#define unlikely(x) __builtin_expect(!!(x), 0)
+#endif
+#else
+#ifndef likely
+#define likely(x) (x)
+#endif
+#ifndef unlikely
+#define unlikely(x) (x)
+#endif
+#endif
+
+#define CHECK_DEBUGLVL( level ) \
   ( ((level) <= MAX_DEBUG_LEVEL) && \
-     ((DEBUGLEVEL_CLASS[ DBGC_CLASS ] >= (level))||  \
+     unlikely((DEBUGLEVEL_CLASS[ DBGC_CLASS ] >= (level))||  \
      (!DEBUGLEVEL_CLASS_ISSET[ DBGC_CLASS ] && \
-      DEBUGLEVEL_CLASS[ DBGC_ALL   ] >= (level))  ) \
-   && dbghdr( level, __FILE__, FUNCTION_MACRO, (__LINE__) ) )
+      DEBUGLEVEL_CLASS[ DBGC_ALL   ] >= (level))  ) )
+
+#define DEBUGLVL( level ) \
+  ( CHECK_DEBUGLVL(level) \
+   && dbghdrclass( level, DBGC_CLASS, __location__, FUNCTION_MACRO ) )
 
 
 #define DEBUGLVLC( dbgc_class, level ) \
   ( ((level) <= MAX_DEBUG_LEVEL) && \
-     ((DEBUGLEVEL_CLASS[ dbgc_class ] >= (level))||  \
+     unlikely((DEBUGLEVEL_CLASS[ dbgc_class ] >= (level))||  \
      (!DEBUGLEVEL_CLASS_ISSET[ dbgc_class ] && \
       DEBUGLEVEL_CLASS[ DBGC_ALL   ] >= (level))  ) \
-   && dbghdr( level, __FILE__, FUNCTION_MACRO, (__LINE__) ) )
+   && dbghdrclass( level, DBGC_CLASS, __location__, FUNCTION_MACRO) )
 
 
 #define DEBUG( level, body ) \
   (void)( ((level) <= MAX_DEBUG_LEVEL) && \
-           ((DEBUGLEVEL_CLASS[ DBGC_CLASS ] >= (level))||  \
+           unlikely((DEBUGLEVEL_CLASS[ DBGC_CLASS ] >= (level))||  \
            (!DEBUGLEVEL_CLASS_ISSET[ DBGC_CLASS ] && \
             DEBUGLEVEL_CLASS[ DBGC_ALL   ] >= (level))  ) \
-       && (dbghdr( level, __FILE__, FUNCTION_MACRO, (__LINE__) )) \
+       && (dbghdrclass( level, DBGC_CLASS, __location__, FUNCTION_MACRO )) \
        && (dbgtext body) )
 
 #define DEBUGC( dbgc_class, level, body ) \
   (void)( ((level) <= MAX_DEBUG_LEVEL) && \
-           ((DEBUGLEVEL_CLASS[ dbgc_class ] >= (level))||  \
+           unlikely((DEBUGLEVEL_CLASS[ dbgc_class ] >= (level))||  \
            (!DEBUGLEVEL_CLASS_ISSET[ dbgc_class ] && \
            DEBUGLEVEL_CLASS[ DBGC_ALL   ] >= (level))  ) \
-       && (dbghdr( level, __FILE__, FUNCTION_MACRO, (__LINE__) )) \
+       && (dbghdrclass( level, DBGC_CLASS, __location__, FUNCTION_MACRO)) \
        && (dbgtext body) )
 
 #define DEBUGADD( level, body ) \
   (void)( ((level) <= MAX_DEBUG_LEVEL) && \
-           ((DEBUGLEVEL_CLASS[ DBGC_CLASS ] >= (level))||  \
+           unlikely((DEBUGLEVEL_CLASS[ DBGC_CLASS ] >= (level))||  \
            (!DEBUGLEVEL_CLASS_ISSET[ DBGC_CLASS ] && \
             DEBUGLEVEL_CLASS[ DBGC_ALL   ] >= (level))  ) \
        && (dbgtext body) )
 
 #define DEBUGADDC( dbgc_class, level, body ) \
   (void)( ((level) <= MAX_DEBUG_LEVEL) && \
-          ((DEBUGLEVEL_CLASS[ dbgc_class ] >= (level))||  \
+          unlikely((DEBUGLEVEL_CLASS[ dbgc_class ] >= (level))||  \
            (!DEBUGLEVEL_CLASS_ISSET[ dbgc_class ] && \
             DEBUGLEVEL_CLASS[ DBGC_ALL   ] >= (level))  ) \
        && (dbgtext body) )
 
+/* Print a separator to the debug log. */
+#define DEBUGSEP(level)\
+       DEBUG((level),("===============================================================\n"))
+
+/* The following definitions come from lib/debug.c  */
+
+/** 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 */
+enum debug_logtype {DEBUG_DEFAULT_STDERR = 0, DEBUG_STDOUT = 1, DEBUG_FILE = 2, DEBUG_STDERR = 3};
+
+void setup_logging(const char *prog_name, enum debug_logtype new_logtype);
+
+void debug_close_dbf(void);
+void gfree_debugsyms(void);
+const char *debug_classname_from_index(int ndx);
+int debug_add_class(const char *classname);
+int debug_lookup_classname(const char *classname);
+bool debug_parse_levels(const char *params_str);
+void debug_message(struct messaging_context *msg_ctx, void *private_data, uint32_t msg_type, struct server_id src, DATA_BLOB *data);
+void debug_init(void);
+void debug_register_msgs(struct messaging_context *msg_ctx);
+void debug_set_logfile(const char *name);
+bool reopen_logs( void );
+void force_check_log_size( void );
+bool need_to_check_log_size( void );
+void check_log_size( void );
+void dbgflush( void );
+bool dbghdrclass(int level, int cls, const char *location, const char *func);
+bool dbghdr(int level, const char *location, const char *func);
+
 #endif
+