From 564a567ed17fa416a7b5328bf87a07976841ff9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaakko=20Ker=C3=A4nen?= Date: Sun, 16 Mar 2014 08:55:23 +0200 Subject: [PATCH] Debug|Unix|libdeng2: Added a backtrace print macro Perhaps the Best Thing Ever for non-invasive debugging. --- doomsday/libdeng2/include/de/libdeng2.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/doomsday/libdeng2/include/de/libdeng2.h b/doomsday/libdeng2/include/de/libdeng2.h index 4ddcbc3f46..8ce95e5f53 100644 --- a/doomsday/libdeng2/include/de/libdeng2.h +++ b/doomsday/libdeng2/include/de/libdeng2.h @@ -137,6 +137,19 @@ # define DENG2_DEBUG # ifdef DENG2_USE_QT # define DENG2_ASSERT(x) Q_ASSERT(x) +# ifdef UNIX +# include +/** + * @macro DENG2_PRINT_BACKTRACE + * Debug utility for dumping the current backtrace using qDebug. + */ +# define DENG2_PRINT_BACKTRACE() { \ + void *callstack[128]; \ + int i, frames = backtrace(callstack, 128); \ + char** strs = backtrace_symbols(callstack, frames); \ + for(i = 0; i < frames; ++i) qDebug("%s", strs[i]); \ + free(strs); } +# endif # else # define DENG2_ASSERT(x) assert(x) # endif