diff options
author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2021-10-27 15:42:04 -0300 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2021-10-27 15:44:10 -0300 |
commit | 43e8216c25ee767f49c19cecd9f45a3070357215 (patch) | |
tree | aff61c44382d2a400d30db85af8c33b66c03a680 | |
parent | c52f6421f21146ad4eb8d1add796eda3ddda4ccf (diff) | |
download | pahole-43e8216c25ee767f49c19cecd9f45a3070357215.tar.gz |
fprintf: Fix __attribute__((__aligned__(N)) handling for struct members
We just need to record if we printed it for a member and if so, deduce
that from the number of spaces left to print before the end of line
comment (offset, size).
Fixes: a59459bb80e7d948 ("fprintf: Account inline type __aligned__ member types for spacing")
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r-- | dwarves_fprintf.c | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/dwarves_fprintf.c b/dwarves_fprintf.c index 1c1d9496..38505a07 100644 --- a/dwarves_fprintf.c +++ b/dwarves_fprintf.c @@ -837,6 +837,7 @@ static size_t class_member__fprintf(struct class_member *member, bool union_memb struct conf_fprintf *conf, FILE *fp) { const int size = member->byte_size; + int member_alignment_printed = 0; struct conf_fprintf sconf = *conf; uint32_t offset = member->byte_offset; size_t printed = 0, printed_cacheline = 0; @@ -886,8 +887,10 @@ static size_t class_member__fprintf(struct class_member *member, bool union_memb printed += fprintf(fp, ":%u", member->bitfield_size); } - if (!sconf.suppress_aligned_attribute && member->alignment != 0) - printed += fprintf(fp, " __attribute__((__aligned__(%u)))", member->alignment); + if (!sconf.suppress_aligned_attribute && member->alignment != 0) { + member_alignment_printed = fprintf(fp, " __attribute__((__aligned__(%u)))", member->alignment); + printed += member_alignment_printed; + } fputc(';', fp); ++printed; @@ -898,7 +901,7 @@ static size_t class_member__fprintf(struct class_member *member, bool union_memb type__name(tag__type(type)) == NULL) { if (!sconf.suppress_offset_comment) { /* Check if this is a anonymous union */ - int slen = cm_name ? (int)strlen(cm_name) : -1; + int slen = member_alignment_printed + (cm_name ? (int)strlen(cm_name) : -1); int size_spacing = 5; if (tag__is_struct(type) && tag__class(type)->is_packed && !conf->suppress_packed) { @@ -906,12 +909,6 @@ static size_t class_member__fprintf(struct class_member *member, bool union_memb slen += packed_len; } - if (tag__type(type)->alignment != 0 && !conf->suppress_aligned_attribute) { - char bftmp[64]; - int aligned_len = snprintf(bftmp, sizeof(bftmp), " __attribute__((__aligned__(%u)))", tag__type(type)->alignment); - slen += aligned_len; - } - printed += fprintf(fp, sconf.hex_fmt ? "%*s/* %#5x" : "%*s/* %5u", |