1 /* ------------------------------------------------------------- */
2 /* function to get a stack backtrace on demand with a message */
10 # define DLL_EXPORT __declspec(dllexport)
15 /* Needed when using ...libtcc1-usegcc=yes in lib/Makefile */
16 #if (defined(__GNUC__) && (__GNUC__ >= 6)) || defined(__clang__)
17 #pragma GCC diagnostic push
18 #pragma GCC diagnostic ignored "-Wframe-address"
21 typedef struct rt_frame
{
26 int _tcc_backtrace(rt_frame
*f
, const char *fmt
, va_list ap
);
28 DLL_EXPORT
int tcc_backtrace(const char *fmt
, ...)
35 f
.fp
= __builtin_frame_address(1);
36 f
.ip
= __builtin_return_address(0);
38 ret
= _tcc_backtrace(&f
, fmt
, ap
);
41 const char *p
, *nl
= "\n";
42 if (fmt
[0] == '^' && (p
= strchr(fmt
+ 1, fmt
[0])))
47 ret
= vfprintf(stderr
, fmt
, ap
);
49 fprintf(stderr
, "%s", nl
), fflush(stderr
);
54 #if (defined(__GNUC__) && (__GNUC__ >= 6)) || defined(__clang__)
55 #pragma GCC diagnostic pop