mirror of
https://github.com/mirror/tinycc.git
synced 2025-01-13 05:10:07 +08:00
a7cd016d71
- abort with notice when tcc_relocate() is called with the former two-step method - support backtrace & bcheck not only with tcc_run() but also for directly called functions from tcc_get_symbol(); enable witn 'tcc_set_options("-bt/-b");' - move struct rt_context and debug sections into compiled code for TCC_OUTPUT_MEMORY also - protect access (g_rc) with semaphore Also: - add armv7/aarch4/riscv64 github tests (qemu emulated) - win32/build-tcc.bat: build cross compiler only with -x
58 lines
1.4 KiB
C
58 lines
1.4 KiB
C
/* ------------------------------------------------------------- */
|
|
/* function to get a stack backtrace on demand with a message */
|
|
|
|
#include <stdarg.h>
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#undef __attribute__
|
|
|
|
#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
|
|
|
|
typedef struct rt_frame
|
|
{
|
|
void *ip, *fp, *sp;
|
|
} rt_frame;
|
|
|
|
__attribute__((weak))
|
|
int _rt_error(rt_frame *f, const char *msg, const char *fmt, va_list ap);
|
|
|
|
DLL_EXPORT int tcc_backtrace(const char *fmt, ...)
|
|
{
|
|
va_list ap;
|
|
int ret;
|
|
|
|
if (_rt_error) {
|
|
rt_frame f;
|
|
f.fp = __builtin_frame_address(1);
|
|
f.ip = __builtin_return_address(0);
|
|
va_start(ap, fmt);
|
|
ret = _rt_error(&f, "", 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, "%s", nl), fflush(stderr);
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
#if (defined(__GNUC__) && (__GNUC__ >= 6)) || defined(__clang__)
|
|
#pragma GCC diagnostic pop
|
|
#endif
|