Libbpf userspace function bpf_program__attach_uprobe_opts
Is just like bpf_program__attach_uprobe
except with a options struct for various configurations.
Definition
struct bpf_link * bpf_program__attach_uprobe_opts(const struct bpf_program *prog, pid_t pid, const char *binary_path, size_t func_offset, const struct bpf_uprobe_opts *opts);
Parameters
prog
: BPF program to attachpid
: Process ID to attach the uprobe to, 0 for self (own process),-1
for all processesbinary_path
: Path to binary that contains the function symbolfunc_offset
: Offset within the binary of the function symbolopts
: Options for altering program attachment
Return
Reference to the newly created BPF link; or NULL
is returned on error, error code is stored in errno
struct bpf_uprobe_opts
struct bpf_uprobe_opts {
/* size of this struct, for forward/backward compatibility */
size_t sz;
size_t ref_ctr_offset;
__u64 bpf_cookie;
bool retprobe;
const char *func_name;
enum probe_attach_mode attach_mode;
size_t :0;
};
ref_ctr_offset
Offset of kernel reference counted USDT semaphore, added in a6ca88b241d5 ("trace_uprobe: support reference counter in
bpf_cookie
Custom user-provided value fetchable through bpf_get_attach_cookie
. This allows you to write one program, load it once, and then attach it to multiple perf events with different bpf_cookie
values, allowing the program to detect which event it is attached to.
retprobe
uprobe is return probe, invoked at function return time.
func_name
Function name to attach to. Could be an unqualified func_name
should be set while func_offset
argument to bpf_prog__attach_uprobe_opts
should be 0
. To trace an offset within a function, specify func_name
and use func_offset
argument to specify offset within the function. Shared library functions must specify the shared library binary_path
.
attach_mode
The mode to attach uprobe force libbpf to attach uprobe in specific mode, -ENOTSUP
will be returned if it is not supported by the kernel.
enum probe_attach_mode {
/* attach probe in latest supported mode by kernel */
PROBE_ATTACH_MODE_DEFAULT = 0,
/* attach probe in legacy mode, using debugfs/tracefs */
PROBE_ATTACH_MODE_LEGACY,
/* create perf event with perf_event_open() syscall */
PROBE_ATTACH_MODE_PERF,
/* attach probe with BPF link */
PROBE_ATTACH_MODE_LINK,
};
Usage
Docs could be improved
This part of the docs is incomplete, contributions are very welcome
Example
Docs could be improved
This part of the docs is incomplete, contributions are very welcome