all repos — mgba @ 2dc710feeb0e36fc2179ec7c5f90b3d0430dd00c

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