/* uprobe/uretprobe expects relative offset of the function to attach * to. libbpf will automatically find the offset for us if we provide the * function name. If the function name is not specified, libbpf will try * to use the function offset instead. */ skel->links.uprobe_add = bpf_program__attach_uprobe_opts(skel->progs.uprobe_add, 0/* self pid */, "/proc/self/exe", 0/* offset for function */, &uprobe_opts /* opts */); if (!skel->links.uprobe_add) { err = -errno; fprintf(stderr, "Failed to attach uprobe: %d\n", err); goto cleanup; }
/* Let libbpf perform auto-attach for uprobe_sub/uretprobe_sub * NOTICE: we provide path and symbol info in SEC for BPF programs */ err = uprobe_bpf__attach(skel); if (err) { fprintf(stderr, "Failed to auto-attach BPF skeleton: %d\n", err); goto cleanup; }
call func
1 2 3 4 5 6 7
for (i = 0;; i++) { /* trigger our BPF programs */ fprintf(stderr, "."); uprobed_add(i, i + 1); uprobed_sub(i * i, i); sleep(1); }