Skip to content

Commit 2cb8bdd

Browse files
committed
Add attribute nodebug support and skip bitfield padding
The following code: typedef struct { unsigned int a __attribute__((nodebug)); unsigned int b; unsigned int : 32; unsigned int c; } tst; Supresses a and also suppresses bitfield padding. So debugger shows only b and c in above example.
1 parent 2cf3a6e commit 2cb8bdd

File tree

4 files changed

+28
-5
lines changed

4 files changed

+28
-5
lines changed

tcc.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,8 @@ struct SymAttr {
548548
nodecorate : 1,
549549
dllimport : 1,
550550
addrtaken : 1,
551-
xxxx : 3; /* not used */
551+
nodebug : 1,
552+
xxxx : 2; /* not used */
552553
};
553554

554555
/* function attributes or temporary attributes for parsing */

tccdbg.c

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1285,6 +1285,15 @@ static void tcc_debug_remove(TCCState *s1, Sym *t)
12851285
}
12861286
}
12871287

1288+
#define STRUCT_NODEBUG(s) \
1289+
(s->a.nodebug || \
1290+
((s->v & ~SYM_FIELD) >= SYM_FIRST_ANOM && \
1291+
((s->type.t & VT_BTYPE) == VT_BYTE || \
1292+
(s->type.t & VT_BTYPE) == VT_BOOL || \
1293+
(s->type.t & VT_BTYPE) == VT_SHORT || \
1294+
(s->type.t & VT_BTYPE) == VT_INT || \
1295+
(s->type.t & VT_BTYPE) == VT_LLONG)))
1296+
12881297
static void tcc_get_debug_info(TCCState *s1, Sym *s, CString *result)
12891298
{
12901299
int type;
@@ -1320,9 +1329,10 @@ static void tcc_get_debug_info(TCCState *s1, Sym *s, CString *result)
13201329
int pos, size, align;
13211330

13221331
t = t->next;
1332+
if (STRUCT_NODEBUG(t))
1333+
continue;
13231334
cstr_printf (&str, "%s:",
1324-
(t->v & ~SYM_FIELD) >= SYM_FIRST_ANOM
1325-
? "" : get_tok_str(t->v & ~SYM_FIELD, NULL));
1335+
get_tok_str(t->v & ~SYM_FIELD, NULL));
13261336
tcc_get_debug_info (s1, t, &str);
13271337
if (t->type.t & VT_BITFIELD) {
13281338
pos = t->c * 8 + BIT_POS(t->type.t);
@@ -1430,6 +1440,8 @@ static int tcc_get_dwarf_info(TCCState *s1, Sym *s)
14301440
i = 0;
14311441
while (e->next) {
14321442
e = e->next;
1443+
if (STRUCT_NODEBUG(e))
1444+
continue;
14331445
i++;
14341446
}
14351447
pos_type = (int *) tcc_malloc(i * sizeof(int));
@@ -1453,12 +1465,13 @@ static int tcc_get_dwarf_info(TCCState *s1, Sym *s)
14531465
i = 0;
14541466
while (e->next) {
14551467
e = e->next;
1468+
if (STRUCT_NODEBUG(e))
1469+
continue;
14561470
dwarf_data1(dwarf_info_section,
14571471
e->type.t & VT_BITFIELD ? DWARF_ABBREV_MEMBER_BF
14581472
: DWARF_ABBREV_MEMBER);
14591473
dwarf_strp(dwarf_info_section,
1460-
(e->v & ~SYM_FIELD) >= SYM_FIRST_ANOM
1461-
? "" : get_tok_str(e->v & ~SYM_FIELD, NULL));
1474+
get_tok_str(e->v & ~SYM_FIELD, NULL));
14621475
dwarf_uleb128(dwarf_info_section, dwarf_line.cur_file);
14631476
dwarf_uleb128(dwarf_info_section, file->line_num);
14641477
pos_type[i++] = dwarf_info_section->data_offset;
@@ -1482,6 +1495,8 @@ static int tcc_get_dwarf_info(TCCState *s1, Sym *s)
14821495
i = 0;
14831496
while (e->next) {
14841497
e = e->next;
1498+
if (STRUCT_NODEBUG(e))
1499+
continue;
14851500
type = tcc_get_dwarf_info(s1, e);
14861501
tcc_debug_check_anon(s1, e, pos_type[i]);
14871502
write32le(dwarf_info_section->data + pos_type[i++],

tccgen.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,6 +1067,7 @@ static void merge_symattr(struct SymAttr *sa, struct SymAttr *sa1)
10671067
sa->aligned = sa1->aligned;
10681068
sa->packed |= sa1->packed;
10691069
sa->weak |= sa1->weak;
1070+
sa->nodebug |= sa1->nodebug;
10701071
if (sa1->visibility != STV_DEFAULT) {
10711072
int vis = sa->visibility;
10721073
if (vis == STV_DEFAULT
@@ -3823,6 +3824,10 @@ static void parse_attribute(AttributeDef *ad)
38233824
case TOK_WEAK2:
38243825
ad->a.weak = 1;
38253826
break;
3827+
case TOK_NODEBUG1:
3828+
case TOK_NODEBUG2:
3829+
ad->a.nodebug = 1;
3830+
break;
38263831
case TOK_UNUSED1:
38273832
case TOK_UNUSED2:
38283833
/* currently, no need to handle it because tcc does not

tcctok.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@
124124
DEF(TOK_ALIAS2, "__alias__")
125125
DEF(TOK_UNUSED1, "unused")
126126
DEF(TOK_UNUSED2, "__unused__")
127+
DEF(TOK_NODEBUG1, "nodebug")
128+
DEF(TOK_NODEBUG2, "__nodebug__")
127129
DEF(TOK_CDECL1, "cdecl")
128130
DEF(TOK_CDECL2, "__cdecl")
129131
DEF(TOK_CDECL3, "__cdecl__")

0 commit comments

Comments
 (0)