From cf459ca16fb22ff0542442512a3b5c7b7899d7b4 Mon Sep 17 00:00:00 2001 From: Arnaldo Carvalho de Melo Date: Tue, 16 Apr 2019 14:26:11 -0300 Subject: [PATCH] fprintf: Pretty print struct members that are pointers to nameless structs I.e. to structs defined inside other structs, without a name: Before: $ pahole -C parsed_partitions /home/acme/git/build/v5.1-rc4+/block/partitions/check.o struct parsed_partitions { struct block_device * bdev; /* 0 8 */ char name[32]; /* 8 32 */ struct * parts; /* 40 8 */ int next; /* 48 4 */ int limit; /* 52 4 */ bool access_beyond_eod; /* 56 1 */ /* XXX 7 bytes hole, try to pack */ /* --- cacheline 1 boundary (64 bytes) --- */ char * pp_buf; /* 64 8 */ /* size: 72, cachelines: 2, members: 7 */ /* sum members: 65, holes: 1, sum holes: 7 */ /* last cacheline: 8 bytes */ }; $ After: $ pahole -C parsed_partitions /home/acme/git/build/v5.1-rc4+/block/partitions/check.o struct parsed_partitions { struct block_device * bdev; /* 0 8 */ char name[32]; /* 8 32 */ struct { sector_t from; /* 40 8 */ sector_t size; /* 48 8 */ int flags; /* 56 4 */ bool has_info; /* 60 1 */ struct partition_meta_info info; /* 61 101 */ } * parts; /* 40 8 */ int next; /* 48 4 */ int limit; /* 52 4 */ bool access_beyond_eod; /* 56 1 */ /* XXX 7 bytes hole, try to pack */ /* --- cacheline 1 boundary (64 bytes) --- */ char * pp_buf; /* 64 8 */ /* size: 72, cachelines: 2, members: 7 */ /* sum members: 65, holes: 1, sum holes: 7 */ /* last cacheline: 8 bytes */ }; $ Still need to align that offsets, leave this for later. Signed-off-by: Arnaldo Carvalho de Melo --- dwarves_fprintf.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/dwarves_fprintf.c b/dwarves_fprintf.c index 492bd66..98bb476 100644 --- a/dwarves_fprintf.c +++ b/dwarves_fprintf.c @@ -595,6 +595,7 @@ static size_t type__fprintf(struct tag *type, const struct cu *cu, { char tbf[128]; char namebf[256]; + char namebfptr[258]; struct type *ctype; struct conf_fprintf tconf; size_t printed = 0; @@ -673,6 +674,7 @@ static size_t type__fprintf(struct tag *type, const struct cu *cu, if (tag__is_struct(type) || tag__is_union(type) || tag__is_enumeration(type)) { +inner_struct: tconf.type_spacing -= 8; tconf.prefix = NULL; tconf.suffix = name; @@ -698,6 +700,13 @@ next_type: &tconf, fp); break; } + if (tag__is_struct(ptype) || tag__is_union(ptype) || + tag__is_enumeration(ptype)) { + snprintf(namebfptr, sizeof(namebfptr), "* %s", name); + name = namebfptr; + type = ptype; + goto inner_struct; + } } /* Fall Thru */ default: