dumpstack_32.c 3.2 KB

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