dumpstack.c 1.5 KB

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