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 mDebuggerType {
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 mDebuggerState {
31 DEBUGGER_PAUSED,
32 DEBUGGER_RUNNING,
33 DEBUGGER_CUSTOM,
34 DEBUGGER_SHUTDOWN
35};
36
37enum mWatchpointType {
38 WATCHPOINT_WRITE = 1,
39 WATCHPOINT_READ = 2,
40 WATCHPOINT_RW = WATCHPOINT_WRITE | WATCHPOINT_READ
41};
42
43enum mBreakpointType {
44 BREAKPOINT_HARDWARE,
45 BREAKPOINT_SOFTWARE
46};
47
48enum mDebuggerEntryReason {
49 DEBUGGER_ENTER_MANUAL,
50 DEBUGGER_ENTER_ATTACHED,
51 DEBUGGER_ENTER_BREAKPOINT,
52 DEBUGGER_ENTER_WATCHPOINT,
53 DEBUGGER_ENTER_ILLEGAL_OP
54};
55
56struct mDebugWatchpoint {
57 uint32_t address;
58 enum mWatchpointType type;
59};
60
61DECLARE_VECTOR(mDebugBreakpointList, struct mDebugBreakpoint);
62DECLARE_VECTOR(mDebugWatchpointList, struct mDebugWatchpoint);
63
64extern const char* ERROR_MISSING_ARGS;
65extern const char* ERROR_OVERFLOW;
66
67struct mDebuggerEntryInfo {
68 uint32_t address;
69 union {
70 struct {
71 uint32_t oldValue;
72 uint32_t newValue;
73 enum mWatchpointType watchType;
74 enum mWatchpointType accessType;
75 };
76
77 struct {
78 uint32_t opcode;
79 enum mBreakpointType breakType;
80 };
81 };
82};
83
84struct mDebugger;
85struct mDebuggerPlatform {
86 struct mDebugger* p;
87
88 void (*init)(void* cpu, struct mDebuggerPlatform*);
89 void (*deinit)(struct mDebuggerPlatform*);
90 void (*entered)(struct mDebuggerPlatform*, enum mDebuggerEntryReason, struct mDebuggerEntryInfo*);
91
92 bool (*hasBreakpoints)(struct mDebuggerPlatform*);
93 void (*setBreakpoint)(struct mDebuggerPlatform*, uint32_t address);
94 void (*clearBreakpoint)(struct mDebuggerPlatform*, uint32_t address);
95 void (*setWatchpoint)(struct mDebuggerPlatform*, uint32_t address, enum mWatchpointType type);
96 void (*clearWatchpoint)(struct mDebuggerPlatform*, uint32_t address);
97 void (*checkBreakpoints)(struct mDebuggerPlatform*);
98};
99
100struct mDebugger {
101 struct mCPUComponent d;
102 struct mDebuggerPlatform* platform;
103 enum mDebuggerState state;
104 struct mCore* core;
105
106 void (*init)(struct mDebugger*);
107 void (*deinit)(struct mDebugger*);
108
109 void (*paused)(struct mDebugger*);
110 void (*entered)(struct mDebugger*, enum mDebuggerEntryReason, struct mDebuggerEntryInfo*);
111 void (*custom)(struct mDebugger*);
112};
113
114struct mDebugger* mDebuggerCreate(enum mDebuggerType type, struct mCore*);
115void mDebuggerAttach(struct mDebugger*, struct mCore*);
116void mDebuggerRun(struct mDebugger*);
117void mDebuggerEnter(struct mDebugger*, enum mDebuggerEntryReason, struct mDebuggerEntryInfo*);
118
119
120#endif