debug.ts 11.4 KB
Newer Older
E
Erich Gamma 已提交
1 2 3 4 5 6
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/

import uri from 'vs/base/common/uri';
I
isidor 已提交
7
import { TPromise } from 'vs/base/common/winjs.base';
8
import { IActionRunner } from 'vs/base/common/actions';
9
import Event from 'vs/base/common/event';
E
Erich Gamma 已提交
10 11
import ee = require('vs/base/common/eventEmitter');
import severity from 'vs/base/common/severity';
I
isidor 已提交
12
import { IViewletView } from 'vs/workbench/browser/viewlet';
E
Erich Gamma 已提交
13 14
import { createDecorator, ServiceIdentifier } from 'vs/platform/instantiation/common/instantiation';
import editor = require('vs/editor/common/editorCommon');
I
isidor 已提交
15
import { Source } from 'vs/workbench/parts/debug/common/debugSource';
E
Erich Gamma 已提交
16

I
isidor 已提交
17 18 19 20
export const VIEWLET_ID = 'workbench.view.debug';
export const REPL_ID = 'workbench.panel.repl';
export const DEBUG_SERVICE_ID = 'debugService';
export const CONTEXT_IN_DEBUG_MODE = 'inDebugMode';
I
isidor 已提交
21
export const EDITOR_CONTRIBUTION_ID = 'editor.contrib.debug';
E
Erich Gamma 已提交
22

I
isidor 已提交
23
// raw
E
Erich Gamma 已提交
24 25 26 27 28

export interface IRawModelUpdate {
	threadId: number;
	thread?: DebugProtocol.Thread;
	callStack?: DebugProtocol.StackFrame[];
I
isidor 已提交
29
	stoppedDetails?: IRawStoppedDetails;
30
	allThreadsStopped?: boolean;
I
isidor 已提交
31 32 33 34 35 36
}

export interface IRawStoppedDetails {
	reason: string;
	threadId?: number;
	text?: string;
I
isidor 已提交
37
	totalFrames?: number;
E
Erich Gamma 已提交
38 39
}

I
isidor 已提交
40
// model
E
Erich Gamma 已提交
41 42 43 44 45 46 47 48 49 50 51 52 53

export interface ITreeElement {
	getId(): string;
}

export interface IExpressionContainer extends ITreeElement {
	reference: number;
	getChildren(debugService: IDebugService): TPromise<IExpression[]>;
}

export interface IExpression extends ITreeElement, IExpressionContainer {
	name: string;
	value: string;
54
	valueChanged: boolean;
E
Erich Gamma 已提交
55 56 57
}

export interface IThread extends ITreeElement {
I
isidor 已提交
58 59 60
	/**
	 * Id of the thread generated by the debug adapter backend.
	 */
E
Erich Gamma 已提交
61
	threadId: number;
I
isidor 已提交
62 63 64 65

	/**
	 * Name of the thread.
	 */
E
Erich Gamma 已提交
66
	name: string;
I
isidor 已提交
67 68 69 70

	/**
	 * Information about the current thread stop event. Null if thread is not stopped.
	 */
I
isidor 已提交
71
	stoppedDetails: IRawStoppedDetails;
72 73 74 75 76

	/**
	 * Queries the debug adapter for the callstack and returns a promise with
	 * the stack frames of the callstack.
	 * If the thread is not stopped, it returns a promise to an empty array.
I
isidor 已提交
77 78
	 * Only gets the first 20 stack frames. Calling this method consecutive times
	 * with getAdditionalStackFrames = true gets the remainder of the call stack.
79
	 */
I
isidor 已提交
80
	getCallStack(debugService: IDebugService, getAdditionalStackFrames?: boolean): TPromise<IStackFrame[]>;
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97

	/**
	 * Gets the callstack if it has already been received from the debug
	 * adapter, otherwise it returns undefined.
	 */
	getCachedCallStack(): IStackFrame[];

	/**
	 * Invalidates the callstack cache
	 */
	clearCallStack(): void;

	/**
	 * Indicates whether this thread is stopped. The callstack for stopped
	 * threads can be retrieved from the debug adapter.
	 */
	stopped: boolean;
E
Erich Gamma 已提交
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
}

export interface IScope extends IExpressionContainer {
	name: string;
	expensive: boolean;
}

export interface IStackFrame extends ITreeElement {
	threadId: number;
	name: string;
	lineNumber: number;
	column: number;
	frameId: number;
	source: Source;
	getScopes(debugService: IDebugService): TPromise<IScope[]>;
}

export interface IEnablement extends ITreeElement {
	enabled: boolean;
}

119 120 121
export interface IRawBreakpoint {
	uri: uri;
	lineNumber: number;
122
	enabled?: boolean;
123 124 125
	condition?: string;
}

E
Erich Gamma 已提交
126 127 128 129
export interface IBreakpoint extends IEnablement {
	source: Source;
	lineNumber: number;
	desiredLineNumber: number;
I
isidor 已提交
130
	condition: string;
131
	verified: boolean;
132
	idFromAdapter: number;
I
isidor 已提交
133
	message: string;
E
Erich Gamma 已提交
134 135
}

I
isidor 已提交
136
export interface IFunctionBreakpoint extends IEnablement {
137
	name: string;
I
isidor 已提交
138
	verified: boolean;
139
	idFromAdapter: number;
I
isidor 已提交
140 141
}

E
Erich Gamma 已提交
142
export interface IExceptionBreakpoint extends IEnablement {
143 144
	filter: string;
	label: string;
E
Erich Gamma 已提交
145 146 147 148 149 150 151 152 153
}

export var SessionEvents = {
	INITIALIZED: 'initialized',
	STOPPED: 'stopped',
	DEBUGEE_TERMINATED: 'terminated',
	SERVER_EXIT: 'exit',
	CONTINUED: 'continued',
	THREAD: 'thread',
I
isidor 已提交
154 155
	OUTPUT: 'output',
	BREAKPOINT: 'breakpoint'
E
Erich Gamma 已提交
156 157
};

I
isidor 已提交
158
// model interfaces
E
Erich Gamma 已提交
159

160
export interface IViewModel extends ITreeElement {
E
Erich Gamma 已提交
161 162 163 164
	getFocusedStackFrame(): IStackFrame;
	getSelectedExpression(): IExpression;
	getFocusedThreadId(): number;
	setSelectedExpression(expression: IExpression);
I
isidor 已提交
165 166
	getSelectedFunctionBreakpoint(): IFunctionBreakpoint;
	setSelectedFunctionBreakpoint(functionBreakpoint: IFunctionBreakpoint): void;
167 168 169 170

	onDidFocusStackFrame: Event<IStackFrame>;
	onDidSelectExpression: Event<IExpression>;
	onDidSelectFunctionBreakpoint: Event<IFunctionBreakpoint>;
E
Erich Gamma 已提交
171 172
}

173
export interface IModel extends ITreeElement {
174
	getThreads(): { [threadId: number]: IThread; };
E
Erich Gamma 已提交
175 176
	getBreakpoints(): IBreakpoint[];
	areBreakpointsActivated(): boolean;
I
isidor 已提交
177
	getFunctionBreakpoints(): IFunctionBreakpoint[];
E
Erich Gamma 已提交
178 179 180
	getExceptionBreakpoints(): IExceptionBreakpoint[];
	getWatchExpressions(): IExpression[];
	getReplElements(): ITreeElement[];
181 182 183 184

	onDidChangeBreakpoints: Event<void>;
	onDidChangeCallStack: Event<void>;
	onDidChangeWatchExpressions: Event<IExpression>;
185
	onDidChangeReplElements: Event<void>;
186
};
E
Erich Gamma 已提交
187

I
isidor 已提交
188
// service enums
E
Erich Gamma 已提交
189 190 191 192 193 194

export enum State {
	Disabled,
	Inactive,
	Initializing,
	Stopped,
I
isidor 已提交
195 196
	Running,
	RunningNoDebug
E
Erich Gamma 已提交
197 198
}

I
isidor 已提交
199
// service interfaces
E
Erich Gamma 已提交
200 201 202

export interface IGlobalConfig {
	version: string;
203
	debugServer?: number;
E
Erich Gamma 已提交
204 205 206 207
	configurations: IConfig[];
}

export interface IConfig {
208
	name?: string;
E
Erich Gamma 已提交
209 210
	type: string;
	request: string;
211 212 213 214 215 216 217 218 219 220 221 222 223 224
	program?: string;
	stopOnEntry?: boolean;
	args?: string[];
	cwd?: string;
	runtimeExecutable?: string;
	runtimeArgs?: string[];
	env?: { [key: string]: string; };
	sourceMaps?: boolean;
	outDir?: string;
	address?: string;
	port?: number;
	preLaunchTask?: string;
	externalConsole?: boolean;
	debugServer?: number;
I
isidor 已提交
225
	noDebug?: boolean;
E
Erich Gamma 已提交
226 227 228
}

export interface IRawEnvAdapter {
I
isidor 已提交
229 230 231 232 233 234
	type?: string;
	label?: string;
	program?: string;
	args?: string[];
	runtime?: string;
	runtimeArgs?: string[];
E
Erich Gamma 已提交
235 236 237
}

export interface IRawAdapter extends IRawEnvAdapter {
I
isidor 已提交
238 239 240
	enableBreakpointsFor?: { languageIds: string[] };
	configurationAttributes?: any;
	initialConfigurations?: any[];
I
isidor 已提交
241
	aiKey?: string;
I
isidor 已提交
242
	win?: IRawEnvAdapter;
I
isidor 已提交
243
	winx86?: IRawEnvAdapter;
244
	windows?: IRawEnvAdapter;
I
isidor 已提交
245 246
	osx?: IRawEnvAdapter;
	linux?: IRawEnvAdapter;
E
Erich Gamma 已提交
247 248 249
}

export interface IRawDebugSession extends ee.EventEmitter {
I
isidor 已提交
250 251
	configuration: { type: string, isAttach: boolean, capabilities: DebugProtocol.Capabilites };

252
	disconnect(restart?: boolean, force?: boolean): TPromise<DebugProtocol.DisconnectResponse>;
E
Erich Gamma 已提交
253

254
	next(args: DebugProtocol.NextArguments): TPromise<DebugProtocol.NextResponse>;
E
Erich Gamma 已提交
255 256 257 258 259
	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>;

260
	stackTrace(args: DebugProtocol.StackTraceArguments): TPromise<DebugProtocol.StackTraceResponse>;
E
Erich Gamma 已提交
261
	scopes(args: DebugProtocol.ScopesArguments): TPromise<DebugProtocol.ScopesResponse>;
262
	variables(args: DebugProtocol.VariablesArguments): TPromise<DebugProtocol.VariablesResponse>;
E
Erich Gamma 已提交
263 264 265
	evaluate(args: DebugProtocol.EvaluateArguments): TPromise<DebugProtocol.EvaluateResponse>;
}

266 267 268 269 270 271 272 273 274 275 276 277 278
export interface IConfigurationManager {
	configurationName: string;
	setConfiguration(name: string): TPromise<void>;
	openConfigFile(sideBySide: boolean): TPromise<boolean>;
	loadLaunchConfig(): TPromise<IGlobalConfig>;
	canSetBreakpointsIn(model: editor.IModel): boolean;

	/**
	 * Allows to register on change of debug configuration.
	 */
	onDidConfigurationChange: Event<string>;
}

E
Erich Gamma 已提交
279 280
export var IDebugService = createDecorator<IDebugService>(DEBUG_SERVICE_ID);

281
export interface IDebugService {
E
Erich Gamma 已提交
282
	serviceId: ServiceIdentifier<any>;
283 284 285 286

	/**
	 * Gets the current debug state.
	 */
I
isidor 已提交
287
	state: State;
E
Erich Gamma 已提交
288

289 290 291 292 293
	/**
	 * Allows to register on debug state changes.
	 */
	onDidChangeState: Event<State>;

294 295 296 297
	/**
	 * Gets the current configuration manager.
	 */
	getConfigurationManager(): IConfigurationManager;
E
Erich Gamma 已提交
298

I
isidor 已提交
299 300 301 302
	/**
	 * Sets the focused stack frame and evaluates all expresions against the newly focused stack frame,
	 */
	setFocusedStackFrameAndEvaluate(focusedStackFrame: IStackFrame): TPromise<void>;
E
Erich Gamma 已提交
303

304
	/**
305
	 * General breakpoints manipulation.
306
	 */
307
	addBreakpoints(rawBreakpoints: IRawBreakpoint[]): TPromise<void[]>;
I
isidor 已提交
308 309
	enableOrDisableAllBreakpoints(enabled: boolean): TPromise<void>;
	toggleEnablement(element: IEnablement): TPromise<void>;
310
	setBreakpointsActivated(activated: boolean): TPromise<void>;
311
	removeBreakpoints(id?: string): TPromise<any>;
I
isidor 已提交
312

313 314 315
	/**
	 * Function breakpoints manipulation.
	 */
I
isidor 已提交
316
	addFunctionBreakpoint(): void;
I
isidor 已提交
317 318
	renameFunctionBreakpoint(id: string, newFunctionName: string): TPromise<void>;
	removeFunctionBreakpoints(id?: string): TPromise<void>;
E
Erich Gamma 已提交
319

320 321 322
	/**
	 * Repl expressions manipulation.
	 */
I
isidor 已提交
323
	addReplExpression(name: string): TPromise<void>;
324
	removeReplExpressions(): void;
325
	logToRepl(value: string | { [key: string]: any }, severity?: severity): void;
E
Erich Gamma 已提交
326 327
	appendReplOutput(value: string, severity?: severity): void;

328 329 330
	/**
	 * Watch expressions manipulation.
	 */
I
isidor 已提交
331 332
	addWatchExpression(name?: string): TPromise<void>;
	renameWatchExpression(id: string, newName: string): TPromise<void>;
333
	removeWatchExpressions(id?: string): void;
E
Erich Gamma 已提交
334

I
isidor 已提交
335 336 337
	/**
	 * Creates a new debug session. Depending on the configuration will either 'launch' or 'attach'.
	 */
I
isidor 已提交
338
	createSession(noDebug: boolean): TPromise<any>;
I
isidor 已提交
339 340 341 342

	/**
	 * Restarts an active debug session or creates a new one if there is no active session.
	 */
I
isidor 已提交
343
	restartSession(): TPromise<any>;
I
isidor 已提交
344 345 346 347

	/**
	 * Returns the active debug session or null if debug is inactive.
	 */
E
Erich Gamma 已提交
348 349
	getActiveSession(): IRawDebugSession;

I
isidor 已提交
350 351 352
	/**
	 * Gets the current debug model.
	 */
E
Erich Gamma 已提交
353
	getModel(): IModel;
I
isidor 已提交
354 355 356 357

	/**
	 * Gets the current view model.
	 */
E
Erich Gamma 已提交
358 359
	getViewModel(): IViewModel;

I
isidor 已提交
360 361 362
	/**
	 * Opens a new or reveals an already visible editor showing the source.
	 */
363
	openOrRevealSource(source: Source, lineNumber: number, preserveFocus: boolean, sideBySide: boolean): TPromise<any>;
E
Erich Gamma 已提交
364 365
}

I
isidor 已提交
366 367 368 369 370
// Editor interfaces
export interface IDebugEditorContribution extends editor.IEditorContribution {
	showHover(range: editor.IEditorRange, hoveringOver: string, focus: boolean): TPromise<void>;
}

371
// Debug view registration
372

373
export interface IDebugViewConstructorSignature {
I
isidor 已提交
374
	new (actionRunner: IActionRunner, viewletSetings: any, ...services: { serviceId: ServiceIdentifier<any>; }[]): IViewletView;
375 376 377
}

export interface IDebugViewRegistry {
378 379
	registerDebugView(view: IDebugViewConstructorSignature, order: number): void;
	getDebugViews(): IDebugViewConstructorSignature[];
380 381 382
}

class DebugViewRegistryImpl implements IDebugViewRegistry {
383
	private debugViews: { view: IDebugViewConstructorSignature, order: number }[];
384 385 386 387 388

	constructor() {
		this.debugViews = [];
	}

389 390
	public registerDebugView(view: IDebugViewConstructorSignature, order: number): void {
		this.debugViews.push({ view, order });
391 392
	}

393 394 395
	public getDebugViews(): IDebugViewConstructorSignature[] {
		return this.debugViews.sort((first, second) => first.order - second.order)
			.map(viewWithOrder => viewWithOrder.view);
396 397 398 399 400
	}
}

export var DebugViewRegistry = <IDebugViewRegistry>new DebugViewRegistryImpl();

I
isidor 已提交
401
// utils
E
Erich Gamma 已提交
402

I
isidor 已提交
403
const _formatPIIRegexp = /{([^}]+)}/g;
E
Erich Gamma 已提交
404 405 406 407 408 409 410

export function formatPII(value:string, excludePII: boolean, args: {[key: string]: string}): string {
	return value.replace(_formatPIIRegexp, function(match, group) {
		if (excludePII && group.length > 0 && group[0] !== '_') {
			return match;
		}

I
isidor 已提交
411
		return args && args.hasOwnProperty(group) ?
E
Erich Gamma 已提交
412 413
			args[group] :
			match;
I
isidor 已提交
414
	});
E
Erich Gamma 已提交
415
}