all repos — mgba @ a2447d09e3e0bacaf8e8c0b750fac18f13de4fdf

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