@theia/debug 1.53.0-next.5 → 1.53.0-next.55
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +62 -62
- package/lib/browser/debug-configuration-manager.js +6 -6
- package/lib/browser/debug-frontend-application-contribution.d.ts.map +1 -1
- package/lib/browser/debug-frontend-application-contribution.js.map +1 -1
- package/lib/common/inline-debug-adapter.d.ts +1 -0
- package/lib/common/inline-debug-adapter.d.ts.map +1 -1
- package/package.json +16 -16
- package/src/browser/breakpoint/breakpoint-manager.ts +369 -369
- package/src/browser/breakpoint/breakpoint-marker.ts +104 -104
- package/src/browser/console/debug-console-contribution.tsx +240 -240
- package/src/browser/console/debug-console-items.tsx +384 -384
- package/src/browser/console/debug-console-session.ts +205 -205
- package/src/browser/debug-call-stack-item-type-key.ts +20 -20
- package/src/browser/debug-configuration-manager.ts +591 -591
- package/src/browser/debug-configuration-model.ts +100 -100
- package/src/browser/debug-contribution.ts +43 -43
- package/src/browser/debug-frontend-application-contribution.ts +1551 -1551
- package/src/browser/debug-frontend-module.ts +133 -133
- package/src/browser/debug-package.spec.ts +20 -20
- package/src/browser/debug-preferences.ts +98 -98
- package/src/browser/debug-prefix-configuration.ts +195 -195
- package/src/browser/debug-resource.ts +59 -59
- package/src/browser/debug-schema-updater.ts +149 -149
- package/src/browser/debug-session-connection.ts +357 -357
- package/src/browser/debug-session-contribution.ts +157 -157
- package/src/browser/debug-session-manager.ts +683 -683
- package/src/browser/debug-session-options.ts +120 -120
- package/src/browser/debug-session.tsx +974 -974
- package/src/browser/debug-tab-bar-decorator.ts +57 -57
- package/src/browser/debug-watch-manager.ts +93 -93
- package/src/browser/disassembly-view/disassembly-view-accessibility-provider.ts +43 -43
- package/src/browser/disassembly-view/disassembly-view-breakpoint-renderer.ts +119 -119
- package/src/browser/disassembly-view/disassembly-view-contribution.ts +109 -109
- package/src/browser/disassembly-view/disassembly-view-instruction-renderer.ts +245 -245
- package/src/browser/disassembly-view/disassembly-view-table-delegate.ts +39 -39
- package/src/browser/disassembly-view/disassembly-view-utilities.ts +55 -55
- package/src/browser/disassembly-view/disassembly-view-widget.ts +463 -463
- package/src/browser/editor/debug-breakpoint-widget.tsx +293 -293
- package/src/browser/editor/debug-editor-model.ts +529 -529
- package/src/browser/editor/debug-editor-service.ts +192 -192
- package/src/browser/editor/debug-editor.ts +20 -20
- package/src/browser/editor/debug-exception-widget.tsx +122 -122
- package/src/browser/editor/debug-expression-provider.ts +78 -78
- package/src/browser/editor/debug-hover-source.tsx +105 -105
- package/src/browser/editor/debug-hover-widget.ts +298 -298
- package/src/browser/editor/debug-inline-value-decorator.ts +373 -373
- package/src/browser/model/debug-breakpoint.tsx +151 -151
- package/src/browser/model/debug-function-breakpoint.tsx +101 -101
- package/src/browser/model/debug-instruction-breakpoint.tsx +68 -68
- package/src/browser/model/debug-source-breakpoint.tsx +237 -237
- package/src/browser/model/debug-source.ts +93 -93
- package/src/browser/model/debug-stack-frame.tsx +177 -177
- package/src/browser/model/debug-thread.tsx +292 -292
- package/src/browser/preferences/launch-preferences.ts +38 -38
- package/src/browser/style/index.css +453 -453
- package/src/browser/view/debug-action.tsx +57 -57
- package/src/browser/view/debug-breakpoints-source.tsx +53 -53
- package/src/browser/view/debug-breakpoints-widget.ts +71 -71
- package/src/browser/view/debug-configuration-select.tsx +269 -269
- package/src/browser/view/debug-configuration-widget.tsx +121 -121
- package/src/browser/view/debug-exception-breakpoint.tsx +68 -68
- package/src/browser/view/debug-session-widget.ts +124 -124
- package/src/browser/view/debug-stack-frames-source.tsx +75 -75
- package/src/browser/view/debug-stack-frames-widget.ts +135 -135
- package/src/browser/view/debug-threads-source.tsx +48 -48
- package/src/browser/view/debug-threads-widget.ts +126 -126
- package/src/browser/view/debug-toolbar-widget.tsx +145 -145
- package/src/browser/view/debug-variables-source.ts +43 -43
- package/src/browser/view/debug-variables-widget.ts +61 -61
- package/src/browser/view/debug-view-model.ts +230 -230
- package/src/browser/view/debug-watch-expression.tsx +88 -88
- package/src/browser/view/debug-watch-source.ts +41 -41
- package/src/browser/view/debug-watch-widget.ts +61 -61
- package/src/browser/view/debug-widget.ts +97 -97
- package/src/common/debug-adapter-contribution-registry.ts +206 -206
- package/src/common/debug-adapter-session.ts +102 -102
- package/src/common/debug-common.ts +19 -19
- package/src/common/debug-compound.ts +33 -33
- package/src/common/debug-configuration.ts +112 -112
- package/src/common/debug-model.ts +200 -200
- package/src/common/debug-service.ts +184 -184
- package/src/common/debug-uri-utils.ts +24 -24
- package/src/common/inline-debug-adapter.ts +47 -47
- package/src/node/debug-adapter-factory.ts +107 -107
- package/src/node/debug-adapter-session-manager.ts +106 -106
- package/src/node/debug-backend-module.ts +57 -57
- package/src/node/debug-service-impl.ts +119 -119
- package/src/node/stream-debug-adapter.ts +126 -126
|
@@ -1,683 +1,683 @@
|
|
|
1
|
-
// *****************************************************************************
|
|
2
|
-
// Copyright (C) 2018 Red Hat, Inc. and others.
|
|
3
|
-
//
|
|
4
|
-
// This program and the accompanying materials are made available under the
|
|
5
|
-
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
-
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
-
//
|
|
8
|
-
// This Source Code may also be made available under the following Secondary
|
|
9
|
-
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
-
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
-
// with the GNU Classpath Exception which is available at
|
|
12
|
-
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
-
//
|
|
14
|
-
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
-
// *****************************************************************************
|
|
16
|
-
|
|
17
|
-
import { DisposableCollection, Emitter, Event, MessageService, nls, ProgressService, WaitUntilEvent } from '@theia/core';
|
|
18
|
-
import { LabelProvider, ApplicationShell } from '@theia/core/lib/browser';
|
|
19
|
-
import { ContextKey, ContextKeyService } from '@theia/core/lib/browser/context-key-service';
|
|
20
|
-
import URI from '@theia/core/lib/common/uri';
|
|
21
|
-
import { EditorManager } from '@theia/editor/lib/browser';
|
|
22
|
-
import { QuickOpenTask } from '@theia/task/lib/browser/quick-open-task';
|
|
23
|
-
import { TaskService, TaskEndedInfo, TaskEndedTypes } from '@theia/task/lib/browser/task-service';
|
|
24
|
-
import { VariableResolverService } from '@theia/variable-resolver/lib/browser';
|
|
25
|
-
import { inject, injectable, postConstruct } from '@theia/core/shared/inversify';
|
|
26
|
-
import { DebugConfiguration } from '../common/debug-common';
|
|
27
|
-
import { DebugError, DebugService } from '../common/debug-service';
|
|
28
|
-
import { BreakpointManager } from './breakpoint/breakpoint-manager';
|
|
29
|
-
import { DebugConfigurationManager } from './debug-configuration-manager';
|
|
30
|
-
import { DebugSession, DebugState, debugStateContextValue } from './debug-session';
|
|
31
|
-
import { DebugSessionContributionRegistry, DebugSessionFactory } from './debug-session-contribution';
|
|
32
|
-
import { DebugCompoundRoot, DebugCompoundSessionOptions, DebugConfigurationSessionOptions, DebugSessionOptions, InternalDebugSessionOptions } from './debug-session-options';
|
|
33
|
-
import { DebugStackFrame } from './model/debug-stack-frame';
|
|
34
|
-
import { DebugThread } from './model/debug-thread';
|
|
35
|
-
import { TaskIdentifier } from '@theia/task/lib/common';
|
|
36
|
-
import { DebugSourceBreakpoint } from './model/debug-source-breakpoint';
|
|
37
|
-
import { DebugFunctionBreakpoint } from './model/debug-function-breakpoint';
|
|
38
|
-
import * as monaco from '@theia/monaco-editor-core';
|
|
39
|
-
import { DebugInstructionBreakpoint } from './model/debug-instruction-breakpoint';
|
|
40
|
-
|
|
41
|
-
export interface WillStartDebugSession extends WaitUntilEvent {
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export interface WillResolveDebugConfiguration extends WaitUntilEvent {
|
|
45
|
-
debugType: string
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export interface DidChangeActiveDebugSession {
|
|
49
|
-
previous: DebugSession | undefined
|
|
50
|
-
current: DebugSession | undefined
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export interface DidChangeBreakpointsEvent {
|
|
54
|
-
session?: DebugSession
|
|
55
|
-
uri: URI
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export interface DebugSessionCustomEvent {
|
|
59
|
-
readonly body?: any // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
60
|
-
readonly event: string
|
|
61
|
-
readonly session: DebugSession
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
@injectable()
|
|
65
|
-
export class DebugSessionManager {
|
|
66
|
-
protected readonly _sessions = new Map<string, DebugSession>();
|
|
67
|
-
|
|
68
|
-
protected readonly onWillStartDebugSessionEmitter = new Emitter<WillStartDebugSession>();
|
|
69
|
-
readonly onWillStartDebugSession: Event<WillStartDebugSession> = this.onWillStartDebugSessionEmitter.event;
|
|
70
|
-
|
|
71
|
-
protected readonly onWillResolveDebugConfigurationEmitter = new Emitter<WillResolveDebugConfiguration>();
|
|
72
|
-
readonly onWillResolveDebugConfiguration: Event<WillResolveDebugConfiguration> = this.onWillResolveDebugConfigurationEmitter.event;
|
|
73
|
-
|
|
74
|
-
protected readonly onDidCreateDebugSessionEmitter = new Emitter<DebugSession>();
|
|
75
|
-
readonly onDidCreateDebugSession: Event<DebugSession> = this.onDidCreateDebugSessionEmitter.event;
|
|
76
|
-
|
|
77
|
-
protected readonly onDidStartDebugSessionEmitter = new Emitter<DebugSession>();
|
|
78
|
-
readonly onDidStartDebugSession: Event<DebugSession> = this.onDidStartDebugSessionEmitter.event;
|
|
79
|
-
|
|
80
|
-
protected readonly onDidStopDebugSessionEmitter = new Emitter<DebugSession>();
|
|
81
|
-
readonly onDidStopDebugSession: Event<DebugSession> = this.onDidStopDebugSessionEmitter.event;
|
|
82
|
-
|
|
83
|
-
protected readonly onDidChangeActiveDebugSessionEmitter = new Emitter<DidChangeActiveDebugSession>();
|
|
84
|
-
readonly onDidChangeActiveDebugSession: Event<DidChangeActiveDebugSession> = this.onDidChangeActiveDebugSessionEmitter.event;
|
|
85
|
-
|
|
86
|
-
protected readonly onDidDestroyDebugSessionEmitter = new Emitter<DebugSession>();
|
|
87
|
-
readonly onDidDestroyDebugSession: Event<DebugSession> = this.onDidDestroyDebugSessionEmitter.event;
|
|
88
|
-
|
|
89
|
-
protected readonly onDidReceiveDebugSessionCustomEventEmitter = new Emitter<DebugSessionCustomEvent>();
|
|
90
|
-
readonly onDidReceiveDebugSessionCustomEvent: Event<DebugSessionCustomEvent> = this.onDidReceiveDebugSessionCustomEventEmitter.event;
|
|
91
|
-
|
|
92
|
-
protected readonly onDidFocusStackFrameEmitter = new Emitter<DebugStackFrame | undefined>();
|
|
93
|
-
readonly onDidFocusStackFrame = this.onDidFocusStackFrameEmitter.event;
|
|
94
|
-
|
|
95
|
-
protected readonly onDidFocusThreadEmitter = new Emitter<DebugThread | undefined>();
|
|
96
|
-
readonly onDidFocusThread = this.onDidFocusThreadEmitter.event;
|
|
97
|
-
|
|
98
|
-
protected readonly onDidChangeBreakpointsEmitter = new Emitter<DidChangeBreakpointsEvent>();
|
|
99
|
-
readonly onDidChangeBreakpoints = this.onDidChangeBreakpointsEmitter.event;
|
|
100
|
-
protected fireDidChangeBreakpoints(event: DidChangeBreakpointsEvent): void {
|
|
101
|
-
this.onDidChangeBreakpointsEmitter.fire(event);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
protected readonly onDidChangeEmitter = new Emitter<DebugSession | undefined>();
|
|
105
|
-
readonly onDidChange: Event<DebugSession | undefined> = this.onDidChangeEmitter.event;
|
|
106
|
-
protected fireDidChange(current: DebugSession | undefined): void {
|
|
107
|
-
this.debugTypeKey.set(current?.configuration.type);
|
|
108
|
-
this.inDebugModeKey.set(this.inDebugMode);
|
|
109
|
-
this.debugStateKey.set(debugStateContextValue(this.state));
|
|
110
|
-
this.onDidChangeEmitter.fire(current);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
@inject(DebugSessionFactory)
|
|
114
|
-
protected readonly debugSessionFactory: DebugSessionFactory;
|
|
115
|
-
|
|
116
|
-
@inject(DebugService)
|
|
117
|
-
protected readonly debug: DebugService;
|
|
118
|
-
|
|
119
|
-
@inject(LabelProvider)
|
|
120
|
-
protected readonly labelProvider: LabelProvider;
|
|
121
|
-
|
|
122
|
-
@inject(EditorManager)
|
|
123
|
-
protected readonly editorManager: EditorManager;
|
|
124
|
-
|
|
125
|
-
@inject(BreakpointManager)
|
|
126
|
-
protected readonly breakpoints: BreakpointManager;
|
|
127
|
-
|
|
128
|
-
@inject(VariableResolverService)
|
|
129
|
-
protected readonly variableResolver: VariableResolverService;
|
|
130
|
-
|
|
131
|
-
@inject(DebugSessionContributionRegistry)
|
|
132
|
-
protected readonly sessionContributionRegistry: DebugSessionContributionRegistry;
|
|
133
|
-
|
|
134
|
-
@inject(MessageService)
|
|
135
|
-
protected readonly messageService: MessageService;
|
|
136
|
-
|
|
137
|
-
@inject(ProgressService)
|
|
138
|
-
protected readonly progressService: ProgressService;
|
|
139
|
-
|
|
140
|
-
@inject(ContextKeyService)
|
|
141
|
-
protected readonly contextKeyService: ContextKeyService;
|
|
142
|
-
|
|
143
|
-
@inject(TaskService)
|
|
144
|
-
protected readonly taskService: TaskService;
|
|
145
|
-
|
|
146
|
-
@inject(DebugConfigurationManager)
|
|
147
|
-
protected readonly debugConfigurationManager: DebugConfigurationManager;
|
|
148
|
-
|
|
149
|
-
@inject(QuickOpenTask)
|
|
150
|
-
protected readonly quickOpenTask: QuickOpenTask;
|
|
151
|
-
|
|
152
|
-
@inject(ApplicationShell)
|
|
153
|
-
protected readonly shell: ApplicationShell;
|
|
154
|
-
|
|
155
|
-
protected debugTypeKey: ContextKey<string>;
|
|
156
|
-
protected inDebugModeKey: ContextKey<boolean>;
|
|
157
|
-
protected debugStateKey: ContextKey<string>;
|
|
158
|
-
|
|
159
|
-
@postConstruct()
|
|
160
|
-
protected init(): void {
|
|
161
|
-
this.debugTypeKey = this.contextKeyService.createKey<string>('debugType', undefined);
|
|
162
|
-
this.inDebugModeKey = this.contextKeyService.createKey<boolean>('inDebugMode', this.inDebugMode);
|
|
163
|
-
this.debugStateKey = this.contextKeyService.createKey<string>('debugState', debugStateContextValue(this.state));
|
|
164
|
-
this.breakpoints.onDidChangeMarkers(uri => this.fireDidChangeBreakpoints({ uri }));
|
|
165
|
-
this.labelProvider.onDidChange(event => {
|
|
166
|
-
for (const uriString of this.breakpoints.getUris()) {
|
|
167
|
-
const uri = new URI(uriString);
|
|
168
|
-
if (event.affects(uri)) {
|
|
169
|
-
this.fireDidChangeBreakpoints({ uri });
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
});
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
get inDebugMode(): boolean {
|
|
176
|
-
return this.state > DebugState.Inactive;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
isCurrentEditorFrame(uri: URI | string | monaco.Uri): boolean {
|
|
180
|
-
return this.currentFrame?.source?.uri.toString() === (uri instanceof URI ? uri : new URI(uri.toString())).toString();
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
protected async saveAll(): Promise<boolean> {
|
|
184
|
-
if (!this.shell.canSaveAll()) {
|
|
185
|
-
return true; // Nothing to save.
|
|
186
|
-
}
|
|
187
|
-
try {
|
|
188
|
-
await this.shell.saveAll();
|
|
189
|
-
return true;
|
|
190
|
-
} catch (error) {
|
|
191
|
-
console.error('saveAll failed:', error);
|
|
192
|
-
return false;
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
async start(options: DebugCompoundSessionOptions): Promise<boolean | undefined>;
|
|
197
|
-
async start(options: DebugConfigurationSessionOptions): Promise<DebugSession | undefined>;
|
|
198
|
-
async start(options: DebugSessionOptions): Promise<DebugSession | boolean | undefined>;
|
|
199
|
-
async start(name: string): Promise<DebugSession | boolean | undefined>;
|
|
200
|
-
async start(optionsOrName: DebugSessionOptions | string): Promise<DebugSession | boolean | undefined> {
|
|
201
|
-
if (typeof optionsOrName === 'string') {
|
|
202
|
-
const options = this.debugConfigurationManager.find(optionsOrName);
|
|
203
|
-
return !!options && this.start(options);
|
|
204
|
-
}
|
|
205
|
-
return optionsOrName.configuration ? this.startConfiguration(optionsOrName) : this.startCompound(optionsOrName);
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
protected async startConfiguration(options: DebugConfigurationSessionOptions): Promise<DebugSession | undefined> {
|
|
209
|
-
return this.progressService.withProgress('Start...', 'debug', async () => {
|
|
210
|
-
try {
|
|
211
|
-
// If a parent session is available saving should be handled by the parent
|
|
212
|
-
if (!options.configuration.parentSessionId && !options.configuration.suppressSaveBeforeStart && !await this.saveAll()) {
|
|
213
|
-
return undefined;
|
|
214
|
-
}
|
|
215
|
-
await this.fireWillStartDebugSession();
|
|
216
|
-
const resolved = await this.resolveConfiguration(options);
|
|
217
|
-
|
|
218
|
-
if (!resolved || !resolved.configuration) {
|
|
219
|
-
// As per vscode API: https://code.visualstudio.com/api/references/vscode-api#DebugConfigurationProvider
|
|
220
|
-
// "Returning the value 'undefined' prevents the debug session from starting.
|
|
221
|
-
// Returning the value 'null' prevents the debug session from starting and opens the
|
|
222
|
-
// underlying debug configuration instead."
|
|
223
|
-
|
|
224
|
-
// eslint-disable-next-line no-null/no-null
|
|
225
|
-
if (resolved === null) {
|
|
226
|
-
this.debugConfigurationManager.openConfiguration();
|
|
227
|
-
}
|
|
228
|
-
return undefined;
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
// preLaunchTask isn't run in case of auto restart as well as postDebugTask
|
|
232
|
-
if (!options.configuration.__restart) {
|
|
233
|
-
const taskRun = await this.runTask(options.workspaceFolderUri, resolved.configuration.preLaunchTask, true);
|
|
234
|
-
if (!taskRun) {
|
|
235
|
-
return undefined;
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
const sessionId = await this.debug.createDebugSession(resolved.configuration, options.workspaceFolderUri);
|
|
240
|
-
return this.doStart(sessionId, resolved);
|
|
241
|
-
} catch (e) {
|
|
242
|
-
if (DebugError.NotFound.is(e)) {
|
|
243
|
-
this.messageService.error(`The debug session type "${e.data.type}" is not supported.`);
|
|
244
|
-
return undefined;
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
this.messageService.error('There was an error starting the debug session, check the logs for more details.');
|
|
248
|
-
console.error('Error starting the debug session', e);
|
|
249
|
-
throw e;
|
|
250
|
-
}
|
|
251
|
-
});
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
protected async startCompound(options: DebugCompoundSessionOptions): Promise<boolean | undefined> {
|
|
255
|
-
let configurations: DebugConfigurationSessionOptions[] = [];
|
|
256
|
-
const compoundRoot = options.compound.stopAll ? new DebugCompoundRoot() : undefined;
|
|
257
|
-
try {
|
|
258
|
-
configurations = this.getCompoundConfigurations(options, compoundRoot);
|
|
259
|
-
} catch (error) {
|
|
260
|
-
this.messageService.error(error.message);
|
|
261
|
-
return;
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
if (options.compound.preLaunchTask) {
|
|
265
|
-
const taskRun = await this.runTask(options.workspaceFolderUri, options.compound.preLaunchTask, true);
|
|
266
|
-
if (!taskRun) {
|
|
267
|
-
return undefined;
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
// Compound launch is a success only if each configuration launched successfully
|
|
272
|
-
const values = await Promise.all(configurations.map(async configuration => {
|
|
273
|
-
const newSession = await this.startConfiguration(configuration);
|
|
274
|
-
if (newSession) {
|
|
275
|
-
compoundRoot?.onDidSessionStop(() => newSession.stop(false, () => this.debug.terminateDebugSession(newSession.id)));
|
|
276
|
-
}
|
|
277
|
-
return newSession;
|
|
278
|
-
}));
|
|
279
|
-
const result = values.every(success => !!success);
|
|
280
|
-
return result;
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
protected getCompoundConfigurations(options: DebugCompoundSessionOptions, compoundRoot: DebugCompoundRoot | undefined): DebugConfigurationSessionOptions[] {
|
|
284
|
-
const compound = options.compound;
|
|
285
|
-
if (!compound.configurations) {
|
|
286
|
-
throw new Error(nls.localizeByDefault('Compound must have "configurations" attribute set in order to start multiple configurations.'));
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
const configurations: DebugConfigurationSessionOptions[] = [];
|
|
290
|
-
|
|
291
|
-
for (const configData of compound.configurations) {
|
|
292
|
-
const name = typeof configData === 'string' ? configData : configData.name;
|
|
293
|
-
if (name === compound.name) {
|
|
294
|
-
throw new Error(nls.localize('theia/debug/compound-cycle', "Launch configuration '{0}' contains a cycle with itself", name));
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
const workspaceFolderUri = typeof configData === 'string' ? options.workspaceFolderUri : configData.folder;
|
|
298
|
-
const matchingOptions = [...this.debugConfigurationManager.all]
|
|
299
|
-
.filter(option => option.name === name && !!option.configuration && option.workspaceFolderUri === workspaceFolderUri);
|
|
300
|
-
if (matchingOptions.length === 1) {
|
|
301
|
-
const match = matchingOptions[0];
|
|
302
|
-
if (DebugSessionOptions.isConfiguration(match)) {
|
|
303
|
-
configurations.push({ ...match, compoundRoot, configuration: { ...match.configuration, noDebug: options.noDebug } });
|
|
304
|
-
} else {
|
|
305
|
-
throw new Error(nls.localizeByDefault("Could not find launch configuration '{0}' in the workspace.", name));
|
|
306
|
-
}
|
|
307
|
-
} else {
|
|
308
|
-
throw new Error(matchingOptions.length === 0
|
|
309
|
-
? workspaceFolderUri
|
|
310
|
-
? nls.localizeByDefault("Can not find folder with name '{0}' for configuration '{1}' in compound '{2}'.", workspaceFolderUri, name, compound.name)
|
|
311
|
-
: nls.localizeByDefault("Could not find launch configuration '{0}' in the workspace.", name)
|
|
312
|
-
: nls.localizeByDefault("There are multiple launch configurations '{0}' in the workspace. Use folder name to qualify the configuration.", name));
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
return configurations;
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
protected async fireWillStartDebugSession(): Promise<void> {
|
|
319
|
-
await WaitUntilEvent.fire(this.onWillStartDebugSessionEmitter, {});
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
protected configurationIds = new Map<string, number>();
|
|
323
|
-
protected async resolveConfiguration(
|
|
324
|
-
options: Readonly<DebugConfigurationSessionOptions>
|
|
325
|
-
): Promise<InternalDebugSessionOptions | undefined | null> {
|
|
326
|
-
if (InternalDebugSessionOptions.is(options)) {
|
|
327
|
-
return options;
|
|
328
|
-
}
|
|
329
|
-
const { workspaceFolderUri } = options;
|
|
330
|
-
let configuration = await this.resolveDebugConfiguration(options.configuration, workspaceFolderUri);
|
|
331
|
-
|
|
332
|
-
if (configuration) {
|
|
333
|
-
// Resolve command variables provided by the debugger
|
|
334
|
-
const commandIdVariables = await this.debug.provideDebuggerVariables(configuration.type);
|
|
335
|
-
configuration = await this.variableResolver.resolve(configuration, {
|
|
336
|
-
context: options.workspaceFolderUri ? new URI(options.workspaceFolderUri) : undefined,
|
|
337
|
-
configurationSection: 'launch',
|
|
338
|
-
commandIdVariables,
|
|
339
|
-
configuration
|
|
340
|
-
});
|
|
341
|
-
|
|
342
|
-
if (configuration) {
|
|
343
|
-
configuration = await this.resolveDebugConfigurationWithSubstitutedVariables(
|
|
344
|
-
configuration,
|
|
345
|
-
workspaceFolderUri
|
|
346
|
-
);
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
if (!configuration) {
|
|
351
|
-
return configuration;
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
const key = configuration.name + workspaceFolderUri;
|
|
355
|
-
const id = this.configurationIds.has(key) ? this.configurationIds.get(key)! + 1 : 0;
|
|
356
|
-
this.configurationIds.set(key, id);
|
|
357
|
-
|
|
358
|
-
return {
|
|
359
|
-
id,
|
|
360
|
-
...options,
|
|
361
|
-
name: configuration.name,
|
|
362
|
-
configuration
|
|
363
|
-
};
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
protected async resolveDebugConfiguration(
|
|
367
|
-
configuration: DebugConfiguration,
|
|
368
|
-
workspaceFolderUri: string | undefined
|
|
369
|
-
): Promise<DebugConfiguration | undefined | null> {
|
|
370
|
-
await this.fireWillResolveDebugConfiguration(configuration.type);
|
|
371
|
-
return this.debug.resolveDebugConfiguration(configuration, workspaceFolderUri);
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
protected async fireWillResolveDebugConfiguration(debugType: string): Promise<void> {
|
|
375
|
-
await WaitUntilEvent.fire(this.onWillResolveDebugConfigurationEmitter, { debugType });
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
protected async resolveDebugConfigurationWithSubstitutedVariables(
|
|
379
|
-
configuration: DebugConfiguration,
|
|
380
|
-
workspaceFolderUri: string | undefined
|
|
381
|
-
): Promise<DebugConfiguration | undefined | null> {
|
|
382
|
-
return this.debug.resolveDebugConfigurationWithSubstitutedVariables(configuration, workspaceFolderUri);
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
protected async doStart(sessionId: string, options: DebugConfigurationSessionOptions): Promise<DebugSession> {
|
|
386
|
-
const parentSession = options.configuration.parentSessionId ? this._sessions.get(options.configuration.parentSessionId) : undefined;
|
|
387
|
-
const contrib = this.sessionContributionRegistry.get(options.configuration.type);
|
|
388
|
-
const sessionFactory = contrib ? contrib.debugSessionFactory() : this.debugSessionFactory;
|
|
389
|
-
const session = sessionFactory.get(this, sessionId, options, parentSession);
|
|
390
|
-
this._sessions.set(sessionId, session);
|
|
391
|
-
|
|
392
|
-
this.debugTypeKey.set(session.configuration.type);
|
|
393
|
-
this.onDidCreateDebugSessionEmitter.fire(session);
|
|
394
|
-
|
|
395
|
-
let state = DebugState.Inactive;
|
|
396
|
-
session.onDidChange(() => {
|
|
397
|
-
if (state !== session.state) {
|
|
398
|
-
state = session.state;
|
|
399
|
-
if (state === DebugState.Stopped) {
|
|
400
|
-
this.onDidStopDebugSessionEmitter.fire(session);
|
|
401
|
-
}
|
|
402
|
-
}
|
|
403
|
-
this.updateCurrentSession(session);
|
|
404
|
-
});
|
|
405
|
-
session.onDidChangeBreakpoints(uri => this.fireDidChangeBreakpoints({ session, uri }));
|
|
406
|
-
session.on('terminated', async event => {
|
|
407
|
-
const restart = event.body && event.body.restart;
|
|
408
|
-
if (restart) {
|
|
409
|
-
// postDebugTask isn't run in case of auto restart as well as preLaunchTask
|
|
410
|
-
this.doRestart(session, !!restart);
|
|
411
|
-
} else {
|
|
412
|
-
await session.disconnect(false, () => this.debug.terminateDebugSession(session.id));
|
|
413
|
-
await this.runTask(session.options.workspaceFolderUri, session.configuration.postDebugTask);
|
|
414
|
-
}
|
|
415
|
-
});
|
|
416
|
-
|
|
417
|
-
session.on('exited', async event => {
|
|
418
|
-
await session.disconnect(false, () => this.debug.terminateDebugSession(session.id));
|
|
419
|
-
});
|
|
420
|
-
|
|
421
|
-
session.onDispose(() => this.cleanup(session));
|
|
422
|
-
session.start().then(() => this.onDidStartDebugSessionEmitter.fire(session)).catch(e => {
|
|
423
|
-
session.stop(false, () => {
|
|
424
|
-
this.debug.terminateDebugSession(session.id);
|
|
425
|
-
});
|
|
426
|
-
});
|
|
427
|
-
session.onDidCustomEvent(({ event, body }) =>
|
|
428
|
-
this.onDidReceiveDebugSessionCustomEventEmitter.fire({ event, body, session })
|
|
429
|
-
);
|
|
430
|
-
return session;
|
|
431
|
-
}
|
|
432
|
-
|
|
433
|
-
protected cleanup(session: DebugSession): void {
|
|
434
|
-
if (this.remove(session.id)) {
|
|
435
|
-
this.onDidDestroyDebugSessionEmitter.fire(session);
|
|
436
|
-
}
|
|
437
|
-
}
|
|
438
|
-
|
|
439
|
-
protected async doRestart(session: DebugSession, isRestart: boolean): Promise<DebugSession | undefined> {
|
|
440
|
-
if (session.canRestart()) {
|
|
441
|
-
await session.restart();
|
|
442
|
-
return session;
|
|
443
|
-
}
|
|
444
|
-
|
|
445
|
-
const { options, configuration } = session;
|
|
446
|
-
session.stop(isRestart, () => this.debug.terminateDebugSession(session.id));
|
|
447
|
-
configuration.__restart = isRestart;
|
|
448
|
-
return this.start(options);
|
|
449
|
-
}
|
|
450
|
-
|
|
451
|
-
async terminateSession(session?: DebugSession): Promise<void> {
|
|
452
|
-
if (!session) {
|
|
453
|
-
this.updateCurrentSession(this._currentSession);
|
|
454
|
-
session = this._currentSession;
|
|
455
|
-
}
|
|
456
|
-
if (session) {
|
|
457
|
-
if (session.options.compoundRoot) {
|
|
458
|
-
session.options.compoundRoot.stopSession();
|
|
459
|
-
} else if (session.parentSession && session.configuration.lifecycleManagedByParent) {
|
|
460
|
-
this.terminateSession(session.parentSession);
|
|
461
|
-
} else {
|
|
462
|
-
session.stop(false, () => this.debug.terminateDebugSession(session!.id));
|
|
463
|
-
}
|
|
464
|
-
}
|
|
465
|
-
}
|
|
466
|
-
|
|
467
|
-
async restartSession(session?: DebugSession): Promise<DebugSession | undefined> {
|
|
468
|
-
if (!session) {
|
|
469
|
-
this.updateCurrentSession(this._currentSession);
|
|
470
|
-
session = this._currentSession;
|
|
471
|
-
}
|
|
472
|
-
|
|
473
|
-
if (session) {
|
|
474
|
-
if (session.parentSession && session.configuration.lifecycleManagedByParent) {
|
|
475
|
-
return this.restartSession(session.parentSession);
|
|
476
|
-
} else {
|
|
477
|
-
return this.doRestart(session, true);
|
|
478
|
-
}
|
|
479
|
-
}
|
|
480
|
-
}
|
|
481
|
-
|
|
482
|
-
protected remove(sessionId: string): boolean {
|
|
483
|
-
const existed = this._sessions.delete(sessionId);
|
|
484
|
-
const { currentSession } = this;
|
|
485
|
-
if (currentSession && currentSession.id === sessionId) {
|
|
486
|
-
this.updateCurrentSession(undefined);
|
|
487
|
-
}
|
|
488
|
-
return existed;
|
|
489
|
-
}
|
|
490
|
-
|
|
491
|
-
getSession(sessionId: string): DebugSession | undefined {
|
|
492
|
-
return this._sessions.get(sessionId);
|
|
493
|
-
}
|
|
494
|
-
|
|
495
|
-
get sessions(): DebugSession[] {
|
|
496
|
-
return Array.from(this._sessions.values()).filter(session => session.state > DebugState.Inactive);
|
|
497
|
-
}
|
|
498
|
-
|
|
499
|
-
protected _currentSession: DebugSession | undefined;
|
|
500
|
-
protected readonly disposeOnCurrentSessionChanged = new DisposableCollection();
|
|
501
|
-
get currentSession(): DebugSession | undefined {
|
|
502
|
-
return this._currentSession;
|
|
503
|
-
}
|
|
504
|
-
set currentSession(current: DebugSession | undefined) {
|
|
505
|
-
if (this._currentSession === current) {
|
|
506
|
-
return;
|
|
507
|
-
}
|
|
508
|
-
this.disposeOnCurrentSessionChanged.dispose();
|
|
509
|
-
const previous = this.currentSession;
|
|
510
|
-
this._currentSession = current;
|
|
511
|
-
this.onDidChangeActiveDebugSessionEmitter.fire({ previous, current });
|
|
512
|
-
if (current) {
|
|
513
|
-
this.disposeOnCurrentSessionChanged.push(current.onDidChange(() => {
|
|
514
|
-
if (this.currentFrame === this.topFrame) {
|
|
515
|
-
this.open();
|
|
516
|
-
}
|
|
517
|
-
this.fireDidChange(current);
|
|
518
|
-
}));
|
|
519
|
-
this.disposeOnCurrentSessionChanged.push(current.onDidFocusStackFrame(frame => this.onDidFocusStackFrameEmitter.fire(frame)));
|
|
520
|
-
this.disposeOnCurrentSessionChanged.push(current.onDidFocusThread(thread => this.onDidFocusThreadEmitter.fire(thread)));
|
|
521
|
-
const { currentThread } = current;
|
|
522
|
-
this.onDidFocusThreadEmitter.fire(currentThread);
|
|
523
|
-
}
|
|
524
|
-
this.updateBreakpoints(previous, current);
|
|
525
|
-
this.open();
|
|
526
|
-
this.fireDidChange(current);
|
|
527
|
-
}
|
|
528
|
-
open(): void {
|
|
529
|
-
const { currentFrame } = this;
|
|
530
|
-
if (currentFrame && currentFrame.thread.stopped) {
|
|
531
|
-
currentFrame.open();
|
|
532
|
-
}
|
|
533
|
-
}
|
|
534
|
-
protected updateBreakpoints(previous: DebugSession | undefined, current: DebugSession | undefined): void {
|
|
535
|
-
const affectedUri = new Set();
|
|
536
|
-
for (const session of [previous, current]) {
|
|
537
|
-
if (session) {
|
|
538
|
-
for (const uriString of session.breakpointUris) {
|
|
539
|
-
if (!affectedUri.has(uriString)) {
|
|
540
|
-
affectedUri.add(uriString);
|
|
541
|
-
this.fireDidChangeBreakpoints({
|
|
542
|
-
session: current,
|
|
543
|
-
uri: new URI(uriString)
|
|
544
|
-
});
|
|
545
|
-
}
|
|
546
|
-
}
|
|
547
|
-
}
|
|
548
|
-
}
|
|
549
|
-
}
|
|
550
|
-
protected updateCurrentSession(session: DebugSession | undefined): void {
|
|
551
|
-
this.currentSession = session || this.sessions[0];
|
|
552
|
-
}
|
|
553
|
-
|
|
554
|
-
get currentThread(): DebugThread | undefined {
|
|
555
|
-
const session = this.currentSession;
|
|
556
|
-
return session && session.currentThread;
|
|
557
|
-
}
|
|
558
|
-
|
|
559
|
-
get state(): DebugState {
|
|
560
|
-
const session = this.currentSession;
|
|
561
|
-
return session ? session.state : DebugState.Inactive;
|
|
562
|
-
}
|
|
563
|
-
|
|
564
|
-
get currentFrame(): DebugStackFrame | undefined {
|
|
565
|
-
const { currentThread } = this;
|
|
566
|
-
return currentThread && currentThread.currentFrame;
|
|
567
|
-
}
|
|
568
|
-
get topFrame(): DebugStackFrame | undefined {
|
|
569
|
-
const { currentThread } = this;
|
|
570
|
-
return currentThread && currentThread.topFrame;
|
|
571
|
-
}
|
|
572
|
-
|
|
573
|
-
getFunctionBreakpoints(session: DebugSession | undefined = this.currentSession): DebugFunctionBreakpoint[] {
|
|
574
|
-
if (session && session.state > DebugState.Initializing) {
|
|
575
|
-
return session.getFunctionBreakpoints();
|
|
576
|
-
}
|
|
577
|
-
const { labelProvider, breakpoints, editorManager } = this;
|
|
578
|
-
return this.breakpoints.getFunctionBreakpoints().map(origin => new DebugFunctionBreakpoint(origin, { labelProvider, breakpoints, editorManager }));
|
|
579
|
-
}
|
|
580
|
-
|
|
581
|
-
getInstructionBreakpoints(session = this.currentSession): DebugInstructionBreakpoint[] {
|
|
582
|
-
if (session && session.state > DebugState.Initializing) {
|
|
583
|
-
return session.getInstructionBreakpoints();
|
|
584
|
-
}
|
|
585
|
-
const { labelProvider, breakpoints, editorManager } = this;
|
|
586
|
-
return this.breakpoints.getInstructionBreakpoints().map(origin => new DebugInstructionBreakpoint(origin, { labelProvider, breakpoints, editorManager }));
|
|
587
|
-
}
|
|
588
|
-
|
|
589
|
-
getBreakpoints(session?: DebugSession): DebugSourceBreakpoint[];
|
|
590
|
-
getBreakpoints(uri: URI, session?: DebugSession): DebugSourceBreakpoint[];
|
|
591
|
-
getBreakpoints(arg?: URI | DebugSession, arg2?: DebugSession): DebugSourceBreakpoint[] {
|
|
592
|
-
const uri = arg instanceof URI ? arg : undefined;
|
|
593
|
-
const session = arg instanceof DebugSession ? arg : arg2 instanceof DebugSession ? arg2 : this.currentSession;
|
|
594
|
-
if (session && session.state > DebugState.Initializing) {
|
|
595
|
-
return session.getSourceBreakpoints(uri);
|
|
596
|
-
}
|
|
597
|
-
const { labelProvider, breakpoints, editorManager } = this;
|
|
598
|
-
return this.breakpoints.findMarkers({ uri }).map(({ data }) => new DebugSourceBreakpoint(data, { labelProvider, breakpoints, editorManager }));
|
|
599
|
-
}
|
|
600
|
-
|
|
601
|
-
getLineBreakpoints(uri: URI, line: number): DebugSourceBreakpoint[] {
|
|
602
|
-
const session = this.currentSession;
|
|
603
|
-
if (session && session.state > DebugState.Initializing) {
|
|
604
|
-
return session.getSourceBreakpoints(uri).filter(breakpoint => breakpoint.line === line);
|
|
605
|
-
}
|
|
606
|
-
const { labelProvider, breakpoints, editorManager } = this;
|
|
607
|
-
return this.breakpoints.getLineBreakpoints(uri, line).map(origin =>
|
|
608
|
-
new DebugSourceBreakpoint(origin, { labelProvider, breakpoints, editorManager })
|
|
609
|
-
);
|
|
610
|
-
}
|
|
611
|
-
|
|
612
|
-
getInlineBreakpoint(uri: URI, line: number, column: number): DebugSourceBreakpoint | undefined {
|
|
613
|
-
const session = this.currentSession;
|
|
614
|
-
if (session && session.state > DebugState.Initializing) {
|
|
615
|
-
return session.getSourceBreakpoints(uri).filter(breakpoint => breakpoint.line === line && breakpoint.column === column)[0];
|
|
616
|
-
}
|
|
617
|
-
const origin = this.breakpoints.getInlineBreakpoint(uri, line, column);
|
|
618
|
-
const { labelProvider, breakpoints, editorManager } = this;
|
|
619
|
-
return origin && new DebugSourceBreakpoint(origin, { labelProvider, breakpoints, editorManager });
|
|
620
|
-
}
|
|
621
|
-
|
|
622
|
-
/**
|
|
623
|
-
* Runs the given tasks.
|
|
624
|
-
* @param taskName the task name to run, see [TaskNameResolver](#TaskNameResolver)
|
|
625
|
-
* @return true if it allowed to continue debugging otherwise it returns false
|
|
626
|
-
*/
|
|
627
|
-
protected async runTask(workspaceFolderUri: string | undefined, taskName: string | TaskIdentifier | undefined, checkErrors?: boolean): Promise<boolean> {
|
|
628
|
-
if (!taskName) {
|
|
629
|
-
return true;
|
|
630
|
-
}
|
|
631
|
-
|
|
632
|
-
const taskInfo = await this.taskService.runWorkspaceTask(this.taskService.startUserAction(), workspaceFolderUri, taskName);
|
|
633
|
-
if (!checkErrors) {
|
|
634
|
-
return true;
|
|
635
|
-
}
|
|
636
|
-
|
|
637
|
-
if (!taskInfo) {
|
|
638
|
-
return this.doPostTaskAction(`Could not run the task '${taskName}'.`);
|
|
639
|
-
}
|
|
640
|
-
|
|
641
|
-
const getExitCodePromise: Promise<TaskEndedInfo> = this.taskService.getExitCode(taskInfo.taskId).then(result =>
|
|
642
|
-
({ taskEndedType: TaskEndedTypes.TaskExited, value: result }));
|
|
643
|
-
const isBackgroundTaskEndedPromise: Promise<TaskEndedInfo> = this.taskService.isBackgroundTaskEnded(taskInfo.taskId).then(result =>
|
|
644
|
-
({ taskEndedType: TaskEndedTypes.BackgroundTaskEnded, value: result }));
|
|
645
|
-
|
|
646
|
-
// After start running the task, we wait for the task process to exit and if it is a background task, we also wait for a feedback
|
|
647
|
-
// that a background task is active, as soon as one of the promises fulfills, we can continue and analyze the results.
|
|
648
|
-
const taskEndedInfo: TaskEndedInfo = await Promise.race([getExitCodePromise, isBackgroundTaskEndedPromise]);
|
|
649
|
-
|
|
650
|
-
if (taskEndedInfo.taskEndedType === TaskEndedTypes.BackgroundTaskEnded && taskEndedInfo.value) {
|
|
651
|
-
return true;
|
|
652
|
-
}
|
|
653
|
-
if (taskEndedInfo.taskEndedType === TaskEndedTypes.TaskExited && taskEndedInfo.value === 0) {
|
|
654
|
-
return true;
|
|
655
|
-
} else if (taskEndedInfo.taskEndedType === TaskEndedTypes.TaskExited && taskEndedInfo.value !== undefined) {
|
|
656
|
-
return this.doPostTaskAction(`Task '${taskName}' terminated with exit code ${taskEndedInfo.value}.`);
|
|
657
|
-
} else {
|
|
658
|
-
const signal = await this.taskService.getTerminateSignal(taskInfo.taskId);
|
|
659
|
-
if (signal !== undefined) {
|
|
660
|
-
return this.doPostTaskAction(`Task '${taskName}' terminated by signal ${signal}.`);
|
|
661
|
-
} else {
|
|
662
|
-
return this.doPostTaskAction(`Task '${taskName}' terminated for unknown reason.`);
|
|
663
|
-
}
|
|
664
|
-
}
|
|
665
|
-
}
|
|
666
|
-
|
|
667
|
-
protected async doPostTaskAction(errorMessage: string): Promise<boolean> {
|
|
668
|
-
const actions = ['Open launch.json', 'Cancel', 'Configure Task', 'Debug Anyway'];
|
|
669
|
-
const result = await this.messageService.error(errorMessage, ...actions);
|
|
670
|
-
switch (result) {
|
|
671
|
-
case actions[0]: // open launch.json
|
|
672
|
-
this.debugConfigurationManager.openConfiguration();
|
|
673
|
-
return false;
|
|
674
|
-
case actions[1]: // cancel
|
|
675
|
-
return false;
|
|
676
|
-
case actions[2]: // configure tasks
|
|
677
|
-
this.quickOpenTask.configure();
|
|
678
|
-
return false;
|
|
679
|
-
default: // continue debugging
|
|
680
|
-
return true;
|
|
681
|
-
}
|
|
682
|
-
}
|
|
683
|
-
}
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2018 Red Hat, Inc. and others.
|
|
3
|
+
//
|
|
4
|
+
// This program and the accompanying materials are made available under the
|
|
5
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
//
|
|
8
|
+
// This Source Code may also be made available under the following Secondary
|
|
9
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
// with the GNU Classpath Exception which is available at
|
|
12
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
//
|
|
14
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
|
|
17
|
+
import { DisposableCollection, Emitter, Event, MessageService, nls, ProgressService, WaitUntilEvent } from '@theia/core';
|
|
18
|
+
import { LabelProvider, ApplicationShell } from '@theia/core/lib/browser';
|
|
19
|
+
import { ContextKey, ContextKeyService } from '@theia/core/lib/browser/context-key-service';
|
|
20
|
+
import URI from '@theia/core/lib/common/uri';
|
|
21
|
+
import { EditorManager } from '@theia/editor/lib/browser';
|
|
22
|
+
import { QuickOpenTask } from '@theia/task/lib/browser/quick-open-task';
|
|
23
|
+
import { TaskService, TaskEndedInfo, TaskEndedTypes } from '@theia/task/lib/browser/task-service';
|
|
24
|
+
import { VariableResolverService } from '@theia/variable-resolver/lib/browser';
|
|
25
|
+
import { inject, injectable, postConstruct } from '@theia/core/shared/inversify';
|
|
26
|
+
import { DebugConfiguration } from '../common/debug-common';
|
|
27
|
+
import { DebugError, DebugService } from '../common/debug-service';
|
|
28
|
+
import { BreakpointManager } from './breakpoint/breakpoint-manager';
|
|
29
|
+
import { DebugConfigurationManager } from './debug-configuration-manager';
|
|
30
|
+
import { DebugSession, DebugState, debugStateContextValue } from './debug-session';
|
|
31
|
+
import { DebugSessionContributionRegistry, DebugSessionFactory } from './debug-session-contribution';
|
|
32
|
+
import { DebugCompoundRoot, DebugCompoundSessionOptions, DebugConfigurationSessionOptions, DebugSessionOptions, InternalDebugSessionOptions } from './debug-session-options';
|
|
33
|
+
import { DebugStackFrame } from './model/debug-stack-frame';
|
|
34
|
+
import { DebugThread } from './model/debug-thread';
|
|
35
|
+
import { TaskIdentifier } from '@theia/task/lib/common';
|
|
36
|
+
import { DebugSourceBreakpoint } from './model/debug-source-breakpoint';
|
|
37
|
+
import { DebugFunctionBreakpoint } from './model/debug-function-breakpoint';
|
|
38
|
+
import * as monaco from '@theia/monaco-editor-core';
|
|
39
|
+
import { DebugInstructionBreakpoint } from './model/debug-instruction-breakpoint';
|
|
40
|
+
|
|
41
|
+
export interface WillStartDebugSession extends WaitUntilEvent {
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface WillResolveDebugConfiguration extends WaitUntilEvent {
|
|
45
|
+
debugType: string
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface DidChangeActiveDebugSession {
|
|
49
|
+
previous: DebugSession | undefined
|
|
50
|
+
current: DebugSession | undefined
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export interface DidChangeBreakpointsEvent {
|
|
54
|
+
session?: DebugSession
|
|
55
|
+
uri: URI
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export interface DebugSessionCustomEvent {
|
|
59
|
+
readonly body?: any // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
60
|
+
readonly event: string
|
|
61
|
+
readonly session: DebugSession
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
@injectable()
|
|
65
|
+
export class DebugSessionManager {
|
|
66
|
+
protected readonly _sessions = new Map<string, DebugSession>();
|
|
67
|
+
|
|
68
|
+
protected readonly onWillStartDebugSessionEmitter = new Emitter<WillStartDebugSession>();
|
|
69
|
+
readonly onWillStartDebugSession: Event<WillStartDebugSession> = this.onWillStartDebugSessionEmitter.event;
|
|
70
|
+
|
|
71
|
+
protected readonly onWillResolveDebugConfigurationEmitter = new Emitter<WillResolveDebugConfiguration>();
|
|
72
|
+
readonly onWillResolveDebugConfiguration: Event<WillResolveDebugConfiguration> = this.onWillResolveDebugConfigurationEmitter.event;
|
|
73
|
+
|
|
74
|
+
protected readonly onDidCreateDebugSessionEmitter = new Emitter<DebugSession>();
|
|
75
|
+
readonly onDidCreateDebugSession: Event<DebugSession> = this.onDidCreateDebugSessionEmitter.event;
|
|
76
|
+
|
|
77
|
+
protected readonly onDidStartDebugSessionEmitter = new Emitter<DebugSession>();
|
|
78
|
+
readonly onDidStartDebugSession: Event<DebugSession> = this.onDidStartDebugSessionEmitter.event;
|
|
79
|
+
|
|
80
|
+
protected readonly onDidStopDebugSessionEmitter = new Emitter<DebugSession>();
|
|
81
|
+
readonly onDidStopDebugSession: Event<DebugSession> = this.onDidStopDebugSessionEmitter.event;
|
|
82
|
+
|
|
83
|
+
protected readonly onDidChangeActiveDebugSessionEmitter = new Emitter<DidChangeActiveDebugSession>();
|
|
84
|
+
readonly onDidChangeActiveDebugSession: Event<DidChangeActiveDebugSession> = this.onDidChangeActiveDebugSessionEmitter.event;
|
|
85
|
+
|
|
86
|
+
protected readonly onDidDestroyDebugSessionEmitter = new Emitter<DebugSession>();
|
|
87
|
+
readonly onDidDestroyDebugSession: Event<DebugSession> = this.onDidDestroyDebugSessionEmitter.event;
|
|
88
|
+
|
|
89
|
+
protected readonly onDidReceiveDebugSessionCustomEventEmitter = new Emitter<DebugSessionCustomEvent>();
|
|
90
|
+
readonly onDidReceiveDebugSessionCustomEvent: Event<DebugSessionCustomEvent> = this.onDidReceiveDebugSessionCustomEventEmitter.event;
|
|
91
|
+
|
|
92
|
+
protected readonly onDidFocusStackFrameEmitter = new Emitter<DebugStackFrame | undefined>();
|
|
93
|
+
readonly onDidFocusStackFrame = this.onDidFocusStackFrameEmitter.event;
|
|
94
|
+
|
|
95
|
+
protected readonly onDidFocusThreadEmitter = new Emitter<DebugThread | undefined>();
|
|
96
|
+
readonly onDidFocusThread = this.onDidFocusThreadEmitter.event;
|
|
97
|
+
|
|
98
|
+
protected readonly onDidChangeBreakpointsEmitter = new Emitter<DidChangeBreakpointsEvent>();
|
|
99
|
+
readonly onDidChangeBreakpoints = this.onDidChangeBreakpointsEmitter.event;
|
|
100
|
+
protected fireDidChangeBreakpoints(event: DidChangeBreakpointsEvent): void {
|
|
101
|
+
this.onDidChangeBreakpointsEmitter.fire(event);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
protected readonly onDidChangeEmitter = new Emitter<DebugSession | undefined>();
|
|
105
|
+
readonly onDidChange: Event<DebugSession | undefined> = this.onDidChangeEmitter.event;
|
|
106
|
+
protected fireDidChange(current: DebugSession | undefined): void {
|
|
107
|
+
this.debugTypeKey.set(current?.configuration.type);
|
|
108
|
+
this.inDebugModeKey.set(this.inDebugMode);
|
|
109
|
+
this.debugStateKey.set(debugStateContextValue(this.state));
|
|
110
|
+
this.onDidChangeEmitter.fire(current);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
@inject(DebugSessionFactory)
|
|
114
|
+
protected readonly debugSessionFactory: DebugSessionFactory;
|
|
115
|
+
|
|
116
|
+
@inject(DebugService)
|
|
117
|
+
protected readonly debug: DebugService;
|
|
118
|
+
|
|
119
|
+
@inject(LabelProvider)
|
|
120
|
+
protected readonly labelProvider: LabelProvider;
|
|
121
|
+
|
|
122
|
+
@inject(EditorManager)
|
|
123
|
+
protected readonly editorManager: EditorManager;
|
|
124
|
+
|
|
125
|
+
@inject(BreakpointManager)
|
|
126
|
+
protected readonly breakpoints: BreakpointManager;
|
|
127
|
+
|
|
128
|
+
@inject(VariableResolverService)
|
|
129
|
+
protected readonly variableResolver: VariableResolverService;
|
|
130
|
+
|
|
131
|
+
@inject(DebugSessionContributionRegistry)
|
|
132
|
+
protected readonly sessionContributionRegistry: DebugSessionContributionRegistry;
|
|
133
|
+
|
|
134
|
+
@inject(MessageService)
|
|
135
|
+
protected readonly messageService: MessageService;
|
|
136
|
+
|
|
137
|
+
@inject(ProgressService)
|
|
138
|
+
protected readonly progressService: ProgressService;
|
|
139
|
+
|
|
140
|
+
@inject(ContextKeyService)
|
|
141
|
+
protected readonly contextKeyService: ContextKeyService;
|
|
142
|
+
|
|
143
|
+
@inject(TaskService)
|
|
144
|
+
protected readonly taskService: TaskService;
|
|
145
|
+
|
|
146
|
+
@inject(DebugConfigurationManager)
|
|
147
|
+
protected readonly debugConfigurationManager: DebugConfigurationManager;
|
|
148
|
+
|
|
149
|
+
@inject(QuickOpenTask)
|
|
150
|
+
protected readonly quickOpenTask: QuickOpenTask;
|
|
151
|
+
|
|
152
|
+
@inject(ApplicationShell)
|
|
153
|
+
protected readonly shell: ApplicationShell;
|
|
154
|
+
|
|
155
|
+
protected debugTypeKey: ContextKey<string>;
|
|
156
|
+
protected inDebugModeKey: ContextKey<boolean>;
|
|
157
|
+
protected debugStateKey: ContextKey<string>;
|
|
158
|
+
|
|
159
|
+
@postConstruct()
|
|
160
|
+
protected init(): void {
|
|
161
|
+
this.debugTypeKey = this.contextKeyService.createKey<string>('debugType', undefined);
|
|
162
|
+
this.inDebugModeKey = this.contextKeyService.createKey<boolean>('inDebugMode', this.inDebugMode);
|
|
163
|
+
this.debugStateKey = this.contextKeyService.createKey<string>('debugState', debugStateContextValue(this.state));
|
|
164
|
+
this.breakpoints.onDidChangeMarkers(uri => this.fireDidChangeBreakpoints({ uri }));
|
|
165
|
+
this.labelProvider.onDidChange(event => {
|
|
166
|
+
for (const uriString of this.breakpoints.getUris()) {
|
|
167
|
+
const uri = new URI(uriString);
|
|
168
|
+
if (event.affects(uri)) {
|
|
169
|
+
this.fireDidChangeBreakpoints({ uri });
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
get inDebugMode(): boolean {
|
|
176
|
+
return this.state > DebugState.Inactive;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
isCurrentEditorFrame(uri: URI | string | monaco.Uri): boolean {
|
|
180
|
+
return this.currentFrame?.source?.uri.toString() === (uri instanceof URI ? uri : new URI(uri.toString())).toString();
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
protected async saveAll(): Promise<boolean> {
|
|
184
|
+
if (!this.shell.canSaveAll()) {
|
|
185
|
+
return true; // Nothing to save.
|
|
186
|
+
}
|
|
187
|
+
try {
|
|
188
|
+
await this.shell.saveAll();
|
|
189
|
+
return true;
|
|
190
|
+
} catch (error) {
|
|
191
|
+
console.error('saveAll failed:', error);
|
|
192
|
+
return false;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
async start(options: DebugCompoundSessionOptions): Promise<boolean | undefined>;
|
|
197
|
+
async start(options: DebugConfigurationSessionOptions): Promise<DebugSession | undefined>;
|
|
198
|
+
async start(options: DebugSessionOptions): Promise<DebugSession | boolean | undefined>;
|
|
199
|
+
async start(name: string): Promise<DebugSession | boolean | undefined>;
|
|
200
|
+
async start(optionsOrName: DebugSessionOptions | string): Promise<DebugSession | boolean | undefined> {
|
|
201
|
+
if (typeof optionsOrName === 'string') {
|
|
202
|
+
const options = this.debugConfigurationManager.find(optionsOrName);
|
|
203
|
+
return !!options && this.start(options);
|
|
204
|
+
}
|
|
205
|
+
return optionsOrName.configuration ? this.startConfiguration(optionsOrName) : this.startCompound(optionsOrName);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
protected async startConfiguration(options: DebugConfigurationSessionOptions): Promise<DebugSession | undefined> {
|
|
209
|
+
return this.progressService.withProgress('Start...', 'debug', async () => {
|
|
210
|
+
try {
|
|
211
|
+
// If a parent session is available saving should be handled by the parent
|
|
212
|
+
if (!options.configuration.parentSessionId && !options.configuration.suppressSaveBeforeStart && !await this.saveAll()) {
|
|
213
|
+
return undefined;
|
|
214
|
+
}
|
|
215
|
+
await this.fireWillStartDebugSession();
|
|
216
|
+
const resolved = await this.resolveConfiguration(options);
|
|
217
|
+
|
|
218
|
+
if (!resolved || !resolved.configuration) {
|
|
219
|
+
// As per vscode API: https://code.visualstudio.com/api/references/vscode-api#DebugConfigurationProvider
|
|
220
|
+
// "Returning the value 'undefined' prevents the debug session from starting.
|
|
221
|
+
// Returning the value 'null' prevents the debug session from starting and opens the
|
|
222
|
+
// underlying debug configuration instead."
|
|
223
|
+
|
|
224
|
+
// eslint-disable-next-line no-null/no-null
|
|
225
|
+
if (resolved === null) {
|
|
226
|
+
this.debugConfigurationManager.openConfiguration();
|
|
227
|
+
}
|
|
228
|
+
return undefined;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
// preLaunchTask isn't run in case of auto restart as well as postDebugTask
|
|
232
|
+
if (!options.configuration.__restart) {
|
|
233
|
+
const taskRun = await this.runTask(options.workspaceFolderUri, resolved.configuration.preLaunchTask, true);
|
|
234
|
+
if (!taskRun) {
|
|
235
|
+
return undefined;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
const sessionId = await this.debug.createDebugSession(resolved.configuration, options.workspaceFolderUri);
|
|
240
|
+
return this.doStart(sessionId, resolved);
|
|
241
|
+
} catch (e) {
|
|
242
|
+
if (DebugError.NotFound.is(e)) {
|
|
243
|
+
this.messageService.error(`The debug session type "${e.data.type}" is not supported.`);
|
|
244
|
+
return undefined;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
this.messageService.error('There was an error starting the debug session, check the logs for more details.');
|
|
248
|
+
console.error('Error starting the debug session', e);
|
|
249
|
+
throw e;
|
|
250
|
+
}
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
protected async startCompound(options: DebugCompoundSessionOptions): Promise<boolean | undefined> {
|
|
255
|
+
let configurations: DebugConfigurationSessionOptions[] = [];
|
|
256
|
+
const compoundRoot = options.compound.stopAll ? new DebugCompoundRoot() : undefined;
|
|
257
|
+
try {
|
|
258
|
+
configurations = this.getCompoundConfigurations(options, compoundRoot);
|
|
259
|
+
} catch (error) {
|
|
260
|
+
this.messageService.error(error.message);
|
|
261
|
+
return;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
if (options.compound.preLaunchTask) {
|
|
265
|
+
const taskRun = await this.runTask(options.workspaceFolderUri, options.compound.preLaunchTask, true);
|
|
266
|
+
if (!taskRun) {
|
|
267
|
+
return undefined;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
// Compound launch is a success only if each configuration launched successfully
|
|
272
|
+
const values = await Promise.all(configurations.map(async configuration => {
|
|
273
|
+
const newSession = await this.startConfiguration(configuration);
|
|
274
|
+
if (newSession) {
|
|
275
|
+
compoundRoot?.onDidSessionStop(() => newSession.stop(false, () => this.debug.terminateDebugSession(newSession.id)));
|
|
276
|
+
}
|
|
277
|
+
return newSession;
|
|
278
|
+
}));
|
|
279
|
+
const result = values.every(success => !!success);
|
|
280
|
+
return result;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
protected getCompoundConfigurations(options: DebugCompoundSessionOptions, compoundRoot: DebugCompoundRoot | undefined): DebugConfigurationSessionOptions[] {
|
|
284
|
+
const compound = options.compound;
|
|
285
|
+
if (!compound.configurations) {
|
|
286
|
+
throw new Error(nls.localizeByDefault('Compound must have "configurations" attribute set in order to start multiple configurations.'));
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
const configurations: DebugConfigurationSessionOptions[] = [];
|
|
290
|
+
|
|
291
|
+
for (const configData of compound.configurations) {
|
|
292
|
+
const name = typeof configData === 'string' ? configData : configData.name;
|
|
293
|
+
if (name === compound.name) {
|
|
294
|
+
throw new Error(nls.localize('theia/debug/compound-cycle', "Launch configuration '{0}' contains a cycle with itself", name));
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
const workspaceFolderUri = typeof configData === 'string' ? options.workspaceFolderUri : configData.folder;
|
|
298
|
+
const matchingOptions = [...this.debugConfigurationManager.all]
|
|
299
|
+
.filter(option => option.name === name && !!option.configuration && option.workspaceFolderUri === workspaceFolderUri);
|
|
300
|
+
if (matchingOptions.length === 1) {
|
|
301
|
+
const match = matchingOptions[0];
|
|
302
|
+
if (DebugSessionOptions.isConfiguration(match)) {
|
|
303
|
+
configurations.push({ ...match, compoundRoot, configuration: { ...match.configuration, noDebug: options.noDebug } });
|
|
304
|
+
} else {
|
|
305
|
+
throw new Error(nls.localizeByDefault("Could not find launch configuration '{0}' in the workspace.", name));
|
|
306
|
+
}
|
|
307
|
+
} else {
|
|
308
|
+
throw new Error(matchingOptions.length === 0
|
|
309
|
+
? workspaceFolderUri
|
|
310
|
+
? nls.localizeByDefault("Can not find folder with name '{0}' for configuration '{1}' in compound '{2}'.", workspaceFolderUri, name, compound.name)
|
|
311
|
+
: nls.localizeByDefault("Could not find launch configuration '{0}' in the workspace.", name)
|
|
312
|
+
: nls.localizeByDefault("There are multiple launch configurations '{0}' in the workspace. Use folder name to qualify the configuration.", name));
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
return configurations;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
protected async fireWillStartDebugSession(): Promise<void> {
|
|
319
|
+
await WaitUntilEvent.fire(this.onWillStartDebugSessionEmitter, {});
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
protected configurationIds = new Map<string, number>();
|
|
323
|
+
protected async resolveConfiguration(
|
|
324
|
+
options: Readonly<DebugConfigurationSessionOptions>
|
|
325
|
+
): Promise<InternalDebugSessionOptions | undefined | null> {
|
|
326
|
+
if (InternalDebugSessionOptions.is(options)) {
|
|
327
|
+
return options;
|
|
328
|
+
}
|
|
329
|
+
const { workspaceFolderUri } = options;
|
|
330
|
+
let configuration = await this.resolveDebugConfiguration(options.configuration, workspaceFolderUri);
|
|
331
|
+
|
|
332
|
+
if (configuration) {
|
|
333
|
+
// Resolve command variables provided by the debugger
|
|
334
|
+
const commandIdVariables = await this.debug.provideDebuggerVariables(configuration.type);
|
|
335
|
+
configuration = await this.variableResolver.resolve(configuration, {
|
|
336
|
+
context: options.workspaceFolderUri ? new URI(options.workspaceFolderUri) : undefined,
|
|
337
|
+
configurationSection: 'launch',
|
|
338
|
+
commandIdVariables,
|
|
339
|
+
configuration
|
|
340
|
+
});
|
|
341
|
+
|
|
342
|
+
if (configuration) {
|
|
343
|
+
configuration = await this.resolveDebugConfigurationWithSubstitutedVariables(
|
|
344
|
+
configuration,
|
|
345
|
+
workspaceFolderUri
|
|
346
|
+
);
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
if (!configuration) {
|
|
351
|
+
return configuration;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
const key = configuration.name + workspaceFolderUri;
|
|
355
|
+
const id = this.configurationIds.has(key) ? this.configurationIds.get(key)! + 1 : 0;
|
|
356
|
+
this.configurationIds.set(key, id);
|
|
357
|
+
|
|
358
|
+
return {
|
|
359
|
+
id,
|
|
360
|
+
...options,
|
|
361
|
+
name: configuration.name,
|
|
362
|
+
configuration
|
|
363
|
+
};
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
protected async resolveDebugConfiguration(
|
|
367
|
+
configuration: DebugConfiguration,
|
|
368
|
+
workspaceFolderUri: string | undefined
|
|
369
|
+
): Promise<DebugConfiguration | undefined | null> {
|
|
370
|
+
await this.fireWillResolveDebugConfiguration(configuration.type);
|
|
371
|
+
return this.debug.resolveDebugConfiguration(configuration, workspaceFolderUri);
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
protected async fireWillResolveDebugConfiguration(debugType: string): Promise<void> {
|
|
375
|
+
await WaitUntilEvent.fire(this.onWillResolveDebugConfigurationEmitter, { debugType });
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
protected async resolveDebugConfigurationWithSubstitutedVariables(
|
|
379
|
+
configuration: DebugConfiguration,
|
|
380
|
+
workspaceFolderUri: string | undefined
|
|
381
|
+
): Promise<DebugConfiguration | undefined | null> {
|
|
382
|
+
return this.debug.resolveDebugConfigurationWithSubstitutedVariables(configuration, workspaceFolderUri);
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
protected async doStart(sessionId: string, options: DebugConfigurationSessionOptions): Promise<DebugSession> {
|
|
386
|
+
const parentSession = options.configuration.parentSessionId ? this._sessions.get(options.configuration.parentSessionId) : undefined;
|
|
387
|
+
const contrib = this.sessionContributionRegistry.get(options.configuration.type);
|
|
388
|
+
const sessionFactory = contrib ? contrib.debugSessionFactory() : this.debugSessionFactory;
|
|
389
|
+
const session = sessionFactory.get(this, sessionId, options, parentSession);
|
|
390
|
+
this._sessions.set(sessionId, session);
|
|
391
|
+
|
|
392
|
+
this.debugTypeKey.set(session.configuration.type);
|
|
393
|
+
this.onDidCreateDebugSessionEmitter.fire(session);
|
|
394
|
+
|
|
395
|
+
let state = DebugState.Inactive;
|
|
396
|
+
session.onDidChange(() => {
|
|
397
|
+
if (state !== session.state) {
|
|
398
|
+
state = session.state;
|
|
399
|
+
if (state === DebugState.Stopped) {
|
|
400
|
+
this.onDidStopDebugSessionEmitter.fire(session);
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
this.updateCurrentSession(session);
|
|
404
|
+
});
|
|
405
|
+
session.onDidChangeBreakpoints(uri => this.fireDidChangeBreakpoints({ session, uri }));
|
|
406
|
+
session.on('terminated', async event => {
|
|
407
|
+
const restart = event.body && event.body.restart;
|
|
408
|
+
if (restart) {
|
|
409
|
+
// postDebugTask isn't run in case of auto restart as well as preLaunchTask
|
|
410
|
+
this.doRestart(session, !!restart);
|
|
411
|
+
} else {
|
|
412
|
+
await session.disconnect(false, () => this.debug.terminateDebugSession(session.id));
|
|
413
|
+
await this.runTask(session.options.workspaceFolderUri, session.configuration.postDebugTask);
|
|
414
|
+
}
|
|
415
|
+
});
|
|
416
|
+
|
|
417
|
+
session.on('exited', async event => {
|
|
418
|
+
await session.disconnect(false, () => this.debug.terminateDebugSession(session.id));
|
|
419
|
+
});
|
|
420
|
+
|
|
421
|
+
session.onDispose(() => this.cleanup(session));
|
|
422
|
+
session.start().then(() => this.onDidStartDebugSessionEmitter.fire(session)).catch(e => {
|
|
423
|
+
session.stop(false, () => {
|
|
424
|
+
this.debug.terminateDebugSession(session.id);
|
|
425
|
+
});
|
|
426
|
+
});
|
|
427
|
+
session.onDidCustomEvent(({ event, body }) =>
|
|
428
|
+
this.onDidReceiveDebugSessionCustomEventEmitter.fire({ event, body, session })
|
|
429
|
+
);
|
|
430
|
+
return session;
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
protected cleanup(session: DebugSession): void {
|
|
434
|
+
if (this.remove(session.id)) {
|
|
435
|
+
this.onDidDestroyDebugSessionEmitter.fire(session);
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
protected async doRestart(session: DebugSession, isRestart: boolean): Promise<DebugSession | undefined> {
|
|
440
|
+
if (session.canRestart()) {
|
|
441
|
+
await session.restart();
|
|
442
|
+
return session;
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
const { options, configuration } = session;
|
|
446
|
+
session.stop(isRestart, () => this.debug.terminateDebugSession(session.id));
|
|
447
|
+
configuration.__restart = isRestart;
|
|
448
|
+
return this.start(options);
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
async terminateSession(session?: DebugSession): Promise<void> {
|
|
452
|
+
if (!session) {
|
|
453
|
+
this.updateCurrentSession(this._currentSession);
|
|
454
|
+
session = this._currentSession;
|
|
455
|
+
}
|
|
456
|
+
if (session) {
|
|
457
|
+
if (session.options.compoundRoot) {
|
|
458
|
+
session.options.compoundRoot.stopSession();
|
|
459
|
+
} else if (session.parentSession && session.configuration.lifecycleManagedByParent) {
|
|
460
|
+
this.terminateSession(session.parentSession);
|
|
461
|
+
} else {
|
|
462
|
+
session.stop(false, () => this.debug.terminateDebugSession(session!.id));
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
async restartSession(session?: DebugSession): Promise<DebugSession | undefined> {
|
|
468
|
+
if (!session) {
|
|
469
|
+
this.updateCurrentSession(this._currentSession);
|
|
470
|
+
session = this._currentSession;
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
if (session) {
|
|
474
|
+
if (session.parentSession && session.configuration.lifecycleManagedByParent) {
|
|
475
|
+
return this.restartSession(session.parentSession);
|
|
476
|
+
} else {
|
|
477
|
+
return this.doRestart(session, true);
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
protected remove(sessionId: string): boolean {
|
|
483
|
+
const existed = this._sessions.delete(sessionId);
|
|
484
|
+
const { currentSession } = this;
|
|
485
|
+
if (currentSession && currentSession.id === sessionId) {
|
|
486
|
+
this.updateCurrentSession(undefined);
|
|
487
|
+
}
|
|
488
|
+
return existed;
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
getSession(sessionId: string): DebugSession | undefined {
|
|
492
|
+
return this._sessions.get(sessionId);
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
get sessions(): DebugSession[] {
|
|
496
|
+
return Array.from(this._sessions.values()).filter(session => session.state > DebugState.Inactive);
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
protected _currentSession: DebugSession | undefined;
|
|
500
|
+
protected readonly disposeOnCurrentSessionChanged = new DisposableCollection();
|
|
501
|
+
get currentSession(): DebugSession | undefined {
|
|
502
|
+
return this._currentSession;
|
|
503
|
+
}
|
|
504
|
+
set currentSession(current: DebugSession | undefined) {
|
|
505
|
+
if (this._currentSession === current) {
|
|
506
|
+
return;
|
|
507
|
+
}
|
|
508
|
+
this.disposeOnCurrentSessionChanged.dispose();
|
|
509
|
+
const previous = this.currentSession;
|
|
510
|
+
this._currentSession = current;
|
|
511
|
+
this.onDidChangeActiveDebugSessionEmitter.fire({ previous, current });
|
|
512
|
+
if (current) {
|
|
513
|
+
this.disposeOnCurrentSessionChanged.push(current.onDidChange(() => {
|
|
514
|
+
if (this.currentFrame === this.topFrame) {
|
|
515
|
+
this.open();
|
|
516
|
+
}
|
|
517
|
+
this.fireDidChange(current);
|
|
518
|
+
}));
|
|
519
|
+
this.disposeOnCurrentSessionChanged.push(current.onDidFocusStackFrame(frame => this.onDidFocusStackFrameEmitter.fire(frame)));
|
|
520
|
+
this.disposeOnCurrentSessionChanged.push(current.onDidFocusThread(thread => this.onDidFocusThreadEmitter.fire(thread)));
|
|
521
|
+
const { currentThread } = current;
|
|
522
|
+
this.onDidFocusThreadEmitter.fire(currentThread);
|
|
523
|
+
}
|
|
524
|
+
this.updateBreakpoints(previous, current);
|
|
525
|
+
this.open();
|
|
526
|
+
this.fireDidChange(current);
|
|
527
|
+
}
|
|
528
|
+
open(): void {
|
|
529
|
+
const { currentFrame } = this;
|
|
530
|
+
if (currentFrame && currentFrame.thread.stopped) {
|
|
531
|
+
currentFrame.open();
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
protected updateBreakpoints(previous: DebugSession | undefined, current: DebugSession | undefined): void {
|
|
535
|
+
const affectedUri = new Set();
|
|
536
|
+
for (const session of [previous, current]) {
|
|
537
|
+
if (session) {
|
|
538
|
+
for (const uriString of session.breakpointUris) {
|
|
539
|
+
if (!affectedUri.has(uriString)) {
|
|
540
|
+
affectedUri.add(uriString);
|
|
541
|
+
this.fireDidChangeBreakpoints({
|
|
542
|
+
session: current,
|
|
543
|
+
uri: new URI(uriString)
|
|
544
|
+
});
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
protected updateCurrentSession(session: DebugSession | undefined): void {
|
|
551
|
+
this.currentSession = session || this.sessions[0];
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
get currentThread(): DebugThread | undefined {
|
|
555
|
+
const session = this.currentSession;
|
|
556
|
+
return session && session.currentThread;
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
get state(): DebugState {
|
|
560
|
+
const session = this.currentSession;
|
|
561
|
+
return session ? session.state : DebugState.Inactive;
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
get currentFrame(): DebugStackFrame | undefined {
|
|
565
|
+
const { currentThread } = this;
|
|
566
|
+
return currentThread && currentThread.currentFrame;
|
|
567
|
+
}
|
|
568
|
+
get topFrame(): DebugStackFrame | undefined {
|
|
569
|
+
const { currentThread } = this;
|
|
570
|
+
return currentThread && currentThread.topFrame;
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
getFunctionBreakpoints(session: DebugSession | undefined = this.currentSession): DebugFunctionBreakpoint[] {
|
|
574
|
+
if (session && session.state > DebugState.Initializing) {
|
|
575
|
+
return session.getFunctionBreakpoints();
|
|
576
|
+
}
|
|
577
|
+
const { labelProvider, breakpoints, editorManager } = this;
|
|
578
|
+
return this.breakpoints.getFunctionBreakpoints().map(origin => new DebugFunctionBreakpoint(origin, { labelProvider, breakpoints, editorManager }));
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
getInstructionBreakpoints(session = this.currentSession): DebugInstructionBreakpoint[] {
|
|
582
|
+
if (session && session.state > DebugState.Initializing) {
|
|
583
|
+
return session.getInstructionBreakpoints();
|
|
584
|
+
}
|
|
585
|
+
const { labelProvider, breakpoints, editorManager } = this;
|
|
586
|
+
return this.breakpoints.getInstructionBreakpoints().map(origin => new DebugInstructionBreakpoint(origin, { labelProvider, breakpoints, editorManager }));
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
getBreakpoints(session?: DebugSession): DebugSourceBreakpoint[];
|
|
590
|
+
getBreakpoints(uri: URI, session?: DebugSession): DebugSourceBreakpoint[];
|
|
591
|
+
getBreakpoints(arg?: URI | DebugSession, arg2?: DebugSession): DebugSourceBreakpoint[] {
|
|
592
|
+
const uri = arg instanceof URI ? arg : undefined;
|
|
593
|
+
const session = arg instanceof DebugSession ? arg : arg2 instanceof DebugSession ? arg2 : this.currentSession;
|
|
594
|
+
if (session && session.state > DebugState.Initializing) {
|
|
595
|
+
return session.getSourceBreakpoints(uri);
|
|
596
|
+
}
|
|
597
|
+
const { labelProvider, breakpoints, editorManager } = this;
|
|
598
|
+
return this.breakpoints.findMarkers({ uri }).map(({ data }) => new DebugSourceBreakpoint(data, { labelProvider, breakpoints, editorManager }));
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
getLineBreakpoints(uri: URI, line: number): DebugSourceBreakpoint[] {
|
|
602
|
+
const session = this.currentSession;
|
|
603
|
+
if (session && session.state > DebugState.Initializing) {
|
|
604
|
+
return session.getSourceBreakpoints(uri).filter(breakpoint => breakpoint.line === line);
|
|
605
|
+
}
|
|
606
|
+
const { labelProvider, breakpoints, editorManager } = this;
|
|
607
|
+
return this.breakpoints.getLineBreakpoints(uri, line).map(origin =>
|
|
608
|
+
new DebugSourceBreakpoint(origin, { labelProvider, breakpoints, editorManager })
|
|
609
|
+
);
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
getInlineBreakpoint(uri: URI, line: number, column: number): DebugSourceBreakpoint | undefined {
|
|
613
|
+
const session = this.currentSession;
|
|
614
|
+
if (session && session.state > DebugState.Initializing) {
|
|
615
|
+
return session.getSourceBreakpoints(uri).filter(breakpoint => breakpoint.line === line && breakpoint.column === column)[0];
|
|
616
|
+
}
|
|
617
|
+
const origin = this.breakpoints.getInlineBreakpoint(uri, line, column);
|
|
618
|
+
const { labelProvider, breakpoints, editorManager } = this;
|
|
619
|
+
return origin && new DebugSourceBreakpoint(origin, { labelProvider, breakpoints, editorManager });
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
/**
|
|
623
|
+
* Runs the given tasks.
|
|
624
|
+
* @param taskName the task name to run, see [TaskNameResolver](#TaskNameResolver)
|
|
625
|
+
* @return true if it allowed to continue debugging otherwise it returns false
|
|
626
|
+
*/
|
|
627
|
+
protected async runTask(workspaceFolderUri: string | undefined, taskName: string | TaskIdentifier | undefined, checkErrors?: boolean): Promise<boolean> {
|
|
628
|
+
if (!taskName) {
|
|
629
|
+
return true;
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
const taskInfo = await this.taskService.runWorkspaceTask(this.taskService.startUserAction(), workspaceFolderUri, taskName);
|
|
633
|
+
if (!checkErrors) {
|
|
634
|
+
return true;
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
if (!taskInfo) {
|
|
638
|
+
return this.doPostTaskAction(`Could not run the task '${taskName}'.`);
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
const getExitCodePromise: Promise<TaskEndedInfo> = this.taskService.getExitCode(taskInfo.taskId).then(result =>
|
|
642
|
+
({ taskEndedType: TaskEndedTypes.TaskExited, value: result }));
|
|
643
|
+
const isBackgroundTaskEndedPromise: Promise<TaskEndedInfo> = this.taskService.isBackgroundTaskEnded(taskInfo.taskId).then(result =>
|
|
644
|
+
({ taskEndedType: TaskEndedTypes.BackgroundTaskEnded, value: result }));
|
|
645
|
+
|
|
646
|
+
// After start running the task, we wait for the task process to exit and if it is a background task, we also wait for a feedback
|
|
647
|
+
// that a background task is active, as soon as one of the promises fulfills, we can continue and analyze the results.
|
|
648
|
+
const taskEndedInfo: TaskEndedInfo = await Promise.race([getExitCodePromise, isBackgroundTaskEndedPromise]);
|
|
649
|
+
|
|
650
|
+
if (taskEndedInfo.taskEndedType === TaskEndedTypes.BackgroundTaskEnded && taskEndedInfo.value) {
|
|
651
|
+
return true;
|
|
652
|
+
}
|
|
653
|
+
if (taskEndedInfo.taskEndedType === TaskEndedTypes.TaskExited && taskEndedInfo.value === 0) {
|
|
654
|
+
return true;
|
|
655
|
+
} else if (taskEndedInfo.taskEndedType === TaskEndedTypes.TaskExited && taskEndedInfo.value !== undefined) {
|
|
656
|
+
return this.doPostTaskAction(`Task '${taskName}' terminated with exit code ${taskEndedInfo.value}.`);
|
|
657
|
+
} else {
|
|
658
|
+
const signal = await this.taskService.getTerminateSignal(taskInfo.taskId);
|
|
659
|
+
if (signal !== undefined) {
|
|
660
|
+
return this.doPostTaskAction(`Task '${taskName}' terminated by signal ${signal}.`);
|
|
661
|
+
} else {
|
|
662
|
+
return this.doPostTaskAction(`Task '${taskName}' terminated for unknown reason.`);
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
protected async doPostTaskAction(errorMessage: string): Promise<boolean> {
|
|
668
|
+
const actions = ['Open launch.json', 'Cancel', 'Configure Task', 'Debug Anyway'];
|
|
669
|
+
const result = await this.messageService.error(errorMessage, ...actions);
|
|
670
|
+
switch (result) {
|
|
671
|
+
case actions[0]: // open launch.json
|
|
672
|
+
this.debugConfigurationManager.openConfiguration();
|
|
673
|
+
return false;
|
|
674
|
+
case actions[1]: // cancel
|
|
675
|
+
return false;
|
|
676
|
+
case actions[2]: // configure tasks
|
|
677
|
+
this.quickOpenTask.configure();
|
|
678
|
+
return false;
|
|
679
|
+
default: // continue debugging
|
|
680
|
+
return true;
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
}
|