all repos — mgba @ a898c1b7558023580efb0919c7cdd70c6eea7737

mGBA Game Boy Advance Emulator

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	void (*printStatus)(struct CLIDebuggerSystem*);
51
52	struct CLIDebuggerCommandSummary* commands;
53	const char* name;
54	struct CLIDebuggerCommandSummary* platformCommands;
55	const char* platformName;
56};
57
58struct CLIDebuggerBackend {
59	struct CLIDebugger* p;
60
61	void (*init)(struct CLIDebuggerBackend*);
62	void (*deinit)(struct CLIDebuggerBackend*);
63
64	ATTRIBUTE_FORMAT(printf, 2, 3)
65	void (*printf)(struct CLIDebuggerBackend*, const char* fmt, ...);
66	const char* (*readline)(struct CLIDebuggerBackend*, size_t* len);
67	void (*lineAppend)(struct CLIDebuggerBackend*, const char* line);
68	const char* (*historyLast)(struct CLIDebuggerBackend*, size_t* len);
69	void (*historyAppend)(struct CLIDebuggerBackend*, const char* line);
70};
71
72struct CLIDebugger {
73	struct mDebugger d;
74
75	struct CLIDebuggerSystem* system;
76	struct CLIDebuggerBackend* backend;
77
78	int traceRemaining;
79};
80
81void CLIDebuggerCreate(struct CLIDebugger*);
82void CLIDebuggerAttachSystem(struct CLIDebugger*, struct CLIDebuggerSystem*);
83void CLIDebuggerAttachBackend(struct CLIDebugger*, struct CLIDebuggerBackend*);
84
85bool CLIDebuggerTabComplete(struct CLIDebugger*, const char* token, bool initial, size_t len);
86
87CXX_GUARD_END
88
89#endif