pahole: Wait to find a DWARF CU with both the class and the type_enum
commit6e665da56c78d436e0a13a0772f70ccb9bdd3f2c
authorArnaldo Carvalho de Melo <acme@redhat.com>
Tue, 20 Feb 2024 13:57:28 +0000 (20 10:57 -0300)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Tue, 20 Feb 2024 13:57:28 +0000 (20 10:57 -0300)
treec97c25ab5440fd9572eff723493c7aabb0a4f738
parentbe638365781ed0c843249c5bcebe90a01e74b2fe
pahole: Wait to find a DWARF CU with both the class and the type_enum

Otherwise this doesn't work:

  $ pahole -F dwarf -V ~/bin/perf --header=perf_file_header --seek_bytes '$header.data.offset' --size_bytes='$header.data.size' -C 'perf_event_header(sizeof,type,type_enum=perf_event_type,filter=type==PERF_RECORD_MMAP2)' --prettify perf.data --count 1
  pahole: sizeof_operator for 'perf_event_header' is 'size'
  pahole: type member for 'perf_event_header' is 'type'
  pahole: type enum for 'perf_event_header' is 'perf_event_type'
  pahole: filter for 'perf_event_header' is 'type==PERF_RECORD_MMAP2'
  Symbolic right operand in 'type==PERF_RECORD_MMAP2' but no way to resolve it to a number (type_enum empty or hasn't found any so far) at CU 'builtin-annotate.c')
  pahole: invalid filter 'type==PERF_RECORD_MMAP2' for 'perf_event_header'
  pahole: type 'perf_event_header' not found or arguments not validated
  $

Because in this case 'struct perf_event_header' and 'struct
perf_event_type' aren't both present in builtin-annotate.o, so wait for
another .o with both.

With that in place:

  $ pahole -F dwarf -V ~/bin/perf --header=perf_file_header --seek_bytes '$header.data.offset' --size_bytes='$header.data.size' -C 'perf_event_header(sizeof,type,type_enum=perf_event_type,filter=type==PERF_RECORD_MMAP2)' --prettify perf.data --count 1
  pahole: sizeof_operator for 'perf_event_header' is 'size'
  pahole: type member for 'perf_event_header' is 'type'
  pahole: type enum for 'perf_event_header' is 'perf_event_type'
  pahole: filter for 'perf_event_header' is 'type==PERF_RECORD_MMAP2'
  pahole: seek bytes evaluated from --seek_bytes=$header.data.offset is 0x3f0
  pahole: size bytes evaluated from --size_bytes=$header.data.size is 0xd10
  // type=perf_event_header, offset=0xc20, sizeof=8, real_sizeof=112
  {
   .header = {
   .type = PERF_RECORD_MMAP2,
   .misc = 2,
   .size = 112,
   },
   .pid = 1533617,
   .tid = 1533617,
   .start = 94667542700032,
   .len = 90112,
   .pgoff = 16384,{
   .maj = 0,
   .min = 33,
   .ino = 35914923,
   .ino_generation = 26870,
   },{
   .build_id_size = 0,
   .__reserved_1 = 0,
   .__reserved_2 = 0,
   .build_id = { 33, 0, 0, 0, -85, 4, 36, 2, 0, 0, 0, 0, -10, 104, 0, 0, 0, 0, 0, 0 },
   },
   .prot = 5,
   .flags = 2,
   .filename = "/usr/bin/ls",
  },
  $

And continues to work with BTF:

  ⬢[acme@toolbox pahole]$ pahole -F btf -V ~/bin/perf --header=perf_file_header --seek_bytes '$header.data.offset' --size_bytes='$header.data.size' -C 'perf_event_header(sizeof,type,type_enum=perf_event_type,filter=type==PERF_RECORD_MMAP2)' --prettify perf.data --count 1
  pahole: sizeof_operator for 'perf_event_header' is 'size'
  pahole: type member for 'perf_event_header' is 'type'
  pahole: type enum for 'perf_event_header' is 'perf_event_type'
  pahole: filter for 'perf_event_header' is 'type==PERF_RECORD_MMAP2'
  pahole: seek bytes evaluated from --seek_bytes=$header.data.offset is 0x3f0
  pahole: size bytes evaluated from --size_bytes=$header.data.size is 0xd10
  // type=perf_event_header, offset=0xc20, sizeof=8, real_sizeof=112
  {
   .header = {
   .type = PERF_RECORD_MMAP2,
   .misc = 2,
   .size = 112,
   },
   .pid = 1533617,
   .tid = 1533617,
   .start = 94667542700032,
   .len = 90112,
   .pgoff = 16384,{
   .maj = 0,
   .min = 33,
   .ino = 35914923,
   .ino_generation = 26870,
   },{
   .build_id_size = 0,
   .__reserved_1 = 0,
   .__reserved_2 = 0,
   .build_id = { 33, 0, 0, 0, -85, 4, 36, 2, 0, 0, 0, 0, -10, 104, 0, 0, 0, 0, 0, 0 },
   },
   .prot = 5,
   .flags = 2,
   .filename = "/usr/bin/ls",
  },
  ⬢[acme@toolbox pahole]$

Now to find some data structures in vmlinux to use in pretty printing
something in vmlinux to try with both BTF and DWARF so that we test this
functionality in 'btfdiff' and keep testing this codebase.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
pahole.c