This source file includes following definitions.
- seed_unwind_frame_info
- arc_unwind_core
- __print_sym
- __collect_all
- __collect_all_but_sched
- __get_first_nonsched
- show_stacktrace
- show_stack
- get_wchan
- save_stack_trace_tsk
- save_stack_trace
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 #include <linux/ptrace.h>
25 #include <linux/export.h>
26 #include <linux/stacktrace.h>
27 #include <linux/kallsyms.h>
28 #include <linux/sched/debug.h>
29
30 #include <asm/arcregs.h>
31 #include <asm/unwind.h>
32 #include <asm/switch_to.h>
33
34
35
36
37
38
39 #ifdef CONFIG_ARC_DW2_UNWIND
40
41 static void seed_unwind_frame_info(struct task_struct *tsk,
42 struct pt_regs *regs,
43 struct unwind_frame_info *frame_info)
44 {
45
46
47
48
49 if (tsk == NULL && regs == NULL) {
50 unsigned long fp, sp, blink, ret;
51 frame_info->task = current;
52
53 __asm__ __volatile__(
54 "mov %0,r27\n\t"
55 "mov %1,r28\n\t"
56 "mov %2,r31\n\t"
57 "mov %3,r63\n\t"
58 : "=r"(fp), "=r"(sp), "=r"(blink), "=r"(ret)
59 );
60
61 frame_info->regs.r27 = fp;
62 frame_info->regs.r28 = sp;
63 frame_info->regs.r31 = blink;
64 frame_info->regs.r63 = ret;
65 frame_info->call_frame = 0;
66 } else if (regs == NULL) {
67
68
69
70
71
72
73 frame_info->task = tsk;
74
75 frame_info->regs.r27 = TSK_K_FP(tsk);
76 frame_info->regs.r28 = TSK_K_ESP(tsk);
77 frame_info->regs.r31 = TSK_K_BLINK(tsk);
78 frame_info->regs.r63 = (unsigned int)__switch_to;
79
80
81
82
83
84
85
86
87
88
89 frame_info->regs.r27 = 0;
90 frame_info->regs.r28 += 60;
91 frame_info->call_frame = 0;
92
93 } else {
94
95
96
97
98 frame_info->task = tsk;
99
100 frame_info->regs.r27 = regs->fp;
101 frame_info->regs.r28 = regs->sp;
102 frame_info->regs.r31 = regs->blink;
103 frame_info->regs.r63 = regs->ret;
104 frame_info->call_frame = 0;
105 }
106 }
107
108 #endif
109
110 notrace noinline unsigned int
111 arc_unwind_core(struct task_struct *tsk, struct pt_regs *regs,
112 int (*consumer_fn) (unsigned int, void *), void *arg)
113 {
114 #ifdef CONFIG_ARC_DW2_UNWIND
115 int ret = 0;
116 unsigned int address;
117 struct unwind_frame_info frame_info;
118
119 seed_unwind_frame_info(tsk, regs, &frame_info);
120
121 while (1) {
122 address = UNW_PC(&frame_info);
123
124 if (!address || !__kernel_text_address(address))
125 break;
126
127 if (consumer_fn(address, arg) == -1)
128 break;
129
130 ret = arc_unwind(&frame_info);
131 if (ret)
132 break;
133
134 frame_info.regs.r63 = frame_info.regs.r31;
135 }
136
137 return address;
138 #else
139
140
141
142
143
144 pr_warn_once("CONFIG_ARC_DW2_UNWIND needs to be enabled\n");
145 return 0;
146
147 #endif
148 }
149
150
151
152
153
154
155
156
157
158
159
160
161 static int __print_sym(unsigned int address, void *unused)
162 {
163 printk(" %pS\n", (void *)address);
164 return 0;
165 }
166
167 #ifdef CONFIG_STACKTRACE
168
169
170
171
172 static int __collect_all(unsigned int address, void *arg)
173 {
174 struct stack_trace *trace = arg;
175
176 if (trace->skip > 0)
177 trace->skip--;
178 else
179 trace->entries[trace->nr_entries++] = address;
180
181 if (trace->nr_entries >= trace->max_entries)
182 return -1;
183
184 return 0;
185 }
186
187 static int __collect_all_but_sched(unsigned int address, void *arg)
188 {
189 struct stack_trace *trace = arg;
190
191 if (in_sched_functions(address))
192 return 0;
193
194 if (trace->skip > 0)
195 trace->skip--;
196 else
197 trace->entries[trace->nr_entries++] = address;
198
199 if (trace->nr_entries >= trace->max_entries)
200 return -1;
201
202 return 0;
203 }
204
205 #endif
206
207 static int __get_first_nonsched(unsigned int address, void *unused)
208 {
209 if (in_sched_functions(address))
210 return 0;
211
212 return -1;
213 }
214
215
216
217
218
219
220 noinline void show_stacktrace(struct task_struct *tsk, struct pt_regs *regs)
221 {
222 pr_info("\nStack Trace:\n");
223 arc_unwind_core(tsk, regs, __print_sym, NULL);
224 }
225 EXPORT_SYMBOL(show_stacktrace);
226
227
228 void show_stack(struct task_struct *tsk, unsigned long *sp)
229 {
230 show_stacktrace(tsk, NULL);
231 }
232
233
234
235
236
237 unsigned int get_wchan(struct task_struct *tsk)
238 {
239 return arc_unwind_core(tsk, NULL, __get_first_nonsched, NULL);
240 }
241
242 #ifdef CONFIG_STACKTRACE
243
244
245
246
247
248 void save_stack_trace_tsk(struct task_struct *tsk, struct stack_trace *trace)
249 {
250
251 arc_unwind_core(tsk, NULL, __collect_all_but_sched, trace);
252 }
253
254 void save_stack_trace(struct stack_trace *trace)
255 {
256
257 arc_unwind_core(NULL, NULL, __collect_all, trace);
258 }
259 EXPORT_SYMBOL_GPL(save_stack_trace);
260 #endif