make SILENT=yes
[tinycc.git] / lib / bt-exe.c
blob350261a8064a37fed060da3c9561bd6256777787
1 /* ------------------------------------------------------------- */
2 /* for linking rt_printline and the signal/exception handler
3 from tccrun.c into executables. */
5 #define CONFIG_TCC_BACKTRACE_ONLY
6 #include "../tccrun.c"
8 int (*__rt_error)(void*, void*, const char *, va_list);
10 #ifndef _WIN32
11 # define __declspec(n)
12 #endif
14 __declspec(dllexport)
15 void __bt_init(rt_context *p, int num_callers)
17 __attribute__((weak)) int main();
18 __attribute__((weak)) void __bound_init(void*);
19 struct rt_context *rc = &g_rtctxt;
20 //fprintf(stderr, "__bt_init %d %p %p\n", num_callers, p->stab_sym, p->bounds_start), fflush(stderr);
21 if (num_callers) {
22 memcpy(rc, p, offsetof(rt_context, next));
23 rc->num_callers = num_callers - 1;
24 rc->top_func = main;
25 __rt_error = _rt_error;
26 set_exception_handler();
27 } else {
28 p->next = rc->next, rc->next = p;
30 if (__bound_init && p->bounds_start)
31 __bound_init(p->bounds_start);
34 /* copy a string and truncate it. */
35 static char *pstrcpy(char *buf, size_t buf_size, const char *s)
37 int l = strlen(s);
38 if (l >= buf_size)
39 l = buf_size - 1;
40 memcpy(buf, s, l);
41 buf[l] = 0;
42 return buf;