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.
This commit is contained in:
herman ten brugge 2023-03-10 12:41:43 +01:00
parent 2cf3a6eb4d
commit 2cb8bddd82
4 changed files with 28 additions and 5 deletions

3
tcc.h
View File

@ -548,7 +548,8 @@ struct SymAttr {
nodecorate : 1,
dllimport : 1,
addrtaken : 1,
xxxx : 3; /* not used */
nodebug : 1,
xxxx : 2; /* not used */
};
/* function attributes or temporary attributes for parsing */

View File

@ -1285,6 +1285,15 @@ static void tcc_debug_remove(TCCState *s1, Sym *t)
}
}
#define STRUCT_NODEBUG(s) \
(s->a.nodebug || \
((s->v & ~SYM_FIELD) >= SYM_FIRST_ANOM && \
((s->type.t & VT_BTYPE) == VT_BYTE || \
(s->type.t & VT_BTYPE) == VT_BOOL || \
(s->type.t & VT_BTYPE) == VT_SHORT || \
(s->type.t & VT_BTYPE) == VT_INT || \
(s->type.t & VT_BTYPE) == VT_LLONG)))
static void tcc_get_debug_info(TCCState *s1, Sym *s, CString *result)
{
int type;
@ -1320,9 +1329,10 @@ static void tcc_get_debug_info(TCCState *s1, Sym *s, CString *result)
int pos, size, align;
t = t->next;
if (STRUCT_NODEBUG(t))
continue;
cstr_printf (&str, "%s:",
(t->v & ~SYM_FIELD) >= SYM_FIRST_ANOM
? "" : get_tok_str(t->v & ~SYM_FIELD, NULL));
get_tok_str(t->v & ~SYM_FIELD, NULL));
tcc_get_debug_info (s1, t, &str);
if (t->type.t & VT_BITFIELD) {
pos = t->c * 8 + BIT_POS(t->type.t);
@ -1430,6 +1440,8 @@ static int tcc_get_dwarf_info(TCCState *s1, Sym *s)
i = 0;
while (e->next) {
e = e->next;
if (STRUCT_NODEBUG(e))
continue;
i++;
}
pos_type = (int *) tcc_malloc(i * sizeof(int));
@ -1453,12 +1465,13 @@ static int tcc_get_dwarf_info(TCCState *s1, Sym *s)
i = 0;
while (e->next) {
e = e->next;
if (STRUCT_NODEBUG(e))
continue;
dwarf_data1(dwarf_info_section,
e->type.t & VT_BITFIELD ? DWARF_ABBREV_MEMBER_BF
: DWARF_ABBREV_MEMBER);
dwarf_strp(dwarf_info_section,
(e->v & ~SYM_FIELD) >= SYM_FIRST_ANOM
? "" : get_tok_str(e->v & ~SYM_FIELD, NULL));
get_tok_str(e->v & ~SYM_FIELD, NULL));
dwarf_uleb128(dwarf_info_section, dwarf_line.cur_file);
dwarf_uleb128(dwarf_info_section, file->line_num);
pos_type[i++] = dwarf_info_section->data_offset;
@ -1482,6 +1495,8 @@ static int tcc_get_dwarf_info(TCCState *s1, Sym *s)
i = 0;
while (e->next) {
e = e->next;
if (STRUCT_NODEBUG(e))
continue;
type = tcc_get_dwarf_info(s1, e);
tcc_debug_check_anon(s1, e, pos_type[i]);
write32le(dwarf_info_section->data + pos_type[i++],

View File

@ -1067,6 +1067,7 @@ static void merge_symattr(struct SymAttr *sa, struct SymAttr *sa1)
sa->aligned = sa1->aligned;
sa->packed |= sa1->packed;
sa->weak |= sa1->weak;
sa->nodebug |= sa1->nodebug;
if (sa1->visibility != STV_DEFAULT) {
int vis = sa->visibility;
if (vis == STV_DEFAULT
@ -3823,6 +3824,10 @@ redo:
case TOK_WEAK2:
ad->a.weak = 1;
break;
case TOK_NODEBUG1:
case TOK_NODEBUG2:
ad->a.nodebug = 1;
break;
case TOK_UNUSED1:
case TOK_UNUSED2:
/* currently, no need to handle it because tcc does not

View File

@ -124,6 +124,8 @@
DEF(TOK_ALIAS2, "__alias__")
DEF(TOK_UNUSED1, "unused")
DEF(TOK_UNUSED2, "__unused__")
DEF(TOK_NODEBUG1, "nodebug")
DEF(TOK_NODEBUG2, "__nodebug__")
DEF(TOK_CDECL1, "cdecl")
DEF(TOK_CDECL2, "__cdecl")
DEF(TOK_CDECL3, "__cdecl__")