Skip to content

Commit bcca13e

Browse files
authored
Merge pull request #341 from brownts/bugfix/target_attach
Process initial commands before attaching to PID.
2 parents 06004ac + 8acaee1 commit bcca13e

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
* fix stack frame expansion in editor via use of the `startFrame` parameter #312 (@brownts)
2020
* allow specification of port/x11port via variable (as numeric string) #265 (@GitMensch)
2121
* Extra debugger arguments now work in all configurations #316, #338 fixing #206 (@GitMensch, @brownts)
22+
* Attaching to local PID now performs initialization prior to attaching #341 fixing #329 (@brownts)
2223

2324
# 0.25.1
2425

src/backend/mi2/mi2.ts

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,6 @@ export class MI2 extends EventEmitter implements IBackend {
143143
}
144144
let sshCMD = this.application + " " + this.preargs.concat(this.extraargs || []).join(" ");
145145
if (args.bootstrap) sshCMD = args.bootstrap + " && " + sshCMD;
146-
if (attach)
147-
sshCMD += " -p " + target;
148146
this.sshConn.exec(sshCMD, execArgs, (err, stream) => {
149147
if (err) {
150148
this.log("stderr", "Could not run " + this.application + "(" + sshCMD +") over ssh!");
@@ -166,7 +164,10 @@ export class MI2 extends EventEmitter implements IBackend {
166164
}).bind(this));
167165
const promises = this.initCommands(target, cwd, attach);
168166
promises.push(this.sendCommand("environment-cd \"" + escape(cwd) + "\""));
169-
if (procArgs && procArgs.length && !attach)
167+
if (attach) {
168+
// Attach to local process
169+
promises.push(this.sendCommand("target-attach " + target));
170+
} else if (procArgs && procArgs.length)
170171
promises.push(this.sendCommand("exec-arguments " + procArgs));
171172
Promise.all(promises).then(() => {
172173
this.emit("debug-ready");
@@ -226,25 +227,22 @@ export class MI2 extends EventEmitter implements IBackend {
226227
let args = [];
227228
if (executable && !path.isAbsolute(executable))
228229
executable = path.join(cwd, executable);
229-
let isExtendedRemote = false;
230230
args = this.preargs.concat(this.extraargs || []);
231-
if (target.startsWith("extended-remote")) {
232-
isExtendedRemote = true;
233-
} else {
234-
if (!executable)
235-
executable = "-p";
236-
args = args.concat([executable, target]);
237-
}
238231
this.process = ChildProcess.spawn(this.application, args, { cwd: cwd, env: this.procEnv });
239232
this.process.stdout.on("data", this.stdout.bind(this));
240233
this.process.stderr.on("data", this.stderr.bind(this));
241234
this.process.on("exit", (() => { this.emit("quit"); }).bind(this));
242235
this.process.on("error", ((err) => { this.emit("launcherror", err); }).bind(this));
243236
const promises = this.initCommands(target, cwd, true);
244-
if (isExtendedRemote) {
237+
if (target.startsWith("extended-remote")) {
245238
promises.push(this.sendCommand("target-select " + target));
246239
if (executable)
247240
promises.push(this.sendCommand("file-symbol-file \"" + escape(executable) + "\""));
241+
} else {
242+
// Attach to local process
243+
if (executable)
244+
promises.push(this.sendCommand("file-exec-and-symbols \"" + escape(executable) + "\""));
245+
promises.push(this.sendCommand("target-attach " + target));
248246
}
249247
Promise.all(promises).then(() => {
250248
this.emit("debug-ready");

0 commit comments

Comments
 (0)