Add --enable-glib-errors-trace configure switch

Mon, 17 Mar 2014 02:56:50 +0100

author
Tomasz Wasilczyk <twasilczyk@pidgin.im>
date
Mon, 17 Mar 2014 02:56:50 +0100
changeset 35633
e4618d775e0d
parent 35632
bd09f4d38bb0
child 35634
3a6156743d75

Add --enable-glib-errors-trace configure switch

configure.ac file | annotate | diff | comparison | revisions
pidgin/gtkdebug.c file | annotate | diff | comparison | revisions
--- a/configure.ac	Thu Mar 13 12:18:06 2014 +0100
+++ b/configure.ac	Mon Mar 17 02:56:50 2014 +0100
@@ -1545,6 +1545,17 @@
 	CFLAGS="$CFLAGS -faddress-sanitizer -g -fno-omit-frame-pointer -fno-inline -fno-optimize-sibling-calls"
 fi
 
+
+AC_ARG_ENABLE(glib-errors-trace, [AS_HELP_STRING([--enable-glib-errors-trace], [print backtraces for glib errors])], enable_glibtrace="$enableval", enable_glibtrace="no")
+if test "x$enable_glibtrace" = "xyes"; then
+	if test "x$have_clang" = "xyes"; then
+		AC_MSG_ERROR([--enable-glib-errors-trace doesn't work with clang])
+	fi
+	AC_DEFINE(ENABLE_GLIBTRACE, 1, [Define if backtraces should be printed for glib errors.])
+	dnl CFLAGS="$CFLAGS -rdynamic"
+	CFLAGS="$CFLAGS -rdynamic"
+fi
+
 dnl #######################################################################
 dnl # Check for D-Bus libraries
 dnl #######################################################################
--- a/pidgin/gtkdebug.c	Thu Mar 13 12:18:06 2014 +0100
+++ b/pidgin/gtkdebug.c	Mon Mar 17 02:56:50 2014 +0100
@@ -32,6 +32,10 @@
 #include "gtkwebview.h"
 #include "pidginstock.h"
 
+#ifdef ENABLE_GLIBTRACE
+#include <execinfo.h>
+#endif
+
 #include <gdk/gdkkeysyms.h>
 
 #include "gtk3compat.h"
@@ -668,6 +672,17 @@
 
 	if (new_msg != NULL)
 	{
+#ifdef ENABLE_GLIBTRACE
+		void *bt_buff[20];
+		size_t bt_size;
+
+		bt_size = backtrace(bt_buff, 20);
+		fprintf(stderr, "\nBacktrace for \"%s\" (%s):\n", new_msg,
+			new_domain != NULL ? new_domain : "g_log");
+		backtrace_symbols_fd(bt_buff, bt_size, STDERR_FILENO);
+		fprintf(stderr, "\n");
+#endif
+
 		purple_debug(level, (new_domain != NULL ? new_domain : "g_log"),
 				   "%s\n", new_msg);
 

mercurial