History

Make debug info smaller

Currently debug size is big because some types are output multiple times. Function scope was not treated correctly. Rename anon(ymous) into forw(ard). Compact string table by reusing names.

herman ten brugge committed 1 year ago

Commit e5e3dc61 parent f52b4803 files · +256 −146Browse files

Unified · Split

3 files
  1. tcc.h +1 −1
  2. tccdbg.c +254 −144
  3. tccgen.c +1 −1
tcc.h+1−1
@@ -1864,7 +1864,7 @@ ST_FUNC void tcc_debug_funcend(TCCState *s1, int size); · 1863 unmodified lines
18641864 ST_FUNC void tcc_debug_extern_sym(TCCState *s1, Sym *sym, int sh_num, int sym_bind, int sym_type);
18651865 ST_FUNC void tcc_debug_typedef(TCCState *s1, Sym *sym);
18661866 ST_FUNC void tcc_debug_stabn(TCCState *s1, int type, int value);
1867−ST_FUNC void tcc_debug_fix_anon(TCCState *s1, CType *t);
1867+ST_FUNC void tcc_debug_fix_forw(TCCState *s1, CType *t);
18681868
18691869 #if !(defined ELF_OBJ_ONLY || defined TCC_TARGET_ARM || defined TARGETOS_BSD)
18701870 ST_FUNC void tcc_eh_frame_start(TCCState *s1);
tccdbg.c+254−144
@@ -310,6 +310,14 @@ static const unsigned char dwarf_line_opcodes[] = { · 309 unmodified lines
310310 /* ------------------------------------------------------------------------- */
311311 /* debug state */
312312
313+#define N_STR_HASH (251)
314+
315+struct dwarf_str_hash {
316+ int len;
317+ unsigned long data_offset;
318+ struct dwarf_str_hash *next;
319+};
320+
313321 struct _tccdbg {
314322
315323 int last_line_num, new_file;
@@ -320,20 +328,25 @@ struct _tccdbg { · 4 unmodified lines
320328 struct _debug_hash {
321329 int debug_type;
322330 Sym *type;
323− } *debug_hash;
331+ } *debug_hash_global, *debug_hash_local;
324332
325− struct _debug_anon_hash {
333+ /* store forward structure/unions types */
334+ struct _debug_forw_hash {
326335 Sym *type;
327336 int n_debug_type;
328337 int *debug_type;
329− } *debug_anon_hash;
338+ } *debug_forw_hash_global, *debug_forw_hash_local;
330339
331− int n_debug_hash;
332− int n_debug_anon_hash;
340+ int n_debug_hash_global;
341+ int n_debug_hash_local;
342+ int n_debug_forw_hash_global;
343+ int n_debug_forw_hash_local;
333344
334345 struct _debug_info {
335346 int start;
336347 int end;
348+ int last_debug_hash;
349+ int last_debug_forw_hash;
337350 int n_sym;
338351 struct debug_sym {
339352 int type;
@@ -381,6 +394,9 @@ struct _tccdbg { · 41 unmodified lines
381394 int base_type_used[N_DEFAULT_DEBUG];
382395 } dwarf_info;
383396
397+ struct dwarf_str_hash *dwarf_str[N_STR_HASH];
398+ struct dwarf_str_hash *dwarf_line_str[N_STR_HASH];
399+
384400 /* test coverage */
385401 struct {
386402 unsigned long offset;
@@ -389,23 +405,28 @@ struct _tccdbg { · 2 unmodified lines
389405 int ind;
390406 int line;
391407 } tcov_data;
392−
393408 };
394409
395−#define last_line_num s1->dState->last_line_num
396−#define new_file s1->dState->new_file
397−#define section_sym s1->dState->section_sym
398−#define debug_next_type s1->dState->debug_next_type
399−#define debug_hash s1->dState->debug_hash
400−#define debug_anon_hash s1->dState->debug_anon_hash
401−#define n_debug_hash s1->dState->n_debug_hash
402−#define n_debug_anon_hash s1->dState->n_debug_anon_hash
403−#define debug_info s1->dState->debug_info
404−#define debug_info_root s1->dState->debug_info_root
405−#define dwarf_sym s1->dState->dwarf_sym
406−#define dwarf_line s1->dState->dwarf_line
407−#define dwarf_info s1->dState->dwarf_info
408−#define tcov_data s1->dState->tcov_data
410+#define last_line_num s1->dState->last_line_num
411+#define new_file s1->dState->new_file
412+#define section_sym s1->dState->section_sym
413+#define debug_next_type s1->dState->debug_next_type
414+#define debug_hash_global s1->dState->debug_hash_global
415+#define debug_hash_local s1->dState->debug_hash_local
416+#define debug_forw_hash_global s1->dState->debug_forw_hash_global
417+#define debug_forw_hash_local s1->dState->debug_forw_hash_local
418+#define n_debug_hash_global s1->dState->n_debug_hash_global
419+#define n_debug_hash_local s1->dState->n_debug_hash_local
420+#define n_debug_forw_hash_global s1->dState->n_debug_forw_hash_global
421+#define n_debug_forw_hash_local s1->dState->n_debug_forw_hash_local
422+#define debug_info s1->dState->debug_info
423+#define debug_info_root s1->dState->debug_info_root
424+#define dwarf_sym s1->dState->dwarf_sym
425+#define dwarf_line s1->dState->dwarf_line
426+#define dwarf_info s1->dState->dwarf_info
427+#define dwarf_str s1->dState->dwarf_str
428+#define dwarf_line_str s1->dState->dwarf_line_str
429+#define tcov_data s1->dState->tcov_data
409430
410431 #define FDE_ENCODING (DW_EH_PE_udata4 | DW_EH_PE_signed | DW_EH_PE_pcrel)
411432
@@ -533,19 +554,46 @@ static void dwarf_reloc(Section *s, int sym, int rel) · 121 unmodified lines
533554 put_elf_reloca(symtab_section, s, s->data_offset, rel, sym, 0);
534555 }
535556
557+static unsigned str_hash(const char *s)
558+{
559+ unsigned h = 5381;
560+
561+ while (*s)
562+ h += (*s++ & 0xffu) + h * 31;
563+ return h;
564+}
565+
536566 static void dwarf_string(Section *s, Section *dw, int sym, const char *str)
537567 {
538568 TCCState *s1 = s->s1;
539− int offset, len;
569+ int len, hash = str_hash(str) % N_STR_HASH;
540570 char *ptr;
571+ struct dwarf_str_hash *new_hash;
572+ struct dwarf_str_hash **dw_hash =
573+ dw == dwarf_str_section ? dwarf_str : dwarf_line_str;
541574
542575 len = strlen(str) + 1;
543− offset = dw->data_offset;
544− ptr = section_ptr_add(dw, len);
545− memmove(ptr, str, len);
576+ new_hash = dw_hash[hash];
577+ while (new_hash) {
578+ if (new_hash->len == len &&
579+ !memcmp(str, dw->data + new_hash->data_offset, len))
580+ break;
581+ new_hash = new_hash->next;
582+ }
583+ if (new_hash == NULL) {
584+ new_hash = (struct dwarf_str_hash *)
585+ tcc_malloc(sizeof(struct dwarf_str_hash));
586+ new_hash->len = len;
587+ new_hash->data_offset = dw->data_offset;
588+ new_hash->next = dw_hash[hash];
589+ dw_hash[hash] = new_hash;
590+ ptr = section_ptr_add(dw, len);
591+ memmove(ptr, str, len);
592+ }
593+ else
546594 put_elf_reloca(symtab_section, s, s->data_offset, R_DATA_32DW, sym,
547− PTR_SIZE == 4 ? 0 : offset);
548− dwarf_data4(s, PTR_SIZE == 4 ? offset : 0);
595+ PTR_SIZE == 4 ? 0 : new_hash->data_offset);
596+ dwarf_data4(s, PTR_SIZE == 4 ? new_hash->data_offset : 0);
549597 }
550598
551599 static void dwarf_strp(Section *s, const char *str)
@@ -1031,10 +1079,14 @@ ST_FUNC void tcc_debug_start(TCCState *s1) · 479 unmodified lines
10311079
10321080 new_file = last_line_num = 0;
10331081 debug_next_type = N_DEFAULT_DEBUG;
1034− debug_hash = NULL;
1035− debug_anon_hash = NULL;
1036− n_debug_hash = 0;
1037− n_debug_anon_hash = 0;
1082+ debug_hash_global = NULL;
1083+ debug_hash_local = NULL;
1084+ debug_forw_hash_global = NULL;
1085+ debug_forw_hash_local = NULL;
1086+ n_debug_hash_global = 0;
1087+ n_debug_hash_local = 0;
1088+ n_debug_forw_hash_global = 0;
1089+ n_debug_forw_hash_local = 0;
10381090
10391091 getcwd(buf, sizeof(buf));
10401092 #ifdef _WIN32
@@ -1192,9 +1244,13 @@ ST_FUNC void tcc_debug_start(TCCState *s1) · 151 unmodified lines
11921244 }
11931245 }
11941246
1247+static void fix_debug_forw_hash(TCCState *s1, int global, int start);
1248+
11951249 /* put end of translation unit info */
11961250 ST_FUNC void tcc_debug_end(TCCState *s1)
11971251 {
1252+ int i;
1253+
11981254 if (!s1->do_debug || debug_next_type == 0)
11991255 return;
12001256
@@ -1202,32 +1258,13 @@ ST_FUNC void tcc_debug_end(TCCState *s1) · 1 unmodified line
12021258 tcc_debug_funcend(s1, 0); /* free stuff in case of errors */
12031259
12041260 if (s1->dwarf) {
1205− int i, j;
12061261 int start_aranges;
12071262 unsigned char *ptr;
12081263 int text_size = text_section->data_offset;
12091264
12101265 /* dwarf_info */
1211− for (i = 0; i < n_debug_anon_hash; i++) {
1212− Sym *t = debug_anon_hash[i].type;
1213− int pos = dwarf_info_section->data_offset;
1214−
1215− dwarf_data1(dwarf_info_section,
1216− IS_UNION (t->type.t) ? DWARF_ABBREV_UNION_EMPTY_TYPE
1217− : DWARF_ABBREV_STRUCTURE_EMPTY_TYPE);
1218− dwarf_strp(dwarf_info_section,
1219− (t->v & ~SYM_STRUCT) >= SYM_FIRST_ANOM
1220− ? "" : get_tok_str(t->v, NULL));
1221− dwarf_uleb128(dwarf_info_section, 0);
1222− dwarf_uleb128(dwarf_info_section, dwarf_line.cur_file);
1223− dwarf_uleb128(dwarf_info_section, file->line_num);
1224− for (j = 0; j < debug_anon_hash[i].n_debug_type; j++)
1225− write32le(dwarf_info_section->data +
1226− debug_anon_hash[i].debug_type[j],
1227− pos - dwarf_info.start);
1228− tcc_free (debug_anon_hash[i].debug_type);
1229− }
1230− tcc_free (debug_anon_hash);
1266+ fix_debug_forw_hash(s1, 0, 0);
1267+ fix_debug_forw_hash(s1, 1, 0);
12311268 dwarf_data1(dwarf_info_section, 0);
12321269 ptr = dwarf_info_section->data + dwarf_info.start;
12331270 write32le(ptr, dwarf_info_section->data_offset - dwarf_info.start - 4);
@@ -1328,7 +1365,22 @@ ST_FUNC void tcc_debug_end(TCCState *s1) · 94 unmodified lines
13281365 put_stabs_r(s1, NULL, N_SO, 0, 0,
13291366 text_section->data_offset, text_section, section_sym);
13301367 }
1331− tcc_free(debug_hash);
1368+ for (i = 0; i < N_STR_HASH; i++) {
1369+ while (dwarf_str[i]) {
1370+ struct dwarf_str_hash *next = dwarf_str[i]->next;
1371+ tcc_free(dwarf_str[i]);
1372+ dwarf_str[i] = next;
1373+ }
1374+ while (dwarf_line_str[i]) {
1375+ struct dwarf_str_hash *next = dwarf_line_str[i]->next;
1376+ tcc_free(dwarf_line_str[i]);
1377+ dwarf_line_str[i] = next;
1378+ }
1379+ }
1380+ tcc_free (debug_forw_hash_global);
1381+ tcc_free (debug_forw_hash_local);
1382+ tcc_free(debug_hash_global);
1383+ tcc_free(debug_hash_local);
13321384 debug_next_type = 0;
13331385 }
13341386
@@ -1473,6 +1525,36 @@ static void tcc_debug_stabs (TCCState *s1, const char *str, int type, unsigned l · 138 unmodified lines
14731525 put_stabs (s1, str, type, 0, 0, value);
14741526 }
14751527
1528+static void fix_debug_forw_hash(TCCState *s1, int global, int start)
1529+{
1530+ if (s1->dwarf) {
1531+ int i, j, n_hash = global
1532+ ? n_debug_forw_hash_global : n_debug_forw_hash_local;
1533+ struct _debug_forw_hash *hash = global
1534+ ? debug_forw_hash_global : debug_forw_hash_local;
1535+
1536+ for (i = start; i < n_hash; i++) {
1537+ Sym *t = hash[i].type;
1538+ int pos = dwarf_info_section->data_offset;
1539+
1540+ dwarf_data1(dwarf_info_section,
1541+ IS_UNION (t->type.t) ? DWARF_ABBREV_UNION_EMPTY_TYPE
1542+ : DWARF_ABBREV_STRUCTURE_EMPTY_TYPE);
1543+ dwarf_strp(dwarf_info_section,
1544+ (t->v & ~SYM_STRUCT) >= SYM_FIRST_ANOM
1545+ ? "" : get_tok_str(t->v, NULL));
1546+ dwarf_uleb128(dwarf_info_section, 0);
1547+ dwarf_uleb128(dwarf_info_section, dwarf_line.cur_file);
1548+ dwarf_uleb128(dwarf_info_section, file->line_num);
1549+ for (j = 0; j < hash[i].n_debug_type; j++)
1550+ write32le(dwarf_info_section->data +
1551+ hash[i].debug_type[j],
1552+ pos - dwarf_info.start);
1553+ tcc_free (hash[i].debug_type);
1554+ }
1555+ }
1556+}
1557+
14761558 ST_FUNC void tcc_debug_stabn(TCCState *s1, int type, int value)
14771559 {
14781560 if (!s1->do_debug)
@@ -1482,6 +1564,8 @@ ST_FUNC void tcc_debug_stabn(TCCState *s1, int type, int value) · 3 unmodified lines
14821564 (struct _debug_info *) tcc_mallocz(sizeof (*info));
14831565
14841566 info->start = value;
1567+ info->last_debug_hash = n_debug_hash_local;
1568+ info->last_debug_forw_hash = n_debug_forw_hash_local;
14851569 info->parent = debug_info;
14861570 if (debug_info) {
14871571 if (debug_info->child) {
@@ -1499,101 +1583,127 @@ ST_FUNC void tcc_debug_stabn(TCCState *s1, int type, int value) · 11 unmodified lines
14991583 debug_info = info;
15001584 }
15011585 else {
1586+ fix_debug_forw_hash(s1, 0, debug_info->last_debug_forw_hash);
1587+ n_debug_hash_local = debug_info->last_debug_hash;
1588+ n_debug_forw_hash_local = debug_info->last_debug_forw_hash;
15021589 debug_info->end = value;
15031590 debug_info = debug_info->parent;
15041591 }
15051592 }
15061593
1507−static int tcc_debug_find(TCCState *s1, Sym *t, int dwarf)
1594+static int check_global(Sym *t)
15081595 {
1509− int i;
1596+ Sym *g = local_stack;
15101597
1511− if (!debug_info && dwarf &&
1512− (t->type.t & VT_BTYPE) == VT_STRUCT && t->c == -1) {
1513− for (i = 0; i < n_debug_anon_hash; i++)
1514− if (t == debug_anon_hash[i].type)
1598+ while (g) {
1599+ if (t == g)
1600+ return 0;
1601+ g = g->prev;
1602+ }
1603+ return 1;
1604+}
1605+
1606+static int tcc_debug_find(TCCState *s1, Sym *t, int dwarf)
1607+{
1608+ int i , g = check_global(t);
1609+ int n_hash, *n_forw_hash;
1610+ struct _debug_hash *hash;
1611+ struct _debug_forw_hash **forw_hash;
1612+
1613+ if ((t->type.t & VT_BTYPE) == VT_STRUCT && t->c == -1) {
1614+ forw_hash = g ? &debug_forw_hash_global : &debug_forw_hash_local;
1615+ n_forw_hash = g ? &n_debug_forw_hash_global : &n_debug_forw_hash_local;
1616+ for (i = 0; i < *n_forw_hash; i++)
1617+ if (t == (*forw_hash)[i].type)
15151618 return 0;
1516− debug_anon_hash = (struct _debug_anon_hash *)
1517− tcc_realloc (debug_anon_hash,
1518− (n_debug_anon_hash + 1) * sizeof(*debug_anon_hash));
1519− debug_anon_hash[n_debug_anon_hash].n_debug_type = 0;
1520− debug_anon_hash[n_debug_anon_hash].debug_type = NULL;
1521− debug_anon_hash[n_debug_anon_hash++].type = t;
1619+ *forw_hash = (struct _debug_forw_hash *)
1620+ tcc_realloc (*forw_hash,
1621+ (*n_forw_hash + 1) * sizeof(**forw_hash));
1622+ (*forw_hash)[*n_forw_hash].n_debug_type = 0;
1623+ (*forw_hash)[*n_forw_hash].debug_type = NULL;
1624+ (*forw_hash)[(*n_forw_hash)++].type = t;
15221625 return 0;
15231626 }
1524− for (i = 0; i < n_debug_hash; i++)
1525− if (t == debug_hash[i].type)
1526− return debug_hash[i].debug_type;
1627+ hash = g ? debug_hash_global : debug_hash_local;
1628+ n_hash = g ? n_debug_hash_global : n_debug_hash_local;
1629+ for (i = 0; i < n_hash; i++)
1630+ if (t == hash[i].type)
1631+ return hash[i].debug_type;
15271632 return -1;
15281633 }
15291634
15301635 static int tcc_get_dwarf_info(TCCState *s1, Sym *s);
15311636
1532−static void tcc_debug_check_anon(TCCState *s1, Sym *t, int debug_type)
1637+static void tcc_debug_check_forw(TCCState *s1, Sym *t, int debug_type)
15331638 {
1534− int i;
1535−
1536− if (!debug_info && (t->type.t & VT_BTYPE) == VT_STRUCT && t->type.ref->c == -1)
1537− for (i = 0; i < n_debug_anon_hash; i++)
1538− if (t->type.ref == debug_anon_hash[i].type) {
1539− debug_anon_hash[i].debug_type =
1540− tcc_realloc(debug_anon_hash[i].debug_type,
1541− (debug_anon_hash[i].n_debug_type + 1) * sizeof(int));
1542− debug_anon_hash[i].debug_type[debug_anon_hash[i].n_debug_type++] =
1543− debug_type;
1544− }
1639+ if ((t->type.t & VT_BTYPE) == VT_STRUCT && t->type.ref->c == -1) {
1640+ int i, j, g = check_global(t);
1641+ int n_forw_hash;
1642+ struct _debug_forw_hash **forw_hash;
1643+
1644+ for (i = g; i <= 1; i++) {
1645+ forw_hash = i ? &debug_forw_hash_global : &debug_forw_hash_local;
1646+ n_forw_hash = i ? n_debug_forw_hash_global : n_debug_forw_hash_local;
1647+ for (j = 0; j < n_forw_hash; j++)
1648+ if (t->type.ref == (*forw_hash)[j].type) {
1649+ (*forw_hash)[j].debug_type =
1650+ tcc_realloc((*forw_hash)[j].debug_type,
1651+ ((*forw_hash)[j].n_debug_type + 1) * sizeof(int));
1652+ (*forw_hash)[j].debug_type[(*forw_hash)[j].n_debug_type++] =
1653+ debug_type;
1654+ return;
1655+ }
1656+ }
1657+ }
15451658 }
15461659
1547−ST_FUNC void tcc_debug_fix_anon(TCCState *s1, CType *t)
1660+ST_FUNC void tcc_debug_fix_forw(TCCState *s1, CType *t)
15481661 {
1549− int i, j, debug_type;
1550−
1551− if (!(s1->do_debug & 2) || !s1->dwarf || debug_info)
1662+ if (!(s1->do_debug & 2))
15521663 return;
15531664
1554− if ((t->t & VT_BTYPE) == VT_STRUCT && t->ref->c != -1)
1555− for (i = 0; i < n_debug_anon_hash; i++)
1556− if (t->ref == debug_anon_hash[i].type) {
1557− Sym sym = {0}; sym .type = *t ;
1558−
1559− /* Trick to not hash this struct */
1560− debug_info = (struct _debug_info *) t;
1561− debug_type = tcc_get_dwarf_info(s1, &sym);
1562− debug_info = NULL;
1563− for (j = 0; j < debug_anon_hash[i].n_debug_type; j++)
1564− write32le(dwarf_info_section->data +
1565− debug_anon_hash[i].debug_type[j],
1566− debug_type - dwarf_info.start);
1567− tcc_free(debug_anon_hash[i].debug_type);
1568− n_debug_anon_hash--;
1569− for (; i < n_debug_anon_hash; i++)
1570− debug_anon_hash[i] = debug_anon_hash[i + 1];
1665+ if ((t->t & VT_BTYPE) == VT_STRUCT && t->ref->c != -1) {
1666+ int i, j, debug_type, g = check_global(t->ref);
1667+ int *n_forw_hash;
1668+ struct _debug_forw_hash **forw_hash;
1669+
1670+ forw_hash = g ? &debug_forw_hash_global : &debug_forw_hash_local;
1671+ n_forw_hash = g ? &n_debug_forw_hash_global : &n_debug_forw_hash_local;
1672+ for (i = 0; i < *n_forw_hash; i++)
1673+ if (t->ref == (*forw_hash)[i].type) {
1674+ if (s1->dwarf) {
1675+ Sym sym = {0}; sym .type = *t ;
1676+
1677+ debug_type = tcc_get_dwarf_info(s1, &sym);
1678+ for (j = 0; j < (*forw_hash)[i].n_debug_type; j++)
1679+ write32le(dwarf_info_section->data +
1680+ (*forw_hash)[i].debug_type[j],
1681+ debug_type - dwarf_info.start);
1682+ tcc_free((*forw_hash)[i].debug_type);
1683+ }
1684+ (*n_forw_hash)--;
1685+ for (; i < *n_forw_hash; i++)
1686+ (*forw_hash)[i] = (*forw_hash)[i + 1];
15711687 }
1688+ }
15721689 }
15731690
15741691 static int tcc_debug_add(TCCState *s1, Sym *t, int dwarf)
15751692 {
15761693 int offset = dwarf ? dwarf_info_section->data_offset : ++debug_next_type;
1577− debug_hash = (struct _debug_hash *)
1578− tcc_realloc (debug_hash,
1579− (n_debug_hash + 1) * sizeof(*debug_hash));
1580− debug_hash[n_debug_hash].debug_type = offset;
1581− debug_hash[n_debug_hash++].type = t;
1694+ int *n_hash, g = check_global(t);
1695+ struct _debug_hash **hash;
1696+
1697+ hash = g ? &debug_hash_global : &debug_hash_local;
1698+ n_hash = g ? &n_debug_hash_global : &n_debug_hash_local;
1699+ *hash = (struct _debug_hash *)
1700+ tcc_realloc (*hash,
1701+ (*n_hash + 1) * sizeof(**hash));
1702+ (*hash)[*n_hash].debug_type = offset;
1703+ (*hash)[(*n_hash)++].type = t;
15821704 return offset;
15831705 }
15841706
1585−static void tcc_debug_remove(TCCState *s1, Sym *t)
1586−{
1587− int i;
1588−
1589− for (i = 0; i < n_debug_hash; i++)
1590− if (t == debug_hash[i].type) {
1591− n_debug_hash--;
1592− for (; i < n_debug_hash; i++)
1593− debug_hash[i] = debug_hash[i+1];
1594− }
1595−}
1596−
15971707 #define STRUCT_NODEBUG(s) \
15981708 (s->a.nodebug || \
15991709 ((s->v & ~SYM_FIELD) >= SYM_FIRST_ANOM && \
@@ -1621,11 +1731,9 @@ static void tcc_get_debug_info(TCCState *s1, Sym *s, CString *result) · 21 unmodified lines
16211731 break;
16221732 }
16231733 if ((type & VT_BTYPE) == VT_STRUCT) {
1624− Sym *e = t;
1625−
16261734 t = t->type.ref;
16271735 debug_type = tcc_debug_find(s1, t, 0);
1628− if (debug_type == -1 && t->c >= 0) {
1736+ if (debug_type == -1) {
16291737 debug_type = tcc_debug_add(s1, t, 0);
16301738 cstr_new (&str);
16311739 cstr_printf (&str, "%s:T%d=%c%d",
@@ -1640,6 +1748,7 @@ static void tcc_get_debug_info(TCCState *s1, Sym *s, CString *result) · 8 unmodified lines
16401748 t = t->next;
16411749 if (STRUCT_NODEBUG(t))
16421750 continue;
1751+ tcc_debug_check_forw(s1, t, -1);
16431752 cstr_printf (&str, "%s:",
16441753 get_tok_str(t->v, NULL));
16451754 tcc_get_debug_info (s1, t, &str);
@@ -1656,15 +1765,13 @@ static void tcc_get_debug_info(TCCState *s1, Sym *s, CString *result) · 10 unmodified lines
16561765 cstr_printf (&str, ";");
16571766 tcc_debug_stabs(s1, str.data, N_LSYM, 0, NULL, 0, 0);
16581767 cstr_free (&str);
1659− if (debug_info)
1660− tcc_debug_remove(s1, e);
16611768 }
16621769 }
16631770 else if (IS_ENUM(type)) {
16641771 Sym *e = t = t->type.ref;
16651772
16661773 debug_type = tcc_debug_find(s1, t, 0);
1667− if (debug_type == -1 && t->c >= 0) {
1774+ if (debug_type == -1) {
16681775 debug_type = tcc_debug_add(s1, t, 0);
16691776 cstr_new (&str);
16701777 cstr_printf (&str, "%s:T%d=e",
@@ -1682,8 +1789,6 @@ static void tcc_get_debug_info(TCCState *s1, Sym *s, CString *result) · 11 unmodified lines
16821789 cstr_printf (&str, ";");
16831790 tcc_debug_stabs(s1, str.data, N_LSYM, 0, NULL, 0, 0);
16841791 cstr_free (&str);
1685− if (debug_info)
1686− tcc_debug_remove(s1, e);
16871792 }
16881793 }
16891794 else if ((type & VT_BTYPE) != VT_FUNC) {
@@ -1713,6 +1818,7 @@ static void tcc_get_debug_info(TCCState *s1, Sym *s, CString *result) · 23 unmodified lines
17131818 }
17141819 else
17151820 break;
1821+ tcc_debug_check_forw(s1, t, -1);
17161822 t = t->type.ref;
17171823 }
17181824 cstr_printf (result, "%d", debug_type);
@@ -1741,7 +1847,7 @@ static int tcc_get_dwarf_info(TCCState *s1, Sym *s) · 22 unmodified lines
17411847 if ((type & VT_BTYPE) == VT_STRUCT) {
17421848 t = t->type.ref;
17431849 debug_type = tcc_debug_find(s1, t, 1);
1744− if (debug_type == -1 && t->c >= 0) {
1850+ if (debug_type == -1) {
17451851 int pos_sib = 0, i, *pos_type;
17461852
17471853 debug_type = tcc_debug_add(s1, t, 1);
@@ -1807,19 +1913,17 @@ static int tcc_get_dwarf_info(TCCState *s1, Sym *s) · 59 unmodified lines
18071913 if (STRUCT_NODEBUG(e))
18081914 continue;
18091915 type = tcc_get_dwarf_info(s1, e);
1810− tcc_debug_check_anon(s1, e, pos_type[i]);
1916+ tcc_debug_check_forw(s1, e, pos_type[i]);
18111917 write32le(dwarf_info_section->data + pos_type[i++],
18121918 type - dwarf_info.start);
18131919 }
18141920 tcc_free(pos_type);
1815− if (debug_info)
1816− tcc_debug_remove(s1, t);
18171921 }
18181922 }
18191923 else if (IS_ENUM(type)) {
18201924 t = t->type.ref;
18211925 debug_type = tcc_debug_find(s1, t, 1);
1822− if (debug_type == -1 && t->c >= 0) {
1926+ if (debug_type == -1) {
18231927 int pos_sib, pos_type;
18241928 Sym sym = {0}; sym.type.t = VT_INT | (type & VT_UNSIGNED);
18251929
@@ -1854,8 +1958,6 @@ static int tcc_get_dwarf_info(TCCState *s1, Sym *s) · 28 unmodified lines
18541958 dwarf_data1(dwarf_info_section, 0);
18551959 write32le(dwarf_info_section->data + pos_sib,
18561960 dwarf_info_section->data_offset - dwarf_info.start);
1857− if (debug_info)
1858− tcc_debug_remove(s1, t);
18591961 }
18601962 }
18611963 else if ((type & VT_BTYPE) != VT_FUNC) {
@@ -1893,7 +1995,7 @@ static int tcc_get_dwarf_info(TCCState *s1, Sym *s) · 31 unmodified lines
18931995 dwarf_data1(dwarf_info_section, DWARF_ABBREV_POINTER);
18941996 dwarf_data1(dwarf_info_section, PTR_SIZE);
18951997 if (last_pos != -1) {
1896− tcc_debug_check_anon(s1, e, last_pos);
1998+ tcc_debug_check_forw(s1, e, last_pos);
18971999 write32le(dwarf_info_section->data + last_pos,
18982000 i - dwarf_info.start);
18992001 }
@@ -1915,7 +2017,7 @@ static int tcc_get_dwarf_info(TCCState *s1, Sym *s) · 15 unmodified lines
19152017 retval = i;
19162018 dwarf_data1(dwarf_info_section, DWARF_ABBREV_ARRAY_TYPE);
19172019 if (last_pos != -1) {
1918− tcc_debug_check_anon(s1, e, last_pos);
2020+ tcc_debug_check_forw(s1, e, last_pos);
19192021 write32le(dwarf_info_section->data + last_pos,
19202022 i - dwarf_info.start);
19212023 }
@@ -1950,7 +2052,7 @@ static int tcc_get_dwarf_info(TCCState *s1, Sym *s) · 28 unmodified lines
19502052 t->type.ref->next ? DWARF_ABBREV_SUBROUTINE_TYPE
19512053 : DWARF_ABBREV_SUBROUTINE_EMPTY_TYPE);
19522054 if (last_pos != -1) {
1953− tcc_debug_check_anon(s1, e, last_pos);
2055+ tcc_debug_check_forw(s1, e, last_pos);
19542056 write32le(dwarf_info_section->data + last_pos,
19552057 i - dwarf_info.start);
19562058 }
@@ -1986,7 +2088,7 @@ static int tcc_get_dwarf_info(TCCState *s1, Sym *s) · 29 unmodified lines
19862088 while (f->next) {
19872089 f = f->next;
19882090 type = tcc_get_dwarf_info(s1, f);
1989− tcc_debug_check_anon(s1, f, pos_type[i]);
2091+ tcc_debug_check_forw(s1, f, pos_type[i]);
19902092 write32le(dwarf_info_section->data + pos_type[i++],
19912093 type - dwarf_info.start);
19922094 }
@@ -1994,7 +2096,7 @@ static int tcc_get_dwarf_info(TCCState *s1, Sym *s) · 1 unmodified line
19942096 }
19952097 else {
19962098 if (last_pos != -1) {
1997− tcc_debug_check_anon(s1, e, last_pos);
2099+ tcc_debug_check_forw(s1, e, last_pos);
19982100 write32le(dwarf_info_section->data + last_pos,
19992101 debug_type - dwarf_info.start);
20002102 }
@@ -2201,7 +2303,7 @@ ST_FUNC void tcc_debug_funcend(TCCState *s1, int size) · 200 unmodified lines
22012303 dwarf_strp(dwarf_info_section, funcname);
22022304 dwarf_uleb128(dwarf_info_section, dwarf_line.cur_file);
22032305 dwarf_uleb128(dwarf_info_section, dwarf_info.line);
2204− tcc_debug_check_anon(s1, sym->type.ref, dwarf_info_section->data_offset);
2306+ tcc_debug_check_forw(s1, sym->type.ref, dwarf_info_section->data_offset);
22052307 dwarf_data4(dwarf_info_section, n_debug_info - dwarf_info.start);
22062308 dwarf_reloc(dwarf_info_section, section_sym, R_DATA_PTR);
22072309 #if PTR_SIZE == 4
@@ -2258,7 +2360,7 @@ ST_FUNC void tcc_debug_extern_sym(TCCState *s1, Sym *sym, int sh_num, int sym_bi · 50 unmodified lines
22582360 dwarf_strp(dwarf_info_section, get_tok_str(sym->v, NULL));
22592361 dwarf_uleb128(dwarf_info_section, dwarf_line.cur_file);
22602362 dwarf_uleb128(dwarf_info_section, file->line_num);
2261− tcc_debug_check_anon(s1, sym, dwarf_info_section->data_offset);
2363+ tcc_debug_check_forw(s1, sym, dwarf_info_section->data_offset);
22622364 dwarf_data4(dwarf_info_section, debug_type - dwarf_info.start);
22632365 if (sym_bind == STB_GLOBAL)
22642366 dwarf_data1(dwarf_info_section, 1);
@@ -2284,6 +2386,7 @@ ST_FUNC void tcc_debug_extern_sym(TCCState *s1, Sym *sym, int sh_num, int sym_bi · 19 unmodified lines
22842386 sym_bind == STB_GLOBAL ? 'G' : func_ind != -1 ? 'V' : 'S'
22852387 );
22862388 tcc_get_debug_info(s1, sym, &str);
2389+ tcc_debug_check_forw(s1, sym, -1);
22872390 if (sym_bind == STB_GLOBAL)
22882391 tcc_debug_stabs(s1, str.data, N_GSYM, 0, NULL, 0, 0);
22892392 else
@@ -2308,7 +2411,7 @@ ST_FUNC void tcc_debug_typedef(TCCState *s1, Sym *sym) · 18 unmodified lines
23082411 dwarf_strp(dwarf_info_section, get_tok_str(sym->v, NULL));
23092412 dwarf_uleb128(dwarf_info_section, dwarf_line.cur_file);
23102413 dwarf_uleb128(dwarf_info_section, file->line_num);
2311− tcc_debug_check_anon(s1, sym, dwarf_info_section->data_offset);
2414+ tcc_debug_check_forw(s1, sym, dwarf_info_section->data_offset);
23122415 dwarf_data4(dwarf_info_section, debug_type - dwarf_info.start);
23132416 }
23142417 }
@@ -2320,6 +2423,7 @@ ST_FUNC void tcc_debug_typedef(TCCState *s1, Sym *sym) · 5 unmodified lines
23202423 (sym->v & ~SYM_FIELD) >= SYM_FIRST_ANOM
23212424 ? "" : get_tok_str(sym->v, NULL));
23222425 tcc_get_debug_info(s1, sym, &str);
2426+ tcc_debug_check_forw(s1, sym, -1);
23232427 tcc_debug_stabs(s1, str.data, N_LSYM, 0, NULL, 0, 0);
23242428 cstr_free (&str);
23252429 }
@@ -2477,13 +2581,19 @@ ST_FUNC void tcc_tcov_reset_ind(TCCState *s1) · 151 unmodified lines
24772581 #undef new_file
24782582 #undef section_sym
24792583 #undef debug_next_type
2480−#undef debug_hash
2481−#undef n_debug_hash
2482−#undef debug_anon_hash
2483−#undef n_debug_anon_hash
2584+#undef debug_hash_global
2585+#undef debug_hash_local
2586+#undef n_debug_hash_global
2587+#undef n_debug_hash_local
2588+#undef debug_forw_hash_global
2589+#undef debug_forw_hash_local
2590+#undef n_debug_forw_hash_global
2591+#undef n_debug_forw_hash_local
24842592 #undef debug_info
24852593 #undef debug_info_root
24862594 #undef dwarf_sym
24872595 #undef dwarf_line
24882596 #undef dwarf_info
2597+#undef dwarf_str
2598+#undef dwarf_line_str
24892599 #undef tcov_data
tccgen.c+1−1
@@ -4612,7 +4612,7 @@ do_decl: · 4611 unmodified lines
46124612 check_fields(type, 0);
46134613 struct_layout(type, &ad);
46144614 if (debug_modes)
4615− tcc_debug_fix_anon(tcc_state, type);
4615+ tcc_debug_fix_forw(tcc_state, type);
46164616 }
46174617 }
46184618 }

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