all repos — mgba @ 67905d281bfecbb06f51f2ca5ac939df378734a5

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 mDebuggerEntryReason {
 44	DEBUGGER_ENTER_MANUAL,
 45	DEBUGGER_ENTER_ATTACHED,
 46	DEBUGGER_ENTER_BREAKPOINT,
 47	DEBUGGER_ENTER_WATCHPOINT,
 48	DEBUGGER_ENTER_ILLEGAL_OP
 49};
 50
 51extern const char* ERROR_MISSING_ARGS;
 52extern const char* ERROR_OVERFLOW;
 53
 54struct mDebuggerEntryInfo {
 55	uint32_t address;
 56	union {
 57		struct {
 58			uint32_t oldValue;
 59			uint32_t newValue;
 60			enum mWatchpointType watchType;
 61			enum mWatchpointType accessType;
 62		};
 63
 64		struct {
 65			uint32_t opcode;
 66		};
 67	};
 68};
 69
 70struct mDebugger;
 71struct mDebuggerPlatform {
 72	struct mDebugger* p;
 73
 74	void (*init)(void* cpu, struct mDebuggerPlatform*);
 75	void (*deinit)(struct mDebuggerPlatform*);
 76	void (*entered)(struct mDebuggerPlatform*, enum mDebuggerEntryReason, struct mDebuggerEntryInfo*);
 77
 78	bool (*hasBreakpoints)(struct mDebuggerPlatform*);
 79	void (*setBreakpoint)(struct mDebuggerPlatform*, uint32_t address);
 80	void (*clearBreakpoint)(struct mDebuggerPlatform*, uint32_t address);
 81	void (*setWatchpoint)(struct mDebuggerPlatform*, uint32_t address, enum mWatchpointType type);
 82	void (*clearWatchpoint)(struct mDebuggerPlatform*, uint32_t address);
 83	void (*checkBreakpoints)(struct mDebuggerPlatform*);
 84};
 85
 86struct mDebugger {
 87	struct mCPUComponent d;
 88	struct mDebuggerPlatform* platform;
 89	enum mDebuggerState state;
 90	struct mCore* core;
 91
 92	void (*init)(struct mDebugger*);
 93	void (*deinit)(struct mDebugger*);
 94
 95	void (*paused)(struct mDebugger*);
 96	void (*entered)(struct mDebugger*, enum mDebuggerEntryReason, struct mDebuggerEntryInfo*);
 97	void (*custom)(struct mDebugger*);
 98};
 99
100struct mDebugger* mDebuggerCreate(enum mDebuggerType type, struct mCore*);
101void mDebuggerAttach(struct mDebugger*, struct mCore*);
102void mDebuggerRun(struct mDebugger*);
103void mDebuggerEnter(struct mDebugger*, enum mDebuggerEntryReason, struct mDebuggerEntryInfo*);
104
105
106#endif