all repos — mgba @ 04f3fdf21ea5bc446c461fc427eec2f0eb46417f

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	char* charValue;
28	int32_t intValue;
29	int segmentValue;
30};
31
32typedef void (*CLIDebuggerCommand)(struct CLIDebugger*, struct CLIDebugVector*);
33typedef struct CLIDebugVector* (*CLIDVParser)(struct CLIDebugger* debugger, const char* string, size_t length);
34
35struct CLIDebuggerCommandSummary {
36	const char* name;
37	CLIDebuggerCommand command;
38	CLIDVParser parser;
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	uint32_t (*lookupIdentifier)(struct CLIDebuggerSystem*, const char* name, struct CLIDebugVector* dv);
51	uint32_t (*lookupPlatformIdentifier)(struct CLIDebuggerSystem*, const char* name, struct CLIDebugVector* dv);
52	void (*printStatus)(struct CLIDebuggerSystem*);
53
54	struct CLIDebuggerCommandSummary* commands;
55	const char* name;
56	struct CLIDebuggerCommandSummary* platformCommands;
57	const char* platformName;
58};
59
60struct CLIDebuggerBackend {
61	struct CLIDebugger* p;
62
63	void (*init)(struct CLIDebuggerBackend*);
64	void (*deinit)(struct CLIDebuggerBackend*);
65
66	ATTRIBUTE_FORMAT(printf, 2, 3)
67	void (*printf)(struct CLIDebuggerBackend*, const char* fmt, ...);
68	const char* (*readline)(struct CLIDebuggerBackend*, size_t* len);
69	void (*lineAppend)(struct CLIDebuggerBackend*, const char* line);
70	const char* (*historyLast)(struct CLIDebuggerBackend*, size_t* len);
71	void (*historyAppend)(struct CLIDebuggerBackend*, const char* line);
72};
73
74struct CLIDebugger {
75	struct mDebugger d;
76
77	struct CLIDebuggerSystem* system;
78	struct CLIDebuggerBackend* backend;
79};
80
81struct CLIDebugVector* CLIDVParse(struct CLIDebugger* debugger, const char* string, size_t length);
82struct CLIDebugVector* CLIDVStringParse(struct CLIDebugger* debugger, const char* string, size_t length);
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