src/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 "util/common.h"
10
11#include "debugger.h"
12
13struct CLIDebugger;
14
15struct CLIDebugVector {
16 struct CLIDebugVector* next;
17 enum CLIDVType {
18 CLIDV_ERROR_TYPE,
19 CLIDV_INT_TYPE,
20 CLIDV_CHAR_TYPE,
21 } type;
22 union {
23 char* charValue;
24 struct {
25 int32_t intValue;
26 int segmentValue;
27 };
28 };
29};
30
31typedef void (*CLIDebuggerCommand)(struct CLIDebugger*, struct CLIDebugVector*);
32typedef struct CLIDebugVector* (*CLIDVParser)(struct CLIDebugger* debugger, const char* string, size_t length);
33
34struct CLIDebuggerCommandSummary {
35 const char* name;
36 CLIDebuggerCommand command;
37 CLIDVParser parser;
38 const char* summary;
39};
40
41struct CLIDebuggerSystem {
42 struct CLIDebugger* p;
43
44 void (*init)(struct CLIDebuggerSystem*);
45 void (*deinit)(struct CLIDebuggerSystem*);
46 bool (*custom)(struct CLIDebuggerSystem*);
47
48 void (*disassemble)(struct CLIDebuggerSystem*, struct CLIDebugVector* dv);
49 uint32_t (*lookupIdentifier)(struct CLIDebuggerSystem*, const char* name, struct CLIDebugVector* dv);
50 uint32_t (*lookupPlatformIdentifier)(struct CLIDebuggerSystem*, const char* name, struct CLIDebugVector* dv);
51 void (*printStatus)(struct CLIDebuggerSystem*);
52
53 struct CLIDebuggerCommandSummary* commands;
54 const char* name;
55 struct CLIDebuggerCommandSummary* platformCommands;
56 const char* platformName;
57};
58
59struct CLIDebuggerBackend {
60 struct CLIDebugger* p;
61
62 void (*init)(struct CLIDebuggerBackend*);
63 void (*deinit)(struct CLIDebuggerBackend*);
64
65 ATTRIBUTE_FORMAT(printf, 2, 3)
66 void (*printf)(struct CLIDebuggerBackend*, const char* fmt, ...);
67 const char* (*readline)(struct CLIDebuggerBackend*, size_t* len);
68 void (*lineAppend)(struct CLIDebuggerBackend*, const char* line);
69 const char* (*historyLast)(struct CLIDebuggerBackend*, size_t* len);
70 void (*historyAppend)(struct CLIDebuggerBackend*, const char* line);
71};
72
73struct CLIDebugger {
74 struct mDebugger d;
75
76 struct CLIDebuggerSystem* system;
77 struct CLIDebuggerBackend* backend;
78};
79
80struct CLIDebugVector* CLIDVParse(struct CLIDebugger* debugger, const char* string, size_t length);
81struct CLIDebugVector* CLIDVStringParse(struct CLIDebugger* debugger, const char* string, size_t length);
82
83void CLIDebuggerCreate(struct CLIDebugger*);
84void CLIDebuggerAttachSystem(struct CLIDebugger*, struct CLIDebuggerSystem*);
85void CLIDebuggerAttachBackend(struct CLIDebugger*, struct CLIDebuggerBackend*);
86
87bool CLIDebuggerTabComplete(struct CLIDebugger*, const char* token, bool initial, size_t len);
88
89#endif