Closed prakashsurya closed 1 year ago
git-ab-pre-push -b bpftrace
is here
ab-pre-push
with https://github.com/delphix/bpftrace/pull/21 is here
This is great Prakash! I just checked the VM - here is bpftrace leveraging the BTF data with the environment variable to print type info:
delphix@ip-10-110-240-110:~$ sudo bpftrace -lv "struct path"
delphix@ip-10-110-240-110:~$ sudo BPFTRACE_BTF=/sys/kernel/btf/vmlinux bpftrace -lv "struct path"
struct path {
struct vfsmount *mnt;
struct dentry *dentry;
};
and here it is again using types without including header in a one-liner just like DTrace (first prompt is the error that we get if we don't set the BTF variable):
$ sudo bpftrace -e 'kprobe:vfs_open { printf("open path: %s\n", str(((struct path *)arg0)->dentry->d_name.name)); }'
stdin:1:45-65: ERROR: Unknown struct/union: 'struct path'
kprobe:vfs_open { printf("open path: %s\n", str(((struct path *)arg0)->dentry->d_name.name)); }
~~~~~~~~~~~~~~~~~~~~
stdin:1:45-93: ERROR: str() expects an integer or a pointer type as first argument (none provided)
kprobe:vfs_open { printf("open path: %s\n", str(((struct path *)arg0)->dentry->d_name.name)); }
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
delphix@ip-10-110-240-110:~$ sudo BPFTRACE_BTF=/sys/kernel/btf/vmlinux bpftrace -e 'kprobe:vfs_open { printf("open path: %s\n", str(((struct path *)arg0)->dentry->d_name.name)); }'
Attaching 1 probe...
open path: fd
open path: systemctl
open path: ld-2.31.so
open path: ld.so.cache
open path: libc-2.31.so
open path: libselinux.so.1
open path: liblzma.so.5.2.4
open path: liblz4.so.1.9.2
open path: libblkid.so.1.1.0
open path: libgcrypt.so.20.2.5
open path: libpthread-2.31.so
open path: libpcre2-8.so.0.9.0
^C
This is sweet! Is there any scenerio where bpftrace knows the type of arg0
so you don't even have to cast it? IIRC, dtrace implemented this as args[0]
.
This is needed for https://github.com/delphix/bpftrace/pull/21