|
NAME | SYNOPSIS | DESCRIPTION | RETURN VALUE | EXAMPLE | FILES | SEE ALSO | AUTHOR | REPORTING BUGS | LICENSE | RESOURCES | NOTES | COLOPHON |
|
|
|
LIBTRACEEVENT(3) libtraceevent Manual LIBTRACEEVENT(3)
tep_load_btf, tep_btf_print_args - Load BTF file and use it to
pretty print function arguments.
#include <event-parse.h>
int tep_load_btf(struct tep_handle *tep, void *raw_data, size_t data_size);
int tep_btf_print_args(struct tep_handle *tep, struct trace_seq *s, void *args,
int nmem, int size, const char *func);
If the Linux kernel has BTF configured, then a binary file will
exist in the path of /sys/kernel/btf/vmlinux. If this file is read
into memory and passed to tep_load_btf() function, then it will be
used to parse the arguments of a given function, if that function
data is found within the BTF file.
The tep_load_btf() takes the tep handle and will load the raw_data
into it. The data_size should be set to the size of the content in
raw_data.
The tep_btf_print_args() takes a tep handle, a trace_seq s pointer
(that was initialized by trace_seq_init(3)), an args array that
holds either 4 byte or 8 byte values, the nmem that is the number
of values in the args parameter, a size that is either 4 or 8 to
denote the size of each value in args, and a func string that is
the name of the function to find the BTF information to use for
parsing. If BTF is not loaded or the func name is not found it
will just print a hex value of all the args into the s descriptor.
tep_load_btf() function returns 0 on success. It returns -1 on
failure and the raw_data will need to be freed by the caller.
tep_btf_print_args() returns 0 on success and -1 on failure, which
happens if the size is not valid or the BTF file that was loaded
is corrupted.
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <event-parse.h>
int print_args(const char *func, unsigned long *args, int nr)
{
struct tep_handle *tep = tep_alloc();
struct trace_seq s;
struct stat st;
void *buf;
int fd;
int ret;
if (!tep)
return -1;
fd = open("/sys/kernel/btf/vmlinux", O_RDONLY);
if (fd < 0)
return -1;
if (fstat(fd, &st) < 0) {
close(fd);
return -1;
}
buf = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
if (buf == MAP_FAILED) {
close(fd);
return -1;
}
ret = tep_load_btf(tep, buf, st.st_size);
munmap(buf, st.st_size);
close(fd);
if (ret < 0)
return -1;
trace_seq_init(&s);
trace_seq_printf(&s, "%s(", func);
tep_btf_print_args(tep, &s, args, nr, sizeof(long), func);
trace_seq_puts(&s, ")\n");
trace_seq_do_printf(&s);
tep_free(tep);
return 0;
}
int main(int argc, char **argv)
{
unsigned long args[] = {0x7ffe7d33f3d0, 0, 0, 0, 0, 0};
print_args("getname_flags", args, 6);
return 0;
}
...
The above may output:
getname_flags(filename=0x7ffe7d33f3d0, flags=0)
If BTF is loaded and the function was found, or it may show:
getname_flags(7ffe7d33f3d0, 0, 0, 0, 0, 0)
If it was not.
...
event-parse.h
Header file to include in order to have access to the library APIs.
-ltraceevent
Linker switch to add when building a program that uses the library.
libtraceevent(3), trace-cmd(1)
Steven Rostedt <rostedt@goodmis.org[1]>, author of libtraceevent.
Report bugs to <linux-trace-devel@vger.kernel.org[2]>
libtraceevent is Free Software licensed under the GNU LGPL 2.1
https://git.kernel.org/pub/scm/libs/libtrace/libtraceevent.git/
1. rostedt@goodmis.org
mailto:rostedt@goodmis.org
2. linux-trace-devel@vger.kernel.org
mailto:linux-trace-devel@vger.kernel.org
This page is part of the libtraceevent (Linux kernel trace event
library) project. Information about the project can be found at
⟨https://www.trace-cmd.org/⟩. If you have a bug report for this
manual page, see ⟨https://www.trace-cmd.org/⟩. This page was
obtained from the project's upstream Git repository
⟨https://git.kernel.org/pub/scm/libs/libtrace/libtraceevent.git⟩
on 2026-01-16. (At that time, the date of the most recent commit
that was found in the repository was 2025-12-30.) If you discover
any rendering problems in this HTML version of the page, or you
believe there is a better or more up-to-date source for the page,
or you have corrections or improvements to the information in this
COLOPHON (which is not part of the original manual page), send a
mail to man-pages@man7.org
libtraceevent 1.8.99 01/15/2026 LIBTRACEEVENT(3)