'\" t
.\" Title: libtraceevent
.\" Author: [see the "AUTHOR" section]
.\" Generator: DocBook XSL Stylesheets v1.79.1
.\" Date: 11/26/2020
.\" Manual: libtraceevent Manual
.\" Source: libtraceevent 1.1.0
.\" Language: English
.\"
.TH "LIBTRACEEVENT" "3" "11/26/2020" "libtraceevent 1\&.1\&.0" "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_find_function, tep_find_function_address, tep_set_function_resolver, tep_reset_function_resolver, tep_register_function, tep_register_print_string \- function related tep APIs
.SH "SYNOPSIS"
.sp
.nf
\fB#include \fR
typedef char *(\fBtep_func_resolver_t\fR)(void *\fIpriv\fR, unsigned long long *\fIaddrp\fR, char **\fImodp\fR);
int \fBtep_set_function_resolver\fR(struct tep_handle *\fItep\fR, tep_func_resolver_t *\fIfunc\fR, void *\fIpriv\fR);
void \fBtep_reset_function_resolver\fR(struct tep_handle *\fItep\fR);
const char *\fBtep_find_function\fR(struct tep_handle *\fItep\fR, unsigned long long \fIaddr\fR);
unsigned long long \fBtep_find_function_address\fR(struct tep_handle *\fItep\fR, unsigned long long \fIaddr\fR);
int \fBtep_register_function\fR(struct tep_handle *\fItep\fR, char *\fIname\fR, unsigned long long \fIaddr\fR, char *\fImod\fR);
int \fBtep_register_print_string\fR(struct tep_handle *\fItep\fR, const char *\fIfmt\fR, unsigned long long \fIaddr\fR);
.fi
.SH "DESCRIPTION"
.sp
Some tools may have already a way to resolve the kernel functions\&. These APIs allow them to keep using it instead of duplicating all the entries inside\&.
.sp
The \fItep_func_resolver_t\fR type is the prototype of the alternative kernel functions resolver\&. This function receives a pointer to its custom context (set with the \fItep_set_function_resolver()\fR call ) and the address of a kernel function, which has to be resolved\&. In case of success, it should return the name of the function and its module (if any) in \fImodp\fR\&.
.sp
The \fItep_set_function_resolver()\fR function registers \fIfunc\fR as an alternative kernel functions resolver\&. The \fItep\fR argument is trace event parser context\&. The \fIpriv\fR argument is a custom context of the \fIfunc\fR function\&. The function resolver is used by the APIs \fItep_find_function()\fR, \fItep_find_function_address()\fR, and \fItep_print_func_field()\fR to resolve a function address to a function name\&.
.sp
The \fItep_reset_function_resolver()\fR function resets the kernel functions resolver to the default function\&. The \fItep\fR argument is trace event parser context\&.
.sp
These APIs can be used to find function name and start address, by given address\&. The given address does not have to be exact, it will select the function that would contain it\&.
.sp
The \fItep_find_function()\fR function returns the function name, which contains the given address \fIaddr\fR\&. The \fItep\fR argument is the trace event parser context\&.
.sp
The \fItep_find_function_address()\fR function returns the function start address, by given address \fIaddr\fR\&. The \fIaddr\fR does not have to be exact, it will select the function that would contain it\&. The \fItep\fR argument is the trace event parser context\&.
.sp
The \fItep_register_function()\fR function registers a function name mapped to an address and (optional) module\&. This mapping is used in case the function tracer or events have "%pS" parameter in its format string\&. It is common to pass in the kallsyms function names with their corresponding addresses with this function\&. The \fItep\fR argument is the trace event parser context\&. The \fIname\fR is the name of the function, the string is copied internally\&. The \fIaddr\fR is the start address of the function\&. The \fImod\fR is the kernel module the function may be in (NULL for none)\&.
.sp
The \fItep_register_print_string()\fR function registers a string by the address it was stored in the kernel\&. Some strings internal to the kernel with static address are passed to certain events\&. The "%s" in the event\(cqs format field which has an address needs to know what string would be at that address\&. The tep_register_print_string() supplies the parsing with the mapping between kernel addresses and those strings\&. The \fItep\fR argument is the trace event parser context\&. The \fIfmt\fR is the string to register, it is copied internally\&. The \fIaddr\fR is the address the string was located at\&.
.SH "RETURN VALUE"
.sp
The \fItep_set_function_resolver()\fR function returns 0 in case of success, or \-1 in case of an error\&.
.sp
The \fItep_find_function()\fR function returns the function name, or NULL in case it cannot be found\&.
.sp
The \fItep_find_function_address()\fR function returns the function start address, or 0 in case it cannot be found\&.
.sp
The \fItep_register_function()\fR function returns 0 in case of success\&. In case of an error \-1 is returned, and errno is set to the appropriate error number\&.
.sp
The \fItep_register_print_string()\fR function returns 0 in case of success\&. In case of an error \-1 is returned, and errno is set to the appropriate error number\&.
.SH "EXAMPLE"
.sp
.if n \{\
.RS 4
.\}
.nf
#include
\&.\&.\&.
struct tep_handle *tep = tep_alloc();
\&.\&.\&.
char *my_resolve_kernel_addr(void *context,
unsigned long long *addrp, char **modp)
{
struct db *function_database = context;
struct symbol *sym = sql_lookup(function_database, *addrp);
if (!sym)
return NULL;
*modp = sym\->module_name;
return sym\->name;
}
void show_function( unsigned long long addr)
{
unsigned long long fstart;
const char *fname;
if (tep_set_function_resolver(tep, my_resolve_kernel_addr,
function_database) != 0) {
/* failed to register my_resolve_kernel_addr */
}
/* These APIs use my_resolve_kernel_addr() to resolve the addr */
fname = tep_find_function(tep, addr);
fstart = tep_find_function_address(tep, addr);
/*
addr is in function named fname, starting at fstart address,
at offset (addr \- fstart)
*/
tep_reset_function_resolver(tep);
}
\&.\&.\&.
if (tep_register_function(tep, "kvm_exit",
(unsigned long long) 0x12345678, "kvm") != 0) {
/* Failed to register kvm_exit address mapping */
}
\&.\&.\&.
if (tep_register_print_string(tep, "print string",
(unsigned long long) 0x87654321, NULL) != 0) {
/* Failed to register "print string" address mapping */
}
\&.\&.\&.
.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
\fIlibtraceevent(3)\fR, \fItrace\-cmd(1)\fR
.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>, author of this man page\&.
.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/linux/kernel/git/torvalds/linux\&.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