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;
17
18struct CLIDebugger;
19
20struct CLIDebugVector {
21 struct CLIDebugVector* next;
22 enum CLIDVType {
23 CLIDV_ERROR_TYPE,
24 CLIDV_INT_TYPE,
25 CLIDV_CHAR_TYPE,
26 } type;
27 union {
28 char* charValue;
29 struct {
30 int32_t intValue;
31 int segmentValue;
32 };
33 };
34};
35
36typedef void (*CLIDebuggerCommand)(struct CLIDebugger*, struct CLIDebugVector*);
37typedef struct CLIDebugVector* (*CLIDVParser)(struct CLIDebugger* debugger, const char* string, size_t length);
38
39struct CLIDebuggerCommandSummary {
40 const char* name;
41 CLIDebuggerCommand command;
42 CLIDVParser parser;
43 const char* summary;
44};
45
46struct CLIDebuggerSystem {
47 struct CLIDebugger* p;
48
49 void (*init)(struct CLIDebuggerSystem*);
50 void (*deinit)(struct CLIDebuggerSystem*);
51 bool (*custom)(struct CLIDebuggerSystem*);
52
53 void (*disassemble)(struct CLIDebuggerSystem*, struct CLIDebugVector* dv);
54 uint32_t (*lookupIdentifier)(struct CLIDebuggerSystem*, const char* name, struct CLIDebugVector* dv);
55 uint32_t (*lookupPlatformIdentifier)(struct CLIDebuggerSystem*, const char* name, struct CLIDebugVector* dv);
56 void (*printStatus)(struct CLIDebuggerSystem*);
57
58 struct CLIDebuggerCommandSummary* commands;
59 const char* name;
60 struct CLIDebuggerCommandSummary* platformCommands;
61 const char* platformName;
62};
63
64struct CLIDebuggerBackend {
65 struct CLIDebugger* p;
66
67 void (*init)(struct CLIDebuggerBackend*);
68 void (*deinit)(struct CLIDebuggerBackend*);
69
70 ATTRIBUTE_FORMAT(printf, 2, 3)
71 void (*printf)(struct CLIDebuggerBackend*, const char* fmt, ...);
72 const char* (*readline)(struct CLIDebuggerBackend*, size_t* len);
73 void (*lineAppend)(struct CLIDebuggerBackend*, const char* line);
74 const char* (*historyLast)(struct CLIDebuggerBackend*, size_t* len);
75 void (*historyAppend)(struct CLIDebuggerBackend*, const char* line);
76};
77
78struct CLIDebugger {
79 struct mDebugger d;
80
81 struct CLIDebuggerSystem* system;
82 struct CLIDebuggerBackend* backend;
83};
84
85struct CLIDebugVector* CLIDVParse(struct CLIDebugger* debugger, const char* string, size_t length);
86struct CLIDebugVector* CLIDVStringParse(struct CLIDebugger* debugger, const char* string, size_t length);
87
88void CLIDebuggerCreate(struct CLIDebugger*);
89void CLIDebuggerAttachSystem(struct CLIDebugger*, struct CLIDebuggerSystem*);
90void CLIDebuggerAttachBackend(struct CLIDebugger*, struct CLIDebuggerBackend*);
91
92bool CLIDebuggerTabComplete(struct CLIDebugger*, const char* token, bool initial, size_t len);
93
94CXX_GUARD_END
95
96#endif