-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Type resolution from DWARF #2034
Conversation
7f29dbf
to
088e696
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the rationale for converting DWARF to C and then parsing C to bpftrace-internal representation? I would have thought that going from DWARF -> bpftrace-internal representation ought to be faster (at runtime) and easier.
FWIW, the reason we go BTF -> C -> bpftrace-internal representation is b/c libbpf already had the C dumping API and it was easier to code from bpftrace's side.
The reason is that the final type resolution is done by Clang parser. So even if we resolved part of the types from DWARF, we still need to dump them to C b/c their defs may be necessary for the parser (e.g. if the user used some of them in his custom types). |
Hmm, is this a likely scenario? What types could the user be defining that are not already available in DWARF? I'm not necessarily against going to C then to clang parser, but I think it should be a conscious tradeoff. If it's significantly less complex to skip C, then we ought to consider that. If it's similar complexity, then going to C has theoretical advantages. What do you think? |
I agree that this seems to be a very unlikely situation (in fact, I haven't come with a reasonable example so far). What I'd suggest is:
Does it make sense? |
Sure, that sounds fine to me |
f0f6ce1
to
f3e40b9
Compare
After some time, coming with version 2. The main change is that parsing of structure types from DWARF is now done in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not very familiar w/ DWARF but nothing stands out to me. Great work!
f3e40b9
to
604a589
Compare
Several refactorings and minor changes done to DwarfParser: - refactor iterations over DWARF DIE children nodes - pass a pointer to BPFtrace to DwarfParser - will be needed for struct fields filling - factor out and introduce some useful DWARF parsing methods
Support for parsing array type information from DWARF and creating appropriate SizedType.
Struct types (stored in StructManager) are filled directly from FieldAnalyser. We also allow ClangParser to rewrite the type parsed from DWARF (this is controlled by the Struct::allow_override field) For now, bitfields are not supported and let on ClangParser to resolve.
Introduces both unit and runtime tests.
604a589
to
3c1e069
Compare
When tracing userspace programs, this extension automatically resolves types from DWARF (if it is available). This has mostly 2 advantages:
Version 2:
Parsing of structure types from DWARF is done in
FieldAnalyser
, which directly fills structs inStructManager
.ClangParser
may override these types if user defined some custom types or included some headers.Version 1 (abandoned):
Since we're relying on Clang parser to do the actual type resolution, we need to dump types from DWARF into compilable C format. Even though there probably exist libraries that can do this (e.g. libdwarves), I decided to implement this by hand, to have more control over the supported types and to avoid yet another dependency.
We now have two sources of type information - BTF and DWARF. To avoid potential collisions, for now we use DWARF for userspace tracing and BTF for kernel tracing.
I also believe that this resolves #1742.
Checklist
man/adoc/bpftrace.adoc
and if needed indocs/reference_guide.md
CHANGELOG.md