]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
freetdm: added debug ftdm_print_stack macro
authorMoises Silva <moy@sangoma.com>
Tue, 25 Oct 2011 21:13:07 +0000 (17:13 -0400)
committerMoises Silva <moy@sangoma.com>
Tue, 25 Oct 2011 21:36:30 +0000 (17:36 -0400)
libs/freetdm/src/include/private/ftdm_core.h

index 9c5c9ad4686bf82b012de6fa3b80011afebbbc60..65ffad677ce5e5136decf6d899aaed1e4451931c 100644 (file)
 #include <sys/time.h>
 #endif
 
+#ifdef __linux__
+#include <execinfo.h>
+#endif
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -220,6 +224,27 @@ extern "C" {
 
 #define ftdm_is_dtmf(key)  ((key > 47 && key < 58) || (key > 64 && key < 69) || (key > 96 && key < 101) || key == 35 || key == 42 || key == 87 || key == 119)
 
+#ifdef __linux__
+#define ftdm_print_stack(level) \
+       do { \
+               void *__stacktrace[100] = { 0 }; \
+               char **__symbols = NULL; \
+               int __size = 0; \
+               int __i = 0; \
+               __size = backtrace(__stacktrace, ftdm_array_len(__stacktrace)); \
+               __symbols = backtrace_symbols(__stacktrace, __size); \
+               if (__symbols) { \
+                       for (__i = 0; __i < __size; __i++) { \
+                               ftdm_log(__level, "%s\n", __symbols[i]); \
+                       } \
+               free(__symbols); \
+               } \
+       } while (0);
+#else
+#define ftdm_print_stack(level) ftdm_log(level, "FTDM_PRINT_STACK is not implemented in this operating system!\n");
+#endif
+
+
 #define FTDM_SPAN_IS_BRI(x)    ((x)->trunk_type == FTDM_TRUNK_BRI || (x)->trunk_type == FTDM_TRUNK_BRI_PTMP)
 /*!
   \brief Copy flags from one arbitrary object to another