From 31664d60ad410a68a9a5a4dde42b725fd206187a Mon Sep 17 00:00:00 2001 From: Arnaldo Carvalho de Melo Date: Mon, 3 Dec 2018 12:51:30 -0300 Subject: [PATCH] pahole: Show tagged enums as well when no class is specified The pahole tool initial goal was to show struct holes, which can't happen with a first level of a tagged union (a union with a name), so those only were displayed when part of a higher level struct. Show the first level tagged enums as well, as this is useful when just wanting to see its members. E.g.: $ pahole ../build/v4.20-rc5/net/core/sock.o | grep ^union union fpregs_state { union irq_stack_union { union sigval { union __sifields { union thread_union { union kernfs_node_id { union flowi_uli { union ethtool_flow_union { union key_payload { union bpf_attr { union tcp_md5_addr { $ Suggested-by: Matthew Wilcox Signed-off-by: Arnaldo Carvalho de Melo --- dwarves.h | 14 ++++++++++++++ pahole.c | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/dwarves.h b/dwarves.h index 904e8b5..29dcbc1 100644 --- a/dwarves.h +++ b/dwarves.h @@ -267,6 +267,20 @@ static inline __pure bool cu__is_c_plus_plus(const struct cu *cu) continue; \ else +/** + * cu__for_each_struct_or_union - iterate thru all the struct and union tags + * @cu: struct cu instance to iterate + * @pos: struct class iterator + * @id: uint16_t tag id + */ +#define cu__for_each_struct_or_union(cu, id, pos) \ + for (id = 1; id < cu->types_table.nr_entries; ++id) \ + if (!(pos = tag__class(cu->types_table.entries[id])) || \ + !(tag__is_struct(class__tag(pos)) || \ + tag__is_union(class__tag(pos)))) \ + continue; \ + else + /** * cu__for_each_function - iterate thru all the function tags * @cu: struct cu instance to iterate diff --git a/pahole.c b/pahole.c index 55803c3..3040eff 100644 --- a/pahole.c +++ b/pahole.c @@ -279,7 +279,7 @@ static void print_classes(struct cu *cu) uint16_t id; struct class *pos; - cu__for_each_struct(cu, id, pos) { + cu__for_each_struct_or_union(cu, id, pos) { bool existing_entry; struct structure *str;