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