diff --git a/app/errors.c b/app/errors.c index bb9644c21a..d61743260a 100644 --- a/app/errors.c +++ b/app/errors.c @@ -24,6 +24,11 @@ #include #endif +#ifdef HAVE_EXECINFO_H +/* Allowing backtrace() API. */ +#include +#endif + #include #include "libgimpbase/gimpbase.h" @@ -442,7 +447,36 @@ gimp_get_stack_trace (void) g_free (gdb_stdout); } } +#endif +#ifdef HAVE_EXECINFO_H + /* As a last resort, try using the backtrace() Linux API. It is a bit + * less fancy than gdb or lldb, which is why it is not given priority. + */ + if (! trace) + { + void *buffer[100]; + char **symbols; + int n_symbols; + int i; + + n_symbols = backtrace (buffer, 100); + symbols = backtrace_symbols (buffer, n_symbols); + if (symbols) + { + GString *gtrace = g_string_new (NULL); + + for (i = 0; i < n_symbols; i++) + { + g_string_append (gtrace, + (const gchar *) symbols[i]); + g_string_append_c (gtrace, '\n'); + } + trace = g_string_free (gtrace, FALSE); + + free (symbols); + } + } #endif return trace; diff --git a/configure.ac b/configure.ac index 9aa5c16f37..0d7b4c1ed0 100644 --- a/configure.ac +++ b/configure.ac @@ -909,6 +909,12 @@ if test "x$platform_win32" = "xyes"; then fi AM_CONDITIONAL(HAVE_EXCHNDL, test "x$ac_cv_lib_exchndl_ExcHndlSetLogFileNameA" = "xyes") +########################### +# Check for backtrace() API +########################### + +AC_CHECK_HEADERS([execinfo.h]) + ########################################## # Check for some special functions we need ##########################################