'\" 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_parse_saved_cmdlines, tep_parse_printk_formats, tep_parse_kallsyms, tep_parse_last_boot_info, tep_load_modules \- Parsing functions to load mappings .SH "SYNOPSIS" .sp .nf \fB#include \fR int \fBtep_parse_saved_cmdlines\fR(struct tep_handle *\fItep\fR, const char *\fIbuf\fR); int \fBtep_parse_printk_formats\fR(struct tep_handle *\fItep\fR, const char *\fIbuf\fR); int \fBtep_parse_kallsyms\fR(struct tep_handle *\fItep\fR, const char *\fIbuf\fR); int \fBtep_parse_last_boot_info\fR(struct tep_handle *\fItep\fR, const char *\fIlbi\fR); int \fBtep_load_modules\fR(struct tep_handle *\fItep\fR, char *\fImodules\fR, size_t \fIsize\fR); .fi .SH "DESCRIPTION" .sp \fBtep_parse_saved_cmdlines()\fR is a helper function to parse content in the tracefs file system of the "saved_cmdlines" file (stored in a string buffer passed in by \fIbuf\fR) and loads the mapping of the process IDs (pid) to the comm names in the \fItep\fR handler\&. The events store the pid and this is used to be able to show the process names associated to those process ids\&. It parses the string \fIbuf\fR that holds the content of saved_cmdlines and ends with a nul character (\fI\e0\fR)\&. .sp \fBtep_parse_printk_formats()\fR is a helper function to parse content in the tracefs file system of the "printk_formats" file (stored in a string buffer passed in by \fIbuf\fR) and loads the mapping of addresses of strings that may be referenced by events\&. Events only store the address of constant strings in the kernel, and the mapping of their address to the string is exported to user space in the printk_formats file\&. It parses the string \fIbuf\fR that holds the content of printk_formats and ends with a nul character (\fI\e0\fR)\&. .sp \fBtep_parse_kallsyms()\fR is a helper function to parse the Linux kernel /proc/kallsyms format (stored in a string buffer passed in by \fIbuf\fR) and load the functions into the \fItep\fR handler such that function IP addresses can be mapped to their name when parsing events with %pS in the print format field\&. It parses the string \fIbuf\fR that holds the content of /proc/kallsyms and ends with a nul character (\fI\e0\fR)\&. .sp \fBtep_parse_last_boot_info()\fR loads information from the last_boot_info file of a persistent ring buffer instance\&. If a tracefs instance is declared as a persistent ring buffer and contains data from a previous boot, the last_boot_info file will have the addresses of the kernel as well as modules\&. It will use this information to base the function offsets in the binary buffer to match the function offsets in the kallsyms (loaded by \fBtep_parse_kallsyms()\fR) into the \fItep\fR handler\&. The \fIlbi\fR is a nul terminated string that contains the content of the last_boot_info file from the persistent ring buffer instance\&. .sp \fBtep_load_modules()\fR loads the contents of the file /proc/modules into the \fItep\fR handler\&. This will be used to match the modules found in the last_boot_info (loaded by \fBtep_parse_last_boot_info()\fR) to match the offsets of the binary data in in a persistent ring buffer that matches the address of a module from the previous boot to a module address found in \fImodules\fR\&. The \fImodules\fR parameter does not need to be nul terminated, but \fIsize\fR is used to denote the size of the \fImodules\fR string\&. This function is useless if \fBtep_parse_last_boot_info()\fR isnt used\&. .SH "RETURN VALUE" .sp The \fBtep_parse_saved_cmdlines\fR() function returns 0 in case of success, or \-1 in case of an error\&. .sp The \fBtep_parse_printk_formats\fR() function returns 0 in case of success, or \-1 in case of an error\&. .sp The \fBtep_parse_kallsyms\fR() function returns 0 in case of success, or \-1 in case of an error\&. .sp The \fBtep_parse_last_boot_info\fR() function retuns 0 in case of success, or \-1 in case of error\&. .sp The \fBtep_load_modules\fR() function returns 0 in case of success, or \-1 in case of error\&. .SH "EXAMPLE" .sp .if n \{\ .RS 4 .\} .nf \&.\&.\&. #include #include #include int load_cmdlines(struct tep_handle *tep) { char *buf = NULL; int r; buf = tracefs_instance_file_read(NULL, "saved_cmdlines", NULL); if (!buf) return \-1; r = tep_parse_saved_cmdlines(tep, buf); free(buf); return r; } int load_print_strings(struct tep_handle *tep) { char *buf = NULL; int r; buf = tracefs_instance_file_read(NULL, "printk_formats", NULL); if (!buf) return \-1; r = tep_parse_printk_formats(tep, buf); free(buf); return r; } static char *read_file(const char *file, size_t *size) { FILE *fp; char *line = NULL; char *buf = NULL; size_t sz = 0; size_t len = 0; int r; fp = fopen(file, "r"); while ((r = getline(&line, &sz, fp)) >= 0) { buf = realloc(buf, len + r + 1); memcpy(buf + len, line, r); len += r; } free(line); fclose(fp); if (!buf) return NULL; buf[len] = 0; *size = len; return buf; } int load_kallsyms(struct tep_handle *tep) { char *buf; size_t sz; int r; buf = read_file("/proc/kallsyms", &sz); if (!buf) return \-1; r = tep_parse_kallsyms(tep, buf); free(buf); return r; } int load_last_boot(struct tep_handle *tep, struct tracefs_instance *instance) { char *buf; size_t sz; int r; buf = tracefs_instance_file_read(instance, "last_boot_info", NULL); if (!buf) return 0; r = tep_parse_last_boot_info(tep, buf); free(buf); if (r < 0) return r; buf = read_file("/proc/modules", &sz); if (!buf) return \-1; r = tep_parse_kallsyms(tep, buf); free(buf); return r; } \&.\&.\&. .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), \fBtep_register_comm\fR(3), \fBtep_register_function\fR(3), \fBtep_register_print_string\fR(3) .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\&. \fBTzvetomir Stoyanov\fR <\m[blue]\fBtz\&.stoyanov@gmail\&.com\fR\m[]\&\s-2\u[2]\d\s+2>, coauthor 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[3]\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 tz.stoyanov@gmail.com .RS 4 \%mailto:tz.stoyanov@gmail.com .RE .IP " 3." 4 linux-trace-devel@vger.kernel.org .RS 4 \%mailto:linux-trace-devel@vger.kernel.org .RE