Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/paulus/powerpc
[deliverable/linux.git] / arch / powerpc / kernel / stacktrace.c
1 /*
2 * Stack trace utility
3 *
4 * Copyright 2008 Christoph Hellwig, IBM Corp.
5 *
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version
10 * 2 of the License, or (at your option) any later version.
11 */
12
13 #include <linux/sched.h>
14 #include <linux/stacktrace.h>
15 #include <asm/ptrace.h>
16
17 /*
18 * Save stack-backtrace addresses into a stack_trace buffer.
19 */
20 void save_stack_trace(struct stack_trace *trace)
21 {
22 unsigned long sp;
23
24 asm("mr %0,1" : "=r" (sp));
25
26 for (;;) {
27 unsigned long *stack = (unsigned long *) sp;
28 unsigned long newsp, ip;
29
30 if (!validate_sp(sp, current, STACK_FRAME_OVERHEAD))
31 return;
32
33 newsp = stack[0];
34 ip = stack[STACK_FRAME_LR_SAVE];
35
36 if (!trace->skip)
37 trace->entries[trace->nr_entries++] = ip;
38 else
39 trace->skip--;
40
41 if (trace->nr_entries >= trace->max_entries)
42 return;
43
44 sp = newsp;
45 }
46 }
This page took 0.034861 seconds and 6 git commands to generate.