2020-01-18 00:58:39 +03:00
|
|
|
/* ------------------------------------------------------------- */
|
|
|
|
/* for linking rt_printline and the signal/exception handler
|
|
|
|
from tccrun.c into executables. */
|
|
|
|
|
|
|
|
#define CONFIG_TCC_BACKTRACE_ONLY
|
|
|
|
#include "../tccrun.c"
|
|
|
|
|
|
|
|
int (*__rt_error)(void*, void*, const char *, va_list);
|
|
|
|
|
|
|
|
#ifndef _WIN32
|
|
|
|
# define __declspec(n)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
__declspec(dllexport)
|
2020-05-22 06:06:08 +03:00
|
|
|
void __bt_init(rt_context *p, int num_callers, int mode)
|
2020-01-18 00:58:39 +03:00
|
|
|
{
|
|
|
|
__attribute__((weak)) int main();
|
2020-05-22 06:06:08 +03:00
|
|
|
__attribute__((weak)) void __bound_init(void*, int);
|
2020-01-18 00:58:39 +03:00
|
|
|
struct rt_context *rc = &g_rtctxt;
|
2020-05-22 06:06:08 +03:00
|
|
|
//fprintf(stderr, "__bt_init %d %p %p %d\n", num_callers, p->stab_sym, p->bounds_start, mode), fflush(stderr);
|
2020-01-18 00:58:39 +03:00
|
|
|
if (num_callers) {
|
|
|
|
memcpy(rc, p, offsetof(rt_context, next));
|
|
|
|
rc->num_callers = num_callers - 1;
|
|
|
|
rc->top_func = main;
|
|
|
|
__rt_error = _rt_error;
|
|
|
|
set_exception_handler();
|
|
|
|
} else {
|
|
|
|
p->next = rc->next, rc->next = p;
|
|
|
|
}
|
|
|
|
if (__bound_init && p->bounds_start)
|
2020-05-22 06:06:08 +03:00
|
|
|
__bound_init(p->bounds_start, mode);
|
2020-01-18 00:58:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* copy a string and truncate it. */
|
|
|
|
static char *pstrcpy(char *buf, size_t buf_size, const char *s)
|
|
|
|
{
|
|
|
|
int l = strlen(s);
|
|
|
|
if (l >= buf_size)
|
|
|
|
l = buf_size - 1;
|
|
|
|
memcpy(buf, s, l);
|
|
|
|
buf[l] = 0;
|
|
|
|
return buf;
|
|
|
|
}
|