Index: configure.ac
===================================================================
RCS file: /cvs/gstreamer/gstreamer/configure.ac,v
retrieving revision 1.494
diff -u -p -r1.494 configure.ac
--- configure.ac	29 Jan 2007 15:54:09 -0000	1.494
+++ configure.ac	5 Feb 2007 15:41:45 -0000
@@ -301,6 +301,9 @@ AC_CHECK_HEADERS([process.h])
 dnl Check for sys/utsname.h for uname
 AC_CHECK_HEADERS([sys/utsname.h])
 
+dnl Check for execinfo.h for libgstcheck backtrace stuff
+AC_CHECK_HEADERS([execinfo.h])
+
 dnl *** checks for types/defines ***
 
 dnl *** checks for structures ***
Index: libs/gst/check/gstcheck.c
===================================================================
RCS file: /cvs/gstreamer/gstreamer/libs/gst/check/gstcheck.c,v
retrieving revision 1.20
diff -u -p -r1.20 gstcheck.c
--- libs/gst/check/gstcheck.c	16 Jan 2007 09:57:50 -0000	1.20
+++ libs/gst/check/gstcheck.c	5 Feb 2007 15:41:45 -0000
@@ -27,6 +27,10 @@
  * inside the 'check' directories of various GStreamer packages.
  */
 
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
 #include "gstcheck.h"
 
 GST_DEBUG_CATEGORY (check_debug);
@@ -76,6 +80,64 @@ void gst_check_log_critical_func
     _gst_check_raised_warning = TRUE;
 }
 
+#if defined(G_OS_UNIX) && defined(HAVE_EXECINFO_H)
+#include <signal.h>
+#include <execinfo.h>
+
+static struct sigaction oldaction;
+static gboolean _gst_check_fault_handler_is_setup; /* FALSE */
+
+static void
+_gst_check_fault_handler_restore (void)
+{
+  if (!_gst_check_fault_handler_is_setup)
+    return;
+
+  _gst_check_fault_handler_is_setup = FALSE;
+
+  sigaction (SIGSEGV, &oldaction, NULL);
+}
+
+static void
+_gst_check_fault_handler_sighandler (int signum)
+{
+  /* We need to restore the fault handler or we'll keep getting it */
+  _gst_check_fault_handler_restore ();
+
+  switch (signum) {
+    case SIGSEGV: {
+      void *bt_arr[20];
+      int num;
+
+      printf ("\nERROR: ");
+      printf ("segmentation fault while running unit test.\n");
+      if ((num =  backtrace ((void **) bt_arr, G_N_ELEMENTS (bt_arr))))
+        backtrace_symbols_fd (bt_arr, num, 2);
+      break;
+    }
+    default:
+      printf ("\nCaught unhandled signal during unit test\n");
+      break;
+  }
+}
+
+static void
+_gst_check_fault_handler_setup (void)
+{
+  struct sigaction action;
+
+  if (_gst_check_fault_handler_is_setup)
+    return;
+
+  _gst_check_fault_handler_is_setup = TRUE;
+
+  memset (&action, 0, sizeof (action));
+  action.sa_handler = _gst_check_fault_handler_sighandler;
+
+  sigaction (SIGSEGV, &action, &oldaction);
+}
+#endif /* G_OS_UNIX && HAVE_EXECINFO_H */
+
 /* initialize GStreamer testing */
 void
 gst_check_init (int *argc, char **argv[])
@@ -98,6 +160,10 @@ gst_check_init (int *argc, char **argv[]
 
   check_cond = g_cond_new ();
   check_mutex = g_mutex_new ();
+
+#if defined(G_OS_UNIX) && defined(HAVE_EXECINFO_H)
+  _gst_check_fault_handler_setup ();
+#endif
 }
 
 /* message checking */
