app: add support for Linux backtrace() API.

It is nice because when available (Linux only?), it is a lot faster than
using a dedicated debugger such as GDB or LLDB, and also it allows to
always have a backtrace, even when no debuggers are installed.
Unfortunately the output is a lot less detailed, with no file paths, no
line numbers (even when debug symbols are there), no local values
printout, etc. It's pretty bare, with function names and the stack
levels. This is why it is not given priority, and GDB and LLDB are still
preferred when available.
This commit is contained in:
Jehan
2018-01-29 01:42:38 +01:00
parent 986b3fd70a
commit 4fd1c6c97c
2 changed files with 40 additions and 0 deletions

View File

@ -24,6 +24,11 @@
#include <unistd.h>
#endif
#ifdef HAVE_EXECINFO_H
/* Allowing backtrace() API. */
#include <execinfo.h>
#endif
#include <gio/gio.h>
#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;

View File

@ -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
##########################################