提交 57106501 编写于 作者: I isidor

debug: do not fabricate fake 'continued' event

上级 8334c894
......@@ -239,12 +239,6 @@ export interface IRawDebugSession {
disconnect(restart?: boolean, force?: boolean): TPromise<DebugProtocol.DisconnectResponse>;
next(args: DebugProtocol.NextArguments): TPromise<DebugProtocol.NextResponse>;
stepIn(args: DebugProtocol.StepInArguments): TPromise<DebugProtocol.StepInResponse>;
stepOut(args: DebugProtocol.StepOutArguments): TPromise<DebugProtocol.StepOutResponse>;
continue(args: DebugProtocol.ContinueArguments): TPromise<DebugProtocol.ContinueResponse>;
pause(args: DebugProtocol.PauseArguments): TPromise<DebugProtocol.PauseResponse>;
stackTrace(args: DebugProtocol.StackTraceArguments): TPromise<DebugProtocol.StackTraceResponse>;
scopes(args: DebugProtocol.ScopesArguments): TPromise<DebugProtocol.ScopesResponse>;
variables(args: DebugProtocol.VariablesArguments): TPromise<DebugProtocol.VariablesResponse>;
......@@ -402,6 +396,12 @@ export interface IDebugService {
* Opens a new or reveals an already visible editor showing the source.
*/
openOrRevealSource(source: Source, lineNumber: number, preserveFocus: boolean, sideBySide: boolean): TPromise<any>;
next(threadId: number): TPromise<void>;
stepIn(threadId: number): TPromise<void>;
stepOut(threadId: number): TPromise<void>;
continue(threadId: number): TPromise<void>;
pause(threadId: number): TPromise<any>;
}
// Editor interfaces
......
......@@ -160,7 +160,7 @@ export class StepOverDebugAction extends AbstractDebugAction {
}
public run(): TPromise<any> {
return this.debugService.getActiveSession().next({ threadId: this.debugService.getViewModel().getFocusedThreadId() });
return this.debugService.next(this.debugService.getViewModel().getFocusedThreadId());
}
protected isEnabled(state: debug.State): boolean {
......@@ -177,7 +177,7 @@ export class StepIntoDebugAction extends AbstractDebugAction {
}
public run(): TPromise<any> {
return this.debugService.getActiveSession().stepIn({ threadId: this.debugService.getViewModel().getFocusedThreadId() });
return this.debugService.stepIn(this.debugService.getViewModel().getFocusedThreadId());
}
protected isEnabled(state: debug.State): boolean {
......@@ -194,7 +194,7 @@ export class StepOutDebugAction extends AbstractDebugAction {
}
public run(): TPromise<any> {
return this.debugService.getActiveSession().stepOut({ threadId: this.debugService.getViewModel().getFocusedThreadId() });
return this.debugService.stepOut(this.debugService.getViewModel().getFocusedThreadId());
}
protected isEnabled(state: debug.State): boolean {
......@@ -236,7 +236,7 @@ export class ContinueAction extends AbstractDebugAction {
}
public run(): TPromise<any> {
return this.debugService.getActiveSession().continue({ threadId: this.debugService.getViewModel().getFocusedThreadId() });
return this.debugService.continue(this.debugService.getViewModel().getFocusedThreadId());
}
protected isEnabled(state: debug.State): boolean {
......@@ -253,7 +253,7 @@ export class PauseAction extends AbstractDebugAction {
}
public run(): TPromise<any> {
return this.debugService.getActiveSession().pause({ threadId: this.debugService.getViewModel().getFocusedThreadId() });
return this.debugService.pause(this.debugService.getViewModel().getFocusedThreadId());
}
protected isEnabled(state: debug.State): boolean {
......@@ -543,7 +543,7 @@ export class RunToCursorAction extends EditorAction {
});
return this.debugService.addBreakpoints([{ uri, lineNumber }]).then(() => {
this.debugService.getActiveSession().continue({ threadId: this.debugService.getViewModel().getFocusedThreadId() });
this.debugService.continue(this.debugService.getViewModel().getFocusedThreadId());
});
}
......
......@@ -267,28 +267,6 @@ export class DebugService implements debug.IDebugService {
}, errors.onUnexpectedError);
}));
this.toDisposeOnSessionEnd.push(this.session.onDidContinue(threadID => {
aria.status(nls.localize('debuggingContinued', "Debugging continued."));
// TODO@Isidor temporary workaround for #5835
if (strings.equalsIgnoreCase(this.session.configuration.type, 'go')) {
this.model.clearThreads(false);
} else {
this.model.clearThreads(false, threadID);
}
// Get a top stack frame of a stopped thread if there is any.
const threads = this.model.getThreads();
const stoppedReference = Object.keys(threads).filter(ref => threads[ref].stopped).pop();
const stoppedThread = stoppedReference ? threads[parseInt(stoppedReference)] : null;
const callStack = stoppedThread ? stoppedThread.getCachedCallStack() : null;
const stackFrameToFocus = callStack && callStack.length > 0 ? callStack[0] : null;
this.setFocusedStackFrameAndEvaluate(stackFrameToFocus).done(null, errors.onUnexpectedError);
if (!stoppedThread) {
this.setStateAndEmit(this.configurationManager.configuration.noDebug ? debug.State.RunningNoDebug : debug.State.Running);
}
}));
this.toDisposeOnSessionEnd.push(this.session.onDidThread(event => {
if (event.body.reason === 'started') {
this.getThreadData().done(null, errors.onUnexpectedError);
......@@ -811,6 +789,91 @@ export class DebugService implements debug.IDebugService {
return this.configurationManager;
}
public next(threadId: number): TPromise<void> {
if (!this.session) {
return TPromise.as(null);
}
return this.session.next({ threadId }).then(() => {
this.lazyTransitionToRunningState(threadId);
});
}
public stepIn(threadId: number): TPromise<void> {
if (!this.session) {
return TPromise.as(null);
}
return this.session.stepIn({ threadId }).then(() => {
this.lazyTransitionToRunningState(threadId);
});
}
public stepOut(threadId: number): TPromise<void> {
if (!this.session) {
return TPromise.as(null);
}
return this.session.stepOut({ threadId }).then(() => {
this.lazyTransitionToRunningState(threadId);
});
}
public continue(threadId: number): TPromise<void> {
if (!this.session) {
return TPromise.as(null);
}
return this.session.continue({ threadId }).then(() => {
this.lazyTransitionToRunningState(threadId);
});
}
public pause(threadId: number): TPromise<any> {
if (!this.session) {
return TPromise.as(null);
}
return this.session.pause({ threadId } );
}
private lazyTransitionToRunningState(threadId: number): void {
let cancelTransitionToRunningState = false;
const toDispose = this.session.onDidStop(e => {
if (e.body.threadId === threadId || e.body.allThreadsStopped) {
cancelTransitionToRunningState = true;
}
});
// Do not immediatly transition to running state since that might cause unnecessery flickering
// of the tree in the debug viewlet. Only transition if no stopped event has arrived in 500ms.
setTimeout(() => {
toDispose.dispose();
if (!cancelTransitionToRunningState) {
aria.status(nls.localize('debuggingContinued', "Debugging continued."));
// TODO@Isidor temporary workaround for #5835
if (strings.equalsIgnoreCase(this.session.configuration.type, 'go')) {
this.model.clearThreads(false);
} else {
this.model.clearThreads(false, threadId);
}
// Get a top stack frame of a stopped thread if there is any.
const threads = this.model.getThreads();
const stoppedReference = Object.keys(threads).filter(ref => threads[ref].stopped).pop();
const stoppedThread = stoppedReference ? threads[parseInt(stoppedReference)] : null;
const callStack = stoppedThread ? stoppedThread.getCachedCallStack() : null;
const stackFrameToFocus = callStack && callStack.length > 0 ? callStack[0] : null;
this.setFocusedStackFrameAndEvaluate(stackFrameToFocus).done(null, errors.onUnexpectedError);
if (!stoppedThread) {
this.setStateAndEmit(this.configurationManager.configuration.noDebug ? debug.State.RunningNoDebug : debug.State.Running);
}
}
}, 500);
}
private getDebugStringEditorInput(source: Source, value: string, mtype: string): DebugStringEditorInput {
const filtered = this.debugStringEditorInputs.filter(input => input.getResource().toString() === source.uri.toString());
......
......@@ -42,8 +42,6 @@ export class RawDebugSession extends v8.V8Protocol implements debug.IRawDebugSes
public emittedStopped: boolean;
public readyForBreakpoints: boolean;
private lastThreadId: number;
private flowEventsCount: number;
private serverProcess: cp.ChildProcess;
private socket: net.Socket = null;
private cachedInitServer: TPromise<void>;
......@@ -57,7 +55,6 @@ export class RawDebugSession extends v8.V8Protocol implements debug.IRawDebugSes
private _onDidStop: Emitter<DebugProtocol.StoppedEvent>;
private _onDidTerminateDebugee: Emitter<SessionTerminatedEvent>;
private _onDidExitAdapter: Emitter<SessionExitedEvent>;
private _onDidContinue: Emitter<number>;
private _onDidThread: Emitter<DebugProtocol.ThreadEvent>;
private _onDidOutput: Emitter<DebugProtocol.OutputEvent>;
private _onDidBreakpoint: Emitter<DebugProtocol.BreakpointEvent>;
......@@ -71,7 +68,6 @@ export class RawDebugSession extends v8.V8Protocol implements debug.IRawDebugSes
private telemtryAdapter: AIAdapter
) {
super();
this.flowEventsCount = 0;
this.emittedStopped = false;
this.readyForBreakpoints = false;
this.sentPromises = [];
......@@ -80,7 +76,6 @@ export class RawDebugSession extends v8.V8Protocol implements debug.IRawDebugSes
this._onDidStop = new Emitter<DebugProtocol.StoppedEvent>();
this._onDidTerminateDebugee = new Emitter<SessionTerminatedEvent>();
this._onDidExitAdapter = new Emitter<SessionExitedEvent>();
this._onDidContinue = new Emitter<number>();
this._onDidThread = new Emitter<DebugProtocol.ThreadEvent>();
this._onDidOutput = new Emitter<DebugProtocol.OutputEvent>();
this._onDidBreakpoint = new Emitter<DebugProtocol.BreakpointEvent>();
......@@ -103,10 +98,6 @@ export class RawDebugSession extends v8.V8Protocol implements debug.IRawDebugSes
return this._onDidExitAdapter.event;
}
public get onDidContinue(): Event<number> {
return this._onDidContinue.event;
}
public get onDidThread(): Event<DebugProtocol.ThreadEvent> {
return this._onDidThread.event;
}
......@@ -182,7 +173,6 @@ export class RawDebugSession extends v8.V8Protocol implements debug.IRawDebugSes
this._onDidInitialize.fire(event);
} else if (event.event === 'stopped') {
this.emittedStopped = true;
this.flowEventsCount++;
this._onDidStop.fire(<DebugProtocol.StoppedEvent>event);
} else if (event.event === 'thread') {
this._onDidThread.fire(<DebugProtocol.ThreadEvent>event);
......@@ -191,15 +181,9 @@ export class RawDebugSession extends v8.V8Protocol implements debug.IRawDebugSes
} else if (event.event === 'breakpoint') {
this._onDidBreakpoint.fire(<DebugProtocol.BreakpointEvent>event);
} else if (event.event === 'terminated') {
this.flowEventsCount++;
this._onDidTerminateDebugee.fire(<SessionTerminatedEvent>event);
} else if (event.event === 'exit') {
this.flowEventsCount++;
this._onDidExitAdapter.fire(<SessionExitedEvent>event);
} else if (event.event === 'continued') {
// TODO@Isidor continued event needs to come from the adapter
this.flowEventsCount++;
this._onDidContinue.fire(this.lastThreadId);
}
this._onDidEvent.fire(event);
......@@ -222,45 +206,28 @@ export class RawDebugSession extends v8.V8Protocol implements debug.IRawDebugSes
public launch(args: DebugProtocol.LaunchRequestArguments): TPromise<DebugProtocol.LaunchResponse> {
this.isAttach = false;
return this.sendAndLazyContinue('launch', args);
return this.send('launch', args);
}
public attach(args: DebugProtocol.AttachRequestArguments): TPromise<DebugProtocol.AttachResponse> {
this.isAttach = true;
return this.sendAndLazyContinue('attach', args);
return this.send('attach', args);
}
public next(args: DebugProtocol.NextArguments): TPromise<DebugProtocol.NextResponse> {
return this.sendAndLazyContinue('next', args);
return this.send('next', args);
}
public stepIn(args: DebugProtocol.StepInArguments): TPromise<DebugProtocol.StepInResponse> {
return this.sendAndLazyContinue('stepIn', args);
return this.send('stepIn', args);
}
public stepOut(args: DebugProtocol.StepOutArguments): TPromise<DebugProtocol.StepOutResponse> {
return this.sendAndLazyContinue('stepOut', args);
return this.send('stepOut', args);
}
public continue(args: DebugProtocol.ContinueArguments): TPromise<DebugProtocol.ContinueResponse> {
return this.sendAndLazyContinue('continue', args);
}
// node sometimes sends "stopped" events earlier than the response for the "step" request.
// due to this we only emit "continued" if we did not miss a stopped event.
// we do not emit straight away to reduce viewlet flickering.
private sendAndLazyContinue(command: string, args: any): TPromise<DebugProtocol.Response> {
const count = this.flowEventsCount;
this.lastThreadId = args.threadId;
return this.send(command, args).then(response => {
setTimeout(() => {
if (this.flowEventsCount === count) {
this.onEvent({ event: 'continued', type: 'event', seq: 0 });
}
}, 500);
return response;
});
return this.send('continue', args);
}
public pause(args: DebugProtocol.PauseArguments): TPromise<DebugProtocol.PauseResponse> {
......
......@@ -102,6 +102,26 @@ export class MockDebugService implements debug.IDebugService {
public openOrRevealSource(source: Source, lineNumber: number, preserveFocus: boolean, sideBySide: boolean): TPromise<any> {
return TPromise.as(null);
}
public next(threadId: number): TPromise<void> {
return TPromise.as(null);
}
public stepIn(threadId: number): TPromise<void> {
return TPromise.as(null);
}
public stepOut(threadId: number): TPromise<void> {
return TPromise.as(null);
}
public continue(threadId: number): TPromise<void> {
return TPromise.as(null);
}
public pause(threadId: number): TPromise<any> {
return TPromise.as(null);
}
}
......@@ -131,26 +151,6 @@ class MockRawSession implements debug.IRawDebugSession {
return TPromise.as(null);
}
public next(args: DebugProtocol.NextArguments): TPromise<DebugProtocol.NextResponse> {
return TPromise.as(null);
}
public stepIn(args: DebugProtocol.StepInArguments): TPromise<DebugProtocol.StepInResponse> {
return TPromise.as(null);
}
public stepOut(args: DebugProtocol.StepOutArguments): TPromise<DebugProtocol.StepOutResponse> {
return TPromise.as(null);
}
public continue(args: DebugProtocol.ContinueArguments): TPromise<DebugProtocol.ContinueResponse> {
return TPromise.as(null);
}
public pause(args: DebugProtocol.PauseArguments): TPromise<DebugProtocol.PauseResponse> {
return TPromise.as(null);
}
public stackTrace(args: DebugProtocol.StackTraceArguments): TPromise<DebugProtocol.StackTraceResponse> {
return TPromise.as({
body: {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册