add debug option to dump asm insns embedded with source
The patch adds a new debug option "DEBUG_SOURCE = 8" to
dump insns embedded with source. In C++ API, users
can change BPF constructor "flag" value to enable debug output.
In Python API, users can change "debug" value to enable
debug output. For example, for python test program test_usdt.py,
the debug output looks like below:
......
Disassembly of section .bpf.fn.do_trace1:
do_trace1:
; int do_trace1(struct pt_regs *ctx) { // Line 110
0: bf 16 00 00 00 00 00 00 r6 = r1
1: b7 01 00 00 00 00 00 00 r1 = 0
; struct probe_result_t1 result = {}; // Line 111
2: 7b 1a f0 ff 00 00 00 00 *(u64 *)(r10 - 16) = r1
; switch(ctx->ip) { // Line 5
3: 79 61 80 00 00 00 00 00 r1 = *(u64 *)(r6 + 128)
4: 15 01 04 00 d7 06 40 00 if r1 == 4196055 goto 4
5: 55 01 06 00 ce 06 40 00 if r1 != 4196046 goto 6
; case 0x4006ceULL: *((int8_t *)dest) = ctx->ax; __asm__ __volatile__("": : :"memory"); return 0; // Line 6
6: 79 61 50 00 00 00 00 00 r1 = *(u64 *)(r6 + 80)
......
For asm insns, byte code is also dumped out (similar to objdump).
For source codes, only lines in the module file are printed (as expected).
The line number is added at the end of source code, which is
especially helpful for inlined functions.
This functionality is only in llvm 6.x (the trunk version), which
provides an public interface to create a dwarf context based on
a set of in-memory debug sections. llvm 5.x also provides
such a public interface in a different way, and this patch
does not support it in bcc yet. llvm 4.x and lower do not
have such a public interface and hence will not be supported
in bcc.
In this patch, the debug output only goes to stderr.
A subsequent patch will dump the per-function output into
<BCC_PROG_TAG_DIR>/bpf_prog_<tag>/ if it is available.
Signed-off-by: Yonghong Song <yhs@fb.com>
Showing
src/cc/bcc_debug.cc
0 → 100644
src/cc/bcc_debug.h
0 → 100644
Please register or sign in to comment