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 DEBUGGER_ID;
15
16enum DebuggerType {
17 DEBUGGER_NONE = 0,
18#ifdef USE_CLI_DEBUGGER
19 DEBUGGER_CLI,
20#endif
21#ifdef USE_GDB_STUB
22 DEBUGGER_GDB,
23#endif
24 DEBUGGER_MAX
25};
26
27enum DebuggerState {
28 DEBUGGER_PAUSED,
29 DEBUGGER_RUNNING,
30 DEBUGGER_CUSTOM,
31 DEBUGGER_SHUTDOWN
32};
33
34struct DebugBreakpoint {
35 uint32_t address;
36 bool isSw;
37 struct {
38 uint32_t opcode;
39 enum ExecutionMode mode;
40 } sw;
41};
42
43enum WatchpointType {
44 WATCHPOINT_WRITE = 1,
45 WATCHPOINT_READ = 2,
46 WATCHPOINT_RW = WATCHPOINT_WRITE | WATCHPOINT_READ
47};
48
49struct DebugWatchpoint {
50 uint32_t address;
51 enum WatchpointType type;
52};
53
54DECLARE_VECTOR(DebugBreakpointList, struct DebugBreakpoint);
55DECLARE_VECTOR(DebugWatchpointList, struct DebugWatchpoint);
56
57enum DebuggerEntryReason {
58 DEBUGGER_ENTER_MANUAL,
59 DEBUGGER_ENTER_ATTACHED,
60 DEBUGGER_ENTER_BREAKPOINT,
61 DEBUGGER_ENTER_WATCHPOINT,
62 DEBUGGER_ENTER_ILLEGAL_OP
63};
64
65struct DebuggerEntryInfo {
66 uint32_t address;
67 union {
68 struct {
69 uint32_t oldValue;
70 uint32_t newValue;
71 enum WatchpointType watchType;
72 enum WatchpointType accessType;
73 };
74
75 struct {
76 uint32_t opcode;
77 };
78 };
79};
80
81enum DebuggerLogLevel {
82 DEBUGGER_LOG_DEBUG = 0x01,
83 DEBUGGER_LOG_INFO = 0x02,
84 DEBUGGER_LOG_WARN = 0x04,
85 DEBUGGER_LOG_ERROR = 0x08
86};
87
88struct Debugger {
89 struct mCPUComponent d;
90 enum DebuggerState state;
91 struct ARMCore* cpu;
92
93 struct DebugBreakpointList breakpoints;
94 struct DebugBreakpointList swBreakpoints;
95 struct DebugWatchpointList watchpoints;
96 struct ARMMemory originalMemory;
97
98 struct DebugBreakpoint* currentBreakpoint;
99
100 void (*init)(struct Debugger*);
101 void (*deinit)(struct Debugger*);
102 void (*paused)(struct Debugger*);
103 void (*entered)(struct Debugger*, enum DebuggerEntryReason, struct DebuggerEntryInfo*);
104 void (*custom)(struct Debugger*);
105
106 bool (*setSoftwareBreakpoint)(struct Debugger*, uint32_t address, enum ExecutionMode mode, uint32_t* opcode);
107 bool (*clearSoftwareBreakpoint)(struct Debugger*, uint32_t address, enum ExecutionMode mode, uint32_t opcode);
108
109 ATTRIBUTE_FORMAT(printf, 3, 4)
110 void (*log)(struct Debugger*, enum DebuggerLogLevel, const char* format, ...);
111};
112
113void DebuggerCreate(struct Debugger*);
114void DebuggerRun(struct Debugger*);
115void DebuggerEnter(struct Debugger*, enum DebuggerEntryReason, struct DebuggerEntryInfo*);
116void DebuggerSetBreakpoint(struct Debugger* debugger, uint32_t address);
117bool DebuggerSetSoftwareBreakpoint(struct Debugger* debugger, uint32_t address, enum ExecutionMode mode);
118void DebuggerClearBreakpoint(struct Debugger* debugger, uint32_t address);
119void DebuggerSetWatchpoint(struct Debugger* debugger, uint32_t address, enum WatchpointType type);
120void DebuggerClearWatchpoint(struct Debugger* debugger, uint32_t address);
121
122#endif