Skip to content

KFunc bpf_stream_print_stack

v7.0

Dump the current BPF program stack trace to a stream.

Definition

Parameters

stream_id: The ID of the stream to write to (BPF_STDOUT(1), or BPF_STDERR(2)).

Returns

0 on success, or -ENOENT if stream_id is invalid.

Signature

int bpf_stream_print_stack(int stream_id)

Usage

This kfunc triggers an immediate stack dump of the current BPF execution context and writes it into the per-program stream.

It is intended for debugging and diagnostics, especially for error paths where capturing stack traces is useful.

The stream output can be read with: bpftool prog tracelog { stdout | stderr } *PROG*.

Program types

The following program types can make use of this kfunc:

Example

The kernel self-tests use this kfunc in tools/testing/selftests/bpf/progs/stream.c with a syscall program that emits the stack to BPF_STDERR:

SEC("syscall")
int stream_print_stack_kfunc(void *ctx)
{
    return bpf_stream_print_stack(BPF_STDERR);
}

Once the program is loaded and triggered, read the stream with:

bpftool prog tracelog stderr <PROG>

The output includes a header (CPU, PID, Comm) and a Call trace: section.