all repos — mgba @ bb1ce789d268b484311b121943acf3ce3809c6d7

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	ssize_t pointId;
 73};
 74
 75struct mBreakpoint {
 76	ssize_t id;
 77	uint32_t address;
 78	int segment;
 79	enum mBreakpointType type;
 80	struct ParseTree* condition;
 81};
 82
 83struct mWatchpoint {
 84	ssize_t id;
 85	uint32_t address;
 86	int segment;
 87	enum mWatchpointType type;
 88	struct ParseTree* condition;
 89};
 90
 91DECLARE_VECTOR(mBreakpointList, struct mBreakpoint);
 92DECLARE_VECTOR(mWatchpointList, struct mWatchpoint);
 93
 94struct mDebugger;
 95struct ParseTree;
 96struct mDebuggerPlatform {
 97	struct mDebugger* p;
 98
 99	void (*init)(void* cpu, struct mDebuggerPlatform*);
100	void (*deinit)(struct mDebuggerPlatform*);
101	void (*entered)(struct mDebuggerPlatform*, enum mDebuggerEntryReason, struct mDebuggerEntryInfo*);
102
103	bool (*hasBreakpoints)(struct mDebuggerPlatform*);
104	void (*checkBreakpoints)(struct mDebuggerPlatform*);
105	bool (*clearBreakpoint)(struct mDebuggerPlatform*, ssize_t id);
106
107	ssize_t (*setBreakpoint)(struct mDebuggerPlatform*, const struct mBreakpoint*);
108	void (*listBreakpoints)(struct mDebuggerPlatform*, struct mBreakpointList*);
109
110	ssize_t (*setWatchpoint)(struct mDebuggerPlatform*, const struct mWatchpoint*);
111	void (*listWatchpoints)(struct mDebuggerPlatform*, struct mWatchpointList*);
112
113	void (*trace)(struct mDebuggerPlatform*, char* out, size_t* length);
114
115	bool (*getRegister)(struct mDebuggerPlatform*, const char* name, int32_t* value);
116	bool (*setRegister)(struct mDebuggerPlatform*, const char* name, int32_t value);
117	bool (*lookupIdentifier)(struct mDebuggerPlatform*, const char* name, int32_t* value, int* segment);
118};
119
120struct mDebugger {
121	struct mCPUComponent d;
122	struct mDebuggerPlatform* platform;
123	enum mDebuggerState state;
124	enum mDebuggerType type;
125	struct mCore* core;
126	struct mScriptBridge* bridge;
127
128	void (*init)(struct mDebugger*);
129	void (*deinit)(struct mDebugger*);
130
131	void (*paused)(struct mDebugger*);
132	void (*entered)(struct mDebugger*, enum mDebuggerEntryReason, struct mDebuggerEntryInfo*);
133	void (*custom)(struct mDebugger*);
134};
135
136struct mDebugger* mDebuggerCreate(enum mDebuggerType type, struct mCore*);
137void mDebuggerAttach(struct mDebugger*, struct mCore*);
138void mDebuggerRun(struct mDebugger*);
139void mDebuggerRunFrame(struct mDebugger*);
140void mDebuggerEnter(struct mDebugger*, enum mDebuggerEntryReason, struct mDebuggerEntryInfo*);
141
142bool mDebuggerLookupIdentifier(struct mDebugger* debugger, const char* name, int32_t* value, int* segment);
143
144CXX_GUARD_END
145
146#endif