all repos — mgba @ a0d223eef7c33382231510db9c851f856c891323

mGBA Game Boy Advance Emulator

src/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 "util/common.h"
 10
 11#include "arm/arm.h"
 12#include "core/log.h"
 13#include "util/vector.h"
 14
 15mLOG_DECLARE_CATEGORY(DEBUGGER);
 16
 17extern const uint32_t DEBUGGER_ID;
 18
 19enum mDebuggerType {
 20	DEBUGGER_NONE = 0,
 21	DEBUGGER_CLI,
 22#ifdef USE_GDB_STUB
 23	DEBUGGER_GDB,
 24#endif
 25	DEBUGGER_MAX
 26};
 27
 28enum mDebuggerState {
 29	DEBUGGER_PAUSED,
 30	DEBUGGER_RUNNING,
 31	DEBUGGER_CUSTOM,
 32	DEBUGGER_SHUTDOWN
 33};
 34
 35enum mWatchpointType {
 36	WATCHPOINT_WRITE = 1,
 37	WATCHPOINT_READ = 2,
 38	WATCHPOINT_RW = WATCHPOINT_WRITE | WATCHPOINT_READ
 39};
 40
 41enum mBreakpointType {
 42	BREAKPOINT_HARDWARE,
 43	BREAKPOINT_SOFTWARE
 44};
 45
 46enum mDebuggerEntryReason {
 47	DEBUGGER_ENTER_MANUAL,
 48	DEBUGGER_ENTER_ATTACHED,
 49	DEBUGGER_ENTER_BREAKPOINT,
 50	DEBUGGER_ENTER_WATCHPOINT,
 51	DEBUGGER_ENTER_ILLEGAL_OP
 52};
 53
 54struct mDebugWatchpoint {
 55	uint32_t address;
 56	enum mWatchpointType type;
 57};
 58
 59extern const char* ERROR_MISSING_ARGS;
 60extern const char* ERROR_OVERFLOW;
 61
 62struct mDebuggerEntryInfo {
 63	uint32_t address;
 64	union {
 65		struct {
 66			uint32_t oldValue;
 67			uint32_t newValue;
 68			enum mWatchpointType watchType;
 69			enum mWatchpointType accessType;
 70		};
 71
 72		struct {
 73			uint32_t opcode;
 74			enum mBreakpointType breakType;
 75		};
 76	};
 77};
 78
 79struct mDebugger;
 80struct mDebuggerPlatform {
 81	struct mDebugger* p;
 82
 83	void (*init)(void* cpu, struct mDebuggerPlatform*);
 84	void (*deinit)(struct mDebuggerPlatform*);
 85	void (*entered)(struct mDebuggerPlatform*, enum mDebuggerEntryReason, struct mDebuggerEntryInfo*);
 86
 87	bool (*hasBreakpoints)(struct mDebuggerPlatform*);
 88	void (*setBreakpoint)(struct mDebuggerPlatform*, uint32_t address);
 89	void (*clearBreakpoint)(struct mDebuggerPlatform*, uint32_t address);
 90	void (*setWatchpoint)(struct mDebuggerPlatform*, uint32_t address, enum mWatchpointType type);
 91	void (*clearWatchpoint)(struct mDebuggerPlatform*, uint32_t address);
 92	void (*checkBreakpoints)(struct mDebuggerPlatform*);
 93};
 94
 95struct mDebugger {
 96	struct mCPUComponent d;
 97	struct mDebuggerPlatform* platform;
 98	enum mDebuggerState state;
 99	struct mCore* core;
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 mDebuggerEnter(struct mDebugger*, enum mDebuggerEntryReason, struct mDebuggerEntryInfo*);
113
114
115#endif