Skip to content

Libbpf userspace function bpf_program__attach_uprobe_opts

0.5.0

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 attach
  • pid: Process ID to attach the uprobe to, 0 for self (own process), -1 for all processes
  • binary_path: Path to binary that contains the function symbol
  • func_offset: Offset within the binary of the function symbol
  • opts: 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

0.5.0

Offset of kernel reference counted USDT semaphore, added in a6ca88b241d5 ("trace_uprobe: support reference counter in fd-based uprobe")

0.5.0

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

0.5.0

uprobe is return probe, invoked at function return time.

func_name

0.8.0

Function name to attach to. Could be an unqualified ("abc") or library-qualified "abc@LIBXYZ" name. To specify function entry, 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

1.2.0

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