From 10bf059b62480d502652408e9c138445859789fc Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 14 Apr 2003 21:49:49 +0000 Subject: Backport my backtrace patch from HEAD (This used to be commit 66fcf6b4938a87e5ded7c7e5830a6a54e4439544) --- source3/configure.in | 4 ++-- source3/include/includes.h | 4 ++++ source3/include/local.h | 4 ++++ source3/lib/util.c | 21 +++++++++++++++++++++ 4 files changed, 31 insertions(+), 2 deletions(-) diff --git a/source3/configure.in b/source3/configure.in index 233cf852d6..6c71882d90 100644 --- a/source3/configure.in +++ b/source3/configure.in @@ -564,7 +564,7 @@ AC_CHECK_HEADERS(sys/mman.h sys/filio.h sys/priv.h sys/shm.h string.h strings.h AC_CHECK_HEADERS(sys/mount.h sys/vfs.h sys/fs/s5param.h sys/filsys.h termios.h termio.h) AC_CHECK_HEADERS(sys/termio.h sys/statfs.h sys/dustat.h sys/statvfs.h stdarg.h sys/sockio.h) AC_CHECK_HEADERS(security/pam_modules.h security/_pam_macros.h ldap.h lber.h dlfcn.h) -AC_CHECK_HEADERS(sys/syslog.h syslog.h) +AC_CHECK_HEADERS(sys/syslog.h syslog.h execinfo.h) # In valgrind 1.0.x, it's just valgrind.h. In 1.9.x+ there's a # subdirectory of headers. @@ -887,7 +887,7 @@ AC_CHECK_FUNCS(fseek64 fseeko64 ftell64 ftello64 setluid getpwanam setlinebuf) AC_CHECK_FUNCS(srandom random srand rand setenv usleep strcasecmp fcvt fcvtl symlink readlink) AC_CHECK_FUNCS(syslog vsyslog getgrouplist timegm) # setbuffer, shmget, shm_open are needed for smbtorture -AC_CHECK_FUNCS(setbuffer shmget shm_open) +AC_CHECK_FUNCS(setbuffer shmget shm_open backtrace_symbols) # syscall() is needed for smbwrapper. AC_CHECK_FUNCS(syscall) diff --git a/source3/include/includes.h b/source3/include/includes.h index 1fc7c3c51a..d406c07d06 100644 --- a/source3/include/includes.h +++ b/source3/include/includes.h @@ -345,6 +345,10 @@ #include #endif +#ifdef HAVE_EXECINFO_H +#include +#endif + #ifdef HAVE_SYS_CAPABILITY_H #if defined(BROKEN_REDHAT_7_SYSTEM_HEADERS) && !defined(_I386_STATFS_H) diff --git a/source3/include/local.h b/source3/include/local.h index 29b0641119..4c3c58e14f 100644 --- a/source3/include/local.h +++ b/source3/include/local.h @@ -223,4 +223,8 @@ /* Max number of simultaneous winbindd socket connections. */ #define WINBINDD_MAX_SIMULTANEOUS_CLIENTS 200 + +/* Buffer size to use when printing backtraces */ +#define BACKTRACE_STACK_SIZE 64 + #endif diff --git a/source3/lib/util.c b/source3/lib/util.c index 1bfbd6f5a0..a392530786 100644 --- a/source3/lib/util.c +++ b/source3/lib/util.c @@ -1400,6 +1400,10 @@ void smb_panic(const char *why) { char *cmd; int result; + size_t i; + void *backtrace_stack[BACKTRACE_STACK_SIZE]; + size_t backtrace_size; + char **backtrace_strings; #ifdef DEVELOPER { @@ -1427,6 +1431,23 @@ void smb_panic(const char *why) WEXITSTATUS(result))); } DEBUG(0,("PANIC: %s\n", why)); + +#ifdef HAVE_BACKTRACE_SYMBOLS + /* get the backtrace (stack frames) */ + backtrace_size = backtrace(backtrace_stack,BACKTRACE_STACK_SIZE); + backtrace_strings = backtrace_symbols(backtrace_stack, backtrace_size); + + DEBUG(0, ("BACKTRACE: %d stack frames:\n", backtrace_size)); + + if (backtrace_strings) { + for (i = 0; i < backtrace_size; i++) + DEBUGADD(0, (" #%u %s\n", i, backtrace_strings[i])); + + SAFE_FREE(backtrace_strings); + } + +#endif + dbgflush(); abort(); } -- cgit