[libdazzle] debug: add backtrace helper



commit 06424ab47ab37e2309a5df4552adb2428ece7dcc
Author: Christian Hergert <chergert redhat com>
Date:   Mon Jan 14 16:18:54 2019 -0800

    debug: add backtrace helper

 src/dzl-debug.h.in | 24 ++++++++++++++++++++----
 1 file changed, 20 insertions(+), 4 deletions(-)
---
diff --git a/src/dzl-debug.h.in b/src/dzl-debug.h.in
index c8286f3..757539a 100644
--- a/src/dzl-debug.h.in
+++ b/src/dzl-debug.h.in
@@ -19,10 +19,6 @@
 #ifndef DZL_DEBUG_H
 #define DZL_DEBUG_H
 
-#include <glib.h>
-
-G_BEGIN_DECLS
-
 #ifndef DZL_ENABLE_TRACE
 # define DZL_ENABLE_TRACE @ENABLE_TRACING@
 #endif
@@ -30,6 +26,14 @@ G_BEGIN_DECLS
 # undef DZL_ENABLE_TRACE
 #endif
 
+#include <glib.h>
+
+#ifdef DZL_ENABLE_TRACE
+# include <execinfo.h>
+#endif
+
+G_BEGIN_DECLS
+
 /**
  * DZL_LOG_LEVEL_TRACE: (skip)
  */
@@ -68,6 +72,17 @@ G_BEGIN_DECLS
             G_STRFUNC, __LINE__);                                        \
       return _r;                                                         \
    } G_STMT_END
+# define DZL_BACKTRACE                                                   \
+  G_STMT_START {                                                         \
+    gpointer btbuf[64];                                                  \
+    int btbuflen = backtrace (btbuf, G_N_ELEMENTS (btbuf));              \
+    char **symnames = backtrace_symbols (btbuf, btbuflen);               \
+    for (guint _i = 0; _i < btbuflen; _i++) {                            \
+      g_log(G_LOG_DOMAIN, DZL_LOG_LEVEL_TRACE, "TRACE: [%-2d]: %s",      \
+            _i, symnames[_i]);                                           \
+    }                                                                    \
+    free (symnames);                                                     \
+  } G_STMT_END
 #else
 # define DZL_TODO(_msg)
 # define DZL_PROBE
@@ -76,6 +91,7 @@ G_BEGIN_DECLS
 # define DZL_GOTO(_l)   goto _l
 # define DZL_EXIT       return
 # define DZL_RETURN(_r) return _r
+# define DZL_BACKTRACE  G_STMT_START { } G_STMT_END
 #endif
 
 G_END_DECLS


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