dumpstack.c 1.0 KB
Newer Older
G
Guo Ren 已提交
1 2 3 4 5 6 7 8 9
// SPDX-License-Identifier: GPL-2.0
// Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd.

#include <linux/ptrace.h>

int kstack_depth_to_print = 48;

void show_trace(unsigned long *stack)
{
G
Guo Ren 已提交
10 11 12
	unsigned long *stack_end;
	unsigned long *stack_start;
	unsigned long *fp;
G
Guo Ren 已提交
13 14
	unsigned long addr;

G
Guo Ren 已提交
15 16 17 18 19 20 21 22 23 24 25 26 27
	addr = (unsigned long) stack & THREAD_MASK;
	stack_start = (unsigned long *) addr;
	stack_end = (unsigned long *) (addr + THREAD_SIZE);

	fp = stack;
	pr_info("\nCall Trace:");

	while (fp > stack_start && fp < stack_end) {
#ifdef CONFIG_STACKTRACE
		addr	= fp[1];
		fp	= (unsigned long *) fp[0];
#else
		addr	= *fp++;
G
Guo Ren 已提交
28
#endif
G
Guo Ren 已提交
29 30
		if (__kernel_text_address(addr))
			pr_cont("\n[<%08lx>] %pS", addr, (void *)addr);
G
Guo Ren 已提交
31 32 33 34 35 36 37 38
	}
	pr_cont("\n");
}

void show_stack(struct task_struct *task, unsigned long *stack)
{
	if (!stack) {
		if (task)
G
Guo Ren 已提交
39
			stack = (unsigned long *)thread_saved_fp(task);
G
Guo Ren 已提交
40
		else
G
Guo Ren 已提交
41 42 43
#ifdef CONFIG_STACKTRACE
			asm volatile("mov %0, r8\n":"=r"(stack)::"memory");
#else
G
Guo Ren 已提交
44
			stack = (unsigned long *)&stack;
G
Guo Ren 已提交
45
#endif
G
Guo Ren 已提交
46 47 48 49
	}

	show_trace(stack);
}