1*436bf2bcSAndroid Build Coastguard Workerlibtraceevent(3) 2*436bf2bcSAndroid Build Coastguard Worker================ 3*436bf2bcSAndroid Build Coastguard Worker 4*436bf2bcSAndroid Build Coastguard WorkerNAME 5*436bf2bcSAndroid Build Coastguard Worker---- 6*436bf2bcSAndroid Build Coastguard Workertep_set_function_resolver, tep_reset_function_resolver, tep_register_function, tep_register_print_string, 7*436bf2bcSAndroid Build Coastguard Workertep_get_function_count - function related tep APIs 8*436bf2bcSAndroid Build Coastguard Worker 9*436bf2bcSAndroid Build Coastguard WorkerSYNOPSIS 10*436bf2bcSAndroid Build Coastguard Worker-------- 11*436bf2bcSAndroid Build Coastguard Worker[verse] 12*436bf2bcSAndroid Build Coastguard Worker-- 13*436bf2bcSAndroid Build Coastguard Worker*#include <event-parse.h>* 14*436bf2bcSAndroid Build Coastguard Worker 15*436bf2bcSAndroid Build Coastguard Workertypedef char pass:[*](*tep_func_resolver_t*)(void pass:[*]_priv_, unsigned long long pass:[*]_addrp_, char pass:[**]_modp_); 16*436bf2bcSAndroid Build Coastguard Workerint *tep_set_function_resolver*(struct tep_handle pass:[*]_tep_, tep_func_resolver_t pass:[*]_func_, void pass:[*]_priv_); 17*436bf2bcSAndroid Build Coastguard Workervoid *tep_reset_function_resolver*(struct tep_handle pass:[*]_tep_); 18*436bf2bcSAndroid Build Coastguard Workerint *tep_register_function*(struct tep_handle pass:[*]_tep_, char pass:[*]_name_, unsigned long long _addr_, char pass:[*]_mod_); 19*436bf2bcSAndroid Build Coastguard Workerint *tep_register_print_string*(struct tep_handle pass:[*]_tep_, const char pass:[*]_fmt_, unsigned long long _addr_); 20*436bf2bcSAndroid Build Coastguard Workerint *tep_get_function_count*(struct tep_handle *_tep_) 21*436bf2bcSAndroid Build Coastguard Worker-- 22*436bf2bcSAndroid Build Coastguard Worker 23*436bf2bcSAndroid Build Coastguard WorkerDESCRIPTION 24*436bf2bcSAndroid Build Coastguard Worker----------- 25*436bf2bcSAndroid Build Coastguard WorkerSome tools may have already a way to resolve the kernel functions. These APIs 26*436bf2bcSAndroid Build Coastguard Workerallow them to keep using it instead of duplicating all the entries inside. 27*436bf2bcSAndroid Build Coastguard Worker 28*436bf2bcSAndroid Build Coastguard WorkerThe _tep_func_resolver_t_ type is the prototype of the alternative kernel 29*436bf2bcSAndroid Build Coastguard Workerfunctions resolver. This function receives a pointer to its custom context 30*436bf2bcSAndroid Build Coastguard Worker(set with the *tep_set_function_resolver()* call ) and the address of a kernel 31*436bf2bcSAndroid Build Coastguard Workerfunction, which has to be resolved. In case of success, it should return 32*436bf2bcSAndroid Build Coastguard Workerthe name of the function and its module (if any) in _modp_. 33*436bf2bcSAndroid Build Coastguard Worker 34*436bf2bcSAndroid Build Coastguard WorkerThe *tep_set_function_resolver()* function registers _func_ as an alternative 35*436bf2bcSAndroid Build Coastguard Workerkernel functions resolver. The _tep_ argument is trace event parser context. 36*436bf2bcSAndroid Build Coastguard WorkerThe _priv_ argument is a custom context of the _func_ function. The function 37*436bf2bcSAndroid Build Coastguard Workerresolver is used by the APIs *tep_find_function*(3), 38*436bf2bcSAndroid Build Coastguard Worker*tep_find_function_address*(3), and *tep_print_func_field()* to resolve 39*436bf2bcSAndroid Build Coastguard Workera function address to a function name. 40*436bf2bcSAndroid Build Coastguard Worker 41*436bf2bcSAndroid Build Coastguard WorkerThe *tep_reset_function_resolver()* function resets the kernel functions 42*436bf2bcSAndroid Build Coastguard Workerresolver to the default function. The _tep_ argument is trace event parser 43*436bf2bcSAndroid Build Coastguard Workercontext. 44*436bf2bcSAndroid Build Coastguard Worker 45*436bf2bcSAndroid Build Coastguard Worker 46*436bf2bcSAndroid Build Coastguard WorkerThese APIs can be used to find function name and start address, by given 47*436bf2bcSAndroid Build Coastguard Workeraddress. The given address does not have to be exact, it will select 48*436bf2bcSAndroid Build Coastguard Workerthe function that would contain it. 49*436bf2bcSAndroid Build Coastguard Worker 50*436bf2bcSAndroid Build Coastguard WorkerThe *tep_register_function()* function registers a function name mapped to an 51*436bf2bcSAndroid Build Coastguard Workeraddress and (optional) module. This mapping is used in case the function tracer 52*436bf2bcSAndroid Build Coastguard Workeror events have "%pS" parameter in its format string. It is common to pass in 53*436bf2bcSAndroid Build Coastguard Workerthe kallsyms function names with their corresponding addresses with this 54*436bf2bcSAndroid Build Coastguard Workerfunction. The _tep_ argument is the trace event parser context. The _name_ is 55*436bf2bcSAndroid Build Coastguard Workerthe name of the function, the string is copied internally. The _addr_ is the 56*436bf2bcSAndroid Build Coastguard Workerstart address of the function. The _mod_ is the kernel module the function may 57*436bf2bcSAndroid Build Coastguard Workerbe in (NULL for none). 58*436bf2bcSAndroid Build Coastguard Worker 59*436bf2bcSAndroid Build Coastguard WorkerThe *tep_register_print_string()* function registers a string by the address 60*436bf2bcSAndroid Build Coastguard Workerit was stored in the kernel. Some strings internal to the kernel with static 61*436bf2bcSAndroid Build Coastguard Workeraddress are passed to certain events. The "%s" in the event's format field 62*436bf2bcSAndroid Build Coastguard Workerwhich has an address needs to know what string would be at that address. The 63*436bf2bcSAndroid Build Coastguard Workertep_register_print_string() supplies the parsing with the mapping between kernel 64*436bf2bcSAndroid Build Coastguard Workeraddresses and those strings. The _tep_ argument is the trace event parser 65*436bf2bcSAndroid Build Coastguard Workercontext. The _fmt_ is the string to register, it is copied internally. 66*436bf2bcSAndroid Build Coastguard WorkerThe _addr_ is the address the string was located at. 67*436bf2bcSAndroid Build Coastguard Worker 68*436bf2bcSAndroid Build Coastguard Worker*tep_get_function_count*() returns the number of registered functions in a tep handler. 69*436bf2bcSAndroid Build Coastguard Worker 70*436bf2bcSAndroid Build Coastguard WorkerRETURN VALUE 71*436bf2bcSAndroid Build Coastguard Worker------------ 72*436bf2bcSAndroid Build Coastguard WorkerThe *tep_set_function_resolver()* function returns 0 in case of success, or -1 73*436bf2bcSAndroid Build Coastguard Workerin case of an error. 74*436bf2bcSAndroid Build Coastguard Worker 75*436bf2bcSAndroid Build Coastguard WorkerThe *tep_register_function()* function returns 0 in case of success. In case of 76*436bf2bcSAndroid Build Coastguard Workeran error -1 is returned, and errno is set to the appropriate error number. 77*436bf2bcSAndroid Build Coastguard Worker 78*436bf2bcSAndroid Build Coastguard WorkerThe *tep_register_print_string()* function returns 0 in case of success. In case 79*436bf2bcSAndroid Build Coastguard Workerof an error -1 is returned, and errno is set to the appropriate error number. 80*436bf2bcSAndroid Build Coastguard Worker 81*436bf2bcSAndroid Build Coastguard WorkerEXAMPLE 82*436bf2bcSAndroid Build Coastguard Worker------- 83*436bf2bcSAndroid Build Coastguard Worker[source,c] 84*436bf2bcSAndroid Build Coastguard Worker-- 85*436bf2bcSAndroid Build Coastguard Worker#include <event-parse.h> 86*436bf2bcSAndroid Build Coastguard Worker... 87*436bf2bcSAndroid Build Coastguard Workerstruct tep_handle *tep = tep_alloc(); 88*436bf2bcSAndroid Build Coastguard Worker... 89*436bf2bcSAndroid Build Coastguard Workerchar *my_resolve_kernel_addr(void *context, 90*436bf2bcSAndroid Build Coastguard Worker unsigned long long *addrp, char **modp) 91*436bf2bcSAndroid Build Coastguard Worker{ 92*436bf2bcSAndroid Build Coastguard Worker struct db *function_database = context; 93*436bf2bcSAndroid Build Coastguard Worker struct symbol *sym = sql_lookup(function_database, *addrp); 94*436bf2bcSAndroid Build Coastguard Worker 95*436bf2bcSAndroid Build Coastguard Worker if (!sym) 96*436bf2bcSAndroid Build Coastguard Worker return NULL; 97*436bf2bcSAndroid Build Coastguard Worker 98*436bf2bcSAndroid Build Coastguard Worker *modp = sym->module_name; 99*436bf2bcSAndroid Build Coastguard Worker return sym->name; 100*436bf2bcSAndroid Build Coastguard Worker} 101*436bf2bcSAndroid Build Coastguard Worker 102*436bf2bcSAndroid Build Coastguard Workervoid show_function( unsigned long long addr) 103*436bf2bcSAndroid Build Coastguard Worker{ 104*436bf2bcSAndroid Build Coastguard Worker unsigned long long fstart; 105*436bf2bcSAndroid Build Coastguard Worker const char *fname; 106*436bf2bcSAndroid Build Coastguard Worker 107*436bf2bcSAndroid Build Coastguard Worker if (tep_set_function_resolver(tep, my_resolve_kernel_addr, 108*436bf2bcSAndroid Build Coastguard Worker function_database) != 0) { 109*436bf2bcSAndroid Build Coastguard Worker /* failed to register my_resolve_kernel_addr */ 110*436bf2bcSAndroid Build Coastguard Worker } 111*436bf2bcSAndroid Build Coastguard Worker 112*436bf2bcSAndroid Build Coastguard Worker /* These APIs use my_resolve_kernel_addr() to resolve the addr */ 113*436bf2bcSAndroid Build Coastguard Worker fname = tep_find_function(tep, addr); 114*436bf2bcSAndroid Build Coastguard Worker fstart = tep_find_function_address(tep, addr); 115*436bf2bcSAndroid Build Coastguard Worker 116*436bf2bcSAndroid Build Coastguard Worker /* 117*436bf2bcSAndroid Build Coastguard Worker addr is in function named fname, starting at fstart address, 118*436bf2bcSAndroid Build Coastguard Worker at offset (addr - fstart) 119*436bf2bcSAndroid Build Coastguard Worker */ 120*436bf2bcSAndroid Build Coastguard Worker 121*436bf2bcSAndroid Build Coastguard Worker tep_reset_function_resolver(tep); 122*436bf2bcSAndroid Build Coastguard Worker 123*436bf2bcSAndroid Build Coastguard Worker} 124*436bf2bcSAndroid Build Coastguard Worker... 125*436bf2bcSAndroid Build Coastguard Worker if (tep_register_function(tep, "kvm_exit", 126*436bf2bcSAndroid Build Coastguard Worker (unsigned long long) 0x12345678, "kvm") != 0) { 127*436bf2bcSAndroid Build Coastguard Worker /* Failed to register kvm_exit address mapping */ 128*436bf2bcSAndroid Build Coastguard Worker } 129*436bf2bcSAndroid Build Coastguard Worker... 130*436bf2bcSAndroid Build Coastguard Worker if (tep_register_print_string(tep, "print string", 131*436bf2bcSAndroid Build Coastguard Worker (unsigned long long) 0x87654321, NULL) != 0) { 132*436bf2bcSAndroid Build Coastguard Worker /* Failed to register "print string" address mapping */ 133*436bf2bcSAndroid Build Coastguard Worker } 134*436bf2bcSAndroid Build Coastguard Worker... 135*436bf2bcSAndroid Build Coastguard Worker-- 136*436bf2bcSAndroid Build Coastguard Worker 137*436bf2bcSAndroid Build Coastguard WorkerFILES 138*436bf2bcSAndroid Build Coastguard Worker----- 139*436bf2bcSAndroid Build Coastguard Worker[verse] 140*436bf2bcSAndroid Build Coastguard Worker-- 141*436bf2bcSAndroid Build Coastguard Worker*event-parse.h* 142*436bf2bcSAndroid Build Coastguard Worker Header file to include in order to have access to the library APIs. 143*436bf2bcSAndroid Build Coastguard Worker*-ltraceevent* 144*436bf2bcSAndroid Build Coastguard Worker Linker switch to add when building a program that uses the library. 145*436bf2bcSAndroid Build Coastguard Worker-- 146*436bf2bcSAndroid Build Coastguard Worker 147*436bf2bcSAndroid Build Coastguard WorkerSEE ALSO 148*436bf2bcSAndroid Build Coastguard Worker-------- 149*436bf2bcSAndroid Build Coastguard Worker*libtraceevent*(3), *trace-cmd*(1) 150*436bf2bcSAndroid Build Coastguard Worker 151*436bf2bcSAndroid Build Coastguard WorkerAUTHOR 152*436bf2bcSAndroid Build Coastguard Worker------ 153*436bf2bcSAndroid Build Coastguard Worker[verse] 154*436bf2bcSAndroid Build Coastguard Worker-- 155*436bf2bcSAndroid Build Coastguard Worker*Steven Rostedt* <[email protected]>, author of *libtraceevent*. 156*436bf2bcSAndroid Build Coastguard Worker*Tzvetomir Stoyanov* <[email protected]>, author of this man page. 157*436bf2bcSAndroid Build Coastguard Worker-- 158*436bf2bcSAndroid Build Coastguard WorkerREPORTING BUGS 159*436bf2bcSAndroid Build Coastguard Worker-------------- 160*436bf2bcSAndroid Build Coastguard WorkerReport bugs to <[email protected]> 161*436bf2bcSAndroid Build Coastguard Worker 162*436bf2bcSAndroid Build Coastguard WorkerLICENSE 163*436bf2bcSAndroid Build Coastguard Worker------- 164*436bf2bcSAndroid Build Coastguard Workerlibtraceevent is Free Software licensed under the GNU LGPL 2.1 165*436bf2bcSAndroid Build Coastguard Worker 166*436bf2bcSAndroid Build Coastguard WorkerRESOURCES 167*436bf2bcSAndroid Build Coastguard Worker--------- 168*436bf2bcSAndroid Build Coastguard Workerhttps://git.kernel.org/pub/scm/libs/libtrace/libtraceevent.git/ 169