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
84enum DebuggerLogLevel {
85 DEBUGGER_LOG_DEBUG = 0x01,
86 DEBUGGER_LOG_INFO = 0x02,
87 DEBUGGER_LOG_WARN = 0x04,
88 DEBUGGER_LOG_ERROR = 0x08
89};
90
91struct Debugger {
92 struct mCPUComponent d;
93 enum DebuggerState state;
94 struct ARMCore* cpu;
95
96 struct DebugBreakpointList breakpoints;
97 struct DebugBreakpointList swBreakpoints;
98 struct DebugWatchpointList watchpoints;
99 struct ARMMemory originalMemory;
100
101 struct DebugBreakpoint* currentBreakpoint;
102
103 void (*init)(struct Debugger*);
104 void (*deinit)(struct Debugger*);
105 void (*paused)(struct Debugger*);
106 void (*entered)(struct Debugger*, enum DebuggerEntryReason, struct DebuggerEntryInfo*);
107 void (*custom)(struct Debugger*);
108
109 bool (*setSoftwareBreakpoint)(struct Debugger*, uint32_t address, enum ExecutionMode mode, uint32_t* opcode);
110 bool (*clearSoftwareBreakpoint)(struct Debugger*, uint32_t address, enum ExecutionMode mode, uint32_t opcode);
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