Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
tvhlog: add tvhlog_backtrace_printf() helper for debugging
  • Loading branch information
perexg committed Nov 15, 2015
1 parent 2afa831 commit 52759be
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/tvhlog.c
Expand Up @@ -23,6 +23,10 @@
#include <stdlib.h>
#include <sys/time.h>

#if ENABLE_EXECINFO
#include <execinfo.h>
#endif

#include "libav.h"
#include "webui/webui.h"

Expand Down Expand Up @@ -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
*/
Expand Down
2 changes: 2 additions & 0 deletions src/tvhlog.h
Expand Up @@ -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__ */

0 comments on commit 52759be

Please sign in to comment.