s3:util add log_stack_trace_with_level
authorChristian Ambach <christian.ambach@de.ibm.com>
Wed, 10 Nov 2010 17:35:19 +0000 (18:35 +0100)
committerVolker Lendecke <vl@samba.org>
Mon, 22 Nov 2010 12:56:45 +0000 (13:56 +0100)
add a new function log_stack_trace_with_level to specify
the debug level with which backtraces will be written to the log

source3/include/proto.h
source3/lib/util.c

index 9726e833e1c2d807ada3b28c8b855778f6867501..b4bc97731dbca85e149a252d4a01e4eb608dfa6f 100644 (file)
@@ -1158,6 +1158,7 @@ uid_t nametouid(const char *name);
 gid_t nametogid(const char *name);
 void smb_panic(const char *const why);
 void log_stack_trace(void);
+void log_stack_trace_with_level(int level);
 const char *readdirname(SMB_STRUCT_DIR *p);
 bool is_in_path(const char *name, name_compare_entry *namelist, bool case_sensitive);
 void set_namearray(name_compare_entry **ppname_array, const char *namelist);
index 8e3cec8084e43cc28b17e3e3326d92bbe54236e1..4bd124743800cf7b0ed39a44ae9f44231bbf7999 100644 (file)
@@ -1514,7 +1514,7 @@ void smb_panic(const char *const why)
 #include <libexc.h>
 #endif
 
-void log_stack_trace(void)
+void log_stack_trace_with_level(int level)
 {
 #ifdef HAVE_LIBUNWIND
        /* Try to use libunwind before any other technique since on ia64
@@ -1538,7 +1538,7 @@ void log_stack_trace(void)
                goto libunwind_failed;
        }
 
-       DEBUG(0, ("BACKTRACE:\n"));
+       DEBUG(level, ("BACKTRACE:\n"));
 
        do {
            ip = sp = 0;
@@ -1551,7 +1551,7 @@ void log_stack_trace(void)
                    /* Name found. */
            case -UNW_ENOMEM:
                    /* Name truncated. */
-                   DEBUGADD(0, (" #%u %s + %#llx [ip=%#llx] [sp=%#llx]\n",
+                   DEBUGADD(level, (" #%u %s + %#llx [ip=%#llx] [sp=%#llx]\n",
                            i, procname, (long long)off,
                            (long long)ip, (long long) sp));
                    break;
@@ -1559,7 +1559,7 @@ void log_stack_trace(void)
            /* case -UNW_ENOINFO: */
            /* case -UNW_EUNSPEC: */
                    /* No symbol name found. */
-                   DEBUGADD(0, (" #%u %s [ip=%#llx] [sp=%#llx]\n",
+                   DEBUGADD(level, (" #%u %s [ip=%#llx] [sp=%#llx]\n",
                            i, "<unknown symbol>",
                            (long long)ip, (long long) sp));
            }
@@ -1569,7 +1569,7 @@ void log_stack_trace(void)
        return;
 
 libunwind_failed:
-       DEBUG(0, ("unable to produce a stack trace with libunwind\n"));
+       DEBUG(level, ("unable to produce a stack trace with libunwind\n"));
 
 #elif HAVE_BACKTRACE_SYMBOLS
        void *backtrace_stack[BACKTRACE_STACK_SIZE];
@@ -1580,14 +1580,14 @@ libunwind_failed:
        backtrace_size = backtrace(backtrace_stack,BACKTRACE_STACK_SIZE);
        backtrace_strings = backtrace_symbols(backtrace_stack, backtrace_size);
 
-       DEBUG(0, ("BACKTRACE: %lu stack frames:\n", 
+       DEBUG(level, ("BACKTRACE: %lu stack frames:\n",
                  (unsigned long)backtrace_size));
        
        if (backtrace_strings) {
                int i;
 
                for (i = 0; i < backtrace_size; i++)
-                       DEBUGADD(0, (" #%u %s\n", i, backtrace_strings[i]));
+                       DEBUGADD(level, (" #%u %s\n", i, backtrace_strings[i]));
 
                /* Leak the backtrace_strings, rather than risk what free() might do */
        }
@@ -1624,17 +1624,22 @@ libunwind_failed:
        levels = trace_back_stack(0, addrs, names,
                        BACKTRACE_STACK_SIZE, NAMESIZE - 1);
 
-       DEBUG(0, ("BACKTRACE: %d stack frames:\n", levels));
+       DEBUG(level, ("BACKTRACE: %d stack frames:\n", levels));
        for (i = 0; i < levels; i++) {
-               DEBUGADD(0, (" #%d 0x%llx %s\n", i, addrs[i], names[i]));
+               DEBUGADD(level, (" #%d 0x%llx %s\n", i, addrs[i], names[i]));
        }
 #undef NAMESIZE
 
 #else
-       DEBUG(0, ("unable to produce a stack trace on this platform\n"));
+       DEBUG(level, ("unable to produce a stack trace on this platform\n"));
 #endif
 }
 
+void log_stack_trace(void)
+{
+       log_stack_trace_with_level(0);
+}
+
 /*******************************************************************
   A readdir wrapper which just returns the file name.
  ********************************************************************/