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 CLIDebuggerSystem {
46 struct CLIDebugger* p;
47
48 void (*init)(struct CLIDebuggerSystem*);
49 void (*deinit)(struct CLIDebuggerSystem*);
50 bool (*custom)(struct CLIDebuggerSystem*);
51
52 void (*disassemble)(struct CLIDebuggerSystem*, 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 int traceRemaining;
82 struct VFile* traceVf;
83};
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