提交 1a344508 编写于 作者: I isidor

debug: make session shutdown private

上级 ce0ccef9
......@@ -117,7 +117,6 @@ export class DebugService implements IDebugService {
this.model = new DebugModel(this.loadBreakpoints(), this.loadFunctionBreakpoints(),
this.loadExceptionBreakpoints(), this.loadDataBreakpoints(), this.loadWatchExpressions(), this.textFileService);
this.toDispose.push(this.model);
const setBreakpointsExistContext = () => this.breakpointsExist.set(!!(this.model.getBreakpoints().length || this.model.getDataBreakpoints().length || this.model.getFunctionBreakpoints().length));
this.breakpointsExist = CONTEXT_BREAKPOINTS_EXIST.bindTo(contextKeyService);
setBreakpointsExistContext();
......@@ -126,7 +125,7 @@ export class DebugService implements IDebugService {
this.taskRunner = this.instantiationService.createInstance(DebugTaskRunner);
this.toDispose.push(this.fileService.onFileChanges(e => this.onFileChanges(e)));
this.lifecycleService.onShutdown(this.dispose, this);
this.toDispose.push(this.lifecycleService.onShutdown(this.dispose, this));
this.toDispose.push(this.extensionHostDebugService.onAttachSession(event => {
const session = this.model.getSession(event.sessionId, true);
......@@ -522,7 +521,6 @@ export class DebugService implements IDebugService {
await this.focusStackFrame(undefined, undefined, session);
}
} catch (err) {
session.shutdown();
if (this.viewModel.focusedSession === session) {
await this.focusStackFrame(undefined);
}
......@@ -567,7 +565,6 @@ export class DebugService implements IDebugService {
this.notificationService.error(err);
}
}
session.shutdown();
this.endInitializingState();
this._onDidEndSession.fire(session);
......
......@@ -33,6 +33,7 @@ import { variableSetEmitter } from 'vs/workbench/contrib/debug/browser/variables
import { CancellationTokenSource, CancellationToken } from 'vs/base/common/cancellation';
import { distinct } from 'vs/base/common/arrays';
import { INotificationService } from 'vs/platform/notification/common/notification';
import { ILifecycleService } from 'vs/platform/lifecycle/common/lifecycle';
export class DebugSession implements IDebugSession {
......@@ -74,7 +75,8 @@ export class DebugSession implements IDebugSession {
@IProductService private readonly productService: IProductService,
@IExtensionHostDebugService private readonly extensionHostDebugService: IExtensionHostDebugService,
@IOpenerService private readonly openerService: IOpenerService,
@INotificationService private readonly notificationService: INotificationService
@INotificationService private readonly notificationService: INotificationService,
@ILifecycleService lifecycleService: ILifecycleService
) {
this.id = generateUuid();
this._options = options || {};
......@@ -83,7 +85,13 @@ export class DebugSession implements IDebugSession {
} else {
this.repl = (this.parentSession as DebugSession).repl;
}
this.repl.onDidChangeElements(() => this._onDidChangeREPLElements.fire());
const toDispose: IDisposable[] = [];
toDispose.push(this.repl.onDidChangeElements(() => this._onDidChangeREPLElements.fire()));
toDispose.push(lifecycleService.onShutdown(() => {
this.shutdown();
dispose(toDispose);
}));
}
getId(): string {
......@@ -213,6 +221,7 @@ export class DebugSession implements IDebugSession {
} catch (err) {
this.initialized = true;
this._onDidChangeState.fire();
this.shutdown();
throw err;
}
}
......@@ -227,8 +236,12 @@ export class DebugSession implements IDebugSession {
// __sessionID only used for EH debugging (but we add it always for now...)
config.__sessionId = this.getId();
await this.raw.launchOrAttach(config);
try {
await this.raw.launchOrAttach(config);
} catch (err) {
this.shutdown();
throw err;
}
}
/**
......@@ -892,19 +905,22 @@ export class DebugSession implements IDebugSession {
this.rawListeners.push(this.raw.onDidExitAdapter(event => {
this.initialized = true;
this.model.setBreakpointSessionData(this.getId(), this.capabilities, undefined);
this.shutdown();
this._onDidEndAdapter.fire(event);
}));
}
shutdown(): void {
// Disconnects and clears state. Session can be initialized again for a new connection.
private shutdown(): void {
dispose(this.rawListeners);
if (this.raw) {
this.raw.disconnect();
this.raw.dispose();
}
this.raw = undefined;
this.fetchThreadsScheduler = undefined;
this.model.clearThreads(this.getId(), true);
if (this.raw) {
const raw = this.raw;
this.raw = undefined;
raw.disconnect();
raw.dispose();
}
this._onDidChangeState.fire();
}
......
......@@ -200,9 +200,6 @@ export interface IDebugSession extends ITreeElement {
readonly onDidLoadedSource: Event<LoadedSourceEvent>;
readonly onDidCustomEvent: Event<DebugProtocol.Event>;
// Disconnects and clears state. Session can be initialized again for a new connection.
shutdown(): void;
// DAP request
initialize(dbgr: IDebugger): Promise<void>;
......
......@@ -6,7 +6,6 @@
import * as nls from 'vs/nls';
import { URI as uri } from 'vs/base/common/uri';
import * as resources from 'vs/base/common/resources';
import * as lifecycle from 'vs/base/common/lifecycle';
import { Event, Emitter } from 'vs/base/common/event';
import { generateUuid } from 'vs/base/common/uuid';
import { RunOnceScheduler } from 'vs/base/common/async';
......@@ -819,7 +818,6 @@ export class ThreadAndSessionIds implements ITreeElement {
export class DebugModel implements IDebugModel {
private sessions: IDebugSession[];
private toDispose: lifecycle.IDisposable[];
private schedulers = new Map<string, RunOnceScheduler>();
private breakpointsActivated = true;
private readonly _onDidChangeBreakpoints = new Emitter<IBreakpointsChangeEvent | undefined>();
......@@ -835,7 +833,6 @@ export class DebugModel implements IDebugModel {
private textFileService: ITextFileService
) {
this.sessions = [];
this.toDispose = [];
}
getId(): string {
......@@ -1227,10 +1224,4 @@ export class DebugModel implements IDebugModel {
});
this._onDidChangeCallStack.fire(undefined);
}
dispose(): void {
// Make sure to shutdown each session, such that no debugged process is left laying around
this.sessions.forEach(s => s.shutdown());
this.toDispose = lifecycle.dispose(this.toDispose);
}
}
......@@ -19,7 +19,7 @@ import { OverviewRulerLane } from 'vs/editor/common/model';
import { MarkdownString } from 'vs/base/common/htmlContent';
function createMockSession(model: DebugModel, name = 'mockSession', options?: IDebugSessionOptions): DebugSession {
return new DebugSession({ resolved: { name, type: 'node', request: 'launch' }, unresolved: undefined }, undefined!, model, options, undefined!, undefined!, undefined!, undefined!, undefined!, undefined!, undefined!, undefined!, NullOpenerService, undefined!);
return new DebugSession({ resolved: { name, type: 'node', request: 'launch' }, unresolved: undefined }, undefined!, model, options, undefined!, undefined!, undefined!, undefined!, undefined!, undefined!, undefined!, undefined!, NullOpenerService, undefined!, undefined!);
}
function addBreakpointsAndCheckEvents(model: DebugModel, uri: uri, data: IBreakpointData[]): void {
......
......@@ -18,7 +18,7 @@ import { getContext, getContextForContributedActions } from 'vs/workbench/contri
import { getStackFrameThreadAndSessionToFocus } from 'vs/workbench/contrib/debug/browser/debugService';
export function createMockSession(model: DebugModel, name = 'mockSession', options?: IDebugSessionOptions): DebugSession {
return new DebugSession({ resolved: { name, type: 'node', request: 'launch' }, unresolved: undefined }, undefined!, model, options, undefined!, undefined!, undefined!, undefined!, undefined!, undefined!, undefined!, undefined!, NullOpenerService, undefined!);
return new DebugSession({ resolved: { name, type: 'node', request: 'launch' }, unresolved: undefined }, undefined!, model, options, undefined!, undefined!, undefined!, undefined!, undefined!, undefined!, undefined!, undefined!, NullOpenerService, undefined!, undefined!);
}
function createTwoStackFrames(session: DebugSession): { firstStackFrame: StackFrame, secondStackFrame: StackFrame } {
......@@ -363,7 +363,7 @@ suite('Debug - CallStack', () => {
get state(): State {
return State.Stopped;
}
}({ resolved: { name: 'stoppedSession', type: 'node', request: 'launch' }, unresolved: undefined }, undefined!, model, undefined, undefined!, undefined!, undefined!, undefined!, undefined!, undefined!, undefined!, undefined!, NullOpenerService, undefined!);
}({ resolved: { name: 'stoppedSession', type: 'node', request: 'launch' }, unresolved: undefined }, undefined!, model, undefined, undefined!, undefined!, undefined!, undefined!, undefined!, undefined!, undefined!, undefined!, NullOpenerService, undefined!, undefined!);
const runningSession = createMockSession(model);
model.addSession(runningSession);
......
......@@ -327,8 +327,6 @@ export class MockSession implements IDebugSession {
goto(threadId: number, targetId: number): Promise<DebugProtocol.GotoResponse> {
throw new Error('Method not implemented.');
}
shutdown(): void { }
}
export class MockRawSession {
......
......@@ -30,7 +30,7 @@ suite('Debug - ANSI Handling', () => {
*/
setup(() => {
model = new DebugModel([], [], [], [], [], <any>{ isDirty: (e: any) => false });
session = new DebugSession({ resolved: { name: 'test', type: 'node', request: 'launch' }, unresolved: undefined }, undefined!, model, undefined, undefined!, undefined!, undefined!, undefined!, undefined!, undefined!, undefined!, undefined!, NullOpenerService, undefined!);
session = new DebugSession({ resolved: { name: 'test', type: 'node', request: 'launch' }, unresolved: undefined }, undefined!, model, undefined, undefined!, undefined!, undefined!, undefined!, undefined!, undefined!, undefined!, undefined!, NullOpenerService, undefined!, undefined!);
const instantiationService: TestInstantiationService = <TestInstantiationService>workbenchInstantiationService();
linkDetector = instantiationService.createInstance(LinkDetector);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册