+#ifdef HAVE_EXECINFO_H
+# include <execinfo.h>
+#endif
+
+/**
+ * Print a backtrace to the standard error for debugging purpose.
+ */
+void vlc_trace (const char *fn, const char *file, unsigned line)
+{
+ fprintf (stderr, "at %s:%u in %s\n", file, line, fn);
+ fflush (stderr); /* needed before switch to low-level I/O */
+#ifdef HAVE_BACKTRACE
+ void *stack[20];
+ int len = backtrace (stack, sizeof (stack) / sizeof (stack[0]));
+ backtrace_symbols_fd (stack, len, 2);
+#endif
+#ifndef WIN32
+ fsync (2);
+#endif
+}
+