Added autorun commands (fix #9)

This commit is contained in:
WebFreak001 2016-02-09 16:04:16 +01:00
commit a480a4cf4a
3 changed files with 38 additions and 2 deletions

View file

@ -47,6 +47,11 @@
"cwd": {
"type": "string",
"description": "Path of project"
},
"autorun": {
"type": "array",
"description": "GDB commands to run when starting to debug",
"default": []
}
}
},
@ -71,6 +76,11 @@
"cwd": {
"type": "string",
"description": "Path of project"
},
"autorun": {
"type": "array",
"description": "GDB commands to run when starting to debug",
"default": []
}
}
}

View file

@ -318,6 +318,18 @@ export class MI2 extends EventEmitter implements IBackend {
this.emit("msg", type, msg[msg.length - 1] == '\n' ? msg : (msg + "\n"));
}
sendUserInput(command: string): Thenable<any> {
return new Promise((resolve, reject) => {
if (command.startsWith("-")) {
this.sendCommand(command.substr(1)).then(resolve, reject);
}
else {
this.sendRaw(command);
resolve(undefined);
}
});
}
sendRaw(raw: string) {
this.process.stdin.write(raw + "\n");
}

View file

@ -8,6 +8,7 @@ import { MI2 } from './backend/mi2/mi2'
export interface LaunchRequestArguments {
cwd: string;
target: string;
autorun: string[];
}
export interface AttachRequestArguments {
@ -15,6 +16,7 @@ export interface AttachRequestArguments {
target: string;
executable: string;
remote: boolean;
autorun: string[];
}
class MI2DebugSession extends DebugSession {
@ -81,6 +83,9 @@ class MI2DebugSession extends DebugSession {
this.attached = false;
this.needContinue = false;
this.gdbDebugger.load(args.cwd, args.target).then(() => {
args.autorun.forEach(command => {
this.gdbDebugger.sendUserInput(command);
});
this.gdbDebugger.start().then(() => {
this.sendResponse(response);
});
@ -93,11 +98,17 @@ class MI2DebugSession extends DebugSession {
this.needContinue = true;
if (args.remote) {
this.gdbDebugger.connect(args.cwd, args.executable, args.target).then(() => {
args.autorun.forEach(command => {
this.gdbDebugger.sendUserInput(command);
});
this.sendResponse(response);
});
}
else {
this.gdbDebugger.attach(args.cwd, args.executable, args.target).then(() => {
args.autorun.forEach(command => {
this.gdbDebugger.sendUserInput(command);
});
this.sendResponse(response);
});
}
@ -300,8 +311,11 @@ class MI2DebugSession extends DebugSession {
this.sendResponse(response);
});
else {
this.gdbDebugger.sendRaw(args.expression);
this.sendResponse(response);
this.gdbDebugger.sendUserInput(args.expression).then(output => {
if (output)
response.body.result = JSON.stringify(output);
this.sendResponse(response);
});
}
}
}