Get argument values of an event using Cilium's eBPF
0. Background
When a Kprobe had a event happening, it will call a function with argument named struct pt_regs *ctx with this, we can know what the register values were using some eBPF functions.
Let's assume that we were watching kprobe/tcp_v4_rcv to monitor TCP packet receive events.
1. Headers
For us to use PT_REGS_PARM1, PT_REGS_RC macros, we need to have following code:
#include <bpf/bpf_tracing.h>
Since retrieving register values are different by architectures, we need to explictly define target architecture by:
#define __TARGET_ARCH_x86
We are assuming that we have x86 system.
If you are using lots of #includes, including vmlinux.h , the target architecture definition must before any #include statements. For example, it shall be like below: