dumpstack_32.c 3.2 KB

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