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 <acme@redhat.com>
This commit is contained in:
Arnaldo Carvalho de Melo 2021-02-20 08:41:11 -03:00
parent f2889ff163
commit 4b7f8c04d0
1 changed files with 6 additions and 3 deletions

View File

@ -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);