include/mgba/internal/debugger/cli-debugger.h (view raw)
1/* Copyright (c) 2013-2016 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 CLI_DEBUGGER_H
7#define CLI_DEBUGGER_H
8
9#include <mgba-util/common.h>
10
11CXX_GUARD_START
12
13#include <mgba/debugger/debugger.h>
14
15extern const char* ERROR_MISSING_ARGS;
16extern const char* ERROR_OVERFLOW;
17extern const char* ERROR_INVALID_ARGS;
18extern const char* INFO_BREAKPOINT_ADDED;
19extern const char* INFO_WATCHPOINT_ADDED;
20
21struct CLIDebugger;
22struct VFile;
23
24struct CLIDebugVector {
25 struct CLIDebugVector* next;
26 enum CLIDVType {
27 CLIDV_ERROR_TYPE,
28 CLIDV_INT_TYPE,
29 CLIDV_CHAR_TYPE,
30 } type;
31 char* charValue;
32 int32_t intValue;
33 int segmentValue;
34};
35
36typedef void (*CLIDebuggerCommand)(struct CLIDebugger*, struct CLIDebugVector*);
37
38struct CLIDebuggerCommandSummary {
39 const char* name;
40 CLIDebuggerCommand command;
41 const char* format;
42 const char* summary;
43};
44
45struct CLIDebuggerCommandAlias {
46 const char* name;
47 const char* original;
48};
49
50struct CLIDebuggerSystem {
51 struct CLIDebugger* p;
52
53 void (*init)(struct CLIDebuggerSystem*);
54 void (*deinit)(struct CLIDebuggerSystem*);
55 bool (*custom)(struct CLIDebuggerSystem*);
56
57 void (*disassemble)(struct CLIDebuggerSystem*, struct CLIDebugVector* dv);
58 void (*printStatus)(struct CLIDebuggerSystem*);
59
60 struct CLIDebuggerCommandSummary* commands;
61 struct CLIDebuggerCommandAlias* commandAliases;
62 const char* name;
63 struct CLIDebuggerCommandSummary* platformCommands;
64 struct CLIDebuggerCommandAlias* platformCommandAliases;
65 const char* platformName;
66};
67
68struct CLIDebuggerBackend {
69 struct CLIDebugger* p;
70
71 void (*init)(struct CLIDebuggerBackend*);
72 void (*deinit)(struct CLIDebuggerBackend*);
73
74 ATTRIBUTE_FORMAT(printf, 2, 3)
75 void (*printf)(struct CLIDebuggerBackend*, const char* fmt, ...);
76 const char* (*readline)(struct CLIDebuggerBackend*, size_t* len);
77 void (*lineAppend)(struct CLIDebuggerBackend*, const char* line);
78 const char* (*historyLast)(struct CLIDebuggerBackend*, size_t* len);
79 void (*historyAppend)(struct CLIDebuggerBackend*, const char* line);
80};
81
82struct CLIDebugger {
83 struct mDebugger d;
84
85 struct CLIDebuggerSystem* system;
86 struct CLIDebuggerBackend* backend;
87
88 int traceRemaining;
89 struct VFile* traceVf;
90};
91
92void CLIDebuggerCreate(struct CLIDebugger*);
93void CLIDebuggerAttachSystem(struct CLIDebugger*, struct CLIDebuggerSystem*);
94void CLIDebuggerAttachBackend(struct CLIDebugger*, struct CLIDebuggerBackend*);
95
96bool CLIDebuggerTabComplete(struct CLIDebugger*, const char* token, bool initial, size_t len);
97
98CXX_GUARD_END
99
100#endif