Added conditional breakpoints
This commit is contained in:
parent
3831f07c2a
commit
97de960df7
4 changed files with 57 additions and 20 deletions
|
|
@ -1,6 +1,7 @@
|
|||
export interface Breakpoint {
|
||||
file: string;
|
||||
line: number;
|
||||
condition: string;
|
||||
}
|
||||
|
||||
export interface Stack {
|
||||
|
|
|
|||
|
|
@ -199,12 +199,26 @@ export class MI2 extends EventEmitter implements IBackend {
|
|||
return resolve(false);
|
||||
this.sendCommand("break-insert " + breakpoint.file + ":" + breakpoint.line).then((result) => {
|
||||
if (result.resultRecords.resultClass == "done") {
|
||||
let bkptNum = parseInt(result.result("bkpt.number"));
|
||||
let newBrk = {
|
||||
file: result.result("bkpt.file"),
|
||||
line: parseInt(result.result("bkpt.line"))
|
||||
line: parseInt(result.result("bkpt.line")),
|
||||
condition: breakpoint.condition
|
||||
};
|
||||
this.breakpoints.set(newBrk, parseInt(result.result("bkpt.number")));
|
||||
resolve([true, newBrk]);
|
||||
if (breakpoint.condition) {
|
||||
this.sendCommand("break-condition " + bkptNum + " " + breakpoint.condition).then((result) => {
|
||||
if (result.resultRecords.resultClass == "done") {
|
||||
this.breakpoints.set(newBrk, bkptNum);
|
||||
resolve([true, newBrk]);
|
||||
} else {
|
||||
resolve([false, null]);
|
||||
}
|
||||
});
|
||||
}
|
||||
else {
|
||||
this.breakpoints.set(newBrk, bkptNum);
|
||||
resolve([true, newBrk]);
|
||||
}
|
||||
}
|
||||
else {
|
||||
resolve([false, null]);
|
||||
|
|
@ -228,13 +242,15 @@ export class MI2 extends EventEmitter implements IBackend {
|
|||
}
|
||||
|
||||
clearBreakPoints(): Thenable<any> {
|
||||
let promisses = [];
|
||||
let it = this.breakpoints.keys();
|
||||
let value;
|
||||
while (!(value = it.next()).done) {
|
||||
promisses.push(this.removeBreakPoint(value.value));
|
||||
}
|
||||
return Promise.all(promisses);
|
||||
return new Promise((resolve, reject) => {
|
||||
this.sendCommand("break-delete").then((result) => {
|
||||
if (result.resultRecords.resultClass == "done") {
|
||||
this.breakpoints.clear();
|
||||
resolve(true);
|
||||
}
|
||||
else resolve(false);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
getStack(maxLevels: number): Thenable<Stack[]> {
|
||||
|
|
|
|||
28
src/gdb.ts
28
src/gdb.ts
|
|
@ -23,12 +23,16 @@ class MI2DebugSession extends DebugSession {
|
|||
private variableHandles = new Handles<any>();
|
||||
private quit: boolean;
|
||||
private attached: boolean;
|
||||
private needContinue: boolean;
|
||||
|
||||
public constructor(debuggerLinesStartAt1: boolean, isServer: boolean = false) {
|
||||
super(debuggerLinesStartAt1, isServer);
|
||||
}
|
||||
|
||||
protected initializeRequest(response: DebugProtocol.InitializeResponse, args: DebugProtocol.InitializeRequestArguments): void {
|
||||
response.body.supportsConfigurationDoneRequest = true;
|
||||
response.body.supportsEvaluateForHovers = true; // Assume working in future releases
|
||||
response.body.supportsFunctionBreakpoints = true; // TODO: Implement in future release
|
||||
this.sendResponse(response);
|
||||
this.gdbDebugger = new MI2("gdb", ["-q", "--interpreter=mi2"]);
|
||||
this.gdbDebugger.on("quit", this.quitEvent.bind(this));
|
||||
|
|
@ -65,6 +69,7 @@ class MI2DebugSession extends DebugSession {
|
|||
protected launchRequest(response: DebugProtocol.LaunchResponse, args: LaunchRequestArguments): void {
|
||||
this.quit = false;
|
||||
this.attached = false;
|
||||
this.needContinue = false;
|
||||
this.gdbDebugger.load(args.cwd, args.target).then(() => {
|
||||
this.gdbDebugger.start().then(() => {
|
||||
this.sendResponse(response);
|
||||
|
|
@ -75,6 +80,7 @@ class MI2DebugSession extends DebugSession {
|
|||
protected attachRequest(response: DebugProtocol.AttachResponse, args: AttachRequestArguments): void {
|
||||
this.quit = false;
|
||||
this.attached = !args.remote;
|
||||
this.needContinue = true;
|
||||
if (args.remote) {
|
||||
this.gdbDebugger.connect(args.cwd, args.executable, args.target).then(() => {
|
||||
this.sendResponse(response);
|
||||
|
|
@ -98,10 +104,9 @@ class MI2DebugSession extends DebugSession {
|
|||
protected setBreakPointsRequest(response: DebugProtocol.SetBreakpointsResponse, args: DebugProtocol.SetBreakpointsArguments): void {
|
||||
this.gdbDebugger.clearBreakPoints().then(() => {
|
||||
let path = args.source.path;
|
||||
let lines = args.lines;
|
||||
let all = [];
|
||||
lines.forEach(line => {
|
||||
all.push(this.gdbDebugger.addBreakPoint({ file: path, line: line }));
|
||||
args.breakpoints.forEach(brk => {
|
||||
all.push(this.gdbDebugger.addBreakPoint({ file: path, line: brk.line, condition: brk.condition }));
|
||||
});
|
||||
Promise.all(all).then(brkpoints => {
|
||||
response.body.breakpoints = brkpoints;
|
||||
|
|
@ -132,6 +137,20 @@ class MI2DebugSession extends DebugSession {
|
|||
});
|
||||
}
|
||||
|
||||
protected configurationDoneRequest(response: DebugProtocol.ConfigurationDoneResponse, args: DebugProtocol.ConfigurationDoneArguments): void {
|
||||
// FIXME: Does not seem to get called in january release
|
||||
if (this.needContinue) {
|
||||
this.gdbDebugger.continue().then(done => {
|
||||
this.sendResponse(response);
|
||||
}, msg => {
|
||||
this.sendResponse(response);
|
||||
this.sendEvent(new OutputEvent(`Could not continue: ${msg}\n`, 'stderr'));
|
||||
});
|
||||
}
|
||||
else
|
||||
this.sendResponse(response);
|
||||
}
|
||||
|
||||
protected scopesRequest(response: DebugProtocol.ScopesResponse, args: DebugProtocol.ScopesArguments): void {
|
||||
const scopes = new Array<Scope>();
|
||||
scopes.push(new Scope("Local", this.variableHandles.create("@frame:" + args.frameId), false));
|
||||
|
|
@ -261,7 +280,8 @@ class MI2DebugSession extends DebugSession {
|
|||
}
|
||||
|
||||
protected evaluateRequest(response: DebugProtocol.EvaluateResponse, args: DebugProtocol.EvaluateArguments): void {
|
||||
if (args.context == "watch")
|
||||
this.handleMsg("console", "Evaluate (" + args.context + "): " + args.expression + "\n")
|
||||
if (args.context == "watch" || args.context == "hover")
|
||||
this.gdbDebugger.evalExpression(args.expression).then((res) => {
|
||||
response.body = {
|
||||
variablesReference: 0,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue