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 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 = 3
36};
37
38struct DebugWatchpoint {
39 struct DebugWatchpoint* next;
40 uint32_t address;
41 enum WatchpointType type;
42};
43
44enum DebuggerEntryReason {
45 DEBUGGER_ENTER_MANUAL,
46 DEBUGGER_ENTER_ATTACHED,
47 DEBUGGER_ENTER_BREAKPOINT,
48 DEBUGGER_ENTER_WATCHPOINT,
49 DEBUGGER_ENTER_ILLEGAL_OP
50};
51
52struct DebuggerEntryInfo {
53 uint32_t address;
54 union {
55 struct {
56 uint32_t oldValue;
57 enum WatchpointType watchType;
58 };
59
60 struct {
61 uint32_t opcode;
62 };
63 };
64};
65
66enum DebuggerLogLevel {
67 DEBUGGER_LOG_DEBUG = 0x01,
68 DEBUGGER_LOG_INFO = 0x02,
69 DEBUGGER_LOG_WARN = 0x04,
70 DEBUGGER_LOG_ERROR = 0x08
71};
72
73struct ARMDebugger {
74 struct ARMComponent d;
75 enum DebuggerState state;
76 struct ARMCore* cpu;
77
78 struct DebugBreakpoint* breakpoints;
79 struct DebugBreakpoint* swBreakpoints;
80 struct DebugWatchpoint* watchpoints;
81 struct ARMMemory originalMemory;
82
83 struct DebugBreakpoint* currentBreakpoint;
84
85 void (*init)(struct ARMDebugger*);
86 void (*deinit)(struct ARMDebugger*);
87 void (*paused)(struct ARMDebugger*);
88 void (*entered)(struct ARMDebugger*, enum DebuggerEntryReason, struct DebuggerEntryInfo*);
89 void (*custom)(struct ARMDebugger*);
90
91 bool (*setSoftwareBreakpoint)(struct ARMDebugger*, uint32_t address, enum ExecutionMode mode, uint32_t* opcode);
92 bool (*clearSoftwareBreakpoint)(struct ARMDebugger*, uint32_t address, enum ExecutionMode mode, uint32_t opcode);
93
94 __attribute__((format (printf, 3, 4)))
95 void (*log)(struct ARMDebugger*, enum DebuggerLogLevel, const char* format, ...);
96};
97
98void ARMDebuggerCreate(struct ARMDebugger*);
99void ARMDebuggerRun(struct ARMDebugger*);
100void ARMDebuggerEnter(struct ARMDebugger*, enum DebuggerEntryReason, struct DebuggerEntryInfo*);
101void ARMDebuggerSetBreakpoint(struct ARMDebugger* debugger, uint32_t address);
102bool ARMDebuggerSetSoftwareBreakpoint(struct ARMDebugger* debugger, uint32_t address, enum ExecutionMode mode);
103void ARMDebuggerClearBreakpoint(struct ARMDebugger* debugger, uint32_t address);
104void ARMDebuggerSetWatchpoint(struct ARMDebugger* debugger, uint32_t address);
105void ARMDebuggerClearWatchpoint(struct ARMDebugger* debugger, uint32_t address);
106
107#endif