From 981e9728390b401404c36241e2ce6bd4cfcb723d Mon Sep 17 00:00:00 2001 From: Aidan MacDonald Date: Mon, 16 May 2022 14:33:26 +0100 Subject: mips: add native backtrace implementation Should make debugging crashes on native MIPS targets far easier. This is by no means a 100% complete or robust implementation but it seems to handle the vast majority of functions. Change-Id: Id5f430270e02b5092b79026b6876675c784aa649 --- lib/mipsunwinder/backtrace-mipsunwinder.h | 65 +++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 lib/mipsunwinder/backtrace-mipsunwinder.h (limited to 'lib/mipsunwinder/backtrace-mipsunwinder.h') diff --git a/lib/mipsunwinder/backtrace-mipsunwinder.h b/lib/mipsunwinder/backtrace-mipsunwinder.h new file mode 100644 index 0000000000..4d6288b5fe --- /dev/null +++ b/lib/mipsunwinder/backtrace-mipsunwinder.h @@ -0,0 +1,65 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2022 Aidan MacDonald + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ + +#ifndef BACKTRACE_MIPSUNWINDER_H +#define BACKTRACE_MIPSUNWINDER_H + +/*#define MIPSUNWINDER_DEBUG*/ + +#include + +enum { + MIPSBT_RA, + MIPSBT_NREG, +}; + +struct mips_bt_context { + void* pc; + void* sp; + int depth; + uint32_t valid; + uint32_t reg[MIPSBT_NREG]; +#ifdef MIPSUNWINDER_DEBUG + void(*debugf)(void*, const char*, ...); + void* debug_arg; +#endif +}; + +int mips_bt_step(struct mips_bt_context* ctx); +void mips_bt_start(struct mips_bt_context* ctx); + +#ifdef MIPSUNWINDER_DEBUG +# define mips_bt_debug(ctx, ...) \ + do { struct mips_bt_context* __ctx = ctx; \ + if(__ctx->debugf) \ + __ctx->debugf(__ctx->debug_arg, __VA_ARGS__);\ + } while(0) +#else +# define mips_bt_debug(...) do { } while(0) +#endif + +/* NOTE: ignores pcAddr and spAddr, backtrace starts from caller */ +void rb_backtrace(int pcAddr, int spAddr, unsigned* line); + +/* given struct mips_bt_context argument, print stack traceback */ +void rb_backtrace_ctx(void* arg, unsigned* line); + +#endif /* BACKTRACE_MIPSUNWINDER_H */ -- cgit v1.2.3