all repos — mgba @ fadd0391d6f2b143a470c97d6ae129346a789239

mGBA Game Boy Advance Emulator

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	STACK_TRACE_RUN_TO_FINISH = 8
24};
25
26struct mStackFrame {
27	uint32_t instruction;
28	uint32_t callAddress;
29	uint32_t entryAddress;
30	uint32_t frameBaseAddress;
31	void* regs;
32	bool finished;
33	bool breakWhenFinished;
34};
35
36DECLARE_VECTOR(mStackFrames, struct mStackFrame);
37
38struct mStackTrace {
39	struct mStackFrames stack;
40	size_t registersSize;
41
42	void (*formatRegisters)(struct mStackFrame* frame, char* out, size_t* length);
43};
44
45void mStackTraceInit(struct mStackTrace* stack, size_t registersSize);
46void mStackTraceDeinit(struct mStackTrace* stack);
47
48void mStackTraceClear(struct mStackTrace* stack);
49size_t mStackTraceGetDepth(struct mStackTrace* stack);
50struct mStackFrame* mStackTracePush(struct mStackTrace* stack, uint32_t instruction, uint32_t pc, uint32_t destAddress, uint32_t sp, void* regs);
51struct mStackFrame* mStackTraceGetFrame(struct mStackTrace* stack, size_t frame);
52void mStackTracePop(struct mStackTrace* stack);
53
54CXX_GUARD_END
55
56#endif