[PATCH] stack trace support for IRIX (bug #1038)

James Peach jpeach at sgi.com
Wed Feb 11 07:53:12 GMT 2004


Hi all,

The attached patch implements smb_panic stack tracing for IRIX by making use
of the standard (on IRIX) libexc stack tracing API. This fixes Samba bug #1038
and SGI #909347.

cheers,

--
James Peach | jpeach at sgi.com | SGI Australian Software Group
I don't speak for SGI.

--- configure.in	3 Feb 2004 03:23:18 -0000	1.300.2.213
+++ samba/source/configure.in	11 Feb 2004 06:44:36 -0000
@@ -919,6 +919,8 @@
 AC_CHECK_FUNCS(setlocale nl_langinfo)
 # setbuffer, shmget, shm_open are needed for smbtorture
 AC_CHECK_FUNCS(setbuffer shmget shm_open backtrace_symbols)
+AC_CHECK_HEADERS(libexc.h)
+AC_CHECK_LIB(exc, trace_back_stack)
 
 # syscall() is needed for smbwrapper.
 AC_CHECK_FUNCS(syscall)

--- lib/util.c	30 Jan 2004 18:38:47 -0000	1.358.2.43
+++ samba/source/lib/util.c	11 Feb 2004 06:44:36 -0000
@@ -1344,6 +1344,10 @@
  Something really nasty happened - panic !
 ********************************************************************/
 
+#ifdef HAVE_LIBEXC_H
+#include <libexc.h>
+#endif
+
 void smb_panic(const char *why)
 {
 	char *cmd;
@@ -1398,6 +1402,42 @@
 		SAFE_FREE(backtrace_strings);
 	}
 
+#elif HAVE_LIBEXC
+
+#define NAMESIZE 32 /* Arbitrary */
+
+	/* The IRIX libexc library provides an API for unwinding the stack. See
+	 * libexc(3) for details. Apparantly trace_back_stack leaks memory, but
+	 * since we are about to abort anyway, it hardly matters.
+	 *
+	 * Note that if we paniced due to a SIGSEGV or SIGBUS (or similar) this
+	 * will fail with a nasty message upon failing to open the /proc entry.
+	 */
+	{
+		__uint64_t	addrs[BACKTRACE_STACK_SIZE];
+		char *      	names[BACKTRACE_STACK_SIZE];
+		char		namebuf[BACKTRACE_STACK_SIZE * NAMESIZE];
+
+		int		i;
+		int		levels;
+
+		ZERO_ARRAY(addrs);
+		ZERO_ARRAY(names);
+		ZERO_ARRAY(namebuf);
+
+		for (i = 0; i < BACKTRACE_STACK_SIZE; i++) {
+			names[i] = namebuf + (i * NAMESIZE);
+		}
+
+		levels = trace_back_stack(0, addrs, names,
+				BACKTRACE_STACK_SIZE, NAMESIZE);
+
+		DEBUG(0, ("BACKTRACE: %d stack frames:\n", levels));
+		for (i = 0; i < levels; i++) {
+			DEBUGADD(0, (" #%d 0x%llx %s\n", i, addrs[i], names[i]));
+		}
+     }
+#undef NAMESIZE
 #endif
 
 	dbgflush();


More information about the samba-technical mailing list