dumpstack_32.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /*
  2. * Copyright (C) 1991, 1992 Linus Torvalds
  3. * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
  4. */
  5. #include <linux/kallsyms.h>
  6. #include <linux/kprobes.h>
  7. #include <linux/uaccess.h>
  8. #include <linux/utsname.h>
  9. #include <linux/hardirq.h>
  10. #include <linux/kdebug.h>
  11. #include <linux/module.h>
  12. #include <linux/ptrace.h>
  13. #include <linux/kexec.h>
  14. #include <linux/bug.h>
  15. #include <linux/nmi.h>
  16. #include <linux/sysfs.h>
  17. #include <asm/stacktrace.h>
  18. #include "dumpstack.h"
  19. void dump_trace(struct task_struct *task, struct pt_regs *regs,
  20. unsigned long *stack, unsigned long bp,
  21. const struct stacktrace_ops *ops, void *data)
  22. {
  23. int graph = 0;
  24. if (!task)
  25. task = current;
  26. if (!stack) {
  27. unsigned long dummy;
  28. stack = &dummy;
  29. if (task && task != current)
  30. stack = (unsigned long *)task->thread.sp;
  31. }
  32. #ifdef CONFIG_FRAME_POINTER
  33. if (!bp) {
  34. if (task == current) {
  35. /* Grab bp right from our regs */
  36. get_bp(bp);
  37. } else {
  38. /* bp is the last reg pushed by switch_to */
  39. bp = *(unsigned long *) task->thread.sp;
  40. }
  41. }
  42. #endif
  43. for (;;) {
  44. struct thread_info *context;
  45. context = (struct thread_info *)
  46. ((unsigned long)stack & (~(THREAD_SIZE - 1)));
  47. bp = print_context_stack(context, stack, bp, ops,
  48. data, NULL, &graph);
  49. stack = (unsigned long *)context->previous_esp;
  50. if (!stack)
  51. break;
  52. if (ops->stack(data, "IRQ") < 0)
  53. break;
  54. touch_nmi_watchdog();
  55. }
  56. }
  57. EXPORT_SYMBOL(dump_trace);
  58. void
  59. show_stack_log_lvl(struct task_struct *task, struct pt_regs *regs,
  60. unsigned long *sp, unsigned long bp, char *log_lvl)
  61. {
  62. unsigned long *stack;
  63. int i;
  64. if (sp == NULL) {
  65. if (task)
  66. sp = (unsigned long *)task->thread.sp;
  67. else
  68. sp = (unsigned long *)&sp;
  69. }
  70. stack = sp;
  71. for (i = 0; i < kstack_depth_to_print; i++) {
  72. if (kstack_end(stack))
  73. break;
  74. if (i && ((i % STACKSLOTS_PER_LINE) == 0))
  75. printk("\n%s", log_lvl);
  76. printk(" %08lx", *stack++);
  77. touch_nmi_watchdog();
  78. }
  79. printk("\n");
  80. show_trace_log_lvl(task, regs, sp, bp, log_lvl);
  81. }
  82. void show_registers(struct pt_regs *regs)
  83. {
  84. int i;
  85. print_modules();
  86. __show_regs(regs, 0);
  87. printk(KERN_EMERG "Process %.*s (pid: %d, ti=%p task=%p task.ti=%p)\n",
  88. TASK_COMM_LEN, current->comm, task_pid_nr(current),
  89. current_thread_info(), current, task_thread_info(current));
  90. /*
  91. * When in-kernel, we also print out the stack and code at the
  92. * time of the fault..
  93. */
  94. if (!user_mode_vm(regs)) {
  95. unsigned int code_prologue = code_bytes * 43 / 64;
  96. unsigned int code_len = code_bytes;
  97. unsigned char c;
  98. u8 *ip;
  99. printk(KERN_EMERG "Stack:\n");
  100. show_stack_log_lvl(NULL, regs, &regs->sp,
  101. 0, KERN_EMERG);
  102. printk(KERN_EMERG "Code: ");
  103. ip = (u8 *)regs->ip - code_prologue;
  104. if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
  105. /* try starting at IP */
  106. ip = (u8 *)regs->ip;
  107. code_len = code_len - code_prologue + 1;
  108. }
  109. for (i = 0; i < code_len; i++, ip++) {
  110. if (ip < (u8 *)PAGE_OFFSET ||
  111. probe_kernel_address(ip, c)) {
  112. printk(" Bad EIP value.");
  113. break;
  114. }
  115. if (ip == (u8 *)regs->ip)
  116. printk("<%02x> ", c);
  117. else
  118. printk("%02x ", c);
  119. }
  120. }
  121. printk("\n");
  122. }
  123. int is_valid_bugaddr(unsigned long ip)
  124. {
  125. unsigned short ud2;
  126. if (ip < PAGE_OFFSET)
  127. return 0;
  128. if (probe_kernel_address((unsigned short *)ip, ud2))
  129. return 0;
  130. return ud2 == 0x0b0f;
  131. }