Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

examples/c: demo how to get IP for uprobe and uretprobe #221

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions examples/c/uprobe.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,45 @@
#include "vmlinux.h"
#include <bpf/bpf_helpers.h>
#include <bpf/bpf_tracing.h>
#include <bpf/bpf_core_read.h>

char LICENSE[] SEC("license") = "Dual BSD/GPL";

SEC("uprobe")
int BPF_KPROBE(uprobe_add, int a, int b)
int BPF_UPROBE(uprobe_add, int a, int b)
{
bpf_printk("uprobed_add ENTRY: a = %d, b = %d", a, b);
long ip;

ip = PT_REGS_IP(ctx);
bpf_printk("UPROBE IP 0x%lx.", ip);
return 0;
}

SEC("uretprobe")
int BPF_KRETPROBE(uretprobe_add, int ret)
int BPF_URETPROBE(uretprobe_add, int ret)
{
bpf_printk("uprobed_add EXIT: return = %d", ret);
struct task_struct *t = (void *)bpf_get_current_task();
struct uprobe_dispatch_data *ud;
long ip;

ud = (void *)BPF_CORE_READ(t, utask, vaddr);
ip = BPF_CORE_READ(ud, bp_addr);
bpf_printk("URETPROBE IP 0x%lx.", ip);
return 0;
}

/*
SEC("uprobe//proc/self/exe:uprobed_sub")
int BPF_KPROBE(uprobe_sub, int a, int b)
int BPF_UPROBE(uprobe_sub, int a, int b)
{
bpf_printk("uprobed_sub ENTRY: a = %d, b = %d", a, b);
return 0;
}

SEC("uretprobe//proc/self/exe:uprobed_sub")
int BPF_KRETPROBE(uretprobe_sub, int ret)
int BPF_URETPROBE(uretprobe_sub, int ret)
{
bpf_printk("uprobed_sub EXIT: return = %d", ret);
return 0;
}
*/
2 changes: 2 additions & 0 deletions examples/c/uprobe.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ static int libbpf_print_fn(enum libbpf_print_level level, const char *format, va
/* It's a global function to make sure compiler doesn't inline it. */
int uprobed_add(int a, int b)
{
printf("Triggering user function test_func, addr %p...\n",
(const void *)&uprobed_add);
return a + b;
}

Expand Down
Loading