Skip to content

API to access btf_dump emit queue and print single type

Eduard Zingerman bpf 2 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest4 patches 10 repliesIn review
  2. v13 patches 2 repliesSuperseded

Changes in v2 from the cover letter

- fix for build issues reported by CI: do not mark typedefs as ORDERED

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/4libbpf: put forward declarations to btf_dump->emit_queuetools/lib/bpf/btf_dump.c+161 -1904 replies
2/4libbpf: API to access btf_dump emit queue and print single typetools/lib/bpf/btf.h tools/lib/bpf/btf_dump.c tools/lib/bpf/libbpf.map+71 -276 replies
3/4selftests/bpf: tests for btf_dump emit queue APItools/testing/selftests/bpf/prog_tests/btf_dump.c+86 -00 replies
4/4selftests/bpf: corner case for typedefs handling in btf_dumptools/testing/selftests/bpf/progs/btf_dump_test_case_ordering.c+10 -00 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v2 yet.

Read the v2 thread

Cover letter [PATCH bpf-next v2 0/4] API to access btf_dump emit queue and print single type

This is a follow-up to the following discussion:
https://lore.kernel.org/bpf/[email protected]/

As suggested by Andrii, this series adds several API functions to allow more flexibility with btf dump:
- a function to add a type and all its dependencies to the emit queue;
- functions to provide access to the emit queue owned by btf_dump object;
- a function to print a given type (skipping any dependencies).

This should allow filtering printed types and also adding attributes / pre-processor statements to specific types.

There are several ways to add such API:
1. The simplest in terms of code changes is to refactor btf_dump_emit_type() to push types and forward declarations to the emit queue, instead of printing those directly;
2. More intrusive: refactor btf_dump_emit_type() and btf_dump_order_type() to avoid doing topological sorting twice and put forward declarations to the emit queue at once.

This series opts for (2) as it seems to simplify library code a bit. For the sake of discussion, source code for option (1) as available at:
https://github.com/eddyz87/bpf/tree/libbpf-sort-for-dump-api-simple

Also, this series opts for the following new API function:

  int btf_dump__dump_one_type(struct btf_dump *d, __u32 id, bool fwd);

As adding _opts variant of btf_dump__dump_type seems a bit clumsy:

  struct btf_dump_opts {
	size_t sz;
	bool fwd;
	bool skip_dependencies;
	bool skip_last_semi;

};

int btf_dump__dump_type_opts(struct btf_dump *d, __u32 id,

			       struct btf_dump_opts *opts);

but maybe community would prefer the later variant.

Changes v1->v2:
- fix for build issues reported by CI: do not mark typedefs as ORDERED

v1: https://lore.kernel.org/bpf/[email protected]/

Eduard Zingerman (4):
libbpf: put forward declarations to btf_dump->emit_queue
libbpf: API to access btf_dump emit queue and print single type selftests/bpf: tests for btf_dump emit queue API selftests/bpf: corner case for typedefs handling in btf_dump

 tools/lib/bpf/btf.h                           |  33 ++
 tools/lib/bpf/btf_dump.c                      | 386 +++++++++---------
 tools/lib/bpf/libbpf.map                      |   4 +
 .../selftests/bpf/prog_tests/btf_dump.c       |  86 ++++
 .../bpf/progs/btf_dump_test_case_ordering.c   |  10 +
 5 files changed, 315 insertions(+), 204 deletions(-)
Signature · 1 line
2.34.1