stacktrace.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. extern int kstack_depth_to_print;
  9. struct thread_info;
  10. struct stacktrace_ops;
  11. typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
  12. unsigned long *stack,
  13. unsigned long bp,
  14. const struct stacktrace_ops *ops,
  15. void *data,
  16. unsigned long *end,
  17. int *graph);
  18. extern unsigned long
  19. print_context_stack(struct thread_info *tinfo,
  20. unsigned long *stack, unsigned long bp,
  21. const struct stacktrace_ops *ops, void *data,
  22. unsigned long *end, int *graph);
  23. extern unsigned long
  24. print_context_stack_bp(struct thread_info *tinfo,
  25. unsigned long *stack, unsigned long bp,
  26. const struct stacktrace_ops *ops, void *data,
  27. unsigned long *end, int *graph);
  28. /* Generic stack tracer with callbacks */
  29. struct stacktrace_ops {
  30. void (*warning)(void *data, char *msg);
  31. /* msg must contain %s for the symbol */
  32. void (*warning_symbol)(void *data, char *msg, unsigned long symbol);
  33. void (*address)(void *data, unsigned long address, int reliable);
  34. /* On negative return stop dumping */
  35. int (*stack)(void *data, char *name);
  36. walk_stack_t walk_stack;
  37. };
  38. void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
  39. unsigned long *stack, unsigned long bp,
  40. const struct stacktrace_ops *ops, void *data);
  41. #ifdef CONFIG_X86_32
  42. #define STACKSLOTS_PER_LINE 8
  43. #define get_bp(bp) asm("movl %%ebp, %0" : "=r" (bp) :)
  44. #else
  45. #define STACKSLOTS_PER_LINE 4
  46. #define get_bp(bp) asm("movq %%rbp, %0" : "=r" (bp) :)
  47. #endif
  48. extern void
  49. show_trace_log_lvl(struct task_struct *task, struct pt_regs *regs,
  50. unsigned long *stack, unsigned long bp, char *log_lvl);
  51. extern void
  52. show_stack_log_lvl(struct task_struct *task, struct pt_regs *regs,
  53. unsigned long *sp, unsigned long bp, char *log_lvl);
  54. extern unsigned int code_bytes;
  55. /* The form of the top of the frame on the stack */
  56. struct stack_frame {
  57. struct stack_frame *next_frame;
  58. unsigned long return_address;
  59. };
  60. struct stack_frame_ia32 {
  61. u32 next_frame;
  62. u32 return_address;
  63. };
  64. static inline unsigned long rewind_frame_pointer(int n)
  65. {
  66. struct stack_frame *frame;
  67. get_bp(frame);
  68. #ifdef CONFIG_FRAME_POINTER
  69. while (n--) {
  70. if (probe_kernel_address(&frame->next_frame, frame))
  71. break;
  72. }
  73. #endif
  74. return (unsigned long)frame;
  75. }
  76. #endif /* _ASM_X86_STACKTRACE_H */