[LIB]: Show the sum of paddings in structs within a struct
Commiter note: Idea and initial patch by Davi Arnaut, I fixed it to do the right thing, to understand why this is useful, nothing better than an example: /* <bd92a0> /home/acme/git/linux-2.6/include/net/xfrm.h:242 */ struct xfrm_tmpl { struct xfrm_id id; /* 0 24 */ xfrm_address_t saddr; /* 24 16 */ short unsigned int encap_family; /* 40 2 */ /* XXX 2 bytes hole, try to pack */ __u32 reqid; /* 44 4 */ __u8 mode; /* 48 1 */ __u8 share; /* 49 1 */ __u8 optional; /* 50 1 */ /* XXX 1 byte hole, try to pack */ __u32 aalgos; /* 52 4 */ __u32 ealgos; /* 56 4 */ __u32 calgos; /* 60 4 */ /* --- cacheline 1 boundary (64 bytes) --- */ }; /* size: 64, cachelines: 1 */ /* sum members: 61, holes: 2, sum holes: 3 */ /* sum padding: 3 */ /* definitions: 22 */ "sum padding" here means there is some member that is a struct and this struct has paddings: struct xfrm_id: /* <bd78b6> /home/acme/git/linux-2.6/include/linux/xfrm.h:24 */ struct xfrm_id { xfrm_address_t daddr; /* 0 16 */ __be32 spi; /* 16 4 */ __u8 proto; /* 20 1 */ }; /* size: 24, cachelines: 1 */ /* padding: 3 */ /* last cacheline: 24 bytes */ /* definitions: 22 */ Signed-off-by: Davi Arnaut <davi@haxent.com.br> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
parent
c9bd654d3b
commit
a7b22b8f2c
11
dwarves.c
11
dwarves.c
|
@ -1808,6 +1808,7 @@ static size_t class__snprintf(const struct class *self, const struct cu *cu,
|
|||
uint8_t newline = 0;
|
||||
uint32_t sum = 0;
|
||||
uint32_t sum_holes = 0;
|
||||
uint32_t sum_padding = 0;
|
||||
uint32_t sum_bit_holes = 0;
|
||||
uint32_t last_cacheline = 0;
|
||||
int last_offset = -1;
|
||||
|
@ -1824,6 +1825,7 @@ static size_t class__snprintf(const struct class *self, const struct cu *cu,
|
|||
|
||||
list_for_each_entry(pos, &tself->members, tag.node) {
|
||||
struct tag *type;
|
||||
const struct class *class;
|
||||
const ssize_t cc_last_size = pos->offset - last_offset;
|
||||
|
||||
n = class__snprintf_cacheline_boundary(bf, l, last_cacheline,
|
||||
|
@ -1885,6 +1887,10 @@ static size_t class__snprintf(const struct class *self, const struct cu *cu,
|
|||
bf += n; l -= n;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (type->tag == DW_TAG_structure_type)
|
||||
sum_padding += tag__class(type)->padding;
|
||||
|
||||
size = tag__size(type, cu);
|
||||
n = snprintf(bf, l, "%.*s", indent + 1, tabs);
|
||||
bf += n; l -= n;
|
||||
|
@ -1968,6 +1974,11 @@ static size_t class__snprintf(const struct class *self, const struct cu *cu,
|
|||
self->padding);
|
||||
bf += n; l -= n;
|
||||
}
|
||||
if (sum_padding > 0) {
|
||||
n = snprintf(bf, l, "%.*s /* sum padding: %u */\n", indent, tabs,
|
||||
sum_padding);
|
||||
bf += n; l -= n;
|
||||
}
|
||||
if (self->bit_padding > 0) {
|
||||
n = snprintf(bf, l, "%.*s /* bit_padding: %u bits */\n",
|
||||
indent, tabs, self->bit_padding);
|
||||
|
|
Loading…
Reference in New Issue