0

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!

pchaigno
  • 11,313
  • 2
  • 29
  • 54
sk_buff
  • 81
  • 7
  • I don't know about `BCC` but in `GCC` you can do it by ```gcc main.c -E``` – Darth-CodeX Feb 24 '22 at 08:11
  • 1
    By the way to access members of a pointer you have to use `->` instead of `.` – Darth-CodeX Feb 24 '22 at 08:13
  • 1
    @Darth-CodeX The `BCC` here refers to [BPF Compiler Collection](https://github.com/iovisor/bcc). It's a toolkit to develope eBPF programs instead of a C compiler like `GCC`. Actually `BCC` embeds `Clang` to compile C programs to eBPF bytecode. Maybe you misinterpret it as `Bruce's C compiler`. Still, thanks for your anwser :) – sk_buff Feb 24 '22 at 15:25
  • I really didn't knew about `BCC` – Darth-CodeX Feb 24 '22 at 15:37

1 Answers1

3

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

BPF(..., debug=DEBUG_PREPROCESSOR)
pchaigno
  • 11,313
  • 2
  • 29
  • 54