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

I
isidor 已提交
15 16 17 18
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 已提交
19
export const EDITOR_CONTRIBUTION_ID = 'editor.contrib.debug';
E
Erich Gamma 已提交
20

I
isidor 已提交
21
// raw
E
Erich Gamma 已提交
22 23 24 25 26

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

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

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

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;
52
	valueChanged: boolean;
E
Erich Gamma 已提交
53 54 55 56 57
}

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

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

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

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

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

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

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

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

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

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 已提交
145 146
	SELECTED_EXPRESSION_UPDATED: 'SelectedExpressionUpdated',
	SELECTED_FUNCTION_BREAKPOINT_UPDATED: 'SelectedFunctionBreakpointUpdated'
E
Erich Gamma 已提交
147 148 149
};

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

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

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

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

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

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

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

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

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

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

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

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

export interface IRawDebugSession extends ee.EventEmitter {
I
isidor 已提交
249
	getType(): string;
250
	isAttach: boolean;
251
	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 266 267 268 269 270
	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 已提交
271
	canSetBreakpointsIn(model: editor.IModel): boolean;
E
Erich Gamma 已提交
272

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

	setFocusedStackFrameAndEvaluate(focusedStackFrame: IStackFrame): void;

280 281 282 283
	/**
	 * Sets breakpoints for a model. Does not send them to the adapter.
	 */
	setBreakpointsForModel(modelUri: uri, rawData: IRawBreakpoint[]): void;
I
isidor 已提交
284 285 286 287 288 289 290
	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 已提交
291

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

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

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

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

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

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

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

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

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

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

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

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

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

I
isidor 已提交
349
// utils
E
Erich Gamma 已提交
350

I
isidor 已提交
351
const _formatPIIRegexp = /{([^}]+)}/g;
E
Erich Gamma 已提交
352 353 354 355 356 357 358

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 已提交
359
		return args && args.hasOwnProperty(group) ?
E
Erich Gamma 已提交
360 361
			args[group] :
			match;
I
isidor 已提交
362
	});
E
Erich Gamma 已提交
363
}