-
Notifications
You must be signed in to change notification settings - Fork 124
Expand file tree
/
Copy pathaliceserver.ts
More file actions
140 lines (125 loc) · 5.04 KB
/
aliceserver.ts
File metadata and controls
140 lines (125 loc) · 5.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
// Manages a debugging session using Aliceserver.
//
// This imports and uses the MI2_ALICE class to manage its session using
// supported commands.
import { MI2DebugSession, RunCommand } from './mibase';
import { DebugSession, InitializedEvent, TerminatedEvent, StoppedEvent, OutputEvent, Thread, StackFrame, Scope, Source, Handles } from 'vscode-debugadapter';
import { DebugProtocol } from 'vscode-debugprotocol';
import { MI2_ALICE } from "./backend/mi2/mi2aliceserver";
import { SSHArguments, ValuesFormattingMode } from './backend/backend';
import { execSync } from 'child_process'; // Temporary import
export interface LaunchRequestArguments extends DebugProtocol.LaunchRequestArguments {
cwd: string;
target: string;
target_arguments: string;
aliceserver_path: string;
env: any;
debugger_args: string[];
autorun: string[];
stopAtEntry: boolean | string;
ssh: SSHArguments;
valuesFormatting: ValuesFormattingMode;
printCalls: boolean;
showDevDebugOutput: boolean;
}
export interface AttachRequestArguments extends DebugProtocol.AttachRequestArguments {
cwd: string;
target: string;
aliceserver_path: string;
env: any;
debugger_args: string[];
executable: string;
autorun: string[];
stopAtConnect: boolean;
stopAtEntry: boolean | string;
printCalls: boolean;
showDevDebugOutput: boolean;
}
class AliceserverDebugSession extends MI2DebugSession {
protected override initializeRequest(response: DebugProtocol.InitializeResponse, args: DebugProtocol.InitializeRequestArguments): void {
response.body.supportsGotoTargetsRequest = false;
response.body.supportsHitConditionalBreakpoints = false;
response.body.supportsConfigurationDoneRequest = false;
response.body.supportsConditionalBreakpoints = false;
response.body.supportsFunctionBreakpoints = false;
response.body.supportsEvaluateForHovers = false;
this.sendResponse(response);
}
// NOTE: Temporary fix that allows absolute executable paths outside of PATH
// Until Aliceserver is fully implemented.
// This fix bypasses the PATH check (performed by Windows' WHERE and
// POSIX's command(1)) by directly invoking the compiler.
protected checkCommand(debuggerName: string): boolean {
try {
execSync(`${debuggerName} --version`, { stdio: 'ignore' });
return true;
} catch (error) {
return false;
}
}
protected override launchRequest(response: DebugProtocol.LaunchResponse, args: LaunchRequestArguments): void {
const dbgCommand = args.aliceserver_path || "aliceserver";
if (args.aliceserver_path === undefined && this.checkCommand(dbgCommand)) {
this.sendErrorResponse(response, 104, `Configured debugger ${dbgCommand} not found.`);
return;
}
this.miDebugger = new MI2_ALICE(dbgCommand, [ "-a", "mi" ], args.debugger_args, args.env);
this.initDebugger();
// Defaults
this.quit = false;
this.attached = false;
this.initialRunCommand = RunCommand.RUN;
this.isSSH = false;
this.started = false;
this.crashed = false;
this.miDebugger.printCalls = !!args.printCalls;
this.miDebugger.debugOutput = !!args.showDevDebugOutput;
this.stopAtEntry = args.stopAtEntry;
// Initiate session
this.isSSH = args.ssh !== undefined;
if (this.isSSH) {
// Set defaults if these are unset
args.ssh.forwardX11 ??= true;
args.ssh.port ??= 22;
args.ssh.x11port ??= 6000;
args.ssh.x11host ??= "localhost";
args.ssh.remotex11screen ??= 0;
this.setSourceFileMap(args.ssh.sourceFileMap, args.ssh.cwd, args.cwd);
this.miDebugger.ssh(args.ssh, args.ssh.cwd, args.target, args.target_arguments, undefined, false, args.autorun || []).then(() => {
this.sendResponse(response);
}, err => {
this.sendErrorResponse(response, 106, `Failed to SSH: ${err.toString()}`);
});
} else { // Local session
this.miDebugger.load(args.cwd, args.target, args.target_arguments, undefined, args.autorun || []).then(() => {
this.sendResponse(response);
}, err => {
this.sendErrorResponse(response, 107, `Failed to load MI Debugger: ${err.toString()}`);
});
}
}
protected override attachRequest(response: DebugProtocol.AttachResponse, args: AttachRequestArguments): void {
const dbgCommand = args.aliceserver_path || "aliceserver";
if (args.aliceserver_path === undefined && this.checkCommand(dbgCommand)) {
this.sendErrorResponse(response, 104, `Configured debugger ${dbgCommand} not found.`);
return;
}
this.miDebugger = new MI2_ALICE(dbgCommand, ["-a", "mi"], args.debugger_args, args.env);
this.initDebugger();
// Defaults
this.quit = false;
this.attached = true;
this.initialRunCommand = args.stopAtConnect ? RunCommand.NONE : RunCommand.CONTINUE;
this.isSSH = false;
this.miDebugger.printCalls = !!args.printCalls;
this.miDebugger.debugOutput = !!args.showDevDebugOutput;
this.stopAtEntry = args.stopAtEntry;
// Start session
this.miDebugger.attach(args.cwd, args.executable, args.target, args.autorun || []).then(() => {
this.sendResponse(response);
}, err => {
this.sendErrorResponse(response, 108, `Failed to attach: ${err.toString()}`);
});
}
}
DebugSession.run(AliceserverDebugSession);