Debian Codegraph @

tapset/linux/ucontext-symbols.stp

raw
1 // User context symbols tapset
2 // Copyright (C) 2009-2016 Red Hat Inc.
3 //
4 // This file is part of systemtap, and is free software. You can
5 // redistribute it and/or modify it under the terms of the GNU General
6 // Public License (GPL); either version 2, or (at your option) any
7 // later version.
8
9 // <tapsetdescription>
10 // User context symbol functions provide additional information about
11 // addresses from an application. These functions can provide
12 // information about the user space map (library) that the event occurred or
13 // the function symbol of an address.
14 // </tapsetdescription>
15
16 @__private30 function __ustack_raw:long (n:long) %{ /* pragma:unwind */ /* pure */
17 /* myproc-unprivileged */ /* pragma:uprobes */
18 /* basic sanity check for bounds: */
19 if (unlikely(STAP_ARG_n < 0 || STAP_ARG_n >= MAXBACKTRACE))
20 STAP_RETVALUE = 0;
21 else
22 STAP_RETVALUE = _stp_stack_user_get (CONTEXT, (unsigned)STAP_ARG_n);
23 %}
24
25 /**
26 * sfunction ustack - Return address at given depth of user stack backtrace
27 * @n: number of levels to descend in the stack.
28 *
29 * Description: Performs a simple (user space) backtrace, and returns the
30 * element at the specified position. The results of the backtrace itself
31 * are cached, so that the backtrace computation is performed at most once
32 * no matter how many times ustack() is called, or in what order.
33 */
34 function ustack:long (n:long) {
35 __r = __ustack_raw(n);
36 if (__r != 0) return __r
37
38 /* fallback: parse backtrace() to go deeper in the stack */
39 __b = ubacktrace (); __orig_n = n;
40 __sym = tokenize (__b, " ");
41 if (__sym == "") @__context_unwind_error(__orig_n);
42 while (n > 0) {
43 __sym = tokenize ("", " ");
44 if (__sym == "") @__context_unwind_error(__orig_n);
45 n--;
46 }
47 return strtol(__sym, 16)
48 }
49
50 /**
51 * sfunction usymname - Return the symbol of an address in the current task.
52 * @addr: The address to translate.
53 *
54 * Description: Returns the (function) symbol name associated with the
55 * given address if known. If not known it will return the hex string
56 * representation of addr.
57 */
58 function usymname:string (addr: long) %{
59 /* pure */ /* myproc-unprivileged */ /* pragma:vma */ /* pragma:symbols */
60 _stp_snprint_addr(STAP_RETVALUE, MAXSTRINGLEN, STAP_ARG_addr,
61 _STP_SYM_SYMBOL, current, CONTEXT);
62 %}
63
64 /**
65 * sfunction usymdata - Return the symbol and module offset of an address.
66 * @addr: The address to translate.
67 *
68 * Description: Returns the (function) symbol name associated with the
69 * given address in the current task if known, the offset from the
70 * start and the size of the symbol, plus the module name (between
71 * brackets). If symbol is unknown, but module is known, the offset
72 * inside the module, plus the size of the module is added. If any
73 * element is not known it will be omitted and if the symbol name is
74 * unknown it will return the hex string for the given address.
75 */
76 function usymdata:string (addr: long) %{
77 /* pure */ /* myproc-unprivileged */ /* pragma:vma */ /* pragma:symbols */
78 _stp_snprint_addr(STAP_RETVALUE, MAXSTRINGLEN, STAP_ARG_addr,
79 _STP_SYM_DATA, current, CONTEXT);
80 %}
81
82 /**
83 * sfunction print_ustack - Print out stack for the current task from string.
84 * @stk: String with list of hexadecimal addresses for the current task.
85 *
86 * Perform a symbolic lookup of the addresses in the given string,
87 * which is assumed to be the result of a prior call to
88 * ubacktrace() for the current task.
89 *
90 * Print one line per address, including the address, the
91 * name of the function containing the address, and an estimate of
92 * its position within that function. Return nothing.
93 *
94 * NOTE: it is recommended to use print_usyms() instead of this function.
95 */
96 function print_ustack(stk:string) { print_usyms(stk) }
97
98 /**
99 * sfunction print_usyms - Print out user stack from string
100 * @callers: String with list of hexadecimal (user) addresses
101 *
102 * Description: This function performs a symbolic lookup of the addresses
103 * in the given string,
104 * which are assumed to be the result of prior calls to ustack(),
105 * ucallers(), and similar functions.
106 *
107 * Prints one line per address, including the address, the
108 * name of the function containing the address, and an estimate of
109 * its position within that function, as obtained by usymdata().
110 * Returns nothing.
111 */
112 function print_usyms (callers:string) {
113 __sym = tokenize (callers, " ");
114 while (__sym != "") {
115 printf (" %s : %s\n", __sym, usymdata (strtol(__sym,16)));
116 __sym = tokenize ("", " ");
117 }
118 }
119
120 /**
121 * sfunction sprint_ustack - Return stack for the current task from string.
122 * @stk: String with list of hexadecimal addresses for the current task.
123 *
124 * Perform a symbolic lookup of the addresses in the given string,
125 * which is assumed to be the result of a prior call to
126 * ubacktrace() for the current task.
127 *
128 * Returns a simple backtrace from the given hex string. One line per
129 * address. Includes the symbol name (or hex address if symbol
130 * couldn't be resolved) and module name (if found). Includes the
131 * offset from the start of the function if found, otherwise the
132 * offset will be added to the module (if found, between
133 * brackets). Returns the backtrace as string (each line terminated by
134 * a newline character). Note that the returned stack will be
135 * truncated to MAXSTRINGLEN, to print fuller and richer stacks use
136 * print_ustack.
137 *
138 * NOTE: it is recommended to use sprint_usyms() instead of this function.
139 */
140 function sprint_ustack:string(stk:string) { return sprint_usyms(stk) }
141
142 /**
143 * sfunction sprint_usyms - Return stack for user addresses from string
144 *
145 * @callers: String with list of hexadecimal (user) addresses
146 *
147 * Perform a symbolic lookup of the addresses in the given string,
148 * which are assumed to be the result of a prior calls to ustack(),
149 * ucallers(), and similar functions.
150 *
151 * Returns a simple backtrace from the given hex string. One line per
152 * address. Includes the symbol name (or hex address if symbol
153 * couldn't be resolved) and module name (if found), as obtained from
154 * usymdata(). Includes the offset from the start of the function if
155 * found, otherwise the offset will be added to the module (if found, between
156 * brackets). Returns the backtrace as string (each line terminated by
157 * a newline character). Note that the returned stack will be
158 * truncated to MAXSTRINGLEN, to print fuller and richer stacks use
159 * print_usyms().
160 */
161 function sprint_usyms (callers:string) {
162 __sym = tokenize (callers, " ");
163 __foo = ""; __l = 0
164 while (__sym != "") {
165 // cleanly handle overflow instead of printing partial line:
166 __line = sprintf (" %s : %s\n", __sym,
167 usymdata (strtol(__sym,16)));
168 __l += strlen(__line)
169 if (__l > @MAXSTRINGLEN) break
170 __foo .= __line
171 __sym = tokenize ("", " ")
172 }
173 return __foo
174 }
175
176 /**
177 * sfunction usymfileline - Return the file name and line number of an address.
178 * @addr: The address to translate.
179 *
180 * Description: Returns the file name and the (approximate) line number of the
181 * given address, if known. If the file name or the line number cannot be
182 * found, the hex string representation of the address will be returned.
183 */
184 function usymfileline:string (addr:long) %{
185 /* pure */ /* myproc-unprivileged */ /* pragma:symbols */ /* pragma:vma */ /* pragma:lines */
186 _stp_snprint_addr(STAP_RETVALUE, MAXSTRINGLEN, STAP_ARG_addr,
187 _STP_SYM_LINENUMBER + _STP_SYM_FILENAME, current, CONTEXT);
188 %}
189
190 /**
191 * sfunction usymfile - Return the file name of a given address.
192 * @addr: The address to translate.
193 *
194 * Description: Returns the file name of the given address, if known. If the
195 * file name cannot be found, the hex string representation of the address
196 * will be returned.
197 */
198 function usymfile:string (addr:long) %{
199 /* pure */ /* myproc-unprivileged */ /* pragma:symbols */ /* pragma:vma */ /* pragma:lines */
200 _stp_snprint_addr(STAP_RETVALUE, MAXSTRINGLEN, STAP_ARG_addr,
201 _STP_SYM_FILENAME, current, CONTEXT);
202 %}
203
204 /**
205 * sfunction usymline - Return the line number of an address.
206 * @addr: The address to translate.
207 *
208 * Description: Returns the (approximate) line number of the given address, if
209 * known. If the line number cannot be found, the hex string representation of
210 * the address will be returned.
211 */
212 function usymline:string (addr:long) %{
213 /* pure */ /* myproc-unprivileged */ /* pragma:symbols */ /* pragma:vma */ /* pragma:lines */
214 _stp_snprint_addr(STAP_RETVALUE, MAXSTRINGLEN, STAP_ARG_addr,
215 _STP_SYM_LINENUMBER, current, CONTEXT);
216 %}