Debian Codegraph @

tapset/linux/ucontext-unwind.stp

raw
1 // User context unwind tapset
2 // Copyright (C) 2009-2019 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 /**
10 * sfunction print_ubacktrace - Print stack back trace for current user-space task.
11 *
12 * Equivalent to print_ustack(ubacktrace()), except that deeper stack
13 * nesting may be supported. Returns nothing. See print_backtrace()
14 * for kernel backtrace.
15 *
16 * Note: To get (full) backtraces for user space applications and shared
17 * shared libraries not mentioned in the current script run stap with
18 * -d /path/to/exe-or-so and/or add --ldd to load all needed unwind data.
19 */
20 function print_ubacktrace () %{ /* pragma:unwind */ /* pragma:symbols */
21 /* myproc-unprivileged */ /* pragma:uprobes */ /* pragma:vma */
22 _stp_stack_user_print(CONTEXT, _STP_SYM_FULL);
23 %}
24
25 /**
26 * sfunction print_ubacktrace - Print stack back trace for current user-space task.
27 * @pc: override PC
28 * @sp: override SP
29 * @fp: override FP
30 *
31 * Equivalent to print_ubacktrace(), but it performs the backtrace
32 * using the pc, sp, and fp provided. Useful
33 *
34 * Note: To get (full) backtraces for user space applications and shared
35 * shared libraries not mentioned in the current script run stap with
36 * -d /path/to/exe-or-so and/or add --ldd to load all needed unwind data.
37 */
38 function print_ubacktrace (pc:long, sp:long, fp:long) %{ /* pragma:unwind */ /* pragma:symbols */
39 /* myproc-unprivileged */ /* pragma:uprobes */ /* pragma:vma */
40 unsigned long saved_pc, saved_sp, saved_fp;
41
42 if (_stp_get_uregs(CONTEXT) == NULL) {
43 _stp_stack_user_print(CONTEXT, _STP_SYM_FULLER); /* expecting a failure message */
44 STAP_RETURN();
45 }
46
47 saved_pc = REG_IP(CONTEXT->uregs);
48 saved_sp = REG_SP(CONTEXT->uregs);
49 SET_REG_IP(CONTEXT->uregs, STAP_ARG_pc);
50 REG_SP(CONTEXT->uregs) = STAP_ARG_sp;
51 #if defined REG_FP
52 saved_fp = REG_FP(CONTEXT->uregs);
53 REG_FP(CONTEXT->uregs) = STAP_ARG_fp;
54 #elif defined REG_LINK
55 saved_fp = REG_LINK(CONTEXT->uregs);
56 REG_LINK(CONTEXT->uregs) = STAP_ARG_fp;
57 #endif
58
59 CONTEXT->uwcache_user.state = uwcache_uninitialized;
60 _stp_stack_user_print(CONTEXT, _STP_SYM_FULL);
61 CONTEXT->uwcache_user.state = uwcache_uninitialized;
62
63 SET_REG_IP(CONTEXT->uregs, saved_pc);
64 REG_SP(CONTEXT->uregs) = saved_sp;
65 #if defined REG_FP
66 REG_FP(CONTEXT->uregs) = saved_fp;
67 #elif defined REG_LINK
68 REG_LINK(CONTEXT->uregs) = saved_fp;
69 #endif
70 %}
71
72 /**
73 * sfunction sprint_ubacktrace - Return stack back trace for current user-space task as string.
74 *
75 * Returns a simple backtrace for the current task. One line per
76 * address. Includes the symbol name (or hex address if symbol
77 * couldn't be resolved) and module name (if found). Includes the
78 * offset from the start of the function if found, otherwise the
79 * offset will be added to the module (if found, between
80 * brackets). Returns the backtrace as string (each line terminated by
81 * a newline character). Note that the returned stack will be
82 * truncated to MAXSTRINGLEN, to print fuller and richer stacks use
83 * print_ubacktrace(). Equivalent to sprint_ustack(ubacktrace()),
84 * but more efficient (no need to translate between hex strings and
85 * final backtrace string).
86 *
87 * Note: To get (full) backtraces for user space applications and shared
88 * shared libraries not mentioned in the current script run stap with
89 * -d /path/to/exe-or-so and/or add --ldd to load all needed unwind data.
90 */
91 function sprint_ubacktrace:string () %{ /* pragma:unwind */ /* pragma:symbols */
92 /* pure */ /* myproc-unprivileged */ /* pragma:uprobes */ /* pragma:vma */
93 _stp_stack_user_sprint (STAP_RETVALUE, MAXSTRINGLEN, CONTEXT,
94 _STP_SYM_SIMPLE);
95 %}
96
97 /**
98 * sfunction print_ubacktrace_brief- Print stack back trace for current user-space task.
99 *
100 * Equivalent to print_ubacktrace(), but output for each symbol is
101 * shorter (just name and offset, or just the hex address of no symbol
102 * could be found).
103 *
104 * Note: To get (full) backtraces for user space applications and shared
105 * shared libraries not mentioned in the current script run stap with
106 * -d /path/to/exe-or-so and/or add --ldd to load all needed unwind data.
107 */
108 function print_ubacktrace_brief () %{ /* pragma:unwind */ /* pragma:symbols */
109 /* myproc-unprivileged */ /* pragma:uprobes */ /* pragma:vma */
110 _stp_stack_user_print(CONTEXT, _STP_SYM_BRIEF);
111 %}
112
113 /**
114 * sfunction print_ubacktrace_fileline - Print stack back trace for current user-space task.
115 *
116 * Equivalent to print_ubacktrace(), but output for each symbol is
117 * longer including file names and line numbers.
118 *
119 * Note: To get (full) backtraces for user space applications and shared
120 * shared libraries not mentioned in the current script run stap with
121 * -d /path/to/exe-or-so and/or add --ldd to load all needed unwind data.
122 */
123 function print_ubacktrace_fileline () %{ /* pragma:unwind */ /* pragma:symbols */
124 /* myproc-unprivileged */ /* pragma:uprobes */ /* pragma:vma */ /* pragma:lines */
125 _stp_stack_user_print(CONTEXT, _STP_SYM_FULLER);
126 %}
127
128 /**
129 * sfunction print_ubacktrace - Print stack back trace for current user-space task.
130 * @pc: override PC
131 * @sp: override SP
132 * @fp: override FP
133 *
134 * Equivalent to print_ubacktrace_fileline(), but it performs the backtrace
135 * using the pc, sp, and fp passed in.
136 *
137 * Note: To get (full) backtraces for user space applications and shared
138 * shared libraries not mentioned in the current script run stap with
139 * -d /path/to/exe-or-so and/or add --ldd to load all needed unwind data.
140 */
141 function print_ubacktrace_fileline (pc:long, sp:long, fp:long) %{ /* pragma:unwind */ /* pragma:symbols */
142 /* myproc-unprivileged */ /* pragma:uprobes */ /* pragma:vma */ /* pragma:lines */
143 unsigned long saved_pc, saved_sp, saved_fp;
144
145 if (_stp_get_uregs(CONTEXT) == NULL) {
146 _stp_stack_user_print(CONTEXT, _STP_SYM_FULLER); /* expecting a failure message */
147 STAP_RETURN();
148 }
149
150 saved_pc = REG_IP(CONTEXT->uregs);
151 saved_sp = REG_SP(CONTEXT->uregs);
152 SET_REG_IP(CONTEXT->uregs, STAP_ARG_pc);
153 REG_SP(CONTEXT->uregs) = STAP_ARG_sp;
154 #if defined REG_FP
155 saved_fp = REG_FP(CONTEXT->uregs);
156 REG_FP(CONTEXT->uregs) = STAP_ARG_fp;
157 #elif defined REG_LINK
158 saved_fp = REG_LINK(CONTEXT->uregs);
159 REG_LINK(CONTEXT->uregs) = STAP_ARG_fp;
160 #endif
161
162 CONTEXT->uwcache_user.state = uwcache_uninitialized;
163 _stp_stack_user_print(CONTEXT, _STP_SYM_FULLER);
164 CONTEXT->uwcache_user.state = uwcache_uninitialized;
165
166 SET_REG_IP(CONTEXT->uregs, saved_pc);
167 REG_SP(CONTEXT->uregs) = saved_sp;
168 #if defined REG_FP
169 REG_FP(CONTEXT->uregs) = saved_fp;
170 #elif defined REG_LINK
171 REG_LINK(CONTEXT->uregs) = saved_fp;
172 #endif
173 %}
174
175 /**
176 * sfunction ubacktrace - Hex backtrace of current user-space task stack.
177 *
178 * Return a string of hex addresses that are a backtrace of the
179 * stack of the current task. Output may be truncated as per maximum
180 * string length. Returns empty string when current probe point cannot
181 * determine user backtrace. See backtrace() for kernel traceback.
182 *
183 * Note: To get (full) backtraces for user space applications and shared
184 * shared libraries not mentioned in the current script run stap with
185 * -d /path/to/exe-or-so and/or add --ldd to load all needed unwind data.
186 */
187 function ubacktrace:string () %{ /* pragma:unwind */
188 /* pure */ /* myproc-unprivileged */ /* pragma:uprobes */ /* pragma:vma */
189 _stp_stack_user_sprint (STAP_RETVALUE, MAXSTRINGLEN, CONTEXT,
190 _STP_SYM_NONE);
191 %}