all repos — mgba @ 7073fa6a24ee44da81c42cd6bed3f902e3610af2

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#ifdef USE_CLI_DEBUGGER
 22	DEBUGGER_CLI,
 23#endif
 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 = WATCHPOINT_WRITE | WATCHPOINT_READ
 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);
 91	void (*clearBreakpoint)(struct mDebuggerPlatform*, uint32_t address);
 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 mDebugger {
 98	struct mCPUComponent d;
 99	struct mDebuggerPlatform* platform;
100	enum mDebuggerState state;
101	struct mCore* core;
102
103	void (*init)(struct mDebugger*);
104	void (*deinit)(struct mDebugger*);
105
106	void (*paused)(struct mDebugger*);
107	void (*entered)(struct mDebugger*, enum mDebuggerEntryReason, struct mDebuggerEntryInfo*);
108	void (*custom)(struct mDebugger*);
109};
110
111struct mDebugger* mDebuggerCreate(enum mDebuggerType type, struct mCore*);
112void mDebuggerAttach(struct mDebugger*, struct mCore*);
113void mDebuggerRun(struct mDebugger*);
114void mDebuggerEnter(struct mDebugger*, enum mDebuggerEntryReason, struct mDebuggerEntryInfo*);
115
116
117#endif