It unwind the stack frame based on prologue code analyze. CONFIG_KALLSYMS is needed, at least the address and length of each function. Three stages when we do unwind, 1) unwind_start(), the prapare of unwinding, fill unwind_state. 2) unwind_done(), judge whether the unwind process is finished or not. 3) unwind_next_frame(), unwind the next frame. Dividing unwinder helps to add new unwinders in the future, e.g.: unwinder_frame, unwinder_orc, .etc. Signed-off-by: Qing Zhang <zhangqing@loongson.cn> Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
42 lines
926 B
C
42 lines
926 B
C
/* SPDX-License-Identifier: GPL-2.0 */
|
|
/*
|
|
* Most of this ideas comes from x86.
|
|
*
|
|
* Copyright (C) 2022 Loongson Technology Corporation Limited
|
|
*/
|
|
#ifndef _ASM_UNWIND_H
|
|
#define _ASM_UNWIND_H
|
|
|
|
#include <linux/sched.h>
|
|
|
|
#include <asm/stacktrace.h>
|
|
|
|
enum unwinder_type {
|
|
UNWINDER_GUESS,
|
|
UNWINDER_PROLOGUE,
|
|
};
|
|
|
|
struct unwind_state {
|
|
char type; /* UNWINDER_XXX */
|
|
struct stack_info stack_info;
|
|
struct task_struct *task;
|
|
bool first, error;
|
|
unsigned long sp, pc, ra;
|
|
};
|
|
|
|
void unwind_start(struct unwind_state *state,
|
|
struct task_struct *task, struct pt_regs *regs);
|
|
bool unwind_next_frame(struct unwind_state *state);
|
|
unsigned long unwind_get_return_address(struct unwind_state *state);
|
|
|
|
static inline bool unwind_done(struct unwind_state *state)
|
|
{
|
|
return state->stack_info.type == STACK_TYPE_UNKNOWN;
|
|
}
|
|
|
|
static inline bool unwind_error(struct unwind_state *state)
|
|
{
|
|
return state->error;
|
|
}
|
|
|
|
#endif /* _ASM_UNWIND_H */
|