stacktrace.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. #define get_bp(bp) asm("movl %%ebp, %0" : "=r" (bp) :)
  43. #else
  44. #define STACKSLOTS_PER_LINE 4
  45. #define get_bp(bp) asm("movq %%rbp, %0" : "=r" (bp) :)
  46. #endif
  47. #ifdef CONFIG_FRAME_POINTER
  48. static inline unsigned long
  49. stack_frame(struct task_struct *task, struct pt_regs *regs)
  50. {
  51. unsigned long bp;
  52. if (regs)
  53. return regs->bp;
  54. if (task == current) {
  55. /* Grab bp right from our regs */
  56. get_bp(bp);
  57. return bp;
  58. }
  59. return ((struct inactive_task_frame *)task->thread.sp)->bp;
  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 */