Proposal to add BTF metadata to asm.Instruction #564
Replies: 3 comments 6 replies
-
@lmb has code that implements this to some degree, but not sure how close it is to landing. A few observations here. This would all be public API (read & write), so exposing Then, when marshaling insns, all metadata would be serialized from scratch based on what's in the type graph and extinfos. All encountered strings like type names, file names, func/lineinfos would be interned and emitted to the BTF blob as a new string table.
Metadata would also contain |
Beta Was this translation helpful? Give feedback.
-
@dylandreimerink you've hit the nail on the head, per instruction metadata would be great. As Timo says, I've been playing around with this, the current state of affairs is at lmb@6af8ec0. With that infrastructure in place I would fix #515 like so: lmb@ef4a4a6. I'm making the following assumptions:
Do you think these assumptions are reasonable, or would your use case violate 1. maybe?
Can you explain this a bit more? I don't follow, sorry.
That should be the end goal, but for a start it would be better if we allowed just retrieving metadata in a read-only way. From scratch serialisation of BTF is a lot of work, as discussed. |
Beta Was this translation helpful? Give feedback.
-
So, in summary. There are 2 goals:
We already have some metadata in the form of I see three approaches:
No matter what we do, That leaves me with 3 questions:
|
Beta Was this translation helpful? Give feedback.
-
Hi everyone.
I would like to make BTF line information better available from outside the
internal/btf
package. I am currently working on a PR to accomplish this and would like some input/feedback before submitting it. The reason I need this functionality is so that I can show the lines of source code when inspecting instructions from theProgramSpec
objects.My proposal is to add a new
InstructionMetadata
structure to the asm package and to add a field toasm.Instruction
of type*InstructionMetadata
. This allows us to add information to the instruction, namely the source file name, line and line number.In the
ebpf.loadFunctions
func, everything we need to add this information is already available(*btf.Spec, elfSection, symbols). We already parse thebtf.LineInfos
from the.BTF.ext
section, which is not very useful to anyone but the kernel in its current form(offsets into the strings table). Adding 2 functions to the LineInfos object to convert the offsets into actual strings should solve this.The main benefit for adding the metadata directly to the Instruction is that we can now rewrite
asm.Instructions
to our harts content and don't have to worry about incorrect offsets in LineInfos. That is because we should be able to marshal these metadata objects back into kernel loadable LineInfos/string table.Being able to add metadata to instruction created via the DSL might also be a nice feature, since we can include comments which will later be visible via
bpftool
when needing to inspect/debug the loaded instructions.Would love to hear what you guys think.
Beta Was this translation helpful? Give feedback.
All reactions