all repos — mgba @ ab44084236a244751d4ecd8e6403d58fb7c38de2

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 DebuggerType {
 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 DebuggerState {
 31	DEBUGGER_PAUSED,
 32	DEBUGGER_RUNNING,
 33	DEBUGGER_CUSTOM,
 34	DEBUGGER_SHUTDOWN
 35};
 36
 37struct DebugBreakpoint {
 38	uint32_t address;
 39	bool isSw;
 40	struct {
 41		uint32_t opcode;
 42		enum ExecutionMode mode;
 43	} sw;
 44};
 45
 46enum WatchpointType {
 47	WATCHPOINT_WRITE = 1,
 48	WATCHPOINT_READ = 2,
 49	WATCHPOINT_RW = WATCHPOINT_WRITE | WATCHPOINT_READ
 50};
 51
 52struct DebugWatchpoint {
 53	uint32_t address;
 54	enum WatchpointType type;
 55};
 56
 57DECLARE_VECTOR(DebugBreakpointList, struct DebugBreakpoint);
 58DECLARE_VECTOR(DebugWatchpointList, struct DebugWatchpoint);
 59
 60enum DebuggerEntryReason {
 61	DEBUGGER_ENTER_MANUAL,
 62	DEBUGGER_ENTER_ATTACHED,
 63	DEBUGGER_ENTER_BREAKPOINT,
 64	DEBUGGER_ENTER_WATCHPOINT,
 65	DEBUGGER_ENTER_ILLEGAL_OP
 66};
 67
 68struct DebuggerEntryInfo {
 69	uint32_t address;
 70	union {
 71		struct {
 72			uint32_t oldValue;
 73			uint32_t newValue;
 74			enum WatchpointType watchType;
 75			enum WatchpointType accessType;
 76		};
 77
 78		struct {
 79			uint32_t opcode;
 80		};
 81	};
 82};
 83
 84struct Debugger {
 85	struct mCPUComponent d;
 86	enum DebuggerState state;
 87	struct ARMCore* cpu;
 88
 89	struct DebugBreakpointList breakpoints;
 90	struct DebugBreakpointList swBreakpoints;
 91	struct DebugWatchpointList watchpoints;
 92	struct ARMMemory originalMemory;
 93
 94	struct DebugBreakpoint* currentBreakpoint;
 95
 96	void (*init)(struct Debugger*);
 97	void (*deinit)(struct Debugger*);
 98	void (*paused)(struct Debugger*);
 99	void (*entered)(struct Debugger*, enum DebuggerEntryReason, struct DebuggerEntryInfo*);
100	void (*custom)(struct Debugger*);
101
102	bool (*setSoftwareBreakpoint)(struct Debugger*, uint32_t address, enum ExecutionMode mode, uint32_t* opcode);
103	bool (*clearSoftwareBreakpoint)(struct Debugger*, uint32_t address, enum ExecutionMode mode, uint32_t opcode);
104};
105
106void DebuggerCreate(struct Debugger*);
107void DebuggerRun(struct Debugger*);
108void DebuggerEnter(struct Debugger*, enum DebuggerEntryReason, struct DebuggerEntryInfo*);
109void DebuggerSetBreakpoint(struct Debugger* debugger, uint32_t address);
110bool DebuggerSetSoftwareBreakpoint(struct Debugger* debugger, uint32_t address, enum ExecutionMode mode);
111void DebuggerClearBreakpoint(struct Debugger* debugger, uint32_t address);
112void DebuggerSetWatchpoint(struct Debugger* debugger, uint32_t address, enum WatchpointType type);
113void DebuggerClearWatchpoint(struct Debugger* debugger, uint32_t address);
114
115#endif