From c51236eee7d28f2e51c3c6a3e534fcb51d047b64 Mon Sep 17 00:00:00 2001 From: Detlef Riekenberg Date: Thu, 1 Sep 2022 15:55:56 +0200 Subject: [PATCH] libtcc: Activate DWARF debug infos with tcc -gdwarf ... This fixes the bug that "tcc -gdwarf ..." still creates the stab debug infos, when tcc was build without using DWARF debug infos by default (configure option: --dwarf=x) -- Regards ... Detlef --- libtcc.c | 7 ++++--- tcc.h | 8 ++++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/libtcc.c b/libtcc.c index 31029616..c2ec5b61 100644 --- a/libtcc.c +++ b/libtcc.c @@ -1867,9 +1867,10 @@ reparse: #endif case TCC_OPTION_g: s->do_debug = 1; - s->dwarf = DWARF_VERSION; - if (strstart("dwarf-", &optarg)) - s->dwarf = atoi(optarg); + s->dwarf = DWARF_VERSION; + + if (strstart("dwarf", &optarg)) + s->dwarf = (*optarg) ? (0 - atoi(optarg)) : DEFAULT_DWARF_VERSION; break; case TCC_OPTION_c: x = TCC_OUTPUT_OBJ; diff --git a/tcc.h b/tcc.h index 9e0388cd..0c7208f7 100644 --- a/tcc.h +++ b/tcc.h @@ -1815,10 +1815,18 @@ ST_FUNC void tcc_tcov_reset_ind(TCCState *s1); #define dwarf_str_section s1->dwarf_str_section #define dwarf_line_str_section s1->dwarf_line_str_section +/* default dwarf version for "-g". use 0 to emit stab debug infos */ #ifndef DWARF_VERSION # define DWARF_VERSION 0 #endif +/* default dwarf version for "-gdwarf" */ +#ifdef TCC_TARGET_MACHO +# define DEFAULT_DWARF_VERSION 2 +#else +# define DEFAULT_DWARF_VERSION 5 +#endif + #if defined TCC_TARGET_PE # define R_DATA_32DW 'Z' /* fake code to avoid DLL relocs */ #elif defined TCC_TARGET_X86_64 -- 2.11.4.GIT