include/mgba/debugger/debugger.h (view raw)
1/* Copyright (c) 2013-2017 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 DEBUGGER_H
7#define DEBUGGER_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
16mLOG_DECLARE_CATEGORY(DEBUGGER);
17
18extern const uint32_t DEBUGGER_ID;
19
20enum mDebuggerType {
21 DEBUGGER_NONE = 0,
22 DEBUGGER_CLI,
23#ifdef USE_GDB_STUB
24 DEBUGGER_GDB,
25#endif
26 DEBUGGER_MAX
27};
28
29enum mDebuggerState {
30 DEBUGGER_PAUSED,
31 DEBUGGER_RUNNING,
32 DEBUGGER_CUSTOM,
33 DEBUGGER_SHUTDOWN
34};
35
36enum mWatchpointType {
37 WATCHPOINT_WRITE = 1,
38 WATCHPOINT_READ = 2,
39 WATCHPOINT_RW = 3
40};
41
42enum mBreakpointType {
43 BREAKPOINT_HARDWARE,
44 BREAKPOINT_SOFTWARE
45};
46
47enum mDebuggerEntryReason {
48 DEBUGGER_ENTER_MANUAL,
49 DEBUGGER_ENTER_ATTACHED,
50 DEBUGGER_ENTER_BREAKPOINT,
51 DEBUGGER_ENTER_WATCHPOINT,
52 DEBUGGER_ENTER_ILLEGAL_OP
53};
54
55struct mDebuggerEntryInfo {
56 uint32_t address;
57 union {
58 struct {
59 uint32_t oldValue;
60 uint32_t newValue;
61 enum mWatchpointType watchType;
62 enum mWatchpointType accessType;
63 };
64
65 struct {
66 uint32_t opcode;
67 enum mBreakpointType breakType;
68 };
69 };
70};
71
72struct mDebugger;
73struct mDebuggerPlatform {
74 struct mDebugger* p;
75
76 void (*init)(void* cpu, struct mDebuggerPlatform*);
77 void (*deinit)(struct mDebuggerPlatform*);
78 void (*entered)(struct mDebuggerPlatform*, enum mDebuggerEntryReason, struct mDebuggerEntryInfo*);
79
80 bool (*hasBreakpoints)(struct mDebuggerPlatform*);
81 void (*setBreakpoint)(struct mDebuggerPlatform*, uint32_t address, int segment);
82 void (*clearBreakpoint)(struct mDebuggerPlatform*, uint32_t address, int segment);
83 void (*setWatchpoint)(struct mDebuggerPlatform*, uint32_t address, int segment, enum mWatchpointType type);
84 void (*clearWatchpoint)(struct mDebuggerPlatform*, uint32_t address, int segment);
85 void (*checkBreakpoints)(struct mDebuggerPlatform*);
86 void (*trace)(struct mDebuggerPlatform*, char* out, size_t* length);
87};
88
89struct mDebuggerSymbols;
90struct mDebugger {
91 struct mCPUComponent d;
92 struct mDebuggerPlatform* platform;
93 enum mDebuggerState state;
94 enum mDebuggerType type;
95 struct mCore* core;
96 struct mScriptBridge* bridge;
97
98 void (*init)(struct mDebugger*);
99 void (*deinit)(struct mDebugger*);
100
101 void (*paused)(struct mDebugger*);
102 void (*entered)(struct mDebugger*, enum mDebuggerEntryReason, struct mDebuggerEntryInfo*);
103 void (*custom)(struct mDebugger*);
104};
105
106struct mDebugger* mDebuggerCreate(enum mDebuggerType type, struct mCore*);
107void mDebuggerAttach(struct mDebugger*, struct mCore*);
108void mDebuggerRun(struct mDebugger*);
109void mDebuggerRunFrame(struct mDebugger*);
110void mDebuggerEnter(struct mDebugger*, enum mDebuggerEntryReason, struct mDebuggerEntryInfo*);
111
112CXX_GUARD_END
113
114#endif