stacktrace.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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 (*warning)(void *data, char *msg);
  32. /* msg must contain %s for the symbol */
  33. void (*warning_symbol)(void *data, char *msg, unsigned long symbol);
  34. void (*address)(void *data, unsigned long address, int reliable);
  35. /* On negative return stop dumping */
  36. int (*stack)(void *data, char *name);
  37. walk_stack_t walk_stack;
  38. };
  39. void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
  40. unsigned long *stack, unsigned long bp,
  41. const struct stacktrace_ops *ops, void *data);
  42. #ifdef CONFIG_X86_32
  43. #define STACKSLOTS_PER_LINE 8
  44. #define get_bp(bp) asm("movl %%ebp, %0" : "=r" (bp) :)
  45. #else
  46. #define STACKSLOTS_PER_LINE 4
  47. #define get_bp(bp) asm("movq %%rbp, %0" : "=r" (bp) :)
  48. #endif
  49. #ifdef CONFIG_FRAME_POINTER
  50. static inline unsigned long
  51. stack_frame(struct task_struct *task, struct pt_regs *regs)
  52. {
  53. unsigned long bp;
  54. if (regs)
  55. return regs->bp;
  56. if (task == current) {
  57. /* Grab bp right from our regs */
  58. get_bp(bp);
  59. return bp;
  60. }
  61. /* bp is the last reg pushed by switch_to */
  62. return *(unsigned long *)task->thread.sp;
  63. }
  64. #else
  65. static inline unsigned long
  66. stack_frame(struct task_struct *task, struct pt_regs *regs)
  67. {
  68. return 0;
  69. }
  70. #endif
  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. get_bp(frame);
  91. #ifdef CONFIG_FRAME_POINTER
  92. frame = frame->next_frame;
  93. #endif
  94. return (unsigned long)frame;
  95. }
  96. #endif /* _ASM_X86_STACKTRACE_H */