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