Paul Mundt | afbfb52 | 2006-12-04 18:17:28 +0900 | [diff] [blame] | 1 | /* |
| 2 | * arch/sh/kernel/stacktrace.c |
| 3 | * |
| 4 | * Stack trace management functions |
| 5 | * |
Paul Mundt | 5a89f1a | 2008-09-13 01:44:03 +0900 | [diff] [blame] | 6 | * Copyright (C) 2006 - 2008 Paul Mundt |
Paul Mundt | afbfb52 | 2006-12-04 18:17:28 +0900 | [diff] [blame] | 7 | * |
| 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 Carstens | 8b95d91 | 2008-07-14 23:32:32 +0200 | [diff] [blame] | 15 | #include <linux/module.h> |
Paul Mundt | afbfb52 | 2006-12-04 18:17:28 +0900 | [diff] [blame] | 16 | #include <asm/ptrace.h> |
Matt Fleming | 4e14dfc | 2009-08-07 16:11:19 +0100 | [diff] [blame^] | 17 | #include <asm/stacktrace.h> |
| 18 | |
| 19 | static void save_stack_warning(void *data, char *msg) |
| 20 | { |
| 21 | } |
| 22 | |
| 23 | static void |
| 24 | save_stack_warning_symbol(void *data, char *msg, unsigned long symbol) |
| 25 | { |
| 26 | } |
| 27 | |
| 28 | static int save_stack_stack(void *data, char *name) |
| 29 | { |
| 30 | return 0; |
| 31 | } |
Paul Mundt | afbfb52 | 2006-12-04 18:17:28 +0900 | [diff] [blame] | 32 | |
| 33 | /* |
| 34 | * Save stack-backtrace addresses into a stack_trace buffer. |
| 35 | */ |
Matt Fleming | 4e14dfc | 2009-08-07 16:11:19 +0100 | [diff] [blame^] | 36 | static 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 | |
| 49 | static 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 Mundt | a3cf4ea8 | 2007-05-09 18:55:14 +0900 | [diff] [blame] | 56 | void save_stack_trace(struct stack_trace *trace) |
Paul Mundt | afbfb52 | 2006-12-04 18:17:28 +0900 | [diff] [blame] | 57 | { |
Christoph Hellwig | ab1b6f0 | 2007-05-08 00:23:29 -0700 | [diff] [blame] | 58 | unsigned long *sp = (unsigned long *)current_stack_pointer; |
Paul Mundt | afbfb52 | 2006-12-04 18:17:28 +0900 | [diff] [blame] | 59 | |
Matt Fleming | 4e14dfc | 2009-08-07 16:11:19 +0100 | [diff] [blame^] | 60 | dump_trace(current, NULL, sp, &save_stack_ops, trace); |
Paul Mundt | afbfb52 | 2006-12-04 18:17:28 +0900 | [diff] [blame] | 61 | } |
Ingo Molnar | 7b4c950 | 2008-07-03 09:17:55 +0200 | [diff] [blame] | 62 | EXPORT_SYMBOL_GPL(save_stack_trace); |
Paul Mundt | 5a89f1a | 2008-09-13 01:44:03 +0900 | [diff] [blame] | 63 | |
Matt Fleming | 4e14dfc | 2009-08-07 16:11:19 +0100 | [diff] [blame^] | 64 | static void |
| 65 | save_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 | |
| 81 | static 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 Mundt | 5a89f1a | 2008-09-13 01:44:03 +0900 | [diff] [blame] | 88 | void save_stack_trace_tsk(struct task_struct *tsk, struct stack_trace *trace) |
| 89 | { |
| 90 | unsigned long *sp = (unsigned long *)tsk->thread.sp; |
| 91 | |
Matt Fleming | 4e14dfc | 2009-08-07 16:11:19 +0100 | [diff] [blame^] | 92 | dump_trace(current, NULL, sp, &save_stack_ops_nosched, trace); |
Paul Mundt | 5a89f1a | 2008-09-13 01:44:03 +0900 | [diff] [blame] | 93 | } |
| 94 | EXPORT_SYMBOL_GPL(save_stack_trace_tsk); |