From a480a4cf4ab16e797510c9dba68bef1083c6aaf0 Mon Sep 17 00:00:00 2001 From: WebFreak001 Date: Tue, 9 Feb 2016 16:04:16 +0100 Subject: [PATCH] Added autorun commands (fix #9) --- package.json | 10 ++++++++++ src/backend/mi2/mi2.ts | 12 ++++++++++++ src/gdb.ts | 18 ++++++++++++++++-- 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 590a8cd..adc756d 100644 --- a/package.json +++ b/package.json @@ -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": [] } } } diff --git a/src/backend/mi2/mi2.ts b/src/backend/mi2/mi2.ts index 6c6e358..851c12f 100644 --- a/src/backend/mi2/mi2.ts +++ b/src/backend/mi2/mi2.ts @@ -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 { + 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"); } diff --git a/src/gdb.ts b/src/gdb.ts index 52f7f77..20d5d43 100644 --- a/src/gdb.ts +++ b/src/gdb.ts @@ -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); + }); } } }