Skip to content

Commit 21a3afc

Browse files
kkdwivediAlexei Starovoitov
authored andcommitted
libbpf: Add bpf_stream_printk() macro
Add a convenience macro to print data to the BPF streams. BPF_STDOUT and BPF_STDERR stream IDs in the vmlinux.h can be passed to the macro to print to the respective streams. Acked-by: Andrii Nakryiko <[email protected]> Acked-by: Eduard Zingerman <[email protected]> Signed-off-by: Kumar Kartikeya Dwivedi <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent ecec5b5 commit 21a3afc

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

tools/lib/bpf/bpf_helpers.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,22 @@ enum libbpf_tristate {
314314
___param, sizeof(___param)); \
315315
})
316316

317+
extern int bpf_stream_vprintk(int stream_id, const char *fmt__str, const void *args,
318+
__u32 len__sz, void *aux__prog) __weak __ksym;
319+
320+
#define bpf_stream_printk(stream_id, fmt, args...) \
321+
({ \
322+
static const char ___fmt[] = fmt; \
323+
unsigned long long ___param[___bpf_narg(args)]; \
324+
\
325+
_Pragma("GCC diagnostic push") \
326+
_Pragma("GCC diagnostic ignored \"-Wint-conversion\"") \
327+
___bpf_fill(___param, args); \
328+
_Pragma("GCC diagnostic pop") \
329+
\
330+
bpf_stream_vprintk(stream_id, ___fmt, ___param, sizeof(___param), NULL);\
331+
})
332+
317333
/* Use __bpf_printk when bpf_printk call has 3 or fewer fmt args
318334
* Otherwise use __bpf_vprintk
319335
*/

0 commit comments

Comments
 (0)