2020-01-18 05:58:39 +08:00
|
|
|
/* ------------------------------------------------------------- */
|
|
|
|
/* for linking rt_printline and the signal/exception handler
|
|
|
|
from tccrun.c into executables. */
|
|
|
|
|
|
|
|
#define CONFIG_TCC_BACKTRACE_ONLY
|
2022-05-09 23:02:09 +08:00
|
|
|
#define ONE_SOURCE 0
|
2020-01-18 05:58:39 +08:00
|
|
|
#include "../tccrun.c"
|
|
|
|
|
|
|
|
int (*__rt_error)(void*, void*, const char *, va_list);
|
|
|
|
|
|
|
|
#ifndef _WIN32
|
|
|
|
# define __declspec(n)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
__declspec(dllexport)
|
2021-01-24 23:20:48 +08:00
|
|
|
void __bt_init(rt_context *p, int num_callers)
|
2020-01-18 05:58:39 +08:00
|
|
|
{
|
|
|
|
__attribute__((weak)) int main();
|
2020-05-22 11:06:08 +08:00
|
|
|
__attribute__((weak)) void __bound_init(void*, int);
|
2020-01-18 05:58:39 +08:00
|
|
|
struct rt_context *rc = &g_rtctxt;
|
2021-01-24 23:20:48 +08:00
|
|
|
//fprintf(stderr, "__bt_init %d %p %p\n", num_callers, p->stab_sym, p->bounds_start), fflush(stderr);
|
Add dwarf support
The new gcc12 release does not support stabs any more.
This was a good reason to add support for dwarf.
The stabs code still works and is used if configure option --dwarf
is not used.
Tested on x86_64, i386, arm, arm64, riscv64 with dwarf-5.
Some debuggers may not support dwarf-5. Try using older dwarf versions
i that case.
The tccmacho.c code probably need some support for dwarf.
arm-gen.c, arm64-gen.c, i386-gen.c, riscv64-gen.c, x86_64-gen.
- fix get_sym_ref symbol size
arm-link.c, arm64-link.c, i386-link.c, riscv64-link.c, x86_64-link.c
- add R_DATA_32U
libtcc.c:
- parse -gdwarf option
tcc.c:
- add dwarf option
tcc.h:
- add dwarf option and sections
tccelf.c:
- init dwarf sections
- avoid adding sh_addr for dwarf sections
- remove dwarf relocs for output dll
- add dwarf sections for tccrun
tccgen.c:
- add dwarf defines + global data
- add dwarf_* functions
- mix dwarf code with stabs code
- a trick is used to emit function name in .debug_line section so
only this section has to be parsed instead of .debug_info and
.debug_abbrev.
- fix init debug_modes
tccrun.c:
- add dwarf sections in rt_context
- init them in tcc_run
- add new dwarf code rt_printline_dwarf to find file/function
dwarf.h:
- New file
tcc-doc.texi:
- document dwarf
configure:
- add dwarf option
lib/Makefile
- change -gstabs into -gdwarf
lib/bt-exe.c, tests/tests2/Makefile, tests/tests2/126_bound_global:
- Add __bound_init call
- Add new testcase to test it
2022-05-05 15:10:37 +08:00
|
|
|
/* call __bound_init here due to redirection of sigaction */
|
|
|
|
/* needed to add global symbols */
|
|
|
|
if (__bound_init && p->bounds_start)
|
|
|
|
__bound_init(p->bounds_start, -1);
|
2020-01-18 05:58:39 +08: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 {
|
2022-05-07 12:54:13 +08:00
|
|
|
p->num_callers = -1;
|
2020-01-18 05:58:39 +08:00
|
|
|
p->next = rc->next, rc->next = p;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* copy a string and truncate it. */
|
2022-05-09 23:02:09 +08:00
|
|
|
ST_FUNC char *pstrcpy(char *buf, size_t buf_size, const char *s)
|
2020-01-18 05:58:39 +08:00
|
|
|
{
|
|
|
|
int l = strlen(s);
|
|
|
|
if (l >= buf_size)
|
|
|
|
l = buf_size - 1;
|
|
|
|
memcpy(buf, s, l);
|
|
|
|
buf[l] = 0;
|
|
|
|
return buf;
|
|
|
|
}
|