blob: 6c24a400b05e761dccb41f8c195c4374e508018b [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>
Paul Mundtafbfb522006-12-04 18:17:28 +090016#include <asm/ptrace.h>
Matt Fleming4e14dfc2009-08-07 16:11:19 +010017#include <asm/stacktrace.h>
18
19static void save_stack_warning(void *data, char *msg)
20{
21}
22
23static void
24save_stack_warning_symbol(void *data, char *msg, unsigned long symbol)
25{
26}
27
28static int save_stack_stack(void *data, char *name)
29{
30 return 0;
31}
Paul Mundtafbfb522006-12-04 18:17:28 +090032
33/*
34 * Save stack-backtrace addresses into a stack_trace buffer.
35 */
Matt Fleming4e14dfc2009-08-07 16:11:19 +010036static void save_stack_address(void *data, unsigned long addr, int reliable)
37{
38 struct stack_trace *trace = data;
39
40 if (trace->skip > 0) {
41 trace->skip--;
42 return;
43 }
44
45 if (trace->nr_entries < trace->max_entries)
46 trace->entries[trace->nr_entries++] = addr;
47}
48
49static const struct stacktrace_ops save_stack_ops = {
50 .warning = save_stack_warning,
51 .warning_symbol = save_stack_warning_symbol,
52 .stack = save_stack_stack,
53 .address = save_stack_address,
54};
55
Paul Mundta3cf4ea82007-05-09 18:55:14 +090056void save_stack_trace(struct stack_trace *trace)
Paul Mundtafbfb522006-12-04 18:17:28 +090057{
Christoph Hellwigab1b6f02007-05-08 00:23:29 -070058 unsigned long *sp = (unsigned long *)current_stack_pointer;
Paul Mundtafbfb522006-12-04 18:17:28 +090059
Matt Fleming4e14dfc2009-08-07 16:11:19 +010060 dump_trace(current, NULL, sp, &save_stack_ops, trace);
Paul Mundtafbfb522006-12-04 18:17:28 +090061}
Ingo Molnar7b4c9502008-07-03 09:17:55 +020062EXPORT_SYMBOL_GPL(save_stack_trace);
Paul Mundt5a89f1a2008-09-13 01:44:03 +090063
Matt Fleming4e14dfc2009-08-07 16:11:19 +010064static void
65save_stack_address_nosched(void *data, unsigned long addr, int reliable)
66{
67 struct stack_trace *trace = (struct stack_trace *)data;
68
69 if (in_sched_functions(addr))
70 return;
71
72 if (trace->skip > 0) {
73 trace->skip--;
74 return;
75 }
76
77 if (trace->nr_entries < trace->max_entries)
78 trace->entries[trace->nr_entries++] = addr;
79}
80
81static const struct stacktrace_ops save_stack_ops_nosched = {
82 .warning = save_stack_warning,
83 .warning_symbol = save_stack_warning_symbol,
84 .stack = save_stack_stack,
85 .address = save_stack_address_nosched,
86};
87
Paul Mundt5a89f1a2008-09-13 01:44:03 +090088void save_stack_trace_tsk(struct task_struct *tsk, struct stack_trace *trace)
89{
90 unsigned long *sp = (unsigned long *)tsk->thread.sp;
91
Matt Fleming4e14dfc2009-08-07 16:11:19 +010092 dump_trace(current, NULL, sp, &save_stack_ops_nosched, trace);
Paul Mundt5a89f1a2008-09-13 01:44:03 +090093}
94EXPORT_SYMBOL_GPL(save_stack_trace_tsk);