dumpstack_32.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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/bug.h>
  14. #include <linux/nmi.h>
  15. #include <linux/sysfs.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 = print_context_stack(context, stack, bp, ops,
  52. data, NULL, &graph);
  53. stack = (unsigned long *)context->previous_esp;
  54. if (!stack)
  55. break;
  56. if (ops->stack(data, "IRQ") < 0)
  57. break;
  58. touch_nmi_watchdog();
  59. }
  60. }
  61. EXPORT_SYMBOL(dump_trace);
  62. void
  63. show_stack_log_lvl(struct task_struct *task, struct pt_regs *regs,
  64. unsigned long *sp, unsigned long bp, char *log_lvl)
  65. {
  66. unsigned long *stack;
  67. int i;
  68. if (sp == NULL) {
  69. if (task)
  70. sp = (unsigned long *)task->thread.sp;
  71. else
  72. sp = (unsigned long *)&sp;
  73. }
  74. stack = sp;
  75. for (i = 0; i < kstack_depth_to_print; i++) {
  76. if (kstack_end(stack))
  77. break;
  78. if (i && ((i % STACKSLOTS_PER_LINE) == 0))
  79. printk("\n%s", log_lvl);
  80. printk(" %08lx", *stack++);
  81. touch_nmi_watchdog();
  82. }
  83. printk("\n");
  84. show_trace_log_lvl(task, regs, sp, bp, log_lvl);
  85. }
  86. void show_registers(struct pt_regs *regs)
  87. {
  88. int i;
  89. print_modules();
  90. __show_regs(regs, 0);
  91. printk(KERN_EMERG "Process %.*s (pid: %d, ti=%p task=%p task.ti=%p)\n",
  92. TASK_COMM_LEN, current->comm, task_pid_nr(current),
  93. current_thread_info(), current, task_thread_info(current));
  94. /*
  95. * When in-kernel, we also print out the stack and code at the
  96. * time of the fault..
  97. */
  98. if (!user_mode_vm(regs)) {
  99. unsigned int code_prologue = code_bytes * 43 / 64;
  100. unsigned int code_len = code_bytes;
  101. unsigned char c;
  102. u8 *ip;
  103. printk(KERN_EMERG "Stack:\n");
  104. show_stack_log_lvl(NULL, regs, &regs->sp,
  105. 0, KERN_EMERG);
  106. printk(KERN_EMERG "Code: ");
  107. ip = (u8 *)regs->ip - code_prologue;
  108. if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
  109. /* try starting at IP */
  110. ip = (u8 *)regs->ip;
  111. code_len = code_len - code_prologue + 1;
  112. }
  113. for (i = 0; i < code_len; i++, ip++) {
  114. if (ip < (u8 *)PAGE_OFFSET ||
  115. probe_kernel_address(ip, c)) {
  116. printk(" Bad EIP value.");
  117. break;
  118. }
  119. if (ip == (u8 *)regs->ip)
  120. printk("<%02x> ", c);
  121. else
  122. printk("%02x ", c);
  123. }
  124. }
  125. printk("\n");
  126. }
  127. int is_valid_bugaddr(unsigned long ip)
  128. {
  129. unsigned short ud2;
  130. if (ip < PAGE_OFFSET)
  131. return 0;
  132. if (probe_kernel_address((unsigned short *)ip, ud2))
  133. return 0;
  134. return ud2 == 0x0b0f;
  135. }