xref: /aosp_15_r20/external/libtraceevent/Documentation/libtraceevent-func_find.txt (revision 436bf2bcd5202612ffffe471bbcc1f277cc8d28e)
1libtraceevent(3)
2================
3
4NAME
5----
6tep_find_function,tep_find_function_address,tep_find_function_info - Find function name / start address.
7
8SYNOPSIS
9--------
10[verse]
11--
12*#include <event-parse.h>*
13
14const char pass:[*]*tep_find_function*(struct tep_handle pass:[*]_tep_, unsigned long long _addr_);
15unsigned long long *tep_find_function_address*(struct tep_handle pass:[*]_tep_, unsigned long long _addr_);
16int *tep_find_function_info*(struct tep_handle pass:[*]_tep_, unsigned long long _addr_, const char pass:[**]_name_,
17			   unsigned long long pass:[*]_start_, unsigned long pass:[*]_size_);
18--
19
20DESCRIPTION
21-----------
22These functions can be used to find function name and start address, by given
23address. The given address does not have to be exact, it will select the function
24that would contain it.
25
26The *tep_find_function()* function returns the function name, which contains the
27given address _addr_. The _tep_ argument is the trace event parser context.
28
29The *tep_find_function_address()* function returns the function start address,
30by given address _addr_. The _addr_ does not have to be exact, it will select the
31function that would contain it. The _tep_ argument is the trace event parser context.
32
33The *tep_find_function_info()* function retrieves the _name_, starting address (_start_),
34and the function text _size_ of the function at _address_, if it is found. Note,
35if the _tep_ handle has a function resolver (used by perf), then _size_ is set to
36zero.
37
38RETURN VALUE
39------------
40The *tep_find_function()* function returns the function name, or NULL in case
41it cannot be found.
42
43The *tep_find_function_address()* function returns the function start address,
44or 0 in case it cannot be found.
45
46The *tep_find_function_info()* function returns 1 if a function is found for the
47given address, or 0 if it is not.
48
49EXAMPLE
50-------
51[source,c]
52--
53#include <event-parse.h>
54...
55struct tep_handle *tep = tep_alloc();
56...
57void show_function_name(unsigned long long addr)
58{
59	const char *fname = tep_find_function(tep, addr);
60
61	if (fname)
62		printf("Found function %s at 0x%0llx\n", fname, addr);
63	else
64		printf("No function found at 0x%0llx\n", addr);
65}
66
67void show_function_start_addr(unsigned long long addr)
68{
69	const char *fname = tep_find_function(tep, addr);
70	unsigned long long fstart;
71
72	if (!fname) {
73		printf("No function found at 0x%0llx\n", addr);
74		return;
75	}
76
77	fstart = tep_find_function_address(tep, addr);
78	printf("Function %s at 0x%llx starts at 0x%0llx\n",
79	       fname, addr, fstart);
80}
81
82void show_function_info(unsigned long long addr)
83{
84	const char *fname;
85	unsigned long long fstart;
86	unsigned long size;
87
88	ret = tep_find_function_info(tep, addr, &fname, &fstart, &size);
89	if (!ret) {
90		printf("No function found at 0x%0lx\n", addr);
91		return;
92	}
93
94	printf("Function %s at 0x%lx starts at 0x%0lx and is %ld in size\n",
95	       fname, addr, fstart, size);
96}
97...
98--
99
100FILES
101-----
102[verse]
103--
104*event-parse.h*
105	Header file to include in order to have access to the library APIs.
106*-ltraceevent*
107	Linker switch to add when building a program that uses the library.
108--
109
110SEE ALSO
111--------
112*libtraceevent*(3), *trace-cmd*(1)
113
114AUTHOR
115------
116[verse]
117--
118*Steven Rostedt* <[email protected]>, author of *libtraceevent*.
119*Tzvetomir Stoyanov* <[email protected]>, author of this man page.
120--
121REPORTING BUGS
122--------------
123Report bugs to  <[email protected]>
124
125LICENSE
126-------
127libtraceevent is Free Software licensed under the GNU LGPL 2.1
128
129RESOURCES
130---------
131https://git.kernel.org/pub/scm/libs/libtrace/libtraceevent.git/
132