]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
tvhlog: add tvhlog_backtrace_printf() helper for debugging
authorJaroslav Kysela <perex@perex.cz>
Sun, 15 Nov 2015 22:15:06 +0000 (23:15 +0100)
committerJaroslav Kysela <perex@perex.cz>
Sun, 15 Nov 2015 22:15:06 +0000 (23:15 +0100)
src/tvhlog.c
src/tvhlog.h

index 7ba7b8a5f8ac64b7ebd5b731e04bd02cb171c5dd..5c4423889416a6edf29ddeca58a4725063dc2e99 100644 (file)
 #include <stdlib.h>
 #include <sys/time.h>
 
+#if ENABLE_EXECINFO
+#include <execinfo.h>
+#endif
+
 #include "libav.h"
 #include "webui/webui.h"
 
@@ -399,6 +403,27 @@ _tvhlog_hexdump(const char *file, int line,
   }
 }
 
+/*
+ *
+ */
+void
+tvhlog_backtrace_printf(const char *fmt, ...)
+{
+#if ENABLE_EXECINFO
+  static void *frames[5];
+  int nframes = backtrace(frames, 5), i;
+  char **strings = backtrace_symbols(frames, nframes);
+  va_list args;
+
+  va_start(args, fmt);
+  vprintf(fmt, args);
+  va_end(args);
+  for (i = 0; i < nframes; i++)
+    printf("  %s\n", strings[i]);
+  free(strings);
+#endif
+}
+
 /*
  * Initialise
  */
index e07cf4fd6bacb003b344b754c82f84d0be942d05..16441423f2c218c089377376393e9265f4bb3180 100644 (file)
@@ -131,4 +131,6 @@ static inline void tvhtrace_no_warnings(const char *fmt, ...) { (void)fmt; }
 
 time_t dispatch_clock_update(struct timespec *ts);
 
+void tvhlog_backtrace_printf(const char *fmt, ...);
+
 #endif /* __TVH_LOGGING_H__ */