[gimp] app: add support for Linux backtrace() API.



commit 4fd1c6c97c6c903117c44f481402ce2ff1cc25a5
Author: Jehan <jehan girinstud io>
Date:   Mon Jan 29 01:42:38 2018 +0100

    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.

 app/errors.c |   34 ++++++++++++++++++++++++++++++++++
 configure.ac |    6 ++++++
 2 files changed, 40 insertions(+), 0 deletions(-)
---
diff --git a/app/errors.c b/app/errors.c
index bb9644c..d617432 100644
--- a/app/errors.c
+++ b/app/errors.c
@@ -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;
diff --git a/configure.ac b/configure.ac
index 9aa5c16..0d7b4c1 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
 ##########################################


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]