dumpstack_32.c 3.3 KB

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