tinycc/lib/bt-log.c
grischka 3f3cbb51ed bcheck: remove "tcc_location()" & x86_64 double fix
using (modified) tcc_backtrace() instead.
Also

Also fix the original bug with doubles on x86_64.
(which was not caused by incr_offset() actually).
See 598134fff6

Also cleanup on_exit() stuff
From fef701b57f
2023-09-06 22:42:21 +02:00

50 lines
1.3 KiB
C

/* ------------------------------------------------------------- */
/* function to get a stack backtrace on demand with a message */
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
int (*__rt_error)(void*, void*, const char *, va_list);
#ifdef _WIN32
# define DLL_EXPORT __declspec(dllexport)
#else
# define DLL_EXPORT
#endif
/* Needed when using ...libtcc1-usegcc=yes in lib/Makefile */
#if (defined(__GNUC__) && (__GNUC__ >= 6)) || defined(__clang__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wframe-address"
#endif
DLL_EXPORT int tcc_backtrace(const char *fmt, ...)
{
va_list ap;
int ret;
if (__rt_error) {
void *fp = __builtin_frame_address(1);
void *ip = __builtin_return_address(0);
va_start(ap, fmt);
ret = __rt_error(fp, ip, fmt, ap);
va_end(ap);
} else {
const char *p, *nl = "\n";
if (fmt[0] == '^' && (p = strchr(fmt + 1, fmt[0])))
fmt = p + 1;
if (fmt[0] == '\001')
++fmt, nl = "";
va_start(ap, fmt);
ret = vfprintf(stderr, fmt, ap);
va_end(ap);
fprintf(stderr, nl), fflush(stderr);
}
return ret;
}
#if (defined(__GNUC__) && (__GNUC__ >= 6)) || defined(__clang__)
#pragma GCC diagnostic pop
#endif