stacktrace.h 3.8 KB
Newer Older
1 2 3 4 5
/*
 *  Copyright (C) 1991, 1992  Linus Torvalds
 *  Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
 */

H
H. Peter Anvin 已提交
6 7
#ifndef _ASM_X86_STACKTRACE_H
#define _ASM_X86_STACKTRACE_H
8

9
#include <linux/uaccess.h>
10
#include <linux/ptrace.h>
11
#include <asm/switch_to.h>
12

13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
enum stack_type {
	STACK_TYPE_UNKNOWN,
	STACK_TYPE_TASK,
	STACK_TYPE_IRQ,
	STACK_TYPE_SOFTIRQ,
	STACK_TYPE_EXCEPTION,
	STACK_TYPE_EXCEPTION_LAST = STACK_TYPE_EXCEPTION + N_EXCEPTION_STACKS-1,
};

struct stack_info {
	enum stack_type type;
	unsigned long *begin, *end, *next_sp;
};

bool in_task_stack(unsigned long *stack, struct task_struct *task,
		   struct stack_info *info);

int get_stack_info(unsigned long *stack, struct task_struct *task,
		   struct stack_info *info, unsigned long *visit_mask);

void stack_type_str(enum stack_type type, const char **begin,
		    const char **end);

static inline bool on_stack(struct stack_info *info, void *addr, size_t len)
{
	void *begin = info->begin;
	void *end   = info->end;

	return (info->type != STACK_TYPE_UNKNOWN &&
		addr >= begin && addr < end &&
		addr + len > begin && addr + len <= end);
}

46 47
extern int kstack_depth_to_print;

48 49 50
struct thread_info;
struct stacktrace_ops;

51
typedef unsigned long (*walk_stack_t)(struct task_struct *task,
52 53 54 55
				      unsigned long *stack,
				      unsigned long bp,
				      const struct stacktrace_ops *ops,
				      void *data,
56
				      struct stack_info *info,
57 58 59
				      int *graph);

extern unsigned long
60
print_context_stack(struct task_struct *task,
61 62
		    unsigned long *stack, unsigned long bp,
		    const struct stacktrace_ops *ops, void *data,
63
		    struct stack_info *info, int *graph);
64

65
extern unsigned long
66
print_context_stack_bp(struct task_struct *task,
67 68
		       unsigned long *stack, unsigned long bp,
		       const struct stacktrace_ops *ops, void *data,
69
		       struct stack_info *info, int *graph);
70

71 72 73
/* Generic stack tracer with callbacks */

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;
78 79
};

80
void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
81
		unsigned long *stack, unsigned long bp,
J
Jan Beulich 已提交
82
		const struct stacktrace_ops *ops, void *data);
83

84 85 86 87 88 89
#ifdef CONFIG_X86_32
#define STACKSLOTS_PER_LINE 8
#else
#define STACKSLOTS_PER_LINE 4
#endif

90
#ifdef CONFIG_FRAME_POINTER
91 92
static inline unsigned long *
get_frame_pointer(struct task_struct *task, struct pt_regs *regs)
93 94
{
	if (regs)
95
		return (unsigned long *)regs->bp;
96

97 98
	if (!task || task == current)
		return __builtin_frame_address(0);
99

100
	return (unsigned long *)((struct inactive_task_frame *)task->thread.sp)->bp;
101 102
}
#else
103 104
static inline unsigned long *
get_frame_pointer(struct task_struct *task, struct pt_regs *regs)
105
{
106 107 108 109 110 111 112 113 114 115 116 117 118 119
	return NULL;
}
#endif /* CONFIG_FRAME_POINTER */

static inline unsigned long *
get_stack_pointer(struct task_struct *task, struct pt_regs *regs)
{
	if (regs)
		return (unsigned long *)kernel_stack_pointer(regs);

	if (!task || task == current)
		return __builtin_frame_address(0);

	return (unsigned long *)task->thread.sp;
120 121
}

122 123
extern void
show_trace_log_lvl(struct task_struct *task, struct pt_regs *regs,
124
		   unsigned long *stack, unsigned long bp, char *log_lvl);
125 126 127

extern void
show_stack_log_lvl(struct task_struct *task, struct pt_regs *regs,
128
		   unsigned long *sp, unsigned long bp, char *log_lvl);
129 130 131 132 133 134 135 136 137 138 139 140 141 142

extern unsigned int code_bytes;

/* The form of the top of the frame on the stack */
struct stack_frame {
	struct stack_frame *next_frame;
	unsigned long return_address;
};

struct stack_frame_ia32 {
    u32 next_frame;
    u32 return_address;
};

143
static inline unsigned long caller_frame_pointer(void)
144 145 146
{
	struct stack_frame *frame;

147
	frame = __builtin_frame_address(0);
148 149

#ifdef CONFIG_FRAME_POINTER
150
	frame = frame->next_frame;
151 152 153 154 155
#endif

	return (unsigned long)frame;
}

H
H. Peter Anvin 已提交
156
#endif /* _ASM_X86_STACKTRACE_H */