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