David S. Miller | 10e2672 | 2006-11-16 13:38:57 -0800 | [diff] [blame] | 1 | #include <linux/sched.h> |
| 2 | #include <linux/stacktrace.h> |
| 3 | #include <linux/thread_info.h> |
| 4 | #include <asm/ptrace.h> |
| 5 | |
| 6 | void save_stack_trace(struct stack_trace *trace, struct task_struct *task) |
| 7 | { |
| 8 | unsigned long ksp, fp, thread_base; |
| 9 | struct thread_info *tp; |
| 10 | |
| 11 | if (!task) |
| 12 | task = current; |
| 13 | tp = task_thread_info(task); |
| 14 | if (task == current) { |
| 15 | flushw_all(); |
| 16 | __asm__ __volatile__( |
| 17 | "mov %%fp, %0" |
| 18 | : "=r" (ksp) |
| 19 | ); |
| 20 | } else |
| 21 | ksp = tp->ksp; |
| 22 | |
| 23 | fp = ksp + STACK_BIAS; |
| 24 | thread_base = (unsigned long) tp; |
| 25 | do { |
| 26 | struct reg_window *rw; |
| 27 | |
| 28 | /* Bogus frame pointer? */ |
| 29 | if (fp < (thread_base + sizeof(struct thread_info)) || |
| 30 | fp >= (thread_base + THREAD_SIZE)) |
| 31 | break; |
| 32 | |
| 33 | rw = (struct reg_window *) fp; |
| 34 | if (trace->skip > 0) |
| 35 | trace->skip--; |
| 36 | else |
| 37 | trace->entries[trace->nr_entries++] = rw->ins[7]; |
| 38 | |
| 39 | fp = rw->ins[6] + STACK_BIAS; |
| 40 | } while (trace->nr_entries < trace->max_entries); |
| 41 | } |