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 <command line> to this function.
This commit is contained in:
herman ten brugge 2023-01-16 20:26:44 +01:00
parent ee3fef2ce2
commit d0efbc5d3a
2 changed files with 24 additions and 23 deletions

View file

@ -571,6 +571,10 @@ static void dwarf_file(TCCState *s1)
int i, j; int i, j;
char *filename; char *filename;
if (!strcmp(file->filename, "<command line>")) {
dwarf_line.cur_file = 1;
return;
}
filename = strrchr(file->filename, '/'); filename = strrchr(file->filename, '/');
if (filename == NULL) { if (filename == NULL) {
for (i = 1; i < dwarf_line.filename_size; i++) for (i = 1; i < dwarf_line.filename_size; i++)
@ -610,21 +614,15 @@ static void dwarf_file(TCCState *s1)
} }
*undo = '/'; *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 = dwarf_line.filename_table =
(struct dwarf_filename_struct *) (struct dwarf_filename_struct *)
tcc_realloc(dwarf_line.filename_table, tcc_realloc(dwarf_line.filename_table,
(dwarf_line.filename_size + 1) * (dwarf_line.filename_size + 1) *
sizeof (struct dwarf_filename_struct)); sizeof (struct dwarf_filename_struct));
dwarf_line.filename_table[dwarf_line.filename_size].dir_entry = i; dwarf_line.filename_table[dwarf_line.filename_size].dir_entry = i;
dwarf_line.filename_table[dwarf_line.filename_size++].name = dwarf_line.filename_table[dwarf_line.filename_size].name =
tcc_strdup(filename); tcc_strdup(filename);
dwarf_line.cur_file = j; dwarf_line.cur_file = dwarf_line.filename_size++;
}
return; return;
} }
@ -1054,14 +1052,10 @@ ST_FUNC void tcc_debug_bincl(TCCState *s1)
{ {
if (!s1->do_debug) if (!s1->do_debug)
return; return;
if (s1->dwarf) { if (s1->dwarf)
if (strcmp(file->filename, "<command line>"))
dwarf_file(s1); dwarf_file(s1);
}
else else
{
put_stabs(s1, file->filename, N_BINCL, 0, 0, 0); put_stabs(s1, file->filename, N_BINCL, 0, 0, 0);
}
new_file = 1; new_file = 1;
} }
@ -1101,7 +1095,11 @@ ST_FUNC void tcc_debug_line(TCCState *s1)
if (dwarf_line.cur_file != dwarf_line.last_file) { if (dwarf_line.cur_file != dwarf_line.last_file) {
dwarf_line.last_file = dwarf_line.cur_file; dwarf_line.last_file = dwarf_line.cur_file;
dwarf_line_op(s1, DW_LNS_set_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); dwarf_uleb128_op(s1, dwarf_line.cur_file);
#endif
} }
if (len_pc && if (len_pc &&
len_line >= DWARF_LINE_BASE && len_line <= (DWARF_OPCODE_BASE + DWARF_LINE_BASE) && len_line >= DWARF_LINE_BASE && len_line <= (DWARF_OPCODE_BASE + DWARF_LINE_BASE) &&

View file

@ -975,6 +975,9 @@ check_pc:
break; break;
case DW_LNS_set_file: case DW_LNS_set_file:
i = dwarf_read_uleb128(&ln, end); i = dwarf_read_uleb128(&ln, end);
#ifdef TCC_TARGET_MACHO
i--;
#endif
if (i < FILE_TABLE_SIZE && i < filename_size) if (i < FILE_TABLE_SIZE && i < filename_size)
filename = filename_table[i].name; filename = filename_table[i].name;
break; break;