From: Jaroslav Kysela Date: Sun, 15 Nov 2015 22:15:06 +0000 (+0100) Subject: tvhlog: add tvhlog_backtrace_printf() helper for debugging X-Git-Tag: v4.2.1~1540 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=52759be3ff193c7d74c8e237c821003395adee5f;p=thirdparty%2Ftvheadend.git tvhlog: add tvhlog_backtrace_printf() helper for debugging --- diff --git a/src/tvhlog.c b/src/tvhlog.c index 7ba7b8a5f..5c4423889 100644 --- a/src/tvhlog.c +++ b/src/tvhlog.c @@ -23,6 +23,10 @@ #include #include +#if ENABLE_EXECINFO +#include +#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 */ diff --git a/src/tvhlog.h b/src/tvhlog.h index e07cf4fd6..16441423f 100644 --- a/src/tvhlog.h +++ b/src/tvhlog.h @@ -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__ */