From d0efbc5d3a5356685b894f64d3b285a7fb27fbae Mon Sep 17 00:00:00 2001 From: herman ten brugge Date: Mon, 16 Jan 2023 20:26:44 +0100 Subject: [PATCH] Fix preprocessor line directive for macos Macos has an offset of 1 for DW_LNS_set_file. Also rewrite dwarf_file to not scan list twice and move check for to this function. --- tccdbg.c | 44 +++++++++++++++++++++----------------------- tccrun.c | 3 +++ 2 files changed, 24 insertions(+), 23 deletions(-) diff --git a/tccdbg.c b/tccdbg.c index 94631290..d5bfbb77 100644 --- a/tccdbg.c +++ b/tccdbg.c @@ -571,12 +571,16 @@ static void dwarf_file(TCCState *s1) int i, j; char *filename; + if (!strcmp(file->filename, "")) { + dwarf_line.cur_file = 1; + return; + } filename = strrchr(file->filename, '/'); if (filename == NULL) { for (i = 1; i < dwarf_line.filename_size; i++) if (dwarf_line.filename_table[i].dir_entry == 0 && strcmp(dwarf_line.filename_table[i].name, - file->filename) == 0) { + file->filename) == 0) { dwarf_line.cur_file = i; return; } @@ -593,7 +597,7 @@ static void dwarf_file(TCCState *s1) for (j = 1; j < dwarf_line.filename_size; j++) if (dwarf_line.filename_table[j].dir_entry == i && strcmp(dwarf_line.filename_table[j].name, - filename) == 0) { + filename) == 0) { *undo = '/'; dwarf_line.cur_file = j; return; @@ -610,21 +614,15 @@ static void dwarf_file(TCCState *s1) } *undo = '/'; } - for (j = 1; j < dwarf_line.filename_size; j++) - if (dwarf_line.filename_table[j].dir_entry == i && - strcmp (dwarf_line.filename_table[j].name, filename) == 0) - break; - if (j == dwarf_line.filename_size) { - dwarf_line.filename_table = - (struct dwarf_filename_struct *) - tcc_realloc(dwarf_line.filename_table, - (dwarf_line.filename_size + 1) * - sizeof (struct dwarf_filename_struct)); - dwarf_line.filename_table[dwarf_line.filename_size].dir_entry = i; - dwarf_line.filename_table[dwarf_line.filename_size++].name = - tcc_strdup(filename); - dwarf_line.cur_file = j; - } + dwarf_line.filename_table = + (struct dwarf_filename_struct *) + tcc_realloc(dwarf_line.filename_table, + (dwarf_line.filename_size + 1) * + sizeof (struct dwarf_filename_struct)); + dwarf_line.filename_table[dwarf_line.filename_size].dir_entry = i; + dwarf_line.filename_table[dwarf_line.filename_size].name = + tcc_strdup(filename); + dwarf_line.cur_file = dwarf_line.filename_size++; return; } @@ -1054,14 +1052,10 @@ ST_FUNC void tcc_debug_bincl(TCCState *s1) { if (!s1->do_debug) return; - if (s1->dwarf) { - if (strcmp(file->filename, "")) - dwarf_file(s1); - } + if (s1->dwarf) + dwarf_file(s1); else - { put_stabs(s1, file->filename, N_BINCL, 0, 0, 0); - } new_file = 1; } @@ -1101,7 +1095,11 @@ ST_FUNC void tcc_debug_line(TCCState *s1) if (dwarf_line.cur_file != dwarf_line.last_file) { dwarf_line.last_file = dwarf_line.cur_file; dwarf_line_op(s1, DW_LNS_set_file); +#ifdef TCC_TARGET_MACHO + dwarf_uleb128_op(s1, dwarf_line.cur_file + 1); +#else dwarf_uleb128_op(s1, dwarf_line.cur_file); +#endif } if (len_pc && len_line >= DWARF_LINE_BASE && len_line <= (DWARF_OPCODE_BASE + DWARF_LINE_BASE) && diff --git a/tccrun.c b/tccrun.c index a8bea03c..d7420092 100644 --- a/tccrun.c +++ b/tccrun.c @@ -975,6 +975,9 @@ check_pc: break; case DW_LNS_set_file: i = dwarf_read_uleb128(&ln, end); +#ifdef TCC_TARGET_MACHO + i--; +#endif if (i < FILE_TABLE_SIZE && i < filename_size) filename = filename_table[i].name; break; -- 2.11.4.GIT