debug.ts 8.8 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';
E
Erich Gamma 已提交
19

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

export interface IRawModelUpdate {
	threadId: number;
	thread?: DebugProtocol.Thread;
	callStack?: DebugProtocol.StackFrame[];
I
isidor 已提交
26
	stoppedReason?: string;
E
Erich Gamma 已提交
27 28
}

I
isidor 已提交
29
// model
E
Erich Gamma 已提交
30 31 32 33 34 35 36 37 38 39 40 41 42

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;
43
	valueChanged: boolean;
E
Erich Gamma 已提交
44 45 46 47 48 49
}

export interface IThread extends ITreeElement {
	threadId: number;
	name: string;
	callStack: IStackFrame[];
I
isidor 已提交
50
	stoppedReason: string;
E
Erich Gamma 已提交
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
}

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

72 73 74 75 76 77 78
export interface IRawBreakpoint {
	uri: uri;
	lineNumber: number;
	enabled: boolean;
	condition?: string;
}

E
Erich Gamma 已提交
79 80 81 82
export interface IBreakpoint extends IEnablement {
	source: Source;
	lineNumber: number;
	desiredLineNumber: number;
I
isidor 已提交
83
	condition: string;
84
	verified: boolean;
85
	idFromAdapter: number;
I
isidor 已提交
86
	message: string;
E
Erich Gamma 已提交
87 88
}

I
isidor 已提交
89
export interface IFunctionBreakpoint extends IEnablement {
90
	name: string;
I
isidor 已提交
91
	verified: boolean;
92
	idFromAdapter: number;
I
isidor 已提交
93 94
}

E
Erich Gamma 已提交
95
export interface IExceptionBreakpoint extends IEnablement {
96 97
	filter: string;
	label: string;
E
Erich Gamma 已提交
98 99
}

I
isidor 已提交
100
// events
E
Erich Gamma 已提交
101 102 103 104 105 106 107 108 109 110

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 已提交
111 112
	SELECTED_EXPRESSION_UPDATED: 'SelectedExpressionUpdated',
	SELECTED_FUNCTION_BREAKPOINT_UPDATED: 'SelectedFunctionBreakpointUpdated'
E
Erich Gamma 已提交
113 114 115
};

export var ServiceEvents = {
116 117
	STATE_CHANGED: 'StateChanged',
	TYPE_NOT_SUPPORTED: 'TypeNotSupported'
E
Erich Gamma 已提交
118 119 120 121 122 123 124 125 126
};

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

I
isidor 已提交
131
// model interfaces
E
Erich Gamma 已提交
132 133 134 135 136 137

export interface IViewModel extends ee.EventEmitter {
	getFocusedStackFrame(): IStackFrame;
	getSelectedExpression(): IExpression;
	getFocusedThreadId(): number;
	setSelectedExpression(expression: IExpression);
I
isidor 已提交
138 139
	getSelectedFunctionBreakpoint(): IFunctionBreakpoint;
	setSelectedFunctionBreakpoint(functionBreakpoint: IFunctionBreakpoint): void;
E
Erich Gamma 已提交
140 141 142
}

export interface IModel extends ee.IEventEmitter, ITreeElement {
143
	getThreads(): { [threadId: number]: IThread; };
E
Erich Gamma 已提交
144 145
	getBreakpoints(): IBreakpoint[];
	areBreakpointsActivated(): boolean;
I
isidor 已提交
146
	getFunctionBreakpoints(): IFunctionBreakpoint[];
E
Erich Gamma 已提交
147 148 149 150 151
	getExceptionBreakpoints(): IExceptionBreakpoint[];
	getWatchExpressions(): IExpression[];
	getReplElements(): ITreeElement[];
}

I
isidor 已提交
152
// service enums
E
Erich Gamma 已提交
153 154 155 156 157 158 159 160 161

export enum State {
	Disabled,
	Inactive,
	Initializing,
	Stopped,
	Running
}

I
isidor 已提交
162
// service interfaces
E
Erich Gamma 已提交
163 164 165

export interface IGlobalConfig {
	version: string;
166
	debugServer?: number;
E
Erich Gamma 已提交
167 168 169 170
	configurations: IConfig[];
}

export interface IConfig {
171
	name?: string;
E
Erich Gamma 已提交
172 173
	type: string;
	request: string;
174 175 176 177 178 179 180 181 182 183 184 185 186 187
	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;
E
Erich Gamma 已提交
188 189 190
}

export interface IRawEnvAdapter {
I
isidor 已提交
191 192 193 194 195 196
	type?: string;
	label?: string;
	program?: string;
	args?: string[];
	runtime?: string;
	runtimeArgs?: string[];
E
Erich Gamma 已提交
197 198 199
}

export interface IRawAdapter extends IRawEnvAdapter {
I
isidor 已提交
200 201 202
	enableBreakpointsFor?: { languageIds: string[] };
	configurationAttributes?: any;
	initialConfigurations?: any[];
I
isidor 已提交
203
	aiKey?: string;
I
isidor 已提交
204
	win?: IRawEnvAdapter;
I
isidor 已提交
205
	winx86?: IRawEnvAdapter;
206
	windows?: IRawEnvAdapter;
I
isidor 已提交
207 208
	osx?: IRawEnvAdapter;
	linux?: IRawEnvAdapter;
E
Erich Gamma 已提交
209 210 211
}

export interface IRawDebugSession extends ee.EventEmitter {
I
isidor 已提交
212
	getType(): string;
213
	isAttach: boolean;
214
	capabilities: DebugProtocol.Capabilites;
215
	disconnect(restart?: boolean, force?: boolean): TPromise<DebugProtocol.DisconnectResponse>;
E
Erich Gamma 已提交
216

217
	next(args: DebugProtocol.NextArguments): TPromise<DebugProtocol.NextResponse>;
E
Erich Gamma 已提交
218 219 220 221 222 223
	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>;

	scopes(args: DebugProtocol.ScopesArguments): TPromise<DebugProtocol.ScopesResponse>;
224
	variables(args: DebugProtocol.VariablesArguments): TPromise<DebugProtocol.VariablesResponse>;
E
Erich Gamma 已提交
225 226 227 228 229 230 231 232
	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 已提交
233
	canSetBreakpointsIn(model: editor.IModel): boolean;
E
Erich Gamma 已提交
234

235
	getConfigurationName(): string;
I
isidor 已提交
236
	setConfiguration(name: string): TPromise<void>;
237
	openConfigFile(sideBySide: boolean): TPromise<boolean>;
E
Erich Gamma 已提交
238 239 240 241
	loadLaunchConfig(): TPromise<IGlobalConfig>;

	setFocusedStackFrameAndEvaluate(focusedStackFrame: IStackFrame): void;

242 243 244 245
	/**
	 * Sets breakpoints for a model. Does not send them to the adapter.
	 */
	setBreakpointsForModel(modelUri: uri, rawData: IRawBreakpoint[]): void;
I
isidor 已提交
246 247 248 249 250 251 252
	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 已提交
253

I
isidor 已提交
254
	addFunctionBreakpoint(): void;
I
isidor 已提交
255 256
	renameFunctionBreakpoint(id: string, newFunctionName: string): TPromise<void>;
	removeFunctionBreakpoints(id?: string): TPromise<void>;
E
Erich Gamma 已提交
257

I
isidor 已提交
258
	addReplExpression(name: string): TPromise<void>;
E
Erich Gamma 已提交
259 260 261 262 263 264 265
	clearReplExpressions(): void;

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

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

I
isidor 已提交
266 267
	addWatchExpression(name?: string): TPromise<void>;
	renameWatchExpression(id: string, newName: string): TPromise<void>;
E
Erich Gamma 已提交
268 269
	clearWatchExpressions(id?: string): void;

I
isidor 已提交
270 271 272
	/**
	 * Creates a new debug session. Depending on the configuration will either 'launch' or 'attach'.
	 */
I
isidor 已提交
273
	createSession(): TPromise<any>;
I
isidor 已提交
274 275 276 277

	/**
	 * Restarts an active debug session or creates a new one if there is no active session.
	 */
I
isidor 已提交
278
	restartSession(): TPromise<any>;
I
isidor 已提交
279 280 281 282

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

I
isidor 已提交
285 286 287
	/**
	 * Gets the current debug model.
	 */
E
Erich Gamma 已提交
288
	getModel(): IModel;
I
isidor 已提交
289 290 291 292

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

I
isidor 已提交
295 296 297
	/**
	 * Opens a new or reveals an already visible editor showing the source.
	 */
I
isidor 已提交
298
	openOrRevealEditor(source: Source, lineNumber: number, preserveFocus: boolean, sideBySide: boolean): TPromise<any>;
I
isidor 已提交
299 300 301 302

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

I
isidor 已提交
306
// utils
E
Erich Gamma 已提交
307

I
isidor 已提交
308
const _formatPIIRegexp = /{([^}]+)}/g;
E
Erich Gamma 已提交
309 310 311 312 313 314 315 316 317 318

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

		return args.hasOwnProperty(group) ?
			args[group] :
			match;
I
isidor 已提交
319
	});
E
Erich Gamma 已提交
320
}