Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

Commit

Permalink
debug: fix updating breakpoints while debuggee is running
Browse files Browse the repository at this point in the history
  • Loading branch information
xiphon committed Nov 16, 2018
1 parent f26c88f commit 003a3e5
Showing 1 changed file with 33 additions and 5 deletions.
38 changes: 33 additions & 5 deletions src/debugAdapter/goDebug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,7 @@ class GoDebugSession extends DebugSession {

private _variableHandles: Handles<DebugVariable>;
private breakpoints: Map<string, DebugBreakpoint[]>;
private skipStopEventOnce: boolean;
private threads: Set<number>;
private debugState: DebuggerState;
private delve: Delve;
Expand All @@ -534,6 +535,7 @@ class GoDebugSession extends DebugSession {
public constructor(debuggerLinesStartAt1: boolean, isServer: boolean = false) {
super(debuggerLinesStartAt1, isServer);
this._variableHandles = new Handles<DebugVariable>();
this.skipStopEventOnce = false;
this.threads = new Set<number>();
this.debugState = null;
this.delve = null;
Expand Down Expand Up @@ -680,15 +682,14 @@ class GoDebugSession extends DebugSession {
return pathToConvert.replace(this.delve.remotePath, this.delve.program).split(this.remotePathSeparator).join(this.localPathSeparator);
}

protected setBreakPointsRequest(response: DebugProtocol.SetBreakpointsResponse, args: DebugProtocol.SetBreakpointsArguments): void {
verbose('SetBreakPointsRequest');
private setBreakPoints(response: DebugProtocol.SetBreakpointsResponse, args: DebugProtocol.SetBreakpointsArguments): Thenable<void> {
let file = normalizePath(args.source.path);
if (!this.breakpoints.get(file)) {
this.breakpoints.set(file, []);
}
let remoteFile = this.toDebuggerPath(file);

Promise.all(this.breakpoints.get(file).map(existingBP => {
return Promise.all(this.breakpoints.get(file).map(existingBP => {
verbose('Clearing: ' + existingBP.id);
return this.delve.callPromise('ClearBreakpoint', [this.delve.isApiV1 ? existingBP.id : { Id: existingBP.id }]);
})).then(() => {
Expand Down Expand Up @@ -737,6 +738,23 @@ class GoDebugSession extends DebugSession {
});
}

protected setBreakPointsRequest(response: DebugProtocol.SetBreakpointsResponse, args: DebugProtocol.SetBreakpointsArguments): void {
verbose('SetBreakPointsRequest');
if (!this.continueRequestRunning) {
this.setBreakPoints(response, args);
} else {
this.skipStopEventOnce = true;
this.delve.callPromise('Command', [{ name: 'halt' }]).then(() => {
return this.setBreakPoints(response, args);
}, err => {
this.sendErrorResponse(response, 2002, 'Failed to set breakpoint: "{e}"', { e: err.toString() });
logError(err);
}).then(() => {
return this.continue();
});
}
}

protected threadsRequest(response: DebugProtocol.ThreadsResponse): void {
if (this.continueRequestRunning) {
// Thread request to delve is syncronous and will block if a previous async continue request didn't return
Expand Down Expand Up @@ -1053,17 +1071,22 @@ class GoDebugSession extends DebugSession {
this.threads.delete(id);
});

if (this.skipStopEventOnce) {
this.skipStopEventOnce = false;
return;
}

let stoppedEvent = new StoppedEvent(reason, this.debugState.currentGoroutine.id);
(<any>stoppedEvent.body).allThreadsStopped = true;
this.sendEvent(stoppedEvent);
verbose('StoppedEvent("' + reason + '")');
});
}
}

private continueEpoch = 0;
private continueRequestRunning = false;
protected continueRequest(response: DebugProtocol.ContinueResponse): void {
verbose('ContinueRequest');
private continue(): void {
this.continueEpoch++;
let closureEpoch = this.continueEpoch;
this.continueRequestRunning = true;
Expand All @@ -1079,6 +1102,11 @@ class GoDebugSession extends DebugSession {
this.debugState = state;
this.handleReenterDebug('breakpoint');
});
}

protected continueRequest(response: DebugProtocol.ContinueResponse): void {
verbose('ContinueRequest');
this.continue();
this.sendResponse(response);
verbose('ContinueResponse');
}
Expand Down

0 comments on commit 003a3e5

Please sign in to comment.