parent
2e636b0a2e
commit
99217775cf
5 changed files with 139 additions and 8 deletions
|
|
@ -14,8 +14,11 @@ export interface Stack {
|
|||
|
||||
export interface IBackend {
|
||||
load(cwd: string, target: string): Thenable<any>;
|
||||
attach(cwd: string, executable: string, target: string): Thenable<any>;
|
||||
connect(cwd: string, executable: string, target: string): Thenable<any>;
|
||||
start(): Thenable<boolean>;
|
||||
stop();
|
||||
detach();
|
||||
interrupt(): Thenable<boolean>;
|
||||
continue(): Thenable<boolean>;
|
||||
next(): Thenable<boolean>;
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ export class MI2 extends EventEmitter implements IBackend {
|
|||
return new Promise((resolve, reject) => {
|
||||
this.process = ChildProcess.spawn(this.application, this.preargs.concat([target]), { cwd: cwd });
|
||||
this.process.stdout.on("data", this.stdout.bind(this));
|
||||
this.process.stderr.on("data", this.stdout.bind(this));
|
||||
this.process.on("exit", (() => { this.emit("quit"); }).bind(this));
|
||||
Promise.all([
|
||||
this.sendCommand("environment-directory \"" + cwd + "\"")
|
||||
|
|
@ -19,6 +20,40 @@ export class MI2 extends EventEmitter implements IBackend {
|
|||
});
|
||||
}
|
||||
|
||||
attach(cwd: string, executable: string, target: string): Thenable<any> {
|
||||
return new Promise((resolve, reject) => {
|
||||
let args = [];
|
||||
if (!executable)
|
||||
executable = "-p";
|
||||
args = args.concat([executable, target], this.preargs);
|
||||
this.process = ChildProcess.spawn(this.application, args, { cwd: cwd });
|
||||
this.process.stdout.on("data", this.stdout.bind(this));
|
||||
this.process.stderr.on("data", this.stdout.bind(this));
|
||||
this.process.on("exit", (() => { this.emit("quit"); }).bind(this));
|
||||
Promise.all([
|
||||
this.sendCommand("environment-directory \"" + cwd + "\"")
|
||||
]).then(resolve, reject);
|
||||
});
|
||||
}
|
||||
|
||||
connect(cwd: string, executable: string, target: string): Thenable<any> {
|
||||
return new Promise((resolve, reject) => {
|
||||
let args = [];
|
||||
if (executable)
|
||||
args = args.concat([executable], this.preargs);
|
||||
else
|
||||
args = this.preargs;
|
||||
this.process = ChildProcess.spawn(this.application, args, { cwd: cwd });
|
||||
this.process.stdout.on("data", this.stdout.bind(this));
|
||||
this.process.stderr.on("data", this.stdout.bind(this));
|
||||
this.process.on("exit", (() => { this.emit("quit"); }).bind(this));
|
||||
Promise.all([
|
||||
this.sendCommand("environment-directory \"" + cwd + "\""),
|
||||
this.sendCommand("target-select remote " + target)
|
||||
]).then(resolve, reject);
|
||||
});
|
||||
}
|
||||
|
||||
stdout(data) {
|
||||
this.buffer += data.toString("utf8");
|
||||
let end = this.buffer.lastIndexOf('\n');
|
||||
|
|
@ -88,13 +123,24 @@ export class MI2 extends EventEmitter implements IBackend {
|
|||
stop() {
|
||||
let proc = this.process;
|
||||
let to = setTimeout(() => {
|
||||
proc.kill();
|
||||
}, 2222);
|
||||
process.kill(-proc.pid);
|
||||
}, 1000);
|
||||
this.process.on("exit", function(code) {
|
||||
clearTimeout(to);
|
||||
});
|
||||
this.sendRaw("-gdb-exit");
|
||||
}
|
||||
|
||||
detach() {
|
||||
let proc = this.process;
|
||||
let to = setTimeout(() => {
|
||||
process.kill(-proc.pid);
|
||||
}, 1000);
|
||||
this.process.on("exit", function(code) {
|
||||
clearTimeout(to);
|
||||
});
|
||||
this.sendRaw("-target-detach");
|
||||
}
|
||||
|
||||
interrupt(): Thenable<boolean> {
|
||||
return new Promise((resolve, reject) => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue