all repos — mgba @ e820e4dcbb71bd3e7486e9a828a0226075103bc3

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	union {
29		char* charValue;
30		struct {
31			int32_t intValue;
32			int segmentValue;
33		};
34	};
35};
36
37typedef void (*CLIDebuggerCommand)(struct CLIDebugger*, struct CLIDebugVector*);
38
39struct CLIDebuggerCommandSummary {
40	const char* name;
41	CLIDebuggerCommand command;
42	const char* format;
43	const char* summary;
44};
45
46struct CLIDebuggerSystem {
47	struct CLIDebugger* p;
48
49	void (*init)(struct CLIDebuggerSystem*);
50	void (*deinit)(struct CLIDebuggerSystem*);
51	bool (*custom)(struct CLIDebuggerSystem*);
52
53	void (*disassemble)(struct CLIDebuggerSystem*, struct CLIDebugVector* dv);
54	uint32_t (*lookupIdentifier)(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