all repos — mgba @ 32f0bb9f1f3b9993af4b563865a038b43c7f0310

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 "util/vector.h"
 13
 14extern const uint32_t ARM_DEBUGGER_ID;
 15
 16enum DebuggerState {
 17	DEBUGGER_PAUSED,
 18	DEBUGGER_RUNNING,
 19	DEBUGGER_CUSTOM,
 20	DEBUGGER_SHUTDOWN
 21};
 22
 23struct DebugBreakpoint {
 24	uint32_t address;
 25	bool isSw;
 26	struct {
 27		uint32_t opcode;
 28		enum ExecutionMode mode;
 29	} sw;
 30};
 31
 32enum WatchpointType {
 33	WATCHPOINT_WRITE = 1,
 34	WATCHPOINT_READ = 2,
 35	WATCHPOINT_RW = WATCHPOINT_WRITE | WATCHPOINT_READ
 36};
 37
 38struct DebugWatchpoint {
 39	uint32_t address;
 40	enum WatchpointType type;
 41};
 42
 43DECLARE_VECTOR(DebugBreakpointList, struct DebugBreakpoint);
 44DECLARE_VECTOR(DebugWatchpointList, struct DebugWatchpoint);
 45
 46enum DebuggerEntryReason {
 47	DEBUGGER_ENTER_MANUAL,
 48	DEBUGGER_ENTER_ATTACHED,
 49	DEBUGGER_ENTER_BREAKPOINT,
 50	DEBUGGER_ENTER_WATCHPOINT,
 51	DEBUGGER_ENTER_ILLEGAL_OP
 52};
 53
 54struct DebuggerEntryInfo {
 55	uint32_t address;
 56	union {
 57		struct {
 58			uint32_t oldValue;
 59			uint32_t newValue;
 60			enum WatchpointType watchType;
 61			enum WatchpointType accessType;
 62		};
 63
 64		struct {
 65			uint32_t opcode;
 66		};
 67	};
 68};
 69
 70enum DebuggerLogLevel {
 71	DEBUGGER_LOG_DEBUG = 0x01,
 72	DEBUGGER_LOG_INFO = 0x02,
 73	DEBUGGER_LOG_WARN = 0x04,
 74	DEBUGGER_LOG_ERROR = 0x08
 75};
 76
 77struct ARMDebugger {
 78	struct ARMComponent d;
 79	enum DebuggerState state;
 80	struct ARMCore* cpu;
 81
 82	struct DebugBreakpointList breakpoints;
 83	struct DebugBreakpointList swBreakpoints;
 84	struct DebugWatchpointList watchpoints;
 85	struct ARMMemory originalMemory;
 86
 87	struct DebugBreakpoint* currentBreakpoint;
 88
 89	void (*init)(struct ARMDebugger*);
 90	void (*deinit)(struct ARMDebugger*);
 91	void (*paused)(struct ARMDebugger*);
 92	void (*entered)(struct ARMDebugger*, enum DebuggerEntryReason, struct DebuggerEntryInfo*);
 93	void (*custom)(struct ARMDebugger*);
 94
 95	bool (*setSoftwareBreakpoint)(struct ARMDebugger*, uint32_t address, enum ExecutionMode mode, uint32_t* opcode);
 96	bool (*clearSoftwareBreakpoint)(struct ARMDebugger*, uint32_t address, enum ExecutionMode mode, uint32_t opcode);
 97
 98	ATTRIBUTE_FORMAT(printf, 3, 4)
 99	void (*log)(struct ARMDebugger*, enum DebuggerLogLevel, const char* format, ...);
100};
101
102void ARMDebuggerCreate(struct ARMDebugger*);
103void ARMDebuggerRun(struct ARMDebugger*);
104void ARMDebuggerEnter(struct ARMDebugger*, enum DebuggerEntryReason, struct DebuggerEntryInfo*);
105void ARMDebuggerSetBreakpoint(struct ARMDebugger* debugger, uint32_t address);
106bool ARMDebuggerSetSoftwareBreakpoint(struct ARMDebugger* debugger, uint32_t address, enum ExecutionMode mode);
107void ARMDebuggerClearBreakpoint(struct ARMDebugger* debugger, uint32_t address);
108void ARMDebuggerSetWatchpoint(struct ARMDebugger* debugger, uint32_t address, enum WatchpointType type);
109void ARMDebuggerClearWatchpoint(struct ARMDebugger* debugger, uint32_t address);
110
111#endif