stacktrace.c 1.1 KB
Newer Older
1 2 3 4
#include <linux/sched.h>
#include <linux/stacktrace.h>
#include <linux/thread_info.h>
#include <asm/ptrace.h>
5
#include <asm/stacktrace.h>
6

C
Christoph Hellwig 已提交
7
void save_stack_trace(struct stack_trace *trace)
8 9
{
	unsigned long ksp, fp, thread_base;
C
Christoph Hellwig 已提交
10
	struct thread_info *tp = task_thread_info(current);
11

12 13
	stack_trace_flush();

C
Christoph Hellwig 已提交
14 15 16 17
	__asm__ __volatile__(
		"mov	%%fp, %0"
		: "=r" (ksp)
	);
18 19 20 21

	fp = ksp + STACK_BIAS;
	thread_base = (unsigned long) tp;
	do {
22
		struct sparc_stackf *sf;
23 24
		struct pt_regs *regs;
		unsigned long pc;
25 26 27 28 29 30

		/* Bogus frame pointer? */
		if (fp < (thread_base + sizeof(struct thread_info)) ||
		    fp >= (thread_base + THREAD_SIZE))
			break;

31 32
		sf = (struct sparc_stackf *) fp;
		regs = (struct pt_regs *) (sf + 1);
33 34

		if ((regs->magic & ~0x1ff) == PT_REGS_MAGIC) {
35 36
			if (!(regs->tstate & TSTATE_PRIV))
				break;
37 38 39
			pc = regs->tpc;
			fp = regs->u_regs[UREG_I6] + STACK_BIAS;
		} else {
40 41
			pc = sf->callers_pc;
			fp = (unsigned long)sf->fp + STACK_BIAS;
42 43
		}

44 45 46
		if (trace->skip > 0)
			trace->skip--;
		else
47
			trace->entries[trace->nr_entries++] = pc;
48 49
	} while (trace->nr_entries < trace->max_entries);
}