linux/tools/bpf/bpftool
Yonghong Song 528bff0cdb tools: bpftool: fix a bitfield pretty print issue
Commit b12d6ec097 ("bpf: btf: add btf print functionality")
added btf pretty print functionality to bpftool.
There is a problem though in printing a bitfield whose type
has modifiers.

For example, for a type like
  typedef int ___int;
  struct tmp_t {
          int a:3;
          ___int b:3;
  };
Suppose we have a map
  struct bpf_map_def SEC("maps") tmpmap = {
          .type = BPF_MAP_TYPE_HASH,
          .key_size = sizeof(__u32),
          .value_size = sizeof(struct tmp_t),
          .max_entries = 1,
  };
and the hash table is populated with one element with
key 0 and value (.a = 1 and .b = 2).

In BTF, the struct member "b" will have a type "typedef" which
points to an int type. The current implementation does not
pass the bit offset during transition from typedef to int type,
hence incorrectly print the value as
  $ bpftool m d id 79
  [{
          "key": 0,
          "value": {
              "a": 0x1,
              "b": 0x1
          }
      }
  ]

This patch fixed the issue by carrying bit_offset along the type
chain during bit_field print. The correct result can be printed as
  $ bpftool m d id 76
  [{
          "key": 0,
          "value": {
              "a": 0x1,
              "b": 0x2
          }
      }
  ]

The kernel pretty print is implemented correctly and does not
have this issue.

Fixes: b12d6ec097 ("bpf: btf: add btf print functionality")
Signed-off-by: Yonghong Song <yhs@fb.com>
Acked-by: Song Liu <songliubraving@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2018-11-28 16:40:02 -08:00
..
bash-completion tools: bpftool: fix completion for "bpftool map update" 2018-10-21 20:45:14 +02:00
Documentation tools: bpftool: update references to other man pages in documentation 2018-11-09 08:20:52 +01:00
.gitignore tools/bpftool: ignore build products 2018-07-26 02:50:26 +02:00
btf_dumper.c tools: bpftool: fix a bitfield pretty print issue 2018-11-28 16:40:02 -08:00
cfg.c tools: bpftool: generate .dot graph from CFG information 2018-03-01 18:29:49 -08:00
cfg.h tools: bpftool: detect sub-programs from the eBPF sequence 2018-03-01 18:29:48 -08:00
cgroup.c bpftool: introduce cgroup tree command 2018-07-07 01:38:38 +02:00
common.c tools: bpftool: pass an argument to silence open_obj_pinned() 2018-11-09 08:20:52 +01:00
jit_disasm.c tools: bpftool: use 4 context mode for the NFP disasm 2018-10-18 22:16:02 +02:00
json_writer.c tools: bpftool: add JSON output for bpftool prog dump xlated * command 2017-10-24 01:25:08 +01:00
json_writer.h tools: bpftool: add JSON output for bpftool prog dump xlated * command 2017-10-24 01:25:08 +01:00
main.c tools: bpftool: print nb of cmds to stdout (not stderr) for batch mode 2018-10-21 20:45:14 +02:00
main.h tools: bpftool: pass an argument to silence open_obj_pinned() 2018-11-09 08:20:52 +01:00
Makefile bpftool: Allow add linker flags via EXTRA_LDFLAGS variable 2018-10-11 10:24:53 +02:00
map_perf_ring.c bpf, libbpf: simplify and cleanup perf ring buffer walk 2018-10-20 23:13:32 -07:00
map.c tools: bpftool: add map create command 2018-10-15 16:39:21 -07:00
net.c libbpf: Consistent prefixes for interfaces in nlattr.h. 2018-10-04 16:04:16 +02:00
netlink_dumper.c libbpf: Consistent prefixes for interfaces in nlattr.h. 2018-10-04 16:04:16 +02:00
netlink_dumper.h bpftool: Fix bpftool net output 2018-09-27 21:07:44 +02:00
perf.c tools/bpftool: fix a bug in bpftool perf 2018-06-13 02:03:17 +02:00
prog.c tools: bpftool: fix potential NULL pointer dereference in do_load 2018-11-22 00:45:51 +01:00
xlated_dumper.c tools: bpf: make use of reallocarray 2018-07-11 22:13:34 +02:00
xlated_dumper.h tools: bpftool: add delimiters to multi-function JITed dumps 2018-05-24 09:20:50 +02:00