blob: 45b1adde3abedeee3b928e6c28cd21195baaee04 [file] [log] [blame]
Paul Mundtafbfb522006-12-04 18:17:28 +09001/*
2 * arch/sh/kernel/stacktrace.c
3 *
4 * Stack trace management functions
5 *
Paul Mundt5a89f1a2008-09-13 01:44:03 +09006 * Copyright (C) 2006 - 2008 Paul Mundt
Paul Mundtafbfb522006-12-04 18:17:28 +09007 *
8 * This file is subject to the terms and conditions of the GNU General Public
9 * License. See the file "COPYING" in the main directory of this archive
10 * for more details.
11 */
12#include <linux/sched.h>
13#include <linux/stacktrace.h>
14#include <linux/thread_info.h>
Heiko Carstens8b95d912008-07-14 23:32:32 +020015#include <linux/module.h>
Matt Fleming0eff9f62009-08-11 22:43:20 +010016#include <asm/unwinder.h>
Paul Mundtafbfb522006-12-04 18:17:28 +090017#include <asm/ptrace.h>
Matt Fleming4e14dfc2009-08-07 16:11:19 +010018#include <asm/stacktrace.h>
19
20static void save_stack_warning(void *data, char *msg)
21{
22}
23
24static void
25save_stack_warning_symbol(void *data, char *msg, unsigned long symbol)
26{
27}
28
29static int save_stack_stack(void *data, char *name)
30{
31 return 0;
32}
Paul Mundtafbfb522006-12-04 18:17:28 +090033
34/*
35 * Save stack-backtrace addresses into a stack_trace buffer.
36 */
Matt Fleming4e14dfc2009-08-07 16:11:19 +010037static void save_stack_address(void *data, unsigned long addr, int reliable)
38{
39 struct stack_trace *trace = data;
40
41 if (trace->skip > 0) {
42 trace->skip--;
43 return;
44 }
45
46 if (trace->nr_entries < trace->max_entries)
47 trace->entries[trace->nr_entries++] = addr;
48}
49
50static const struct stacktrace_ops save_stack_ops = {
51 .warning = save_stack_warning,
52 .warning_symbol = save_stack_warning_symbol,
53 .stack = save_stack_stack,
54 .address = save_stack_address,
55};
56
Paul Mundta3cf4ea2007-05-09 18:55:14 +090057void save_stack_trace(struct stack_trace *trace)
Paul Mundtafbfb522006-12-04 18:17:28 +090058{
Christoph Hellwigab1b6f02007-05-08 00:23:29 -070059 unsigned long *sp = (unsigned long *)current_stack_pointer;
Paul Mundtafbfb522006-12-04 18:17:28 +090060
Matt Fleming0eff9f62009-08-11 22:43:20 +010061 unwind_stack(current, NULL, sp, &save_stack_ops, trace);
Paul Mundtafbfb522006-12-04 18:17:28 +090062}
Ingo Molnar7b4c9502008-07-03 09:17:55 +020063EXPORT_SYMBOL_GPL(save_stack_trace);
Paul Mundt5a89f1a2008-09-13 01:44:03 +090064
Matt Fleming4e14dfc2009-08-07 16:11:19 +010065static void
66save_stack_address_nosched(void *data, unsigned long addr, int reliable)
67{
68 struct stack_trace *trace = (struct stack_trace *)data;
69
70 if (in_sched_functions(addr))
71 return;
72
73 if (trace->skip > 0) {
74 trace->skip--;
75 return;
76 }
77
78 if (trace->nr_entries < trace->max_entries)
79 trace->entries[trace->nr_entries++] = addr;
80}
81
82static const struct stacktrace_ops save_stack_ops_nosched = {
83 .warning = save_stack_warning,
84 .warning_symbol = save_stack_warning_symbol,
85 .stack = save_stack_stack,
86 .address = save_stack_address_nosched,
87};
88
Paul Mundt5a89f1a2008-09-13 01:44:03 +090089void save_stack_trace_tsk(struct task_struct *tsk, struct stack_trace *trace)
90{
91 unsigned long *sp = (unsigned long *)tsk->thread.sp;
92
Matt Fleming0eff9f62009-08-11 22:43:20 +010093 unwind_stack(current, NULL, sp, &save_stack_ops_nosched, trace);
Paul Mundt5a89f1a2008-09-13 01:44:03 +090094}
95EXPORT_SYMBOL_GPL(save_stack_trace_tsk);