stacktrace.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. extern int kstack_depth_to_print;
  10. struct thread_info;
  11. struct stacktrace_ops;
  12. typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
  13. unsigned long *stack,
  14. unsigned long bp,
  15. const struct stacktrace_ops *ops,
  16. void *data,
  17. unsigned long *end,
  18. int *graph);
  19. extern unsigned long
  20. print_context_stack(struct thread_info *tinfo,
  21. unsigned long *stack, unsigned long bp,
  22. const struct stacktrace_ops *ops, void *data,
  23. unsigned long *end, int *graph);
  24. extern unsigned long
  25. print_context_stack_bp(struct thread_info *tinfo,
  26. unsigned long *stack, unsigned long bp,
  27. const struct stacktrace_ops *ops, void *data,
  28. unsigned long *end, int *graph);
  29. /* Generic stack tracer with callbacks */
  30. struct stacktrace_ops {
  31. void (*address)(void *data, unsigned long address, int reliable);
  32. /* On negative return stop dumping */
  33. int (*stack)(void *data, char *name);
  34. walk_stack_t walk_stack;
  35. };
  36. void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
  37. unsigned long *stack, unsigned long bp,
  38. const struct stacktrace_ops *ops, void *data);
  39. #ifdef CONFIG_X86_32
  40. #define STACKSLOTS_PER_LINE 8
  41. #define get_bp(bp) asm("movl %%ebp, %0" : "=r" (bp) :)
  42. #else
  43. #define STACKSLOTS_PER_LINE 4
  44. #define get_bp(bp) asm("movq %%rbp, %0" : "=r" (bp) :)
  45. #endif
  46. #ifdef CONFIG_FRAME_POINTER
  47. static inline unsigned long
  48. stack_frame(struct task_struct *task, struct pt_regs *regs)
  49. {
  50. unsigned long bp;
  51. if (regs)
  52. return regs->bp;
  53. if (task == current) {
  54. /* Grab bp right from our regs */
  55. get_bp(bp);
  56. return bp;
  57. }
  58. /* bp is the last reg pushed by switch_to */
  59. return *(unsigned long *)task->thread.sp;
  60. }
  61. #else
  62. static inline unsigned long
  63. stack_frame(struct task_struct *task, struct pt_regs *regs)
  64. {
  65. return 0;
  66. }
  67. #endif
  68. extern void
  69. show_trace_log_lvl(struct task_struct *task, struct pt_regs *regs,
  70. unsigned long *stack, unsigned long bp, char *log_lvl);
  71. extern void
  72. show_stack_log_lvl(struct task_struct *task, struct pt_regs *regs,
  73. unsigned long *sp, unsigned long bp, char *log_lvl);
  74. extern unsigned int code_bytes;
  75. /* The form of the top of the frame on the stack */
  76. struct stack_frame {
  77. struct stack_frame *next_frame;
  78. unsigned long return_address;
  79. };
  80. struct stack_frame_ia32 {
  81. u32 next_frame;
  82. u32 return_address;
  83. };
  84. static inline unsigned long caller_frame_pointer(void)
  85. {
  86. struct stack_frame *frame;
  87. get_bp(frame);
  88. #ifdef CONFIG_FRAME_POINTER
  89. frame = frame->next_frame;
  90. #endif
  91. return (unsigned long)frame;
  92. }
  93. #endif /* _ASM_X86_STACKTRACE_H */