Open yunwei37 opened 1 year ago
int probe_mysql_query(struct pt_regs *ctx) {
void *thd = (void *)ctx->di;
char *query = (char *)ctx->si;
size_t len = (size_t)ctx->dx;
this part will be x86-specific for not good reason. Consider utilizing libbpf's BPF_KPROBE/BPF_UPROBE macros, which in this case would be:
int BPF_UPROBE(probe_mysql_query, void *thd, char* query, size_t len) {
}
Note that BPF_UPROBE is just an alias to BPF_KPROBE, added very recently, so depending on how recent libbpf you have, you might need to stick to BPF_KPROBE instead.
Thanks! I will continue to improve this.
Hi! I have some working PoC and ideas, and I would like to get some comments or feedbacks before I going on this.
motivation
A Prove of Concept converter for convert BCC style kernel source to libbpf style kernel source
we have created a source to source converter base on bcc frontend: see https://github.com/eunomia-bpf/bcc/tree/master/src/cc/converter
This work will introduce:
A new flag
aot_mode
and an example converter may also works:The
BPF(bool aot_mode = true)
may be used to enable the converter and aot build.The converter may include two passes to generate a libbpf source from bcc source:
libbpf_frontend_action:
bpf_map_update_elem
bpf_probe_read*
tobpf_core_read*
a->b->c
access toBPF_CORE_READ(a, b, c)
bpf_map_lookup_or_try_init
preprocesseo pass: work like
clang -E -P -C -nostdinc source_rewrite.bcc.c 1> pre_output.bpf.c
example
A bcc source:
will results in:
which can be compile with clang and
CO-RE
enabled, and load with libbpf loader. The compiled BPF code can pass the verifier.Unsolved problems
TracepointFrontendAction
support for libbpf sourceAOT support
I have tried to AOT load the compiled libbpf code through the
bpf-loader
in eunomia-bpf: https://github.com/eunomia-bpf/eunomia-bpf, maybe I can add a similar libbpf CO-RE ELF loader in bcc? It should not be difficult to add one with the high level libbpf API, compare to the bcc frontend implement.(TODO: add more detail design and api examples for aot build)
reference