dumpstack_32.c 3.3 KB

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