History

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.

herman ten brugge committed 3 years ago

Commit d0efbc51 parent ee3fef22 files · +24 −23Browse files

Unified · Split

2 files
  1. tccdbg.c +21 −23
  2. tccrun.c +3 −0
tccdbg.c+21−23
@@ -571,12 +571,16 @@ static void dwarf_file(TCCState *s1) · 570 unmodified lines
571571 int i, j;
572572 char *filename;
573573
574+ if (!strcmp(file->filename, "<command line>")) {
575+ dwarf_line.cur_file = 1;
576+ return;
577+ }
574578 filename = strrchr(file->filename, '/');
575579 if (filename == NULL) {
576580 for (i = 1; i < dwarf_line.filename_size; i++)
577581 if (dwarf_line.filename_table[i].dir_entry == 0 &&
578582 strcmp(dwarf_line.filename_table[i].name,
579− file->filename) == 0) {
583+ file->filename) == 0) {
580584 dwarf_line.cur_file = i;
581585 return;
582586 }
@@ -593,7 +597,7 @@ static void dwarf_file(TCCState *s1) · 10 unmodified lines
593597 for (j = 1; j < dwarf_line.filename_size; j++)
594598 if (dwarf_line.filename_table[j].dir_entry == i &&
595599 strcmp(dwarf_line.filename_table[j].name,
596− filename) == 0) {
600+ filename) == 0) {
597601 *undo = '/';
598602 dwarf_line.cur_file = j;
599603 return;
@@ -610,21 +614,15 @@ static void dwarf_file(TCCState *s1) · 10 unmodified lines
610614 }
611615 *undo = '/';
612616 }
613− for (j = 1; j < dwarf_line.filename_size; j++)
614− if (dwarf_line.filename_table[j].dir_entry == i &&
615− strcmp (dwarf_line.filename_table[j].name, filename) == 0)
616− break;
617− if (j == dwarf_line.filename_size) {
618− dwarf_line.filename_table =
619− (struct dwarf_filename_struct *)
620− tcc_realloc(dwarf_line.filename_table,
621− (dwarf_line.filename_size + 1) *
622− sizeof (struct dwarf_filename_struct));
623− dwarf_line.filename_table[dwarf_line.filename_size].dir_entry = i;
624− dwarf_line.filename_table[dwarf_line.filename_size++].name =
625− tcc_strdup(filename);
626− dwarf_line.cur_file = j;
627− }
617+ dwarf_line.filename_table =
618+ (struct dwarf_filename_struct *)
619+ tcc_realloc(dwarf_line.filename_table,
620+ (dwarf_line.filename_size + 1) *
621+ sizeof (struct dwarf_filename_struct));
622+ dwarf_line.filename_table[dwarf_line.filename_size].dir_entry = i;
623+ dwarf_line.filename_table[dwarf_line.filename_size].name =
624+ tcc_strdup(filename);
625+ dwarf_line.cur_file = dwarf_line.filename_size++;
628626 return;
629627 }
630628
@@ -1054,14 +1052,10 @@ ST_FUNC void tcc_debug_bincl(TCCState *s1) · 423 unmodified lines
10541052 {
10551053 if (!s1->do_debug)
10561054 return;
1057− if (s1->dwarf) {
1058− if (strcmp(file->filename, "<command line>"))
1059− dwarf_file(s1);
1060− }
1055+ if (s1->dwarf)
1056+ dwarf_file(s1);
10611057 else
1062− {
10631058 put_stabs(s1, file->filename, N_BINCL, 0, 0, 0);
1064− }
10651059 new_file = 1;
10661060 }
10671061
@@ -1101,7 +1095,11 @@ ST_FUNC void tcc_debug_line(TCCState *s1) · 33 unmodified lines
11011095 if (dwarf_line.cur_file != dwarf_line.last_file) {
11021096 dwarf_line.last_file = dwarf_line.cur_file;
11031097 dwarf_line_op(s1, DW_LNS_set_file);
1098+#ifdef TCC_TARGET_MACHO
1099+ dwarf_uleb128_op(s1, dwarf_line.cur_file + 1);
1100+#else
11041101 dwarf_uleb128_op(s1, dwarf_line.cur_file);
1102+#endif
11051103 }
11061104 if (len_pc &&
11071105 len_line >= DWARF_LINE_BASE && len_line <= (DWARF_OPCODE_BASE + DWARF_LINE_BASE) &&
tccrun.c+3−0
@@ -975,6 +975,9 @@ check_pc: · 974 unmodified lines
975975 break;
976976 case DW_LNS_set_file:
977977 i = dwarf_read_uleb128(&ln, end);
978+#ifdef TCC_TARGET_MACHO
979+ i--;
980+#endif
978981 if (i < FILE_TABLE_SIZE && i < filename_size)
979982 filename = filename_table[i].name;
980983 break;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t