all repos — mgba @ f2134880898dd3ceaba7945c992c8ff34e245682

mGBA Game Boy Advance Emulator

include/mgba/debugger/debugger.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 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	WATCHPOINT_WRITE_CHANGE = 4,
 42};
 43
 44enum mBreakpointType {
 45	BREAKPOINT_HARDWARE,
 46	BREAKPOINT_SOFTWARE
 47};
 48
 49enum mDebuggerEntryReason {
 50	DEBUGGER_ENTER_MANUAL,
 51	DEBUGGER_ENTER_ATTACHED,
 52	DEBUGGER_ENTER_BREAKPOINT,
 53	DEBUGGER_ENTER_WATCHPOINT,
 54	DEBUGGER_ENTER_ILLEGAL_OP
 55};
 56
 57struct mDebuggerEntryInfo {
 58	uint32_t address;
 59	union {
 60		struct {
 61			uint32_t oldValue;
 62			uint32_t newValue;
 63			enum mWatchpointType watchType;
 64			enum mWatchpointType accessType;
 65		} wp;
 66
 67		struct {
 68			uint32_t opcode;
 69			enum mBreakpointType breakType;
 70		} bp;
 71	} type;
 72};
 73
 74struct mBreakpoint {
 75	ssize_t id;
 76	uint32_t address;
 77	int segment;
 78	enum mBreakpointType type;
 79	struct ParseTree* condition;
 80};
 81
 82struct mWatchpoint {
 83	ssize_t id;
 84	uint32_t address;
 85	int segment;
 86	enum mWatchpointType type;
 87	struct ParseTree* condition;
 88};
 89
 90DECLARE_VECTOR(mBreakpointList, struct mBreakpoint);
 91DECLARE_VECTOR(mWatchpointList, struct mWatchpoint);
 92
 93struct mDebugger;
 94struct ParseTree;
 95struct mDebuggerPlatform {
 96	struct mDebugger* p;
 97
 98	void (*init)(void* cpu, struct mDebuggerPlatform*);
 99	void (*deinit)(struct mDebuggerPlatform*);
100	void (*entered)(struct mDebuggerPlatform*, enum mDebuggerEntryReason, struct mDebuggerEntryInfo*);
101
102	bool (*hasBreakpoints)(struct mDebuggerPlatform*);
103	void (*checkBreakpoints)(struct mDebuggerPlatform*);
104	bool (*clearBreakpoint)(struct mDebuggerPlatform*, ssize_t id);
105
106	ssize_t (*setBreakpoint)(struct mDebuggerPlatform*, const struct mBreakpoint*);
107	void (*listBreakpoints)(struct mDebuggerPlatform*, struct mBreakpointList*);
108
109	ssize_t (*setWatchpoint)(struct mDebuggerPlatform*, const struct mWatchpoint*);
110	void (*listWatchpoints)(struct mDebuggerPlatform*, struct mWatchpointList*);
111
112	void (*trace)(struct mDebuggerPlatform*, char* out, size_t* length);
113
114	bool (*getRegister)(struct mDebuggerPlatform*, const char* name, int32_t* value);
115	bool (*setRegister)(struct mDebuggerPlatform*, const char* name, int32_t value);
116	bool (*lookupIdentifier)(struct mDebuggerPlatform*, const char* name, int32_t* value, int* segment);
117};
118
119struct mDebugger {
120	struct mCPUComponent d;
121	struct mDebuggerPlatform* platform;
122	enum mDebuggerState state;
123	enum mDebuggerType type;
124	struct mCore* core;
125	struct mScriptBridge* bridge;
126
127	void (*init)(struct mDebugger*);
128	void (*deinit)(struct mDebugger*);
129
130	void (*paused)(struct mDebugger*);
131	void (*entered)(struct mDebugger*, enum mDebuggerEntryReason, struct mDebuggerEntryInfo*);
132	void (*custom)(struct mDebugger*);
133};
134
135struct mDebugger* mDebuggerCreate(enum mDebuggerType type, struct mCore*);
136void mDebuggerAttach(struct mDebugger*, struct mCore*);
137void mDebuggerRun(struct mDebugger*);
138void mDebuggerRunFrame(struct mDebugger*);
139void mDebuggerEnter(struct mDebugger*, enum mDebuggerEntryReason, struct mDebuggerEntryInfo*);
140
141bool mDebuggerLookupIdentifier(struct mDebugger* debugger, const char* name, int32_t* value, int* segment);
142
143CXX_GUARD_END
144
145#endif