# Description: Store g_assert* message into glibc's __abort_msg variable, just like glibs' own assert() function. This keeps the assertion message in the core dump for easier debugging, and can be used by automatic crash processing systems like Apport. This needs http://sourceware.org/git/?p=glibc.git;a=commitdiff;h=48dcd0ba
# Upstream: TODO

Index: glib2.0-2.21.6/configure.in
===================================================================
--- glib2.0-2.21.6.orig/configure.in	2009-09-11 11:57:45.000000000 +0200
+++ glib2.0-2.21.6/configure.in	2009-09-11 12:05:08.000000000 +0200
@@ -227,11 +227,19 @@
               [AC_HELP_STRING([--disable-visibility],
                               [don't use ELF visibility attributes])],,
               [enable_visibility=yes])
+AC_ARG_ENABLE(assert-messages,
+              [AC_HELP_STRING([--enable-assert-messages],
+                              [store assertion messages in glibc's __abort_msg variable])],
+              [enable_assert_messages=yes],)
 
 if test "x$enable_threads" != "xyes"; then
   enable_threads=no
 fi
 
+if test "x$enable_assert_messages" = "xyes"; then
+  AC_DEFINE(USE_ABORT_MSG, 1, [store assertion messages in glib'c __abort_msg variable])
+fi
+
 AC_MSG_CHECKING([whether to enable garbage collector friendliness])
 if test "x$enable_gc_friendly" = "xyes"; then
   AC_DEFINE(ENABLE_GC_FRIENDLY_DEFAULT, 1, [Whether to enable GC friendliness by default])
Index: glib2.0-2.21.6/glib/gtestutils.c
===================================================================
--- glib2.0-2.21.6.orig/glib/gtestutils.c	2009-09-11 11:55:34.000000000 +0200
+++ glib2.0-2.21.6/glib/gtestutils.c	2009-09-11 11:56:03.000000000 +0200
@@ -41,6 +41,10 @@
 #include <sys/select.h>
 #endif /* HAVE_SYS_SELECT_H */
 
+#ifdef USE_ABORT_MSG
+extern char *__abort_msg;
+#endif
+
 /* --- structures --- */
 struct GTestCase
 {
@@ -1296,8 +1300,19 @@
                    func, func[0] ? ":" : "",
                    " ", message, NULL);
   g_printerr ("**\n%s\n", s);
+
+  /* store assertion message in global glibc field */
+#ifdef USE_ABORT_MSG
+  if (__abort_msg)
+      /* free the old one */
+      g_free (__abort_msg);
+  __abort_msg = s;
+#endif
+
   g_test_log (G_TEST_LOG_ERROR, s, NULL, 0, NULL);
+#ifndef USE_ABORT_MSG
   g_free (s);
+#endif
   abort();
 }
 
