From 8c5fe8766517bd3fc19070cf5946ce0a3e56695f Mon Sep 17 00:00:00 2001 From: grischka Date: Wed, 6 Sep 2023 22:17:03 +0200 Subject: [PATCH] tcc -g1 : small debug info (lines/functions only) --- lib/Makefile | 2 +- libtcc.c | 22 +++++++++++++--------- tccdbg.c | 13 +++++++++---- win32/build-tcc.bat | 2 +- 4 files changed, 24 insertions(+), 15 deletions(-) diff --git a/lib/Makefile b/lib/Makefile index 81e390bb..f7a7c585 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -84,7 +84,7 @@ $(X)%.o : %.S $(TOP)/%.o : %.c $S$(XCC) -c $< -o $@ $(XFLAGS) -$(TOP)/bcheck.o : XFLAGS += -g $(if $(CONFIG_musl),-DTCC_MUSL) +$(TOP)/bcheck.o : XFLAGS += -bt $(if $(CONFIG_musl),-DTCC_MUSL) $(TOP)/bt-exe.o : $(TOP)/tccrun.c $(X)crt1w.o : crt1.c diff --git a/libtcc.c b/libtcc.c index 8b425667..44a292d7 100644 --- a/libtcc.c +++ b/libtcc.c @@ -1959,29 +1959,33 @@ dorun: break; #ifdef CONFIG_TCC_BACKTRACE case TCC_OPTION_bt: - s->rt_num_callers = atoi(optarg); + s->rt_num_callers = atoi(optarg); /* zero = default (6) */ + enable_backtrace: s->do_backtrace = 1; s->do_debug = 1; s->dwarf = DWARF_VERSION; break; -#endif #ifdef CONFIG_TCC_BCHECK case TCC_OPTION_b: s->do_bounds_check = 1; - s->do_backtrace = 1; - s->do_debug = 1; - s->dwarf = DWARF_VERSION; - break; + goto enable_backtrace; +#endif #endif case TCC_OPTION_g: - s->do_debug = 1; + s->do_debug = 2; s->dwarf = DWARF_VERSION; - if (strstart("dwarf", &optarg)) + if (strstart("dwarf", &optarg)) { s->dwarf = (*optarg) ? (0 - atoi(optarg)) : DEFAULT_DWARF_VERSION; + } else if (isnum(*optarg)) { + x = *optarg - '0'; + /* -g0 = no info, -g1 = lines/functions only, -g2 = full info */ + if (x <= 2) + s->do_debug = x; #ifdef TCC_TARGET_PE - else if (0 == strcmp(".pdb", optarg)) + } else if (0 == strcmp(".pdb", optarg)) { s->dwarf = 5, s->do_debug |= 16; #endif + } break; case TCC_OPTION_c: x = TCC_OUTPUT_OBJ; diff --git a/tccdbg.c b/tccdbg.c index 56d878df..2509bace 100644 --- a/tccdbg.c +++ b/tccdbg.c @@ -1245,8 +1245,9 @@ ST_FUNC void tcc_debug_fix_anon(TCCState *s1, CType *t) { int i, j, debug_type; - if (!s1->do_debug || !s1->dwarf || debug_info) + if (!(s1->do_debug & 2) || !s1->dwarf || debug_info) return; + if ((t->t & VT_BTYPE) == VT_STRUCT && t->ref->c != -1) for (i = 0; i < n_debug_anon_hash; i++) if (t->ref == debug_anon_hash[i].type) { @@ -1789,8 +1790,10 @@ static void tcc_debug_finish (TCCState *s1, struct _debug_info *cur) ST_FUNC void tcc_add_debug_info(TCCState *s1, int param, Sym *s, Sym *e) { CString debug_str; - if (!s1->do_debug) + + if (!(s1->do_debug & 2)) return; + cstr_new (&debug_str); for (; s != e; s = s->prev) { if (!s->v || (s->r & VT_VALMASK) != VT_LOCAL) @@ -1931,8 +1934,9 @@ ST_FUNC void tcc_debug_funcend(TCCState *s1, int size) ST_FUNC void tcc_debug_extern_sym(TCCState *s1, Sym *sym, int sh_num, int sym_bind, int sym_type) { - if (!s1->do_debug) + if (!(s1->do_debug & 2)) return; + if (sym_type == STT_FUNC || sym->v >= SYM_FIRST_ANOM) return; if (s1->dwarf) { @@ -1984,8 +1988,9 @@ ST_FUNC void tcc_debug_extern_sym(TCCState *s1, Sym *sym, int sh_num, int sym_bi ST_FUNC void tcc_debug_typedef(TCCState *s1, Sym *sym) { - if (!s1->do_debug) + if (!(s1->do_debug & 2)) return; + if (s1->dwarf) { int debug_type; diff --git a/win32/build-tcc.bat b/win32/build-tcc.bat index 10ae66da..83730169 100644 --- a/win32/build-tcc.bat +++ b/win32/build-tcc.bat @@ -156,7 +156,7 @@ call :makelib %T% @if errorlevel 1 goto :the_end @if exist %PX%-tcc.exe call :makelib %TX% @if errorlevel 1 goto :the_end -.\tcc -m%T% -c ../lib/bcheck.c -o lib/bcheck.o -g +.\tcc -m%T% -c ../lib/bcheck.c -o lib/bcheck.o -bt .\tcc -m%T% -c ../lib/bt-exe.c -o lib/bt-exe.o .\tcc -m%T% -c ../lib/bt-log.c -o lib/bt-log.o .\tcc -m%T% -c ../lib/bt-dll.c -o lib/bt-dll.o