KFunc bpf_stream_print_stack
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:
BPF_PROG_TYPE_CGROUP_DEVICEv6.12 -BPF_PROG_TYPE_CGROUP_SKBBPF_PROG_TYPE_CGROUP_SOCKv6.12 -BPF_PROG_TYPE_CGROUP_SOCKOPTv6.12 -BPF_PROG_TYPE_CGROUP_SOCK_ADDRv6.7 -BPF_PROG_TYPE_CGROUP_SYSCTLv6.12 -BPF_PROG_TYPE_LSMBPF_PROG_TYPE_LWT_INBPF_PROG_TYPE_LWT_OUTBPF_PROG_TYPE_LWT_SEG6LOCALBPF_PROG_TYPE_LWT_XMITBPF_PROG_TYPE_NETFILTERBPF_PROG_TYPE_PERF_EVENTv6.12 -BPF_PROG_TYPE_SCHED_ACTBPF_PROG_TYPE_SCHED_CLSBPF_PROG_TYPE_SK_SKBBPF_PROG_TYPE_SOCKET_FILTERBPF_PROG_TYPE_SOCK_OPSv6.15 -BPF_PROG_TYPE_STRUCT_OPSBPF_PROG_TYPE_SYSCALLBPF_PROG_TYPE_TRACEPOINTv6.12 -BPF_PROG_TYPE_TRACINGBPF_PROG_TYPE_XDP
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.