我可以访问 BCC(BPF 编译器集合)生成的中间 C 代码吗?
我正在开发使用 BCC 进行内核跟踪的 eBPF 程序。一旦我在运行代码时收到以下错误消息:
/virtual/main.c:16:36: error: member reference type 'struct Qdisc *' is a pointer; did you mean to use '->'?
bpf_trace_printk("%ld\n", qdisc.limit);
~~~~~^
我知道我的代码出了什么问题,并且很容易纠正。但我注意到有一个名为 /virtual/main.c
的文件。我猜 BCC 将我的原始 C 代码(传递给 Python 中的 BPF 对象)转换为中间 C 代码,该代码存储在名为 /virtual/main.c
的文件中。然后中间的C代码通过Clang
和LLVM
编译为BPF字节码,最后将BPF代码挂接到内核中。
我想知道我的猜测是否正确。如果是,有什么方法可以看到存储在 /virtual/main.c
中的中间代码吗?我想知道 BCC 对我的原始代码做了哪些更改。
多谢!
I'm developing eBPF programs for kernel tracing using BCC. Once I got the following error message when running my code:
/virtual/main.c:16:36: error: member reference type 'struct Qdisc *' is a pointer; did you mean to use '->'?
bpf_trace_printk("%ld\n", qdisc.limit);
~~~~~^
I know what is wrong with my code, and it's easy to correct. But I notice there's a file called /virtual/main.c
. I guess BCC transforms my original C code, which is passed to the BPF
object in Python, to intermediate C code which is stored in a file called /virtual/main.c
. Then the intermediate C code is compiled to BPF byte code by Clang
and LLVM
, and the BPF code is finally hooked into the kernel.
I wonder if my guess is correct. If it is, is there any way that I can see the intermediate code which is stored in /virtual/main.c
? I want to know what changes is made by BCC to my original code.
Thanks a lot!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以通过传递
DEBUG_PREPROCESSOR
到BPF()
调用。You can tell bcc to dump the rewritten C code by passing
DEBUG_PREPROCESSOR
to theBPF()
call.