]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - arch/sh/kernel/dumpstack.c
sched/headers: Prepare for new header dependencies before moving code to <linux/sched...
[mirror_ubuntu-bionic-kernel.git] / arch / sh / kernel / dumpstack.c
CommitLineData
4e14dfc7
MF
1/*
2 * Copyright (C) 1991, 1992 Linus Torvalds
3 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
4 * Copyright (C) 2009 Matt Fleming
49453264
PM
5 * Copyright (C) 2002 - 2012 Paul Mundt
6 *
7 * This file is subject to the terms and conditions of the GNU General Public
8 * License. See the file "COPYING" in the main directory of this archive
9 * for more details.
4e14dfc7
MF
10 */
11#include <linux/kallsyms.h>
12#include <linux/ftrace.h>
13#include <linux/debug_locks.h>
b17b0153 14#include <linux/sched/debug.h>
49453264
PM
15#include <linux/kdebug.h>
16#include <linux/export.h>
17#include <linux/uaccess.h>
0eff9f66 18#include <asm/unwinder.h>
4e14dfc7
MF
19#include <asm/stacktrace.h>
20
49453264
PM
21void dump_mem(const char *str, unsigned long bottom, unsigned long top)
22{
23 unsigned long p;
24 int i;
25
26 printk("%s(0x%08lx to 0x%08lx)\n", str, bottom, top);
27
28 for (p = bottom & ~31; p < top; ) {
29 printk("%04lx: ", p & 0xffff);
30
31 for (i = 0; i < 8; i++, p += 4) {
32 unsigned int val;
33
34 if (p < bottom || p >= top)
35 printk(" ");
36 else {
37 if (__get_user(val, (unsigned int __user *)p)) {
38 printk("\n");
39 return;
40 }
41 printk("%08x ", val);
42 }
43 }
44 printk("\n");
45 }
46}
47
4e14dfc7
MF
48void printk_address(unsigned long address, int reliable)
49{
50 printk(" [<%p>] %s%pS\n", (void *) address,
51 reliable ? "" : "? ", (void *) address);
52}
53
54#ifdef CONFIG_FUNCTION_GRAPH_TRACER
55static void
56print_ftrace_graph_addr(unsigned long addr, void *data,
57 const struct stacktrace_ops *ops,
58 struct thread_info *tinfo, int *graph)
59{
60 struct task_struct *task = tinfo->task;
61 unsigned long ret_addr;
62 int index = task->curr_ret_stack;
63
64 if (addr != (unsigned long)return_to_handler)
65 return;
66
67 if (!task->ret_stack || index < *graph)
68 return;
69
70 index -= *graph;
71 ret_addr = task->ret_stack[index].ret;
72
73 ops->address(data, ret_addr, 1);
74
75 (*graph)++;
76}
77#else
78static inline void
79print_ftrace_graph_addr(unsigned long addr, void *data,
80 const struct stacktrace_ops *ops,
81 struct thread_info *tinfo, int *graph)
82{ }
83#endif
84
0eff9f66
MF
85void
86stack_reader_dump(struct task_struct *task, struct pt_regs *regs,
87 unsigned long *sp, const struct stacktrace_ops *ops,
88 void *data)
4e14dfc7
MF
89{
90 struct thread_info *context;
91 int graph = 0;
92
93 context = (struct thread_info *)
94 ((unsigned long)sp & (~(THREAD_SIZE - 1)));
95
96 while (!kstack_end(sp)) {
97 unsigned long addr = *sp++;
98
99 if (__kernel_text_address(addr)) {
f9967e23 100 ops->address(data, addr, 1);
4e14dfc7
MF
101
102 print_ftrace_graph_addr(addr, data, ops,
103 context, &graph);
104 }
105 }
106}
4e14dfc7 107
4e14dfc7
MF
108static int print_trace_stack(void *data, char *name)
109{
110 printk("%s <%s> ", (char *)data, name);
111 return 0;
112}
113
114/*
115 * Print one address/symbol entries per line.
116 */
117static void print_trace_address(void *data, unsigned long addr, int reliable)
118{
a0c32761 119 printk("%s", (char *)data);
4e14dfc7
MF
120 printk_address(addr, reliable);
121}
122
123static const struct stacktrace_ops print_trace_ops = {
4e14dfc7
MF
124 .stack = print_trace_stack,
125 .address = print_trace_address,
126};
127
128void show_trace(struct task_struct *tsk, unsigned long *sp,
129 struct pt_regs *regs)
130{
131 if (regs && user_mode(regs))
132 return;
133
134 printk("\nCall trace:\n");
135
0eff9f66 136 unwind_stack(tsk, regs, sp, &print_trace_ops, "");
4e14dfc7
MF
137
138 printk("\n");
139
140 if (!tsk)
141 tsk = current;
142
143 debug_show_held_locks(tsk);
144}
49453264
PM
145
146void show_stack(struct task_struct *tsk, unsigned long *sp)
147{
148 unsigned long stack;
149
150 if (!tsk)
151 tsk = current;
152 if (tsk == current)
153 sp = (unsigned long *)current_stack_pointer;
154 else
155 sp = (unsigned long *)tsk->thread.sp;
156
157 stack = (unsigned long)sp;
158 dump_mem("Stack: ", stack, THREAD_SIZE +
159 (unsigned long)task_stack_page(tsk));
160 show_trace(tsk, sp, NULL);
161}