mirror of
https://github.com/mirror/tinycc.git
synced 2024-12-26 03:50:07 +08:00
04810db83a
Needed when using ...libtcc1-usegcc=yes in lib/Makefile. lib/bcheck.c: Add __clang__ for pragma diagnostic lib/bt-log.c: Add pragma diagnostic as in lib/bcheck.c lib/builtin.c: Add a lot of alias code to allow building with gcc/clang lib/stdatomic.c: Same as lib/builtin.c lib/tcov.c: Avoid clang compiler warning
48 lines
1.2 KiB
C
48 lines
1.2 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;
|
|
if (fmt[0] == '^' && (p = strchr(fmt + 1, fmt[0])))
|
|
fmt = p + 1;
|
|
va_start(ap, fmt);
|
|
ret = vfprintf(stderr, fmt, ap);
|
|
va_end(ap);
|
|
fprintf(stderr, "\n"), fflush(stderr);
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
#if (defined(__GNUC__) && (__GNUC__ >= 6)) || defined(__clang__)
|
|
#pragma GCC diagnostic pop
|
|
#endif
|