History

Update dwarf2 support

tccgen.c: - add anon support. So tcc_state in tcc works now. - add function pointer support - remove DW_FORM_implicit_const from DW_TAG_pointer_type tccrun.c: - set initial file name - correctly use pc in DW_LNE_set_address (see lib/bt-exe.c) - add DW_LNE_define_file support (even if it is deprecated) tccelf.c - do not include debug/test_coverage information for stub functions lib/bt-exe.c - use num_callers=-1 to mark dll

herman ten brugge committed 4 years ago

Commit 18808e31 parent f0df48f4 files · +224 −23Browse files

Unified · Split

4 files
  1. lib/bt-exe.c +1 −0
  2. tccelf.c +15 −2
  3. tccgen.c +188 −16
  4. tccrun.c +20 −5
lib/bt-exe.c+1−0
@@ -29,6 +29,7 @@ void __bt_init(rt_context *p, int num_callers) · 28 unmodified lines
29 __rt_error = _rt_error;29 __rt_error = _rt_error;
30 set_exception_handler();30 set_exception_handler();
31 } else {31 } else {
32 p->num_callers = -1;
32 p->next = rc->next, rc->next = p;33 p->next = rc->next, rc->next = p;
33 }34 }
34}35}
tccelf.c+15−2
@@ -1426,6 +1426,19 @@ static void set_local_sym(TCCState *s1, const char *name, Section *s, int offset · 1425 unmodified lines
1426 }1426 }
1427}1427}
1428 1428
1429/* avoid generating debug/test_coverage code for stub functions */
1430static void tcc_compile_string_no_debug(TCCState *s, const char *str)
1431{
1432 int save_do_debug = s->do_debug;
1433 int save_test_coverage = s->test_coverage;
1434
1435 s->do_debug = 0;
1436 s->test_coverage = 0;
1437 tcc_compile_string(s, str);
1438 s->do_debug = save_do_debug;
1439 s->test_coverage = save_test_coverage;
1440}
1441
1429#ifdef CONFIG_TCC_BACKTRACE1442#ifdef CONFIG_TCC_BACKTRACE
1430static void put_ptr(TCCState *s1, Section *s, int offs, const char *name)1443static void put_ptr(TCCState *s1, Section *s, int offs, const char *name)
1431{1444{
@@ -1489,7 +1502,7 @@ ST_FUNC void tcc_add_btstub(TCCState *s1) · 57 unmodified lines
1489#endif1502#endif
1490 cstr_printf(&cstr, "__bt_init(__rt_info,%d);}",1503 cstr_printf(&cstr, "__bt_init(__rt_info,%d);}",
1491 s1->output_type == TCC_OUTPUT_DLL ? 0 : s1->rt_num_callers + 1);1504 s1->output_type == TCC_OUTPUT_DLL ? 0 : s1->rt_num_callers + 1);
1492 tcc_compile_string(s1, cstr.data);1505 tcc_compile_string_no_debug(s1, cstr.data);
1493 cstr_free(&cstr);1506 cstr_free(&cstr);
1494 set_local_sym(s1, &"___rt_info"[!s1->leading_underscore], s, o);1507 set_local_sym(s1, &"___rt_info"[!s1->leading_underscore], s, o);
1495}1508}
@@ -1528,7 +1541,7 @@ static void tcc_tcov_add_file(TCCState *s1, const char *filename) · 32 unmodified lines
1528 "__attribute__((destructor)) static void __tcov_exit() {"1541 "__attribute__((destructor)) static void __tcov_exit() {"
1529 "__store_test_coverage(__tcov_data);"1542 "__store_test_coverage(__tcov_data);"
1530 "}");1543 "}");
1531 tcc_compile_string(s1, cstr.data);1544 tcc_compile_string_no_debug(s1, cstr.data);
1532 cstr_free(&cstr);1545 cstr_free(&cstr);
1533 set_local_sym(s1, &"___tcov_data"[!s1->leading_underscore], tcov_section, 0);1546 set_local_sym(s1, &"___tcov_data"[!s1->leading_underscore], tcov_section, 0);
1534}1547}
tccgen.c+188−16
@@ -187,7 +187,7 @@ static const struct { · 186 unmodified lines
187 { VT_BYTE | VT_UNSIGNED, 1, DW_ATE_unsigned_char, "unsigned char:t25=r25;0;255;" },187 { VT_BYTE | VT_UNSIGNED, 1, DW_ATE_unsigned_char, "unsigned char:t25=r25;0;255;" },
188 /* boolean type */188 /* boolean type */
189 { VT_BOOL, 1, DW_ATE_unsigned_char, "bool:t26=r26;0;255;" },189 { VT_BOOL, 1, DW_ATE_unsigned_char, "bool:t26=r26;0;255;" },
190 { VT_VOID, 1, DW_ATE_void, "void:t27=27" },190 { VT_VOID, 1, DW_ATE_unsigned_char, "void:t27=27" },
191};191};
192 192
193#define N_DEFAULT_DEBUG (sizeof (default_debug) / sizeof (default_debug[0]))193#define N_DEFAULT_DEBUG (sizeof (default_debug) / sizeof (default_debug[0]))
@@ -199,7 +199,14 @@ static struct debug_hash { · 5 unmodified lines
199 Sym *type;199 Sym *type;
200} *debug_hash;200} *debug_hash;
201 201
202static struct debug_anon_hash {
203 Sym *type;
204 int n_debug_type;
205 int *debug_type;
206} *debug_anon_hash;
207
202static int n_debug_hash;208static int n_debug_hash;
209static int n_debug_anon_hash;
203 210
204static struct debug_info {211static struct debug_info {
205 int start;212 int start;
@@ -251,7 +258,12 @@ static struct debug_info { · 45 unmodified lines
251#define DWARF_ABBREV_SUBPROGRAM_EXTERNAL 17258#define DWARF_ABBREV_SUBPROGRAM_EXTERNAL 17
252#define DWARF_ABBREV_SUBPROGRAM_STATIC 18259#define DWARF_ABBREV_SUBPROGRAM_STATIC 18
253#define DWARF_ABBREV_LEXICAL_BLOCK 19260#define DWARF_ABBREV_LEXICAL_BLOCK 19
261#define DWARF_ABBREV_SUBROUTINE_TYPE 20
262#define DWARF_ABBREV_FORMAL_PARAMETER2 21
254 263
264/* all entries should have been generated with dwarf_uleb128 except
265 has_children. All values are currently below 128 so this currently
266 works. */
255static const unsigned char dwarf_abbrev_init[] = {267static const unsigned char dwarf_abbrev_init[] = {
256 DWARF_ABBREV_COMPILE_UNIT, DW_TAG_compile_unit, 1,268 DWARF_ABBREV_COMPILE_UNIT, DW_TAG_compile_unit, 1,
257 DW_AT_producer, DW_FORM_strp,269 DW_AT_producer, DW_FORM_strp,
@@ -298,7 +310,6 @@ static const unsigned char dwarf_abbrev_init[] = { · 40 unmodified lines
298 0, 0,310 0, 0,
299 DWARF_ABBREV_POINTER, DW_TAG_pointer_type, 0,311 DWARF_ABBREV_POINTER, DW_TAG_pointer_type, 0,
300 DW_AT_byte_size, DW_FORM_data1,312 DW_AT_byte_size, DW_FORM_data1,
301 DW_AT_byte_size, DW_FORM_implicit_const, 8,
302 DW_AT_type, DW_FORM_ref4,313 DW_AT_type, DW_FORM_ref4,
303 0, 0,314 0, 0,
304 DWARF_ABBREV_ARRAY_TYPE, DW_TAG_array_type, 1,315 DWARF_ABBREV_ARRAY_TYPE, DW_TAG_array_type, 1,
@@ -394,6 +405,13 @@ static const unsigned char dwarf_abbrev_init[] = { · 89 unmodified lines
394 DW_AT_high_pc, DW_FORM_data8,405 DW_AT_high_pc, DW_FORM_data8,
395#endif406#endif
396 0, 0,407 0, 0,
408 DWARF_ABBREV_SUBROUTINE_TYPE, DW_TAG_subroutine_type, 1,
409 DW_AT_type, DW_FORM_ref4,
410 DW_AT_sibling, DW_FORM_ref4,
411 0, 0,
412 DWARF_ABBREV_FORMAL_PARAMETER2, DW_TAG_formal_parameter, 0,
413 DW_AT_type, DW_FORM_ref4,
414 0, 0,
397 0415 0
398};416};
399 417
@@ -945,7 +963,9 @@ ST_FUNC void tcc_debug_start(TCCState *s1) · 545 unmodified lines
945 func_ind = -1;963 func_ind = -1;
946 debug_next_type = N_DEFAULT_DEBUG;964 debug_next_type = N_DEFAULT_DEBUG;
947 debug_hash = NULL;965 debug_hash = NULL;
966 debug_anon_hash = NULL;
948 n_debug_hash = 0;967 n_debug_hash = 0;
968 n_debug_anon_hash = 0;
949 /* we're currently 'including' the <command line> */969 /* we're currently 'including' the <command line> */
950 tcc_debug_bincl(s1);970 tcc_debug_bincl(s1);
951 }971 }
@@ -963,12 +983,35 @@ ST_FUNC void tcc_debug_end(TCCState *s1) · 11 unmodified lines
963 if (!s1->do_debug)983 if (!s1->do_debug)
964 return;984 return;
965 if (s1->dwarf) {985 if (s1->dwarf) {
966 int i;986 int i, j;
967 int start_aranges;987 int start_aranges;
968 unsigned char *ptr;988 unsigned char *ptr;
969 int text_size = text_section->data_offset;989 int text_size = text_section->data_offset;
970 990
971 /* dwarf_info */991 /* dwarf_info */
992 for (i = 0; i < n_debug_anon_hash; i++) {
993 Sym *t = debug_anon_hash[i].type;
994 int pos = dwarf_info_section->data_offset;
995
996 dwarf_data1(dwarf_info_section,
997 IS_UNION (t->type.t) ? DWARF_ABBREV_UNION_TYPE
998 : DWARF_ABBREV_STRUCTURE_TYPE);
999 dwarf_strp(dwarf_info_section,
1000 (t->v & ~SYM_STRUCT) >= SYM_FIRST_ANOM
1001 ? "" : get_tok_str(t->v & ~SYM_STRUCT, NULL));
1002 dwarf_uleb128(dwarf_info_section, 0);
1003 dwarf_uleb128(dwarf_info_section, dwarf_line.cur_file);
1004 dwarf_uleb128(dwarf_info_section, file->line_num);
1005 j = dwarf_info_section->data_offset + 5 - dwarf_info.start;
1006 dwarf_data4(dwarf_info_section, j);
1007 dwarf_data1(dwarf_info_section, 0);
1008 for (j = 0; j < debug_anon_hash[i].n_debug_type; j++)
1009 write32le(dwarf_info_section->data +
1010 debug_anon_hash[i].debug_type[j],
1011 pos - dwarf_info.start);
1012 tcc_free (debug_anon_hash[i].debug_type);
1013 }
1014 tcc_free (debug_anon_hash);
972 dwarf_data1(dwarf_info_section, 0);1015 dwarf_data1(dwarf_info_section, 0);
973 ptr = dwarf_info_section->data + dwarf_info.start;1016 ptr = dwarf_info_section->data + dwarf_info.start;
974 write32le(ptr, dwarf_info_section->data_offset - dwarf_info.start - 4);1017 write32le(ptr, dwarf_info_section->data_offset - dwarf_info.start - 4);
@@ -1276,16 +1319,69 @@ static void tcc_debug_stabn(TCCState *s1, int type, int value) · 301 unmodified lines
1276 }1319 }
1277}1320}
1278 1321
1279static int tcc_debug_find(Sym *t)1322static int tcc_get_dwarf_info(TCCState *s1, Sym *s);
1323
1324static int tcc_debug_find(Sym *t, int dwarf)
1280{1325{
1281 int i;1326 int i;
1282 1327
1328 if (!debug_info && dwarf &&
1329 (t->type.t & VT_BTYPE) == VT_STRUCT && t->c == -1) {
1330 for (i = 0; i < n_debug_anon_hash; i++)
1331 if (t == debug_anon_hash[i].type)
1332 return 0;
1333 debug_anon_hash = (struct debug_anon_hash *)
1334 tcc_realloc (debug_anon_hash,
1335 (n_debug_anon_hash + 1) * sizeof(*debug_anon_hash));
1336 debug_anon_hash[n_debug_anon_hash].n_debug_type = 0;
1337 debug_anon_hash[n_debug_anon_hash].debug_type = NULL;
1338 debug_anon_hash[n_debug_anon_hash++].type = t;
1339 return 0;
1340 }
1283 for (i = 0; i < n_debug_hash; i++)1341 for (i = 0; i < n_debug_hash; i++)
1284 if (t == debug_hash[i].type)1342 if (t == debug_hash[i].type)
1285 return debug_hash[i].debug_type;1343 return debug_hash[i].debug_type;
1286 return -1;1344 return -1;
1287}1345}
1288 1346
1347static void tcc_debug_check_anon(Sym *t, int debug_type)
1348{
1349 int i;
1350
1351 if (!debug_info && (t->type.t & VT_BTYPE) == VT_STRUCT && t->type.ref->c == -1)
1352 for (i = 0; i < n_debug_anon_hash; i++)
1353 if (t->type.ref == debug_anon_hash[i].type) {
1354 debug_anon_hash[i].debug_type =
1355 tcc_realloc(debug_anon_hash[i].debug_type,
1356 (debug_anon_hash[i].n_debug_type + 1) * sizeof(int));
1357 debug_anon_hash[i].debug_type[debug_anon_hash[i].n_debug_type++] =
1358 debug_type;
1359 }
1360}
1361
1362static void tcc_debug_fix_anon(CType *t)
1363{
1364 int i, j, debug_type;
1365 TCCState *s1 = tcc_state;
1366
1367 if (!s1->do_debug || !s1->dwarf || debug_info)
1368 return;
1369 if ((t->t & VT_BTYPE) == VT_STRUCT && t->ref->c != -1)
1370 for (i = 0; i < n_debug_anon_hash; i++)
1371 if (t->ref == debug_anon_hash[i].type) {
1372 Sym sym = { .type = *t };
1373
1374 debug_type = tcc_get_dwarf_info(s1, &sym);
1375 for (j = 0; j < debug_anon_hash[i].n_debug_type; j++)
1376 write32le(dwarf_info_section->data +
1377 debug_anon_hash[i].debug_type[j], debug_type);
1378 tcc_free(debug_anon_hash[i].debug_type);
1379 n_debug_anon_hash--;
1380 for (; i < n_debug_anon_hash; i++)
1381 debug_anon_hash[i] = debug_anon_hash[i + 1];
1382 }
1383}
1384
1289static int tcc_debug_add(Sym *t, int dwarf)1385static int tcc_debug_add(Sym *t, int dwarf)
1290{1386{
1291 int offset = dwarf ? dwarf_info_section->data_offset : ++debug_next_type;1387 int offset = dwarf ? dwarf_info_section->data_offset : ++debug_next_type;
@@ -1331,7 +1427,7 @@ static void tcc_get_debug_info(TCCState *s1, Sym *s, CString *result) · 39 unmodified lines
1331 Sym *e = t;1427 Sym *e = t;
1332 1428
1333 t = t->type.ref;1429 t = t->type.ref;
1334 debug_type = tcc_debug_find(t);1430 debug_type = tcc_debug_find(t, 0);
1335 if (debug_type == -1) {1431 if (debug_type == -1) {
1336 debug_type = tcc_debug_add(t, 0);1432 debug_type = tcc_debug_add(t, 0);
1337 cstr_new (&str);1433 cstr_new (&str);
@@ -1369,7 +1465,7 @@ static void tcc_get_debug_info(TCCState *s1, Sym *s, CString *result) · 31 unmodified lines
1369 else if (IS_ENUM(type)) {1465 else if (IS_ENUM(type)) {
1370 Sym *e = t = t->type.ref;1466 Sym *e = t = t->type.ref;
1371 1467
1372 debug_type = tcc_debug_find(t);1468 debug_type = tcc_debug_find(t, 0);
1373 if (debug_type == -1) {1469 if (debug_type == -1) {
1374 debug_type = tcc_debug_add(t, 0);1470 debug_type = tcc_debug_add(t, 0);
1375 cstr_new (&str);1471 cstr_new (&str);
@@ -1430,6 +1526,8 @@ static int tcc_get_dwarf_info(TCCState *s1, Sym *s) · 54 unmodified lines
1430 int debug_type = -1;1526 int debug_type = -1;
1431 Sym *e, *t = s;1527 Sym *e, *t = s;
1432 int i;1528 int i;
1529 int last_pos = -1;
1530 int retval;
1433 1531
1434 for (;;) {1532 for (;;) {
1435 type = t->type.t & ~(VT_STORAGE | VT_CONSTANT | VT_VOLATILE);1533 type = t->type.t & ~(VT_STORAGE | VT_CONSTANT | VT_VOLATILE);
@@ -1442,7 +1540,7 @@ static int tcc_get_dwarf_info(TCCState *s1, Sym *s) · 6 unmodified lines
1442 }1540 }
1443 if ((type & VT_BTYPE) == VT_STRUCT) {1541 if ((type & VT_BTYPE) == VT_STRUCT) {
1444 t = t->type.ref;1542 t = t->type.ref;
1445 debug_type = tcc_debug_find(t);1543 debug_type = tcc_debug_find(t, 1);
1446 if (debug_type == -1) {1544 if (debug_type == -1) {
1447 int pos_sib, i, *pos_type;1545 int pos_sib, i, *pos_type;
1448 1546
@@ -1504,6 +1602,7 @@ static int tcc_get_dwarf_info(TCCState *s1, Sym *s) · 55 unmodified lines
1504 while (e->next) {1602 while (e->next) {
1505 e = e->next;1603 e = e->next;
1506 type = tcc_get_dwarf_info(s1, e);1604 type = tcc_get_dwarf_info(s1, e);
1605 tcc_debug_check_anon(e, pos_type[i]);
1507 write32le(dwarf_info_section->data + pos_type[i++],1606 write32le(dwarf_info_section->data + pos_type[i++],
1508 type - dwarf_info.start);1607 type - dwarf_info.start);
1509 }1608 }
@@ -1514,7 +1613,7 @@ static int tcc_get_dwarf_info(TCCState *s1, Sym *s) · 4 unmodified lines
1514 }1613 }
1515 else if (IS_ENUM(type)) {1614 else if (IS_ENUM(type)) {
1516 t = t->type.ref;1615 t = t->type.ref;
1517 debug_type = tcc_debug_find(t);1616 debug_type = tcc_debug_find(t, 1);
1518 if (debug_type == -1) {1617 if (debug_type == -1) {
1519 int pos_sib, pos_type;1618 int pos_sib, pos_type;
1520 CType ct = { VT_INT | (type & VT_UNSIGNED) , NULL };1619 CType ct = { VT_INT | (type & VT_UNSIGNED) , NULL };
@@ -1569,8 +1668,9 @@ static int tcc_get_dwarf_info(TCCState *s1, Sym *s) · 48 unmodified lines
1569 *strchr(name, ':') = 0;1668 *strchr(name, ':') = 0;
1570 dwarf_strp(dwarf_info_section, name);1669 dwarf_strp(dwarf_info_section, name);
1571 dwarf_info.base_type_used[i - 1] = debug_type;1670 dwarf_info.base_type_used[i - 1] = debug_type;
1572 } 1671 }
1573 }1672 }
1673 retval = debug_type;
1574 t = s;1674 t = s;
1575 for (;;) {1675 for (;;) {
1576 type = t->type.t & ~(VT_STORAGE | VT_CONSTANT | VT_VOLATILE);1676 type = t->type.t & ~(VT_STORAGE | VT_CONSTANT | VT_VOLATILE);
@@ -1578,10 +1678,18 @@ static int tcc_get_dwarf_info(TCCState *s1, Sym *s) · 1 unmodified line
1578 type &= ~VT_DEFSIGN;1678 type &= ~VT_DEFSIGN;
1579 if (type == VT_PTR) {1679 if (type == VT_PTR) {
1580 i = dwarf_info_section->data_offset;1680 i = dwarf_info_section->data_offset;
1681 if (retval == debug_type)
1682 retval = i;
1581 dwarf_data1(dwarf_info_section, DWARF_ABBREV_POINTER);1683 dwarf_data1(dwarf_info_section, DWARF_ABBREV_POINTER);
1582 dwarf_data1(dwarf_info_section, PTR_SIZE);1684 dwarf_data1(dwarf_info_section, PTR_SIZE);
1583 dwarf_data4(dwarf_info_section, debug_type - dwarf_info.start);1685 if (last_pos != -1) {
1584 debug_type = i;1686 tcc_debug_check_anon(e, last_pos);
1687 write32le(dwarf_info_section->data + last_pos,
1688 i - dwarf_info.start);
1689 }
1690 last_pos = dwarf_info_section->data_offset;
1691 e = t->type.ref;
1692 dwarf_data4(dwarf_info_section, 0);
1585 }1693 }
1586 else if (type == (VT_PTR | VT_ARRAY)) {1694 else if (type == (VT_PTR | VT_ARRAY)) {
1587 int sib_pos, sub_type;1695 int sib_pos, sub_type;
@@ -1590,8 +1698,17 @@ static int tcc_get_dwarf_info(TCCState *s1, Sym *s) · 2 unmodified lines
1590 1698
1591 sub_type = tcc_get_dwarf_info(s1, &sym);1699 sub_type = tcc_get_dwarf_info(s1, &sym);
1592 i = dwarf_info_section->data_offset;1700 i = dwarf_info_section->data_offset;
1701 if (retval == debug_type)
1702 retval = i;
1593 dwarf_data1(dwarf_info_section, DWARF_ABBREV_ARRAY_TYPE);1703 dwarf_data1(dwarf_info_section, DWARF_ABBREV_ARRAY_TYPE);
1594 dwarf_data4(dwarf_info_section, debug_type - dwarf_info.start);1704 if (last_pos != -1) {
1705 tcc_debug_check_anon(e, last_pos);
1706 write32le(dwarf_info_section->data + last_pos,
1707 i - dwarf_info.start);
1708 }
1709 last_pos = dwarf_info_section->data_offset;
1710 e = t->type.ref;
1711 dwarf_data4(dwarf_info_section, 0);
1595 sib_pos = dwarf_info_section->data_offset;1712 sib_pos = dwarf_info_section->data_offset;
1596 dwarf_data4(dwarf_info_section, 0);1713 dwarf_data4(dwarf_info_section, 0);
1597 for (;;) {1714 for (;;) {
@@ -1607,16 +1724,66 @@ static int tcc_get_dwarf_info(TCCState *s1, Sym *s) · 9 unmodified lines
1607 dwarf_data1(dwarf_info_section, 0);1724 dwarf_data1(dwarf_info_section, 0);
1608 write32le(dwarf_info_section->data + sib_pos,1725 write32le(dwarf_info_section->data + sib_pos,
1609 dwarf_info_section->data_offset - dwarf_info.start);1726 dwarf_info_section->data_offset - dwarf_info.start);
1610 debug_type = i;
1611 }1727 }
1612 else if (type == VT_FUNC) {1728 else if (type == VT_FUNC) {
1613 return tcc_get_dwarf_info (s1, t->type.ref);1729 int sib_pos, *pos_type;
1730 Sym *f;
1731
1732 i = dwarf_info_section->data_offset;
1733 debug_type = tcc_get_dwarf_info(s1, t->type.ref);
1734 if (retval == debug_type)
1735 retval = i;
1736 dwarf_data1(dwarf_info_section, DWARF_ABBREV_SUBROUTINE_TYPE);
1737 if (last_pos != -1) {
1738 tcc_debug_check_anon(e, last_pos);
1739 write32le(dwarf_info_section->data + last_pos,
1740 i - dwarf_info.start);
1741 }
1742 last_pos = dwarf_info_section->data_offset;
1743 e = t->type.ref;
1744 dwarf_data4(dwarf_info_section, 0);
1745 sib_pos = dwarf_info_section->data_offset;
1746 dwarf_data4(dwarf_info_section, 0);
1747 f = t->type.ref;
1748 i = 0;
1749 while (f->next) {
1750 f = f->next;
1751 i++;
1752 }
1753 pos_type = (int *) tcc_malloc(i * sizeof(int));
1754 f = t->type.ref;
1755 i = 0;
1756 while (f->next) {
1757 f = f->next;
1758 dwarf_data1(dwarf_info_section, DWARF_ABBREV_FORMAL_PARAMETER2);
1759 pos_type[i++] = dwarf_info_section->data_offset;
1760 dwarf_data4(dwarf_info_section, 0);
1761 }
1762 dwarf_data1(dwarf_info_section, 0);
1763 write32le(dwarf_info_section->data + sib_pos,
1764 dwarf_info_section->data_offset - dwarf_info.start);
1765 f = t->type.ref;
1766 i = 0;
1767 while (f->next) {
1768 f = f->next;
1769 type = tcc_get_dwarf_info(s1, f);
1770 tcc_debug_check_anon(f, pos_type[i]);
1771 write32le(dwarf_info_section->data + pos_type[i++],
1772 type - dwarf_info.start);
1773 }
1774 tcc_free(pos_type);
1614 }1775 }
1615 else1776 else {
1777 if (last_pos != -1) {
1778 tcc_debug_check_anon(e, last_pos);
1779 write32le(dwarf_info_section->data + last_pos,
1780 debug_type - dwarf_info.start);
1781 }
1616 break;1782 break;
1783 }
1617 t = t->type.ref;1784 t = t->type.ref;
1618 }1785 }
1619 return debug_type;1786 return retval;
1620}1787}
1621 1788
1622static void tcc_debug_finish (TCCState *s1, struct debug_info *cur)1789static void tcc_debug_finish (TCCState *s1, struct debug_info *cur)
@@ -1787,6 +1954,7 @@ static void tcc_debug_funcend(TCCState *s1, int size) · 164 unmodified lines
1787 dwarf_strp(dwarf_info_section, funcname);1954 dwarf_strp(dwarf_info_section, funcname);
1788 dwarf_uleb128(dwarf_info_section, dwarf_line.cur_file);1955 dwarf_uleb128(dwarf_info_section, dwarf_line.cur_file);
1789 dwarf_uleb128(dwarf_info_section, dwarf_info.line);1956 dwarf_uleb128(dwarf_info_section, dwarf_info.line);
1957 tcc_debug_check_anon(sym->type.ref, dwarf_info_section->data_offset);
1790 dwarf_data4(dwarf_info_section, debug_info - dwarf_info.start);1958 dwarf_data4(dwarf_info_section, debug_info - dwarf_info.start);
1791 dwarf_reloc(dwarf_info_section, section_sym, R_DATA_PTR);1959 dwarf_reloc(dwarf_info_section, section_sym, R_DATA_PTR);
1792#if PTR_SIZE == 41960#if PTR_SIZE == 4
@@ -1843,6 +2011,7 @@ static void tcc_debug_extern_sym(TCCState *s1, Sym *sym, int sh_num, int sym_bin · 50 unmodified lines
1843 dwarf_strp(dwarf_info_section, get_tok_str(sym->v, NULL));2011 dwarf_strp(dwarf_info_section, get_tok_str(sym->v, NULL));
1844 dwarf_uleb128(dwarf_info_section, dwarf_line.cur_file);2012 dwarf_uleb128(dwarf_info_section, dwarf_line.cur_file);
1845 dwarf_uleb128(dwarf_info_section, file->line_num);2013 dwarf_uleb128(dwarf_info_section, file->line_num);
2014 tcc_debug_check_anon(sym, dwarf_info_section->data_offset);
1846 dwarf_data4(dwarf_info_section, debug_type - dwarf_info.start);2015 dwarf_data4(dwarf_info_section, debug_type - dwarf_info.start);
1847 if (sym_bind == STB_GLOBAL)2016 if (sym_bind == STB_GLOBAL)
1848 dwarf_data1(dwarf_info_section, 1);2017 dwarf_data1(dwarf_info_section, 1);
@@ -1888,6 +2057,7 @@ static void tcc_debug_typedef(TCCState *s1, Sym *sym) · 39 unmodified lines
1888 dwarf_strp(dwarf_info_section, get_tok_str(sym->v & ~SYM_FIELD, NULL));2057 dwarf_strp(dwarf_info_section, get_tok_str(sym->v & ~SYM_FIELD, NULL));
1889 dwarf_uleb128(dwarf_info_section, dwarf_line.cur_file);2058 dwarf_uleb128(dwarf_info_section, dwarf_line.cur_file);
1890 dwarf_uleb128(dwarf_info_section, file->line_num);2059 dwarf_uleb128(dwarf_info_section, file->line_num);
2060 tcc_debug_check_anon(sym, dwarf_info_section->data_offset);
1891 dwarf_data4(dwarf_info_section, debug_type - dwarf_info.start);2061 dwarf_data4(dwarf_info_section, debug_type - dwarf_info.start);
1892 }2062 }
1893 return;2063 return;
@@ -6106,6 +6276,8 @@ do_decl: · 4212 unmodified lines
6106 check_fields(type, 1);6276 check_fields(type, 1);
6107 check_fields(type, 0);6277 check_fields(type, 0);
6108 struct_layout(type, &ad);6278 struct_layout(type, &ad);
6279 if (debug_modes)
6280 tcc_debug_fix_anon(type);
6109 }6281 }
6110 }6282 }
6111}6283}
tccrun.c+20−5
@@ -754,14 +754,14 @@ next: · 753 unmodified lines
754 }754 }
755 }755 }
756 else {756 else {
757 while ((i = DW_GETC(ln, end))) {757 while ((DW_GETC(ln, end))) {
758#if 0758#if 0
759 if (++dir_size < DIR_TABLE_SIZE)759 if (++dir_size < DIR_TABLE_SIZE)
760 dirs[dir_size - 1] = (char *)ln - 1;760 dirs[dir_size - 1] = (char *)ln - 1;
761#endif761#endif
762 while (DW_GETC(ln, end)) {}762 while (DW_GETC(ln, end)) {}
763 }763 }
764 while ((i = DW_GETC(ln, end))) {764 while ((DW_GETC(ln, end))) {
765 if (++filename_size < FILE_TABLE_SIZE) {765 if (++filename_size < FILE_TABLE_SIZE) {
766 filename_table[filename_size - 1].name = (char *)ln - 1;766 filename_table[filename_size - 1].name = (char *)ln - 1;
767 while (DW_GETC(ln, end)) {}767 while (DW_GETC(ln, end)) {}
@@ -776,6 +776,8 @@ next: · 8 unmodified lines
776 dwarf_read_uleb128(&ln, end); // size776 dwarf_read_uleb128(&ln, end); // size
777 }777 }
778 }778 }
779 if (filename_size >= 2)
780 filename = filename_table[1].name;
779 while (ln < end) {781 while (ln < end) {
780 last_pc = pc;782 last_pc = pc;
781 switch (DW_GETC(ln, end)) {783 switch (DW_GETC(ln, end)) {
@@ -790,14 +792,27 @@ next: · 8 unmodified lines
790 goto next_line;792 goto next_line;
791 case DW_LNE_set_address:793 case DW_LNE_set_address:
792#if PTR_SIZE == 4794#if PTR_SIZE == 4
793 dwarf_read_32(&cp, end);795 pc = dwarf_read_32(&cp, end);
794#else796#else
795 dwarf_read_64(&cp, end);797 pc = dwarf_read_64(&cp, end);
796#endif798#endif
797 pc = rc->dwarf_text;799 if (rc->num_callers < 0)
800 pc = rc->dwarf_text; /* dll */
798 opindex = 0;801 opindex = 0;
799 break;802 break;
800 case DW_LNE_define_file: /* deprecated */803 case DW_LNE_define_file: /* deprecated */
804 if (++filename_size < FILE_TABLE_SIZE) {
805 filename_table[filename_size - 1].name = (char *)ln - 1;
806 while (DW_GETC(ln, end)) {}
807 filename_table[filename_size - 1].dir_entry =
808 dwarf_read_uleb128(&ln, end);
809 }
810 else {
811 while (DW_GETC(ln, end)) {}
812 dwarf_read_uleb128(&ln, end);
813 }
814 dwarf_read_uleb128(&ln, end); // time
815 dwarf_read_uleb128(&ln, end); // size
801 break;816 break;
802 case DW_LNE_set_discriminator:817 case DW_LNE_set_discriminator:
803 dwarf_read_uleb128(&cp, end);818 dwarf_read_uleb128(&cp, end);

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