Search code examples
cebpfbpfbcc-bpf

Can I access the intermediate C code generated by BCC (BPF Compiler Collection)?


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!


Solution

  • You can tell bcc to dump the rewritten C code by passing DEBUG_PREPROCESSOR to the BPF() call.

    BPF(..., debug=DEBUG_PREPROCESSOR)