debug.ts 11.3 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';
E
Erich Gamma 已提交
9 10
import ee = require('vs/base/common/eventEmitter');
import severity from 'vs/base/common/severity';
I
isidor 已提交
11
import { IViewletView } from 'vs/workbench/browser/viewlet';
E
Erich Gamma 已提交
12 13
import { createDecorator, ServiceIdentifier } from 'vs/platform/instantiation/common/instantiation';
import editor = require('vs/editor/common/editorCommon');
I
isidor 已提交
14
import editorbrowser = require('vs/editor/browser/editorBrowser');
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 58 59
}

export interface IThread extends ITreeElement {
	threadId: number;
	name: string;
I
isidor 已提交
60
	stoppedDetails: IRawStoppedDetails;
61 62 63 64 65

	/**
	 * 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 已提交
66 67
	 * Only gets the first 20 stack frames. Calling this method consecutive times
	 * with getAdditionalStackFrames = true gets the remainder of the call stack.
68
	 */
I
isidor 已提交
69
	getCallStack(debugService: IDebugService, getAdditionalStackFrames?: boolean): TPromise<IStackFrame[]>;
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86

	/**
	 * 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 已提交
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
}

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;
}

108 109 110 111 112 113 114
export interface IRawBreakpoint {
	uri: uri;
	lineNumber: number;
	enabled: boolean;
	condition?: string;
}

E
Erich Gamma 已提交
115 116 117 118
export interface IBreakpoint extends IEnablement {
	source: Source;
	lineNumber: number;
	desiredLineNumber: number;
I
isidor 已提交
119
	condition: string;
120
	verified: boolean;
121
	idFromAdapter: number;
I
isidor 已提交
122
	message: string;
E
Erich Gamma 已提交
123 124
}

I
isidor 已提交
125
export interface IFunctionBreakpoint extends IEnablement {
126
	name: string;
I
isidor 已提交
127
	verified: boolean;
128
	idFromAdapter: number;
I
isidor 已提交
129 130
}

E
Erich Gamma 已提交
131
export interface IExceptionBreakpoint extends IEnablement {
132 133
	filter: string;
	label: string;
E
Erich Gamma 已提交
134 135
}

I
isidor 已提交
136
// events
E
Erich Gamma 已提交
137 138 139 140 141 142 143 144 145 146

export var ModelEvents = {
	BREAKPOINTS_UPDATED: 'BreakpointsUpdated',
	CALLSTACK_UPDATED: 'CallStackUpdated',
	WATCH_EXPRESSIONS_UPDATED: 'WatchExpressionsUpdated',
	REPL_ELEMENTS_UPDATED: 'ReplElementsUpdated'
};

export var ViewModelEvents = {
	FOCUSED_STACK_FRAME_UPDATED: 'FocusedStackFrameUpdated',
I
isidor 已提交
147 148
	SELECTED_EXPRESSION_UPDATED: 'SelectedExpressionUpdated',
	SELECTED_FUNCTION_BREAKPOINT_UPDATED: 'SelectedFunctionBreakpointUpdated'
E
Erich Gamma 已提交
149 150 151
};

export var ServiceEvents = {
152
	STATE_CHANGED: 'StateChanged',
153 154
	TYPE_NOT_SUPPORTED: 'TypeNotSupported',
	CONFIGURATION_CHANGED: 'ConfigurationChanged'
E
Erich Gamma 已提交
155 156 157 158 159 160 161 162 163
};

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

I
isidor 已提交
168
// model interfaces
E
Erich Gamma 已提交
169 170 171 172 173 174

export interface IViewModel extends ee.EventEmitter {
	getFocusedStackFrame(): IStackFrame;
	getSelectedExpression(): IExpression;
	getFocusedThreadId(): number;
	setSelectedExpression(expression: IExpression);
I
isidor 已提交
175 176
	getSelectedFunctionBreakpoint(): IFunctionBreakpoint;
	setSelectedFunctionBreakpoint(functionBreakpoint: IFunctionBreakpoint): void;
E
Erich Gamma 已提交
177 178 179
}

export interface IModel extends ee.IEventEmitter, ITreeElement {
180
	getThreads(): { [threadId: number]: IThread; };
E
Erich Gamma 已提交
181 182
	getBreakpoints(): IBreakpoint[];
	areBreakpointsActivated(): boolean;
I
isidor 已提交
183
	getFunctionBreakpoints(): IFunctionBreakpoint[];
E
Erich Gamma 已提交
184 185 186 187 188
	getExceptionBreakpoints(): IExceptionBreakpoint[];
	getWatchExpressions(): IExpression[];
	getReplElements(): ITreeElement[];
}

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

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

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

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

export interface IConfig {
209
	name?: string;
E
Erich Gamma 已提交
210 211
	type: string;
	request: string;
212 213 214 215 216 217 218 219 220 221 222 223 224 225
	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 已提交
226
	noDebug?: boolean;
E
Erich Gamma 已提交
227 228 229
}

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

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

export interface IRawDebugSession extends ee.EventEmitter {
I
isidor 已提交
251
	getType(): string;
252
	isAttach: boolean;
253
	capabilities: DebugProtocol.Capabilites;
254
	disconnect(restart?: boolean, force?: boolean): TPromise<DebugProtocol.DisconnectResponse>;
E
Erich Gamma 已提交
255

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

262
	stackTrace(args: DebugProtocol.StackTraceArguments): TPromise<DebugProtocol.StackTraceResponse>;
E
Erich Gamma 已提交
263
	scopes(args: DebugProtocol.ScopesArguments): TPromise<DebugProtocol.ScopesResponse>;
264
	variables(args: DebugProtocol.VariablesArguments): TPromise<DebugProtocol.VariablesResponse>;
E
Erich Gamma 已提交
265 266 267 268 269 270 271 272
	evaluate(args: DebugProtocol.EvaluateArguments): TPromise<DebugProtocol.EvaluateResponse>;
}

export var IDebugService = createDecorator<IDebugService>(DEBUG_SERVICE_ID);

export interface IDebugService extends ee.IEventEmitter {
	serviceId: ServiceIdentifier<any>;
	getState(): State;
I
isidor 已提交
273
	canSetBreakpointsIn(model: editor.IModel): boolean;
E
Erich Gamma 已提交
274

275
	getConfigurationName(): string;
I
isidor 已提交
276
	setConfiguration(name: string): TPromise<void>;
277
	openConfigFile(sideBySide: boolean): TPromise<boolean>;
E
Erich Gamma 已提交
278 279 280 281
	loadLaunchConfig(): TPromise<IGlobalConfig>;

	setFocusedStackFrameAndEvaluate(focusedStackFrame: IStackFrame): void;

282 283 284 285
	/**
	 * Sets breakpoints for a model. Does not send them to the adapter.
	 */
	setBreakpointsForModel(modelUri: uri, rawData: IRawBreakpoint[]): void;
I
isidor 已提交
286 287 288 289 290 291 292
	toggleBreakpoint(IRawBreakpoint): TPromise<void>;
	enableOrDisableAllBreakpoints(enabled: boolean): TPromise<void>;
	toggleEnablement(element: IEnablement): TPromise<void>;
	toggleBreakpointsActivated(): TPromise<void>;
	removeAllBreakpoints(): TPromise<any>;
	sendAllBreakpoints(): TPromise<any>;
	editBreakpoint(editor: editorbrowser.ICodeEditor, lineNumber: number): TPromise<void>;
I
isidor 已提交
293

I
isidor 已提交
294
	addFunctionBreakpoint(): void;
I
isidor 已提交
295 296
	renameFunctionBreakpoint(id: string, newFunctionName: string): TPromise<void>;
	removeFunctionBreakpoints(id?: string): TPromise<void>;
E
Erich Gamma 已提交
297

I
isidor 已提交
298
	addReplExpression(name: string): TPromise<void>;
E
Erich Gamma 已提交
299 300 301 302 303 304 305
	clearReplExpressions(): void;

	logToRepl(value: string, severity?: severity): void;
	logToRepl(value: { [key: string]: any }, severity?: severity): void;

	appendReplOutput(value: string, severity?: severity): void;

I
isidor 已提交
306 307
	addWatchExpression(name?: string): TPromise<void>;
	renameWatchExpression(id: string, newName: string): TPromise<void>;
E
Erich Gamma 已提交
308 309
	clearWatchExpressions(id?: string): void;

I
isidor 已提交
310 311 312
	/**
	 * Creates a new debug session. Depending on the configuration will either 'launch' or 'attach'.
	 */
I
isidor 已提交
313
	createSession(noDebug: boolean): TPromise<any>;
I
isidor 已提交
314 315 316 317

	/**
	 * Restarts an active debug session or creates a new one if there is no active session.
	 */
I
isidor 已提交
318
	restartSession(): TPromise<any>;
I
isidor 已提交
319 320 321 322

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

I
isidor 已提交
325 326 327
	/**
	 * Gets the current debug model.
	 */
E
Erich Gamma 已提交
328
	getModel(): IModel;
I
isidor 已提交
329 330 331 332

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

I
isidor 已提交
335 336 337
	/**
	 * Opens a new or reveals an already visible editor showing the source.
	 */
I
isidor 已提交
338
	openOrRevealEditor(source: Source, lineNumber: number, preserveFocus: boolean, sideBySide: boolean): TPromise<any>;
I
isidor 已提交
339 340 341 342

	/**
	 * Reveals the repl.
	 */
343
	revealRepl(focus?: boolean): TPromise<void>;
E
Erich Gamma 已提交
344 345
}

I
isidor 已提交
346 347 348 349 350
// Editor interfaces
export interface IDebugEditorContribution extends editor.IEditorContribution {
	showHover(range: editor.IEditorRange, hoveringOver: string, focus: boolean): TPromise<void>;
}

351
// Debug view registration
352

353
export interface IDebugViewConstructorSignature {
I
isidor 已提交
354
	new (actionRunner: IActionRunner, viewletSetings: any, ...services: { serviceId: ServiceIdentifier<any>; }[]): IViewletView;
355 356 357
}

export interface IDebugViewRegistry {
358 359
	registerDebugView(view: IDebugViewConstructorSignature, order: number): void;
	getDebugViews(): IDebugViewConstructorSignature[];
360 361 362
}

class DebugViewRegistryImpl implements IDebugViewRegistry {
363
	private debugViews: { view: IDebugViewConstructorSignature, order: number }[];
364 365 366 367 368

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

369 370
	public registerDebugView(view: IDebugViewConstructorSignature, order: number): void {
		this.debugViews.push({ view, order });
371 372
	}

373 374 375
	public getDebugViews(): IDebugViewConstructorSignature[] {
		return this.debugViews.sort((first, second) => first.order - second.order)
			.map(viewWithOrder => viewWithOrder.view);
376 377 378 379 380
	}
}

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

I
isidor 已提交
381
// utils
E
Erich Gamma 已提交
382

I
isidor 已提交
383
const _formatPIIRegexp = /{([^}]+)}/g;
E
Erich Gamma 已提交
384 385 386 387 388 389 390

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 已提交
391
		return args && args.hasOwnProperty(group) ?
E
Erich Gamma 已提交
392 393
			args[group] :
			match;
I
isidor 已提交
394
	});
E
Erich Gamma 已提交
395
}