From 95d329e1b97e918b8111a7173c145fe6926dc3c0 Mon Sep 17 00:00:00 2001 From: Christian Ambach Date: Wed, 10 Nov 2010 18:35:19 +0100 Subject: [PATCH] s3:util add log_stack_trace_with_level 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 | 1 + source3/lib/util.c | 25 +++++++++++++++---------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/source3/include/proto.h b/source3/include/proto.h index 9726e833e1..b4bc97731d 100644 --- a/source3/include/proto.h +++ b/source3/include/proto.h @@ -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); diff --git a/source3/lib/util.c b/source3/lib/util.c index 8e3cec8084..4bd1247438 100644 --- a/source3/lib/util.c +++ b/source3/lib/util.c @@ -1514,7 +1514,7 @@ void smb_panic(const char *const why) #include #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, "", (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. ********************************************************************/ -- 2.34.1