summaryrefslogtreecommitdiff
path: root/lib/mipsunwinder/backtrace-mipsunwinder.h
diff options
context:
space:
mode:
Diffstat (limited to 'lib/mipsunwinder/backtrace-mipsunwinder.h')
-rw-r--r--lib/mipsunwinder/backtrace-mipsunwinder.h65
1 files changed, 65 insertions, 0 deletions
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 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2022 Aidan MacDonald
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#ifndef BACKTRACE_MIPSUNWINDER_H
23#define BACKTRACE_MIPSUNWINDER_H
24
25/*#define MIPSUNWINDER_DEBUG*/
26
27#include <stdint.h>
28
29enum {
30 MIPSBT_RA,
31 MIPSBT_NREG,
32};
33
34struct mips_bt_context {
35 void* pc;
36 void* sp;
37 int depth;
38 uint32_t valid;
39 uint32_t reg[MIPSBT_NREG];
40#ifdef MIPSUNWINDER_DEBUG
41 void(*debugf)(void*, const char*, ...);
42 void* debug_arg;
43#endif
44};
45
46int mips_bt_step(struct mips_bt_context* ctx);
47void mips_bt_start(struct mips_bt_context* ctx);
48
49#ifdef MIPSUNWINDER_DEBUG
50# define mips_bt_debug(ctx, ...) \
51 do { struct mips_bt_context* __ctx = ctx; \
52 if(__ctx->debugf) \
53 __ctx->debugf(__ctx->debug_arg, __VA_ARGS__);\
54 } while(0)
55#else
56# define mips_bt_debug(...) do { } while(0)
57#endif
58
59/* NOTE: ignores pcAddr and spAddr, backtrace starts from caller */
60void rb_backtrace(int pcAddr, int spAddr, unsigned* line);
61
62/* given struct mips_bt_context argument, print stack traceback */
63void rb_backtrace_ctx(void* arg, unsigned* line);
64
65#endif /* BACKTRACE_MIPSUNWINDER_H */