at v2.6.39 121 lines 3.0 kB view raw
1/* 2 * Copyright (C) 1991, 1992 Linus Torvalds 3 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs 4 */ 5 6#ifndef _ASM_X86_STACKTRACE_H 7#define _ASM_X86_STACKTRACE_H 8 9#include <linux/uaccess.h> 10#include <linux/ptrace.h> 11 12extern int kstack_depth_to_print; 13 14struct thread_info; 15struct stacktrace_ops; 16 17typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo, 18 unsigned long *stack, 19 unsigned long bp, 20 const struct stacktrace_ops *ops, 21 void *data, 22 unsigned long *end, 23 int *graph); 24 25extern unsigned long 26print_context_stack(struct thread_info *tinfo, 27 unsigned long *stack, unsigned long bp, 28 const struct stacktrace_ops *ops, void *data, 29 unsigned long *end, int *graph); 30 31extern unsigned long 32print_context_stack_bp(struct thread_info *tinfo, 33 unsigned long *stack, unsigned long bp, 34 const struct stacktrace_ops *ops, void *data, 35 unsigned long *end, int *graph); 36 37/* Generic stack tracer with callbacks */ 38 39struct stacktrace_ops { 40 void (*warning)(void *data, char *msg); 41 /* msg must contain %s for the symbol */ 42 void (*warning_symbol)(void *data, char *msg, unsigned long symbol); 43 void (*address)(void *data, unsigned long address, int reliable); 44 /* On negative return stop dumping */ 45 int (*stack)(void *data, char *name); 46 walk_stack_t walk_stack; 47}; 48 49void dump_trace(struct task_struct *tsk, struct pt_regs *regs, 50 unsigned long *stack, unsigned long bp, 51 const struct stacktrace_ops *ops, void *data); 52 53#ifdef CONFIG_X86_32 54#define STACKSLOTS_PER_LINE 8 55#define get_bp(bp) asm("movl %%ebp, %0" : "=r" (bp) :) 56#else 57#define STACKSLOTS_PER_LINE 4 58#define get_bp(bp) asm("movq %%rbp, %0" : "=r" (bp) :) 59#endif 60 61#ifdef CONFIG_FRAME_POINTER 62static inline unsigned long 63stack_frame(struct task_struct *task, struct pt_regs *regs) 64{ 65 unsigned long bp; 66 67 if (regs) 68 return regs->bp; 69 70 if (task == current) { 71 /* Grab bp right from our regs */ 72 get_bp(bp); 73 return bp; 74 } 75 76 /* bp is the last reg pushed by switch_to */ 77 return *(unsigned long *)task->thread.sp; 78} 79#else 80static inline unsigned long 81stack_frame(struct task_struct *task, struct pt_regs *regs) 82{ 83 return 0; 84} 85#endif 86 87extern void 88show_trace_log_lvl(struct task_struct *task, struct pt_regs *regs, 89 unsigned long *stack, unsigned long bp, char *log_lvl); 90 91extern void 92show_stack_log_lvl(struct task_struct *task, struct pt_regs *regs, 93 unsigned long *sp, unsigned long bp, char *log_lvl); 94 95extern unsigned int code_bytes; 96 97/* The form of the top of the frame on the stack */ 98struct stack_frame { 99 struct stack_frame *next_frame; 100 unsigned long return_address; 101}; 102 103struct stack_frame_ia32 { 104 u32 next_frame; 105 u32 return_address; 106}; 107 108static inline unsigned long caller_frame_pointer(void) 109{ 110 struct stack_frame *frame; 111 112 get_bp(frame); 113 114#ifdef CONFIG_FRAME_POINTER 115 frame = frame->next_frame; 116#endif 117 118 return (unsigned long)frame; 119} 120 121#endif /* _ASM_X86_STACKTRACE_H */