all repos — mgba @ 178017a9e0ae8ad56a1273b95bbe6e071cf7ee40

mGBA Game Boy Advance Emulator

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		} wp;
 64
 65		struct {
 66			uint32_t opcode;
 67			enum mBreakpointType breakType;
 68		} bp;
 69	} type;
 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	bool (*getRegister)(struct mDebuggerPlatform*, const char* name, int32_t* value);
 89	bool (*setRegister)(struct mDebuggerPlatform*, const char* name, int32_t value);
 90	bool (*lookupIdentifier)(struct mDebuggerPlatform*, const char* name, int32_t* value, int* segment);
 91};
 92
 93struct mDebugger {
 94	struct mCPUComponent d;
 95	struct mDebuggerPlatform* platform;
 96	enum mDebuggerState state;
 97	enum mDebuggerType type;
 98	struct mCore* core;
 99	struct mScriptBridge* bridge;
100
101	void (*init)(struct mDebugger*);
102	void (*deinit)(struct mDebugger*);
103
104	void (*paused)(struct mDebugger*);
105	void (*entered)(struct mDebugger*, enum mDebuggerEntryReason, struct mDebuggerEntryInfo*);
106	void (*custom)(struct mDebugger*);
107};
108
109struct mDebugger* mDebuggerCreate(enum mDebuggerType type, struct mCore*);
110void mDebuggerAttach(struct mDebugger*, struct mCore*);
111void mDebuggerRun(struct mDebugger*);
112void mDebuggerRunFrame(struct mDebugger*);
113void mDebuggerEnter(struct mDebugger*, enum mDebuggerEntryReason, struct mDebuggerEntryInfo*);
114
115bool mDebuggerLookupIdentifier(struct mDebugger* debugger, const char* name, int32_t* value, int* segment);
116
117CXX_GUARD_END
118
119#endif