stacktrace.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /*
  2. * Copyright (C) 1991, 1992 Linus Torvalds
  3. * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
  4. */
  5. #ifndef _ASM_X86_STACKTRACE_H
  6. #define _ASM_X86_STACKTRACE_H
  7. #include <linux/uaccess.h>
  8. #include <linux/ptrace.h>
  9. #include <asm/switch_to.h>
  10. extern int kstack_depth_to_print;
  11. struct thread_info;
  12. struct stacktrace_ops;
  13. typedef unsigned long (*walk_stack_t)(struct task_struct *task,
  14. unsigned long *stack,
  15. unsigned long bp,
  16. const struct stacktrace_ops *ops,
  17. void *data,
  18. unsigned long *end,
  19. int *graph);
  20. extern unsigned long
  21. print_context_stack(struct task_struct *task,
  22. unsigned long *stack, unsigned long bp,
  23. const struct stacktrace_ops *ops, void *data,
  24. unsigned long *end, int *graph);
  25. extern unsigned long
  26. print_context_stack_bp(struct task_struct *task,
  27. unsigned long *stack, unsigned long bp,
  28. const struct stacktrace_ops *ops, void *data,
  29. unsigned long *end, int *graph);
  30. /* Generic stack tracer with callbacks */
  31. struct stacktrace_ops {
  32. int (*address)(void *data, unsigned long address, int reliable);
  33. /* On negative return stop dumping */
  34. int (*stack)(void *data, char *name);
  35. walk_stack_t walk_stack;
  36. };
  37. void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
  38. unsigned long *stack, unsigned long bp,
  39. const struct stacktrace_ops *ops, void *data);
  40. #ifdef CONFIG_X86_32
  41. #define STACKSLOTS_PER_LINE 8
  42. #else
  43. #define STACKSLOTS_PER_LINE 4
  44. #endif
  45. #ifdef CONFIG_FRAME_POINTER
  46. static inline unsigned long *
  47. get_frame_pointer(struct task_struct *task, struct pt_regs *regs)
  48. {
  49. if (regs)
  50. return (unsigned long *)regs->bp;
  51. if (!task || task == current)
  52. return __builtin_frame_address(0);
  53. return (unsigned long *)((struct inactive_task_frame *)task->thread.sp)->bp;
  54. }
  55. #else
  56. static inline unsigned long *
  57. get_frame_pointer(struct task_struct *task, struct pt_regs *regs)
  58. {
  59. return NULL;
  60. }
  61. #endif /* CONFIG_FRAME_POINTER */
  62. static inline unsigned long *
  63. get_stack_pointer(struct task_struct *task, struct pt_regs *regs)
  64. {
  65. if (regs)
  66. return (unsigned long *)kernel_stack_pointer(regs);
  67. if (!task || task == current)
  68. return __builtin_frame_address(0);
  69. return (unsigned long *)task->thread.sp;
  70. }
  71. extern void
  72. show_trace_log_lvl(struct task_struct *task, struct pt_regs *regs,
  73. unsigned long *stack, unsigned long bp, char *log_lvl);
  74. extern void
  75. show_stack_log_lvl(struct task_struct *task, struct pt_regs *regs,
  76. unsigned long *sp, unsigned long bp, char *log_lvl);
  77. extern unsigned int code_bytes;
  78. /* The form of the top of the frame on the stack */
  79. struct stack_frame {
  80. struct stack_frame *next_frame;
  81. unsigned long return_address;
  82. };
  83. struct stack_frame_ia32 {
  84. u32 next_frame;
  85. u32 return_address;
  86. };
  87. static inline unsigned long caller_frame_pointer(void)
  88. {
  89. struct stack_frame *frame;
  90. frame = __builtin_frame_address(0);
  91. #ifdef CONFIG_FRAME_POINTER
  92. frame = frame->next_frame;
  93. #endif
  94. return (unsigned long)frame;
  95. }
  96. #endif /* _ASM_X86_STACKTRACE_H */