mirror of
https://github.com/frida/tinycc
synced 2024-11-23 16:19:35 +03:00
6a4f3cf127
tested on win32/64 to pass the tests when enabled - libtcc.c : let tcc define __leading_underscore if enabled tcc_add_symbol() : add _ automatically - tccelf.c : remove tcc_get_symbol_err(), find_c_sym() currently symbol length is limited to 256 in several places, so we can use a fixed local buffer for now as well. - win32/lib/crtinit.c : new file for init/fini - lib/*.S, tests7* : use __leading_underscore - bt-log.c: this file wont work relibaly if compiled with gcc
38 lines
911 B
C
38 lines
911 B
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
|
|
|
|
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;
|
|
}
|