Hi!
Is there any way to print the resulting BPF bytecode from b = BPF(src_file="my_prog.c", debug=0)? Eg.: a simply b.print() that displays the bytecodes of b.
b = BPF(src_file="my_prog.c", debug=2)
will print the bytecode. debug=4 prints the intermediate C (rewritten by bcc).
Well, not really working in some cases. I have tried the program below.
I'm getting the output below. There is a warning but no errors. I only get the object's address, similar to debug=0.
>>> BPF(src_file="my_counter.c", debug=2)
In file included from /virtual/main.c:6:
In file included from include/linux/skbuff.h:29:
In file included from include/linux/net.h:28:
include/linux/fs.h:2659:9: warning: comparison of unsigned enum expression < 0
is always false [-Wtautological-compare]
if (id < 0 || id >= READING_MAX_ID)
~~ ^ ~
1 warning generated.
<bcc.BPF object at 0x7f094310c690>
Does anyone have any idea on what's going on?
When you set debug to be 2 (i.e. DEBUG_BPF), the library will print out the BPF bytecode when you load the function. You don't need to print the BPF object.
Yes, I have realized that however it's not working for some cases. I could not spot an error. As an example, take my last comment above. The said program (my_counter.c.zip) does not result in any bytecodes even though debug is set to 2.
In your my_counter.c, the bpf program is not auto-recognizable by bcc. It needs explicit load.
Hence, BPF(src_file="my_counter.c", debug=2) will not dump the byte code to you since
the program has not been loaded into the kernel.
Thanks!! It works fine now.
Most helpful comment
When you set
debugto be 2 (i.e.DEBUG_BPF), the library will print out the BPF bytecode when you load the function. You don't need to print theBPFobject.