sysrq.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * Copyright (C) 2001 Jeff Dike (jdike@karaya.com)
  3. * Licensed under the GPL
  4. */
  5. #include "linux/sched.h"
  6. #include "linux/kernel.h"
  7. #include "linux/module.h"
  8. #include "linux/kallsyms.h"
  9. #include "asm/page.h"
  10. #include "asm/processor.h"
  11. #include "sysrq.h"
  12. #include "user_util.h"
  13. void show_trace(unsigned long * stack)
  14. {
  15. /* XXX: Copy the CONFIG_FRAME_POINTER stack-walking backtrace from
  16. * arch/i386/kernel/traps.c, and then move this to sys-i386/sysrq.c.*/
  17. unsigned long addr;
  18. if (!stack) {
  19. stack = (unsigned long*) &stack;
  20. WARN_ON(1);
  21. }
  22. printk("Call Trace: \n");
  23. while (((long) stack & (THREAD_SIZE-1)) != 0) {
  24. addr = *stack;
  25. if (__kernel_text_address(addr)) {
  26. printk("%08lx: [<%08lx>]", (unsigned long) stack, addr);
  27. print_symbol(" %s", addr);
  28. printk("\n");
  29. }
  30. stack++;
  31. }
  32. printk("\n");
  33. }
  34. /*
  35. * stack dumps generator - this is used by arch-independent code.
  36. * And this is identical to i386 currently.
  37. */
  38. void dump_stack(void)
  39. {
  40. unsigned long stack;
  41. show_trace(&stack);
  42. }
  43. EXPORT_SYMBOL(dump_stack);
  44. /*Stolen from arch/i386/kernel/traps.c */
  45. static int kstack_depth_to_print = 24;
  46. /* This recently started being used in arch-independent code too, as in
  47. * kernel/sched.c.*/
  48. void show_stack(struct task_struct *task, unsigned long *esp)
  49. {
  50. unsigned long *stack;
  51. int i;
  52. if (esp == NULL) {
  53. if (task != current) {
  54. esp = (unsigned long *) KSTK_ESP(task);
  55. /* Which one? No actual difference - just coding style.*/
  56. //esp = (unsigned long *) PT_REGS_IP(&task->thread.regs);
  57. } else {
  58. esp = (unsigned long *) &esp;
  59. }
  60. }
  61. stack = esp;
  62. for(i = 0; i < kstack_depth_to_print; i++) {
  63. if (kstack_end(stack))
  64. break;
  65. if (i && ((i % 8) == 0))
  66. printk("\n ");
  67. printk("%08lx ", *stack++);
  68. }
  69. show_trace(esp);
  70. }