From 4b7f8c04d009942b6a7d61bf0990035eb18f70e2 Mon Sep 17 00:00:00 2001 From: Arnaldo Carvalho de Melo Date: Sat, 20 Feb 2021 08:41:11 -0300 Subject: [PATCH] fprintf: Honour conf_fprintf.hex when printing enumerations Now this works: $ pahole --hex perf_event_type enum perf_event_type { PERF_RECORD_MMAP = 0x1, PERF_RECORD_LOST = 0x2, PERF_RECORD_COMM = 0x3, PERF_RECORD_EXIT = 0x4, PERF_RECORD_THROTTLE = 0x5, PERF_RECORD_UNTHROTTLE = 0x6, PERF_RECORD_FORK = 0x7, PERF_RECORD_READ = 0x8, PERF_RECORD_SAMPLE = 0x9, PERF_RECORD_MMAP2 = 0xa, PERF_RECORD_AUX = 0xb, PERF_RECORD_ITRACE_START = 0xc, PERF_RECORD_LOST_SAMPLES = 0xd, PERF_RECORD_SWITCH = 0xe, PERF_RECORD_SWITCH_CPU_WIDE = 0xf, PERF_RECORD_NAMESPACES = 0x10, PERF_RECORD_KSYMBOL = 0x11, PERF_RECORD_BPF_EVENT = 0x12, PERF_RECORD_CGROUP = 0x13, PERF_RECORD_TEXT_POKE = 0x14, PERF_RECORD_MAX = 0x15, }; $ Signed-off-by: Arnaldo Carvalho de Melo --- dwarves_fprintf.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/dwarves_fprintf.c b/dwarves_fprintf.c index c96a6fb..3099e96 100644 --- a/dwarves_fprintf.c +++ b/dwarves_fprintf.c @@ -401,9 +401,12 @@ size_t enumeration__fprintf(const struct tag *tag, const struct cu *cu, if (indent >= (int)sizeof(tabs)) indent = sizeof(tabs) - 1; - type__for_each_enumerator(type, pos) - printed += fprintf(fp, "%.*s\t%-*s = %u,\n", indent, tabs, - max_entry_name_len, enumerator__name(pos, cu), pos->value); + type__for_each_enumerator(type, pos) { + printed += fprintf(fp, "%.*s\t%-*s = ", indent, tabs, + max_entry_name_len, enumerator__name(pos, cu)); + printed += fprintf(fp, conf->hex_fmt ? "%#x" : "%u", pos->value); + printed += fprintf(fp, ",\n"); + } printed += fprintf(fp, "%.*s}", indent, tabs);