2 * Copyright (C) 1991, 1992 Linus Torvalds
3 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
6 #ifndef _ASM_X86_STACKTRACE_H
7 #define _ASM_X86_STACKTRACE_H
9 #include <linux/uaccess.h>
10 #include <linux/ptrace.h>
11 #include <asm/switch_to.h>
19 STACK_TYPE_EXCEPTION_LAST = STACK_TYPE_EXCEPTION + N_EXCEPTION_STACKS-1,
24 unsigned long *begin, *end, *next_sp;
27 bool in_task_stack(unsigned long *stack, struct task_struct *task,
28 struct stack_info *info);
30 int get_stack_info(unsigned long *stack, struct task_struct *task,
31 struct stack_info *info, unsigned long *visit_mask);
33 void stack_type_str(enum stack_type type, const char **begin,
36 static inline bool on_stack(struct stack_info *info, void *addr, size_t len)
38 void *begin = info->begin;
39 void *end = info->end;
41 return (info->type != STACK_TYPE_UNKNOWN &&
42 addr >= begin && addr < end &&
43 addr + len > begin && addr + len <= end);
46 extern int kstack_depth_to_print;
49 struct stacktrace_ops;
51 typedef unsigned long (*walk_stack_t)(struct task_struct *task,
54 const struct stacktrace_ops *ops,
56 struct stack_info *info,
60 print_context_stack(struct task_struct *task,
61 unsigned long *stack, unsigned long bp,
62 const struct stacktrace_ops *ops, void *data,
63 struct stack_info *info, int *graph);
66 print_context_stack_bp(struct task_struct *task,
67 unsigned long *stack, unsigned long bp,
68 const struct stacktrace_ops *ops, void *data,
69 struct stack_info *info, int *graph);
71 /* Generic stack tracer with callbacks */
73 struct stacktrace_ops {
74 int (*address)(void *data, unsigned long address, int reliable);
75 /* On negative return stop dumping */
76 int (*stack)(void *data, const char *name);
77 walk_stack_t walk_stack;
80 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
81 unsigned long *stack, unsigned long bp,
82 const struct stacktrace_ops *ops, void *data);
85 #define STACKSLOTS_PER_LINE 8
87 #define STACKSLOTS_PER_LINE 4
90 #ifdef CONFIG_FRAME_POINTER
91 static inline unsigned long *
92 get_frame_pointer(struct task_struct *task, struct pt_regs *regs)
95 return (unsigned long *)regs->bp;
97 if (!task || task == current)
98 return __builtin_frame_address(0);
100 return (unsigned long *)((struct inactive_task_frame *)task->thread.sp)->bp;
103 static inline unsigned long *
104 get_frame_pointer(struct task_struct *task, struct pt_regs *regs)
108 #endif /* CONFIG_FRAME_POINTER */
110 static inline unsigned long *
111 get_stack_pointer(struct task_struct *task, struct pt_regs *regs)
114 return (unsigned long *)kernel_stack_pointer(regs);
116 if (!task || task == current)
117 return __builtin_frame_address(0);
119 return (unsigned long *)task->thread.sp;
123 show_trace_log_lvl(struct task_struct *task, struct pt_regs *regs,
124 unsigned long *stack, unsigned long bp, char *log_lvl);
127 show_stack_log_lvl(struct task_struct *task, struct pt_regs *regs,
128 unsigned long *sp, unsigned long bp, char *log_lvl);
130 extern unsigned int code_bytes;
132 /* The form of the top of the frame on the stack */
134 struct stack_frame *next_frame;
135 unsigned long return_address;
138 struct stack_frame_ia32 {
143 static inline unsigned long caller_frame_pointer(void)
145 struct stack_frame *frame;
147 frame = __builtin_frame_address(0);
149 #ifdef CONFIG_FRAME_POINTER
150 frame = frame->next_frame;
153 return (unsigned long)frame;
156 #endif /* _ASM_X86_STACKTRACE_H */