'\" t
.\" Title: libtraceevent
.\" Author: [see the "AUTHOR" section]
.\" Generator: DocBook XSL Stylesheets vsnapshot
.\" Date: 03/09/2026
.\" Manual: libtraceevent Manual
.\" Source: libtraceevent
.\" Language: English
.\"
.TH "LIBTRACEEVENT" "3" "03/09/2026" "libtraceevent" "libtraceevent Manual"
.\" -----------------------------------------------------------------
.\" * Define some portability stuff
.\" -----------------------------------------------------------------
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.\" http://bugs.debian.org/507673
.\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.\" -----------------------------------------------------------------
.\" * set default formatting
.\" -----------------------------------------------------------------
.\" disable hyphenation
.nh
.\" disable justification (adjust text to left margin only)
.ad l
.\" -----------------------------------------------------------------
.\" * MAIN CONTENT STARTS HERE *
.\" -----------------------------------------------------------------
.SH "NAME"
tep_load_btf, tep_btf_print_args \- Load BTF file and use it to pretty print function arguments\&.
.SH "SYNOPSIS"
.sp
.nf
\fB#include \fR
int \fBtep_load_btf\fR(struct tep_handle *\fItep\fR, void *\fIraw_data\fR, size_t \fIdata_size\fR);
int \fBtep_btf_print_args\fR(struct tep_handle *\fItep\fR, struct trace_seq *\fIs\fR, void *\fIargs\fR,
int \fInmem\fR, int \fIsize\fR, const char *\fIfunc\fR);
.fi
.SH "DESCRIPTION"
.sp
If the Linux kernel has BTF configured, then a binary file will exist in the path of \fB/sys/kernel/btf/vmlinux\fR\&. If this file is read into memory and passed to \fBtep_load_btf()\fR function, then it will be used to parse the arguments of a given function, if that function data is found within the BTF file\&.
.sp
The \fBtep_load_btf()\fR takes the \fItep\fR handle and will load the \fIraw_data\fR into it\&. The \fIdata_size\fR should be set to the size of the content in \fIraw_data\fR\&.
.sp
The \fBtep_btf_print_args()\fR takes a \fItep\fR handle, a trace_seq \fIs\fR pointer (that was initialized by \fBtrace_seq_init(3)\fR), an \fIargs\fR array that holds either 4 byte or 8 byte values, the \fInmem\fR that is the number of values in the \fIargs\fR parameter, a \fIsize\fR that is either 4 or 8 to denote the size of each value in \fIargs\fR, and a \fIfunc\fR string that is the name of the function to find the BTF information to use for parsing\&. If BTF is not loaded or the \fIfunc\fR name is not found it will just print a hex value of all the \fIargs\fR into the \fIs\fR descriptor\&.
.SH "RETURN VALUE"
.sp
\fBtep_load_btf()\fR function returns 0 on success\&. It returns \-1 on failure and the \fIraw_data\fR will need to be freed by the caller\&.
.sp
\fBtep_btf_print_args()\fR returns 0 on success and \-1 on failure, which happens if the \fIsize\fR is not valid or the BTF file that was loaded is corrupted\&.
.SH "EXAMPLE"
.sp
.if n \{\
.RS 4
.\}
.nf
#include
#include
#include
#include
#include
#include
#include
#include
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, ")\en");
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\&.
\&.\&.\&.
.fi
.if n \{\
.RE
.\}
.SH "FILES"
.sp
.if n \{\
.RS 4
.\}
.nf
\fBevent\-parse\&.h\fR
Header file to include in order to have access to the library APIs\&.
\fB\-ltraceevent\fR
Linker switch to add when building a program that uses the library\&.
.fi
.if n \{\
.RE
.\}
.SH "SEE ALSO"
.sp
\fBlibtraceevent\fR(3), \fBtrace\-cmd\fR(1)
.SH "AUTHOR"
.sp
.if n \{\
.RS 4
.\}
.nf
\fBSteven Rostedt\fR <\m[blue]\fBrostedt@goodmis\&.org\fR\m[]\&\s-2\u[1]\d\s+2>, author of \fBlibtraceevent\fR\&.
.fi
.if n \{\
.RE
.\}
.SH "REPORTING BUGS"
.sp
Report bugs to <\m[blue]\fBlinux\-trace\-devel@vger\&.kernel\&.org\fR\m[]\&\s-2\u[2]\d\s+2>
.SH "LICENSE"
.sp
libtraceevent is Free Software licensed under the GNU LGPL 2\&.1
.SH "RESOURCES"
.sp
\m[blue]\fBhttps://git\&.kernel\&.org/pub/scm/libs/libtrace/libtraceevent\&.git/\fR\m[]
.SH "NOTES"
.IP " 1." 4
rostedt@goodmis.org
.RS 4
\%mailto:rostedt@goodmis.org
.RE
.IP " 2." 4
linux-trace-devel@vger.kernel.org
.RS 4
\%mailto:linux-trace-devel@vger.kernel.org
.RE