LIBTRACEEVENT(3)
π NAME π
okay so bestie, this is the libtraceevent manual, section 3 (that's library calls, iykyk), and today's main characters are the function-related tep APIs. Say hi to the whole squad:
tep_set_function_resolvertep_reset_function_resolvertep_register_functiontep_register_print_stringtep_get_function_count
They're the ones who handle function names, addresses, and modules. periodt. π
β¨ SYNOPSIS β¨
lowkey just copy this exactly, don't improvise:
#include <event-parse.h>
typedef char *(tep_func_resolver_t)(void *priv, unsigned long long *addrp, char **modp);
int tep_set_function_resolver(struct tep_handle *tep, tep_func_resolver_t *func, void *priv);
void tep_reset_function_resolver(struct tep_handle *tep);
int tep_register_function(struct tep_handle *tep, char *name, unsigned long long addr, char *mod);
int tep_register_print_string(struct tep_handle *tep, const char *fmt, unsigned long long addr);
int tep_get_function_count(struct tep_handle *tep)
(and yes, that last one has no semicolon up there. iconic behavior. we don't question it. π)
πΈ DESCRIPTION πΈ
So like, some tools already have their own whole thing for resolving kernel functions, right? And these APIs let them keep using it instead of duplicating every single entry inside. No cap, it's giving "stop copy-pasting your symbol table, bestie."
π¦ the resolver type
tep_func_resolver_t is the prototype of the alternative kernel functions resolver. Not me writing a typedef that's basically a personality test for your symbol lookup. π
This function receives:
- a pointer to its custom context (set with the
tep_set_function_resolver()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 modp. slay. β¨
π the functions themselves
- The
tep_set_function_resolver()function registersfuncas an alternative kernel functions resolver.- The
tepargument is the trace event parser context. - The
privargument is a custom context of thefuncfunction. - The function resolver is used by the APIs
tep_find_function(3),tep_find_function_address(3), andtep_print_func_field()to resolve a function address to a function name.
- The
- The
tep_reset_function_resolver()function resets the kernel functions resolver to the default function. Thetepargument is the trace event parser context. (Basically the "jk, back to normal" button. π«Ά) - 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. like, it's chill about it. β¨
- The
tep_register_function()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
tepargument is the trace event parser context. - The
nameis the name of the function, the string is copied internally. - The
addris the start address of the function. - The
modis the kernel module the function may be in (NULLfor none).
- The
- The
tep_register_print_string()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's format field which has an address needs to know what string would be at that address. Thetep_register_print_string()supplies the parsing with the mapping between kernel addresses and those strings.- The
tepargument is the trace event parser context. - The
fmtis the string to register, it is copied internally. - The
addris the address the string was located at.
- The
tep_get_function_count()returns the number of registered functions in atephandler. counting the girlies. π
π« RETURN VALUE π«
- The
tep_set_function_resolver()function returns0in case of success, or-1in case of an error. - The
tep_register_function()function returns0in case of success. In case of an error-1is returned, anderrnois set to the appropriate error number. - The
tep_register_print_string()function returns0in case of success. In case of an error-1is returned, anderrnois set to the appropriate error number.
fr fr, check that return value.0is the good one here. not-1. bestie. π
π₯ EXAMPLE π₯
here's the whole vibe in code form, copied exactly, don't @ me:
#include <event-parse.h>
...
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 */
}
...
π FILES π
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.
π SEE ALSO π
libtraceevent(3), trace-cmd(1)
π AUTHOR π
- Steven Rostedt <rostedt@goodmis.org>, author of libtraceevent.
- Tzvetomir Stoyanov <tz.stoyanov@gmail.com>, author of this man page.
π«Ά REPORTING BUGS π«Ά
Report bugs to <linux-trace-devel@vger.kernel.org>
π LICENSE π
libtraceevent is Free Software licensed under the GNU LGPL 2.1
β RESOURCES β
https://git.kernel.org/pub/scm/libs/libtrace/libtraceevent.git/
π§ NOTES π§
- rostedt@goodmis.org mailto:rostedt@goodmis.org
- tz.stoyanov@gmail.com mailto:tz.stoyanov@gmail.com
- linux-trace-devel@vger.kernel.org mailto:linux-trace-devel@vger.kernel.org
and that's the whole page, bestie!! this was libtraceevent 1.9.0, dated 06/15/2026, and it's LIBTRACEEVENT(3) forever and always. go register some functions, you absolute icon. πβ¨π
π¦ where this page comes from
- ubuntu stonking: libtraceevent-doc 1:1.9.0-2 Β· LGPL-2.1-only
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms