Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

btf: Allow referencing an enum value to pull in enum definition #1274

Merged
merged 2 commits into from Apr 24, 2020

Conversation

danobi
Copy link
Member

@danobi danobi commented Apr 16, 2020

It's useful to be able to reference an enum value to have bpftrace pull
in the enum definition from BTF. This is especially useful for anonymous
enums which cannot be correctly referenced.

@danobi
Copy link
Member Author

danobi commented Apr 16, 2020

This PR depends on #1268 and #1269. Will rebase away all but the last commit when the previous ones are in.

@danobi danobi added the do-not-merge Changes are not ready to be merged into master yet label Apr 16, 2020
danobi added a commit to danobi/linux that referenced this pull request Apr 17, 2020
BPF Type Format (BTF) is especially powerful for tracing tools like
bcc and bpftrace. It allows tools to know about kernel data structures
and layouts without having to parse headers. Headers are problematic
because (1) they do not always come installed on production / user
systems, (2) headers may not always describe the correct struct layout
due to compile time flags, and (3) can be tricky to parse [0][1].

As BTF becomes enabled on more systems [2], it becomes more desirable to
have BTF contain everything a tracing tool needs. BTF overhead is quite
minimal (~1.5MB) [3] so using BTF in lieu of parsing headers is very
attractive.

While BTF already contains almost everything tracing tools need (eg
structs, enums, unions, function signatures, etc.), it is missing a lot
of flags. The reason is that most flags are defined as preprocessor
macros and are thus invisible to the compiler when it generates debug
info.

However, there is a solution: we can convert macro flags into enums.
This would be quite a complicated and long running task so I'm hoping
this patch can start a discussion. I'm sure I haven't fully considered
the implications so hopefully we can discuss it.

This patch, when applied to a kernel with BTF, allows bpftrace to "see"
the flags [4]:

    # bpftrace --btf -e 'BEGIN { printf("%d\n", S_IRWXG); }'
    Attaching 1 probe...
    56
    ^C

[0]: iovisor/bcc#2133
[1]: iovisor/bcc#2547
[2]: https://www.spinics.net/linux/fedora/fedora-kernel/msg07746.html
[3]: https://facebookmicrosites.github.io/bpf/blog/2018/11/14/btf-enhancement.html
[4]: bpftrace/bpftrace#1274
It's useful to be able to reference an enum value to have bpftrace pull
in the enum definition from BTF. This is especially useful for anonymous
enums which cannot be correctly referenced.
@danobi danobi removed the do-not-merge Changes are not ready to be merged into master yet label Apr 24, 2020
@danobi danobi requested a review from olsajiri April 24, 2020 02:29
@danobi danobi marked this pull request as ready for review April 24, 2020 02:29
@olsajiri
Copy link
Contributor

nice result of that refactoring you did before, I don't see any problem

@danobi danobi merged commit bd090f8 into bpftrace:master Apr 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants