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 enum WatchpointType watchType;
60 };
61
62 struct {
63 uint32_t opcode;
64 };
65 };
66};
67
68enum DebuggerLogLevel {
69 DEBUGGER_LOG_DEBUG = 0x01,
70 DEBUGGER_LOG_INFO = 0x02,
71 DEBUGGER_LOG_WARN = 0x04,
72 DEBUGGER_LOG_ERROR = 0x08
73};
74
75struct ARMDebugger {
76 struct ARMComponent d;
77 enum DebuggerState state;
78 struct ARMCore* cpu;
79
80 struct DebugBreakpointList breakpoints;
81 struct DebugBreakpointList swBreakpoints;
82 struct DebugWatchpointList watchpoints;
83 struct ARMMemory originalMemory;
84
85 struct DebugBreakpoint* currentBreakpoint;
86
87 void (*init)(struct ARMDebugger*);
88 void (*deinit)(struct ARMDebugger*);
89 void (*paused)(struct ARMDebugger*);
90 void (*entered)(struct ARMDebugger*, enum DebuggerEntryReason, struct DebuggerEntryInfo*);
91 void (*custom)(struct ARMDebugger*);
92
93 bool (*setSoftwareBreakpoint)(struct ARMDebugger*, uint32_t address, enum ExecutionMode mode, uint32_t* opcode);
94 bool (*clearSoftwareBreakpoint)(struct ARMDebugger*, uint32_t address, enum ExecutionMode mode, uint32_t opcode);
95
96 ATTRIBUTE_FORMAT(printf, 3, 4)
97 void (*log)(struct ARMDebugger*, enum DebuggerLogLevel, const char* format, ...);
98};
99
100void ARMDebuggerCreate(struct ARMDebugger*);
101void ARMDebuggerRun(struct ARMDebugger*);
102void ARMDebuggerEnter(struct ARMDebugger*, enum DebuggerEntryReason, struct DebuggerEntryInfo*);
103void ARMDebuggerSetBreakpoint(struct ARMDebugger* debugger, uint32_t address);
104bool ARMDebuggerSetSoftwareBreakpoint(struct ARMDebugger* debugger, uint32_t address, enum ExecutionMode mode);
105void ARMDebuggerClearBreakpoint(struct ARMDebugger* debugger, uint32_t address);
106void ARMDebuggerSetWatchpoint(struct ARMDebugger* debugger, uint32_t address, enum WatchpointType type);
107void ARMDebuggerClearWatchpoint(struct ARMDebugger* debugger, uint32_t address);
108
109#endif