Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is an early (ugly) draft of a type finder based on BTF! I'm hoping to get some advice on direction if possible, and once we have an idea of where to take this, I can clean up the branch into logical changes and we can move it out of the draft state.
Currently, this supports the basics:
It is missing:
The way I've been able to exercise the functionality is by adding
prog.add_btf_info(address, bytes)
, which will read the data from the program memory and interpret it as BTF, registering the type finder. So right now, I'm able to load a normal vmcore with debuginfo, get the addresses of__start_BTF
and__stop_BTF
symbols, and then run drgn again without the debuginfo, callingprog.add_btf_info(__start_BTF, __stop_BTF - __start_BTF)
.I've tested it on some large/interesting structs within the kernel (
task_struct
,dentry
,dentry_operations
,inode
), by runningprint(prog.type("..."))
. They all look correct to me.I have a few specific questions (corresponding with TODOs or other outlined issues in comments):
may not be fully up-to-date. So I grabbed a copy from linux 5.17. The license
identifier on <linux/btf.h> is GPLv2, is this an issue for inclusion?
that in drgn?
there any good way to create such a type without relying on the language's
name? This is for inclusion in the "compatible_type" field of the enum.
However, the biggest question I have is if you can recommend a direction for
me to go next? For the most part, this has been an "automatic" process of
reading and implementing the BTF spec, while also learning the drgn type system.
Now that a large chunk of this is complete, I'm unsure how to integrate this
module with the rest of drgn. Should the BTF registry have a pointer in
prog.dbinfo
?Using the BTF integration automatically seems to be a ways off. After all, we
still need kallsyms support, and at least a few new symbols in the vmcoreinfo
note to help us find the kallsyms in the vmcore. Without both pieces, the BTF
code is pretty unhelpful. To find the BTF information, you need a symbol table,
and if you have that you probably have DWARF info too. Plus, even if you find
the BTF information, you'll still want the symbol table so you can find data
structures to analyze with the BTF types. So would the best way forward right
now be to expose this as some sort of Python interface (cleaned up from what I
have here)?