|
| 1 | +// SPDX-License-Identifier: GPL-2.0 |
| 2 | +// Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd. |
| 3 | + |
| 4 | +#include <linux/ptrace.h> |
| 5 | + |
| 6 | +int kstack_depth_to_print = 48; |
| 7 | + |
| 8 | +void show_trace(unsigned long *stack) |
| 9 | +{ |
| 10 | + unsigned long *endstack; |
| 11 | + unsigned long addr; |
| 12 | + int i; |
| 13 | + |
| 14 | + pr_info("Call Trace:\n"); |
| 15 | + addr = (unsigned long)stack + THREAD_SIZE - 1; |
| 16 | + endstack = (unsigned long *)(addr & -THREAD_SIZE); |
| 17 | + i = 0; |
| 18 | + while (stack + 1 <= endstack) { |
| 19 | + addr = *stack++; |
| 20 | + /* |
| 21 | + * If the address is either in the text segment of the |
| 22 | + * kernel, or in the region which contains vmalloc'ed |
| 23 | + * memory, it *may* be the address of a calling |
| 24 | + * routine; if so, print it so that someone tracing |
| 25 | + * down the cause of the crash will be able to figure |
| 26 | + * out the call path that was taken. |
| 27 | + */ |
| 28 | + if (__kernel_text_address(addr)) { |
| 29 | +#ifndef CONFIG_KALLSYMS |
| 30 | + if (i % 5 == 0) |
| 31 | + pr_cont("\n "); |
| 32 | +#endif |
| 33 | + pr_cont(" [<%08lx>] %pS\n", addr, (void *)addr); |
| 34 | + i++; |
| 35 | + } |
| 36 | + } |
| 37 | + pr_cont("\n"); |
| 38 | +} |
| 39 | + |
| 40 | +void show_stack(struct task_struct *task, unsigned long *stack) |
| 41 | +{ |
| 42 | + unsigned long *p; |
| 43 | + unsigned long *endstack; |
| 44 | + int i; |
| 45 | + |
| 46 | + if (!stack) { |
| 47 | + if (task) |
| 48 | + stack = (unsigned long *)task->thread.esp0; |
| 49 | + else |
| 50 | + stack = (unsigned long *)&stack; |
| 51 | + } |
| 52 | + endstack = (unsigned long *) |
| 53 | + (((unsigned long)stack + THREAD_SIZE - 1) & -THREAD_SIZE); |
| 54 | + |
| 55 | + pr_info("Stack from %08lx:", (unsigned long)stack); |
| 56 | + p = stack; |
| 57 | + for (i = 0; i < kstack_depth_to_print; i++) { |
| 58 | + if (p + 1 > endstack) |
| 59 | + break; |
| 60 | + if (i % 8 == 0) |
| 61 | + pr_cont("\n "); |
| 62 | + pr_cont(" %08lx", *p++); |
| 63 | + } |
| 64 | + pr_cont("\n"); |
| 65 | + show_trace(stack); |
| 66 | +} |
0 commit comments