| 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> | 
 | 17 |  | 
 | 18 | /* | 
 | 19 |  * Save stack-backtrace addresses into a stack_trace buffer. | 
 | 20 |  */ | 
| Paul Mundt | a3cf4ea | 2007-05-09 18:55:14 +0900 | [diff] [blame] | 21 | void save_stack_trace(struct stack_trace *trace) | 
| Paul Mundt | afbfb52 | 2006-12-04 18:17:28 +0900 | [diff] [blame] | 22 | { | 
| Christoph Hellwig | ab1b6f0 | 2007-05-08 00:23:29 -0700 | [diff] [blame] | 23 | 	unsigned long *sp = (unsigned long *)current_stack_pointer; | 
| Paul Mundt | afbfb52 | 2006-12-04 18:17:28 +0900 | [diff] [blame] | 24 |  | 
 | 25 | 	while (!kstack_end(sp)) { | 
 | 26 | 		unsigned long addr = *sp++; | 
 | 27 |  | 
 | 28 | 		if (__kernel_text_address(addr)) { | 
 | 29 | 			if (trace->skip > 0) | 
 | 30 | 				trace->skip--; | 
 | 31 | 			else | 
 | 32 | 				trace->entries[trace->nr_entries++] = addr; | 
 | 33 | 			if (trace->nr_entries >= trace->max_entries) | 
 | 34 | 				break; | 
 | 35 | 		} | 
 | 36 | 	} | 
 | 37 | } | 
| Ingo Molnar | 7b4c950 | 2008-07-03 09:17:55 +0200 | [diff] [blame] | 38 | EXPORT_SYMBOL_GPL(save_stack_trace); | 
| Paul Mundt | 5a89f1a | 2008-09-13 01:44:03 +0900 | [diff] [blame] | 39 |  | 
 | 40 | void save_stack_trace_tsk(struct task_struct *tsk, struct stack_trace *trace) | 
 | 41 | { | 
 | 42 | 	unsigned long *sp = (unsigned long *)tsk->thread.sp; | 
 | 43 |  | 
 | 44 | 	while (!kstack_end(sp)) { | 
 | 45 | 		unsigned long addr = *sp++; | 
 | 46 |  | 
 | 47 | 		if (__kernel_text_address(addr)) { | 
 | 48 | 			if (in_sched_functions(addr)) | 
 | 49 | 				break; | 
 | 50 | 			if (trace->skip > 0) | 
 | 51 | 				trace->skip--; | 
 | 52 | 			else | 
 | 53 | 				trace->entries[trace->nr_entries++] = addr; | 
 | 54 | 			if (trace->nr_entries >= trace->max_entries) | 
 | 55 | 				break; | 
 | 56 | 		} | 
 | 57 | 	} | 
 | 58 | } | 
 | 59 | EXPORT_SYMBOL_GPL(save_stack_trace_tsk); |