Added LLDB support (fix #39)

This commit is contained in:
WebFreak001 2016-03-06 12:02:11 +01:00
commit 35afccfd77
12 changed files with 756 additions and 376 deletions

View file

@ -2,6 +2,8 @@ const resultRegex = /^([a-zA-Z_\-][a-zA-Z0-9_\-]*)\s*=\s*/;
const variableRegex = /^[a-zA-Z_\-][a-zA-Z0-9_\-]*/;
const errorRegex = /^\<.+?\>/;
const referenceRegex = /^0x[0-9a-fA-F]+/;
const nullpointerRegex = /^0x0+\b/;
const charRegex = /^([0-9]+) ['"]/;
const numberRegex = /^[0-9]+/;
const pointerCombineChar = ".";
@ -10,11 +12,13 @@ export function isExpandable(value: string): number {
let match;
value = value.trim();
if (value.length == 0) return 0;
else if (value.startsWith("{...}")) return 2; // lldb string/array
else if (value[0] == '{') return 1; // object
else if (value.startsWith("true")) return 0;
else if (value.startsWith("false")) return 0;
else if (value.startsWith("0x0")) return 0;
else if (match = nullpointerRegex.exec(value)) return 0;
else if (match = referenceRegex.exec(value)) return 2; // reference
else if (match = charRegex.exec(value)) return 0;
else if (match = numberRegex.exec(value)) return 0;
else if (match = variableRegex.exec(value)) return 0;
else if (match = errorRegex.exec(value)) return 0;
@ -24,10 +28,11 @@ export function isExpandable(value: string): number {
export function expandValue(variableCreate: Function, value: string, root: string = ""): any {
let parseCString = () => {
value = value.trim();
if (value[0] != '"')
if (value[0] != '"' && value[0] != '\'')
return "";
let stringEnd = 1;
let inString = true;
let charStr = value[0];
let remaining = value.substr(1);
let escaped = false;
while (inString) {
@ -35,7 +40,7 @@ export function expandValue(variableCreate: Function, value: string, root: strin
escaped = false;
else if (remaining[0] == '\\')
escaped = true;
else if (remaining[0] == '"')
else if (remaining[0] == charStr)
inString = false;
remaining = remaining.substr(1);
@ -82,8 +87,17 @@ export function expandValue(variableCreate: Function, value: string, root: strin
return undefined;
let oldContent = value;
value = value.substr(1).trim();
if (value[0] == '}')
if (value[0] == '}') {
value = value.substr(1).trim();
return [];
}
if (value.startsWith("...")) {
value = value.substr(3).trim();
if (value[0] == '}') {
value = value.substr(1).trim();
return <any>"<...>";
}
}
let eqPos = value.indexOf("=");
let newValPos1 = value.indexOf("{");
let newValPos2 = value.indexOf(",");
@ -138,7 +152,7 @@ export function expandValue(variableCreate: Function, value: string, root: strin
primitive = "false";
value = value.substr(5).trim();
}
else if (value.startsWith("0x0")) {
else if (match = nullpointerRegex.exec(value)) {
primitive = "<nullptr>";
value = value.substr(3).trim();
}
@ -146,6 +160,11 @@ export function expandValue(variableCreate: Function, value: string, root: strin
primitive = "*" + match[0];
value = value.substr(match[0].length).trim();
}
else if (match = charRegex.exec(value)) {
primitive = match[1];
value = value.substr(match[0].length - 1);
primitive += " " + parseCString();
}
else if (match = numberRegex.exec(value)) {
primitive = match[0];
value = value.substr(match[0].length).trim();
@ -199,6 +218,10 @@ export function expandValue(variableCreate: Function, value: string, root: strin
ref = variableCreate(getNamespace("*" + name));
val = "Object@" + val;
}
if (typeof val == "string" && val.startsWith("<...>")) {
ref = variableCreate(getNamespace(name));
val = "...";
}
return {
name: name,
value: val,

View file

@ -10,7 +10,7 @@ import * as nativePath from "path"
let path = posix;
var Client = require("ssh2").Client;
function escape(str: string) {
export function escape(str: string) {
return str.replace(/\\/g, "\\\\").replace(/"/g, "\\\"");
}
@ -32,14 +32,11 @@ export class MI2 extends EventEmitter implements IBackend {
target = nativePath.join(cwd, target);
return new Promise((resolve, reject) => {
this.isSSH = false;
this.process = ChildProcess.spawn(this.application, this.preargs.concat([target]), { cwd: cwd });
this.process = ChildProcess.spawn(this.application, this.preargs, { 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));
let promises = [
this.sendCommand("gdb-set target-async on"),
this.sendCommand("environment-directory \"" + escape(cwd) + "\"")
];
let promises = this.initCommands(target, cwd);
if (procArgs && procArgs.length)
promises.push(this.sendCommand("exec-arguments " + procArgs));
if (process.platform == "win32") {
@ -139,12 +136,8 @@ export class MI2 extends EventEmitter implements IBackend {
this.emit("quit");
this.sshConn.end();
}).bind(this));
let promises = [
this.sendCommand("gdb-set target-async on"),
this.sendCommand("environment-directory \"" + escape(cwd) + "\""),
this.sendCommand("environment-cd \"" + escape(cwd) + "\""),
this.sendCommand("file-exec-and-symbols \"" + escape(target) + "\"")
];
let promises = this.initCommands(target, cwd);
promises.push(this.sendCommand("environment-cd \"" + escape(cwd) + "\""));
if (procArgs && procArgs.length)
promises.push(this.sendCommand("exec-arguments " + procArgs));
Promise.all(promises).then(() => {
@ -161,6 +154,14 @@ export class MI2 extends EventEmitter implements IBackend {
});
}
protected initCommands(target: string, cwd: string) {
return [
this.sendCommand("gdb-set target-async on"),
this.sendCommand("environment-directory \"" + escape(cwd) + "\""),
this.sendCommand("file-exec-and-symbols \"" + escape(target) + "\"")
];
}
attach(cwd: string, executable: string, target: string): Thenable<any> {
return new Promise((resolve, reject) => {
let args = [];
@ -380,6 +381,10 @@ export class MI2 extends EventEmitter implements IBackend {
return Promise.all(promisses);
}
setBreakPointCondition(bkptNum, condition): Thenable<any> {
return this.sendCommand("break-condition " + bkptNum + " " + condition);
}
addBreakPoint(breakpoint: Breakpoint): Thenable<[boolean, Breakpoint]> {
return new Promise((resolve, reject) => {
if (this.breakpoints.has(breakpoint))
@ -393,7 +398,7 @@ export class MI2 extends EventEmitter implements IBackend {
condition: breakpoint.condition
};
if (breakpoint.condition) {
this.sendCommand("break-condition " + bkptNum + " " + breakpoint.condition).then((result) => {
this.setBreakPointCondition(bkptNum, breakpoint.condition).then((result) => {
if (result.resultRecords.resultClass == "done") {
this.breakpoints.set(newBrk, bkptNum);
resolve([true, newBrk]);
@ -467,7 +472,7 @@ export class MI2 extends EventEmitter implements IBackend {
});
});
resolve(ret);
});
}, reject);
});
}
@ -520,18 +525,15 @@ export class MI2 extends EventEmitter implements IBackend {
}
sendCommand(command: string): Thenable<MINode> {
let sel = this.currentToken++;
return new Promise((resolve, reject) => {
this.handlers[this.currentToken] = (node: MINode) => {
if (node.resultRecords && node.resultRecords.resultClass == "error") {
let msg = node.result("msg") || "Internal error";
this.log("stderr", "Failed to run command `" + command + "`: " + msg);
reject(msg);
}
this.handlers[sel] = (node: MINode) => {
if (node && node.resultRecords && node.resultRecords.resultClass === "error")
reject(node.result("msg") || "Internal error");
else
resolve(node);
};
this.sendRaw(this.currentToken + "-" + command);
this.currentToken++;
this.sendRaw(sel + "-" + command);
});
}
@ -540,13 +542,13 @@ export class MI2 extends EventEmitter implements IBackend {
}
printCalls: boolean;
private isSSH: boolean;
private sshReady: boolean;
private currentToken: number = 1;
private handlers: { [index: number]: (info: MINode) => any } = {};
private breakpoints: Map<Breakpoint, Number> = new Map();
private buffer: string;
private process: ChildProcess.ChildProcess;
private stream;
private sshConn;
protected isSSH: boolean;
protected sshReady: boolean;
protected currentToken: number = 1;
protected handlers: { [index: number]: (info: MINode) => any } = {};
protected breakpoints: Map<Breakpoint, Number> = new Map();
protected buffer: string;
protected process: ChildProcess.ChildProcess;
protected stream;
protected sshConn;
}

View file

@ -0,0 +1,50 @@
import { MI2, escape } from "./mi2"
import { Breakpoint } from "../backend"
import * as ChildProcess from "child_process"
import { posix } from "path"
import * as nativePath from "path"
let path = posix;
export class MI2_LLDB extends MI2 {
protected initCommands(target: string, cwd: string) {
return [
this.sendCommand("gdb-set target-async on"),
this.sendCommand("file-exec-and-symbols \"" + escape(target) + "\"")
];
}
attach(cwd: string, executable: string, target: string): Thenable<any> {
return new Promise((resolve, reject) => {
this.process = ChildProcess.spawn(this.application, this.preargs, { 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("gdb-set target-async on"),
this.sendCommand("file-exec-and-symbols \"" + escape(executable) + "\""),
this.sendCommand("target-attach " + target)
]).then(() => {
this.emit("debug-ready");
resolve();
}, reject);
});
}
clearBreakPoints(): Thenable<any> {
return new Promise((resolve, reject) => {
let promises = [];
for (let k in this.breakpoints.values) {
promises.push(this.sendCommand("break-delete " + k).then((result) => {
if (result.resultRecords.resultClass == "done") resolve(true);
else resolve(false);
}));
}
this.breakpoints.clear();
Promise.all(promises).then(resolve, reject);
});
}
setBreakPointCondition(bkptNum, condition): Thenable<any> {
return this.sendCommand("break-condition " + bkptNum + " \"" + escape(condition) + "\" 1");
}
}