Skip to content

Commit f37ffb2

Browse files
committed
Allow autorun commands to complete before continuing or running.
The update makes sure that the `autorun` commands are completed prior to setting breakpoints initiated from the editor, as well as performing additional processing related to continuing or running the application. Also corrected non-unique error response codes in the GDB launch and attach and added missing error responses for the LLDB and Mago launch and attach.
1 parent d6c5778 commit f37ffb2

File tree

7 files changed

+39
-61
lines changed

7 files changed

+39
-61
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# [Unreleased]
22
## Fixed
3+
* Fixes #348 - Not waiting for `autorun` commands to complete before continuing execution (@brownts).
34
* Fixes #382 - Breakpoints not always cleared over SSH - PR #383 (@abussy-aldebaran)
45
* Fixes #346 - Case-sensitivity not respected in SSH path mapping - PR #352 (@brownts)
56
* Fixes #342 - Local variables not displayed more than 2 stack frames deep - PR #345 (@brownts)

src/backend/backend.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ export interface SSHArguments {
5050
}
5151

5252
export interface IBackend {
53-
load(cwd: string, target: string, procArgs: string, separateConsole: string): Thenable<any>;
54-
ssh(args: SSHArguments, cwd: string, target: string, procArgs: string, separateConsole: string, attach: boolean): Thenable<any>;
55-
attach(cwd: string, executable: string, target: string): Thenable<any>;
56-
connect(cwd: string, executable: string, target: string): Thenable<any>;
53+
load(cwd: string, target: string, procArgs: string, separateConsole: string, autorun: string[]): Thenable<any>;
54+
ssh(args: SSHArguments, cwd: string, target: string, procArgs: string, separateConsole: string, attach: boolean, autorun: string[]): Thenable<any>;
55+
attach(cwd: string, executable: string, target: string, autorun: string[]): Thenable<any>;
56+
connect(cwd: string, executable: string, target: string, autorun: string[]): Thenable<any>;
5757
start(runToStart: boolean): Thenable<boolean>;
5858
stop();
5959
detach();

src/backend/mi2/mi2.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export class MI2 extends EventEmitter implements IBackend {
4848
}
4949
}
5050

51-
load(cwd: string, target: string, procArgs: string, separateConsole: string): Thenable<any> {
51+
load(cwd: string, target: string, procArgs: string, separateConsole: string, autorun: string[]): Thenable<any> {
5252
if (!path.isAbsolute(target))
5353
target = path.join(cwd, target);
5454
return new Promise((resolve, reject) => {
@@ -65,6 +65,7 @@ export class MI2 extends EventEmitter implements IBackend {
6565
if (process.platform == "win32") {
6666
if (separateConsole !== undefined)
6767
promises.push(this.sendCommand("gdb-set new-console on"));
68+
promises.push(...autorun.map(value => { return this.sendUserInput(value); }));
6869
Promise.all(promises).then(() => {
6970
this.emit("debug-ready");
7071
resolve(undefined);
@@ -73,12 +74,14 @@ export class MI2 extends EventEmitter implements IBackend {
7374
if (separateConsole !== undefined) {
7475
linuxTerm.spawnTerminalEmulator(separateConsole).then(tty => {
7576
promises.push(this.sendCommand("inferior-tty-set " + tty));
77+
promises.push(...autorun.map(value => { return this.sendUserInput(value); }));
7678
Promise.all(promises).then(() => {
7779
this.emit("debug-ready");
7880
resolve(undefined);
7981
}, reject);
8082
});
8183
} else {
84+
promises.push(...autorun.map(value => { return this.sendUserInput(value); }));
8285
Promise.all(promises).then(() => {
8386
this.emit("debug-ready");
8487
resolve(undefined);
@@ -88,7 +91,7 @@ export class MI2 extends EventEmitter implements IBackend {
8891
});
8992
}
9093

91-
ssh(args: SSHArguments, cwd: string, target: string, procArgs: string, separateConsole: string, attach: boolean): Thenable<any> {
94+
ssh(args: SSHArguments, cwd: string, target: string, procArgs: string, separateConsole: string, attach: boolean, autorun: string[]): Thenable<any> {
9295
return new Promise((resolve, reject) => {
9396
this.isSSH = true;
9497
this.sshReady = false;
@@ -169,6 +172,7 @@ export class MI2 extends EventEmitter implements IBackend {
169172
promises.push(this.sendCommand("target-attach " + target));
170173
} else if (procArgs && procArgs.length)
171174
promises.push(this.sendCommand("exec-arguments " + procArgs));
175+
promises.push(...autorun.map(value => { return this.sendUserInput(value); }));
172176
Promise.all(promises).then(() => {
173177
this.emit("debug-ready");
174178
resolve(undefined);
@@ -222,7 +226,7 @@ export class MI2 extends EventEmitter implements IBackend {
222226
return cmds;
223227
}
224228

225-
attach(cwd: string, executable: string, target: string): Thenable<any> {
229+
attach(cwd: string, executable: string, target: string, autorun: string[]): Thenable<any> {
226230
return new Promise((resolve, reject) => {
227231
let args = [];
228232
if (executable && !path.isAbsolute(executable))
@@ -244,14 +248,15 @@ export class MI2 extends EventEmitter implements IBackend {
244248
promises.push(this.sendCommand("file-exec-and-symbols \"" + escape(executable) + "\""));
245249
promises.push(this.sendCommand("target-attach " + target));
246250
}
251+
promises.push(...autorun.map(value => { return this.sendUserInput(value); }));
247252
Promise.all(promises).then(() => {
248253
this.emit("debug-ready");
249254
resolve(undefined);
250255
}, reject);
251256
});
252257
}
253258

254-
connect(cwd: string, executable: string, target: string): Thenable<any> {
259+
connect(cwd: string, executable: string, target: string, autorun: string[]): Thenable<any> {
255260
return new Promise((resolve, reject) => {
256261
let args = [];
257262
if (executable && !path.isAbsolute(executable))
@@ -266,6 +271,7 @@ export class MI2 extends EventEmitter implements IBackend {
266271
this.process.on("error", ((err) => { this.emit("launcherror", err); }).bind(this));
267272
const promises = this.initCommands(target, cwd, true);
268273
promises.push(this.sendCommand("target-select remote " + target));
274+
promises.push(...autorun.map(value => { return this.sendUserInput(value); }));
269275
Promise.all(promises).then(() => {
270276
this.emit("debug-ready");
271277
resolve(undefined);

src/backend/mi2/mi2lldb.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export class MI2_LLDB extends MI2 {
3535
return cmds;
3636
}
3737

38-
attach(cwd: string, executable: string, target: string): Thenable<any> {
38+
attach(cwd: string, executable: string, target: string, autorun: string[]): Thenable<any> {
3939
return new Promise((resolve, reject) => {
4040
const args = this.preargs.concat(this.extraargs || []);
4141
this.process = ChildProcess.spawn(this.application, args, { cwd: cwd, env: this.procEnv });
@@ -46,6 +46,7 @@ export class MI2_LLDB extends MI2 {
4646
const promises = this.initCommands(target, cwd, true);
4747
promises.push(this.sendCommand("file-exec-and-symbols \"" + escape(executable) + "\""));
4848
promises.push(this.sendCommand("target-attach " + target));
49+
promises.push(...autorun.map(value => { return this.sendUserInput(value); }));
4950
Promise.all(promises).then(() => {
5051
this.emit("debug-ready");
5152
resolve(undefined);

src/gdb.ts

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -79,21 +79,13 @@ class GDBDebugSession extends MI2DebugSession {
7979
args.ssh.remotex11screen = 0;
8080
this.isSSH = true;
8181
this.setSourceFileMap(args.ssh.sourceFileMap, args.ssh.cwd, args.cwd);
82-
this.miDebugger.ssh(args.ssh, args.ssh.cwd, args.target, args.arguments, args.terminal, false).then(() => {
83-
if (args.autorun)
84-
args.autorun.forEach(command => {
85-
this.miDebugger.sendUserInput(command);
86-
});
82+
this.miDebugger.ssh(args.ssh, args.ssh.cwd, args.target, args.arguments, args.terminal, false, args.autorun || []).then(() => {
8783
this.sendResponse(response);
8884
}, err => {
89-
this.sendErrorResponse(response, 102, `Failed to SSH: ${err.toString()}`);
85+
this.sendErrorResponse(response, 105, `Failed to SSH: ${err.toString()}`);
9086
});
9187
} else {
92-
this.miDebugger.load(args.cwd, args.target, args.arguments, args.terminal).then(() => {
93-
if (args.autorun)
94-
args.autorun.forEach(command => {
95-
this.miDebugger.sendUserInput(command);
96-
});
88+
this.miDebugger.load(args.cwd, args.target, args.arguments, args.terminal, args.autorun || []).then(() => {
9789
this.sendResponse(response);
9890
}, err => {
9991
this.sendErrorResponse(response, 103, `Failed to load MI Debugger: ${err.toString()}`);
@@ -126,32 +118,20 @@ class GDBDebugSession extends MI2DebugSession {
126118
args.ssh.remotex11screen = 0;
127119
this.isSSH = true;
128120
this.setSourceFileMap(args.ssh.sourceFileMap, args.ssh.cwd, args.cwd);
129-
this.miDebugger.ssh(args.ssh, args.ssh.cwd, args.target, "", undefined, true).then(() => {
130-
if (args.autorun)
131-
args.autorun.forEach(command => {
132-
this.miDebugger.sendUserInput(command);
133-
});
121+
this.miDebugger.ssh(args.ssh, args.ssh.cwd, args.target, "", undefined, true, args.autorun || []).then(() => {
134122
this.sendResponse(response);
135123
}, err => {
136-
this.sendErrorResponse(response, 102, `Failed to SSH: ${err.toString()}`);
124+
this.sendErrorResponse(response, 104, `Failed to SSH: ${err.toString()}`);
137125
});
138126
} else {
139127
if (args.remote) {
140-
this.miDebugger.connect(args.cwd, args.executable, args.target).then(() => {
141-
if (args.autorun)
142-
args.autorun.forEach(command => {
143-
this.miDebugger.sendUserInput(command);
144-
});
128+
this.miDebugger.connect(args.cwd, args.executable, args.target, args.autorun || []).then(() => {
145129
this.sendResponse(response);
146130
}, err => {
147131
this.sendErrorResponse(response, 102, `Failed to attach: ${err.toString()}`);
148132
});
149133
} else {
150-
this.miDebugger.attach(args.cwd, args.executable, args.target).then(() => {
151-
if (args.autorun)
152-
args.autorun.forEach(command => {
153-
this.miDebugger.sendUserInput(command);
154-
});
134+
this.miDebugger.attach(args.cwd, args.executable, args.target, args.autorun || []).then(() => {
155135
this.sendResponse(response);
156136
}, err => {
157137
this.sendErrorResponse(response, 101, `Failed to attach: ${err.toString()}`);

src/lldb.ts

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -74,20 +74,16 @@ class LLDBDebugSession extends MI2DebugSession {
7474
args.ssh.remotex11screen = 0;
7575
this.isSSH = true;
7676
this.setSourceFileMap(args.ssh.sourceFileMap, args.ssh.cwd, args.cwd);
77-
this.miDebugger.ssh(args.ssh, args.ssh.cwd, args.target, args.arguments, undefined, false).then(() => {
78-
if (args.autorun)
79-
args.autorun.forEach(command => {
80-
this.miDebugger.sendUserInput(command);
81-
});
77+
this.miDebugger.ssh(args.ssh, args.ssh.cwd, args.target, args.arguments, undefined, false, args.autorun || []).then(() => {
8278
this.sendResponse(response);
79+
}, err => {
80+
this.sendErrorResponse(response, 106, `Failed to SSH: ${err.toString()}`);
8381
});
8482
} else {
85-
this.miDebugger.load(args.cwd, args.target, args.arguments, undefined).then(() => {
86-
if (args.autorun)
87-
args.autorun.forEach(command => {
88-
this.miDebugger.sendUserInput(command);
89-
});
83+
this.miDebugger.load(args.cwd, args.target, args.arguments, undefined, args.autorun || []).then(() => {
9084
this.sendResponse(response);
85+
}, err => {
86+
this.sendErrorResponse(response, 107, `Failed to load MI Debugger: ${err.toString()}`);
9187
});
9288
}
9389
}
@@ -104,12 +100,10 @@ class LLDBDebugSession extends MI2DebugSession {
104100
this.miDebugger.printCalls = !!args.printCalls;
105101
this.miDebugger.debugOutput = !!args.showDevDebugOutput;
106102
this.stopAtEntry = args.stopAtEntry;
107-
this.miDebugger.attach(args.cwd, args.executable, args.target).then(() => {
108-
if (args.autorun)
109-
args.autorun.forEach(command => {
110-
this.miDebugger.sendUserInput(command);
111-
});
103+
this.miDebugger.attach(args.cwd, args.executable, args.target, args.autorun || []).then(() => {
112104
this.sendResponse(response);
105+
}, err => {
106+
this.sendErrorResponse(response, 108, `Failed to attach: ${err.toString()}`);
113107
});
114108
}
115109

src/mago.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,10 @@ class MagoDebugSession extends MI2DebugSession {
6161
this.setValuesFormattingMode(args.valuesFormatting);
6262
this.miDebugger.printCalls = !!args.printCalls;
6363
this.miDebugger.debugOutput = !!args.showDevDebugOutput;
64-
this.miDebugger.load(args.cwd, args.target, args.arguments, undefined).then(() => {
65-
if (args.autorun)
66-
args.autorun.forEach(command => {
67-
this.miDebugger.sendUserInput(command);
68-
});
64+
this.miDebugger.load(args.cwd, args.target, args.arguments, undefined, args.autorun || []).then(() => {
6965
this.sendResponse(response);
66+
}, err => {
67+
this.sendErrorResponse(response, 109, `Failed to load MI Debugger: ${err.toString()}`);
7068
});
7169
}
7270

@@ -80,12 +78,10 @@ class MagoDebugSession extends MI2DebugSession {
8078
this.setValuesFormattingMode(args.valuesFormatting);
8179
this.miDebugger.printCalls = !!args.printCalls;
8280
this.miDebugger.debugOutput = !!args.showDevDebugOutput;
83-
this.miDebugger.attach(args.cwd, args.executable, args.target).then(() => {
84-
if (args.autorun)
85-
args.autorun.forEach(command => {
86-
this.miDebugger.sendUserInput(command);
87-
});
81+
this.miDebugger.attach(args.cwd, args.executable, args.target, args.autorun || []).then(() => {
8882
this.sendResponse(response);
83+
}, err => {
84+
this.sendErrorResponse(response, 110, `Failed to attach: ${err.toString()}`);
8985
});
9086
}
9187
}

0 commit comments

Comments
 (0)