]> sourceware.org Git - systemtap.git/blob - tapset/context-symbols.stp
Rename CONTEXT regflags to probe_flags. Now simply indicates user mode.
[systemtap.git] / tapset / context-symbols.stp
1 // context-symbols tapset
2 // Copyright (C) 2005-2008, 2011 Red Hat Inc.
3 // Copyright (C) 2006 Intel Corporation.
4 //
5 // This file is part of systemtap, and is free software. You can
6 // redistribute it and/or modify it under the terms of the GNU General
7 // Public License (GPL); either version 2, or (at your option) any
8 // later version.
9 // <tapsetdescription>
10 // Context functions provide additional information about where an event occurred. These functions can
11 //provide information such as a backtrace to where the event occurred and the current register values for the
12 //processor.
13 // </tapsetdescription>
14
15 /**
16 * sfunction print_stack - Print out kernel stack from string
17 * @stk: String with list of hexadecimal addresses
18 *
19 * Description: This function performs a symbolic lookup of the addresses
20 * in the given string,
21 * which is assumed to be the result of a prior call to
22 * backtrace().
23 *
24 * Print one line per address, including the address, the
25 * name of the function containing the address, and an estimate of
26 * its position within that function. Return nothing.
27 */
28 function print_stack(stk:string) %{ /* pragma:symbols */
29 char *ptr = THIS->stk;
30 char *tok = strsep(&ptr, " ");
31 while (tok && *tok) {
32 _stp_print_addr (simple_strtol(tok, NULL, 16),
33 _STP_SYM_FULL, NULL);
34 tok = strsep(&ptr, " ");
35 }
36 %}
37
38 /**
39 * sfunction sprint_stack - Return stack for kernel addresses from string (EXPERIMENTAL)
40 * @stk: String with list of hexadecimal (kernel) addresses
41 *
42 * Perform a symbolic lookup of the addresses in the given string,
43 * which is assumed to be the result of a prior call to backtrace().
44 *
45 * Returns a simple backtrace from the given hex string. One line per
46 * address. Includes the symbol name (or hex address if symbol
47 * couldn't be resolved) and module name (if found). Includes the
48 * offset from the start of the function if found, otherwise the
49 * offset will be added to the module (if found, between
50 * brackets). Returns the backtrace as string (each line terminated by
51 * a newline character). Note that the returned stack will be
52 * truncated to MAXSTRINGLEN, to print fuller and richer stacks use
53 * print_stack.
54 */
55 function sprint_stack:string(stk:string) %{ /* pure */ /* pragma:symbols */
56 char *ptr = THIS->stk;
57 char *tok = strsep(&ptr, " ");
58 char *str = THIS->__retvalue;
59 size_t len = MAXSTRINGLEN - 1;
60 while (tok && *tok && len > 0) {
61 int s = _stp_snprint_addr(str, len,
62 simple_strtol(tok, NULL, 16),
63 _STP_SYM_SIMPLE, NULL);
64 len -= s;
65 str += s;
66 tok = strsep(&ptr, " ");
67 }
68
69 str--;
70 if (len > 0)
71 str[0] = '\0';
72 else
73 THIS->__retvalue[MAXSTRINGLEN - 1] = '\0';
74 %}
75
76 /**
77 * sfunction probefunc - Return the probe point's function name, if known
78 *
79 * Description: This function returns the name of the function being probed.
80 * It will do this based on the probe point string as returned by pp().
81 * Please note: this function is deprecated, please use symname() and/or
82 * usymname(). This function might return a function name based on the
83 * current address if the probe point context couldn't be parsed.
84 */
85 function probefunc:string () %{ /* pure */ /* pragma:symbols */
86 char *ptr, *start;
87
88 start = strstr(CONTEXT->probe_point, "function(\"");
89 ptr = start + 10;
90 if (!start) {
91 start = strstr(CONTEXT->probe_point, "inline(\"");
92 ptr = start + 8;
93 }
94
95 if (start) {
96 int len = MAXSTRINGLEN;
97 char *dst = THIS->__retvalue;
98 while (*ptr != '@' && *ptr != '"' && --len > 0 && *ptr)
99 *dst++ = *ptr++;
100 *dst = 0;
101
102 } else if (CONTEXT->regs) {
103 _stp_snprint_addr(THIS->__retvalue, MAXSTRINGLEN,
104 REG_IP(CONTEXT->regs),
105 _STP_SYM_SYMBOL,
106 (CONTEXT->probe_flags & _STP_PROBE_STATE_USER_MODE
107 ? current : NULL));
108 if (THIS->__retvalue[0] == '.') /* powerpc symbol has a dot*/
109 strlcpy(THIS->__retvalue,THIS->__retvalue + 1,MAXSTRINGLEN);
110 } else {
111 THIS->__retvalue[0] = '\0';
112 }
113 %}
114
115 /**
116 * sfunction probemod - Return the probe point's kernel module name
117 *
118 * Description: This function returns the name of the kernel module
119 * containing the probe point, if known.
120 */
121 function probemod:string () %{ /* pure */
122 char *ptr, *start;
123
124 start = strstr(CONTEXT->probe_point, "module(\"");
125 ptr = start + 8;
126
127 if (start) {
128 int len = MAXSTRINGLEN;
129 char *dst = THIS->__retvalue;
130 while (*ptr != '"' && --len && *ptr)
131 *dst++ = *ptr++;
132 *dst = 0;
133 } else if (CONTEXT->regs
134 && ! (CONTEXT->probe_flags & _STP_PROBE_STATE_USER_MODE)) {
135 struct _stp_module *m;
136 m = _stp_kmod_sec_lookup (REG_IP(CONTEXT->regs), NULL);
137 if (m && m->name)
138 strlcpy (THIS->__retvalue, m->name, MAXSTRINGLEN);
139 else
140 strlcpy (THIS->__retvalue, "<unknown>", MAXSTRINGLEN);
141 } else
142 strlcpy (THIS->__retvalue, "<unknown>", MAXSTRINGLEN);
143 %}
144
145 /**
146 * sfunction modname - Return the kernel module name loaded at the address
147 * @addr: The address to map to a kernel module name
148 *
149 * Description: Returns the module name associated with the given
150 * address if known. If not known it will return the string "<unknown>".
151 * If the address was not in a kernel module, but in the kernel itself,
152 * then the string "kernel" will be returned.
153 */
154 function modname:string (addr: long) %{ /* pure */
155 struct _stp_module *m;
156 m = _stp_kmod_sec_lookup (THIS->addr, NULL);
157 if (m && m->name)
158 strlcpy (THIS->__retvalue, m->name, MAXSTRINGLEN);
159 else
160 strlcpy (THIS->__retvalue, "<unknown>", MAXSTRINGLEN);
161 %}
162
163 /**
164 * sfunction symname - Return the kernel symbol associated with the given address
165 * @addr: The address to translate
166 *
167 * Description: Returns the (function) symbol name associated with the
168 * given address if known. If not known it will return the hex string
169 * representation of addr.
170 */
171 function symname:string (addr: long) %{ /* pure */ /* pragma:symbols */
172 _stp_snprint_addr(THIS->__retvalue, MAXSTRINGLEN, THIS->addr,
173 _STP_SYM_SYMBOL, NULL);
174 %}
175
176 /**
177 * sfunction symdata - Return the kernel symbol and module offset for the address
178 * @addr: The address to translate
179 *
180 * Description: Returns the (function) symbol name associated with the
181 * given address if known, the offset from the start and size of the
182 * symbol, plus module name (between brackets). If symbol is unknown,
183 * but module is known, the offset inside the module, plus the size of
184 * the module is added. If any element is not known it will be
185 * omitted and if the symbol name is unknown it will return the hex
186 * string for the given address.
187 */
188 function symdata:string (addr: long) %{ /* pure */ /* pragma:symbols */
189 _stp_snprint_addr(THIS->__retvalue, MAXSTRINGLEN, THIS->addr,
190 _STP_SYM_DATA, NULL);
191 %}
This page took 0.044101 seconds and 5 git commands to generate.