dumpstack_32.c 3.1 KB

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