include/mgba/internal/debugger/stack-trace.h (view raw)
1/* Copyright (c) 2013-2019 Jeffrey Pfau
2 *
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6#ifndef STACK_TRACE_H
7#define STACK_TRACE_H
8
9#include <mgba-util/common.h>
10
11CXX_GUARD_START
12
13#include <mgba/core/cpu.h>
14#include <mgba/core/log.h>
15#include <mgba-util/vector.h>
16
17enum mStackTraceMode {
18 STACK_TRACE_DISABLED = 0,
19 STACK_TRACE_ENABLED = 1,
20 STACK_TRACE_BREAK_ON_RETURN = 2,
21 STACK_TRACE_BREAK_ON_CALL = 4,
22 STACK_TRACE_BREAK_ON_BOTH = STACK_TRACE_BREAK_ON_RETURN | STACK_TRACE_BREAK_ON_CALL
23};
24
25struct mStackFrame {
26 uint32_t callAddress;
27 uint32_t entryAddress;
28 uint32_t frameBaseAddress;
29 void* regs;
30 bool finished;
31 bool breakWhenFinished;
32 bool interrupt;
33};
34
35DECLARE_VECTOR(mStackFrames, struct mStackFrame);
36
37struct mStackTrace {
38 struct mStackFrames stack;
39 size_t registersSize;
40
41 void (*formatRegisters)(struct mStackFrame* frame, char* out, size_t* length);
42};
43
44void mStackTraceInit(struct mStackTrace* stack, size_t registersSize);
45void mStackTraceDeinit(struct mStackTrace* stack);
46
47void mStackTraceClear(struct mStackTrace* stack);
48size_t mStackTraceGetDepth(struct mStackTrace* stack);
49struct mStackFrame* mStackTracePush(struct mStackTrace* stack, uint32_t pc, uint32_t destAddress, uint32_t sp, void* regs);
50struct mStackFrame* mStackTraceGetFrame(struct mStackTrace* stack, uint32_t frame);
51void mStackTraceFormatFrame(struct mStackTrace* stack, uint32_t frame, char* out, size_t* length);
52void mStackTracePop(struct mStackTrace* stack);
53
54CXX_GUARD_END
55
56#endif