Minimal eBPF (libbpf) usage example from C/C++
Tracepoint events (src/structs.h) are submitted to the ringbuffer, at which point they
can be handled further in userspace (src/handler.c).
To check if you have support bpf, run: sudo bpftool feature
- CMake project usable from CLion
- Compiles bpf object/skeleton via CMake
- and recompiles when
src/bpf/execsnoop.bpf.cchanges
- and recompiles when
- Type completion in
*.bpf.cfiles - Uses libbpf/bpftool/vmlinux.h/blazesym from
external/(submodules)
# git clone this repository recursively
sudo apt install libelf-dev clang llvm cmake build-essential
# ... and possibly install more stuffcd external/libbpf/src/
mkdir -p build output
BUILD_STATIC_ONLY=y OBJDIR=build DESTDIR=output make installAt this point you can load this project in CLion, or just compile with CMake:
cmake -Bbuild .
make -Cbuild -j6Produces build/bin/execsnoop
- the two symlinks in
src/bpfare present so the IDE has type completion - you can safely remove them. - official starter project libbpf/libbpf-bootstrap exists, but it's a mess.
[exec_exit] pid=1313180 ppid=811561 comm=postgres
[statfs_enter] pid=799678 path=/home/dsc/snap/firefox/common/.mozilla/firefox/tr55fwnp.default/storage/default/https+++www.youtube.com/idb/3235%sC
[statfs_exit] pid=799678
[exec_enter] pid=1313191 ppid=358186 comm=git path=/usr/bin/git
[exec_exit] pid=1313191 ppid=358186 comm=git
[exec_enter] pid=1313192 ppid=358186 comm=jspawnhelper path=/home/dsc/apps/clion-2024.3.1/jbr/lib/jspawnhelper
[exec_enter] pid=1313192 ppid=358186 comm=git path=/usr/bin/git
[exec_exit] pid=1313192 ppid=358186 comm=git