debug.ts 7.6 KB
Newer Older
E
Erich Gamma 已提交
1 2 3 4 5 6 7 8 9 10 11
/*---------------------------------------------------------------------------------------------
 *  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';
import { TPromise, Promise } from 'vs/base/common/winjs.base';
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 { Source } from 'vs/workbench/parts/debug/common/debugSource';
E
Erich Gamma 已提交
13 14 15 16 17

export var VIEWLET_ID = 'workbench.view.debug';
export var DEBUG_SERVICE_ID = 'debugService';
export var CONTEXT_IN_DEBUG_MODE = 'inDebugMode';

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

export interface IRawModelUpdate {
	threadId: number;
	thread?: DebugProtocol.Thread;
	callStack?: DebugProtocol.StackFrame[];
	exception?: boolean;
}

I
isidor 已提交
27
// model
E
Erich Gamma 已提交
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68

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

export interface IThread extends ITreeElement {
	threadId: number;
	name: string;
	callStack: IStackFrame[];
	exception: boolean;
}

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

69 70 71 72 73 74 75
export interface IRawBreakpoint {
	uri: uri;
	lineNumber: number;
	enabled: boolean;
	condition?: string;
}

E
Erich Gamma 已提交
76 77 78 79
export interface IBreakpoint extends IEnablement {
	source: Source;
	lineNumber: number;
	desiredLineNumber: number;
I
isidor 已提交
80
	condition: string;
81
	verified: boolean;
E
Erich Gamma 已提交
82 83
}

I
isidor 已提交
84
export interface IFunctionBreakpoint extends IEnablement {
85
	name: string;
I
isidor 已提交
86 87
}

E
Erich Gamma 已提交
88 89 90 91
export interface IExceptionBreakpoint extends IEnablement {
	name: string;
}

I
isidor 已提交
92
// events
E
Erich Gamma 已提交
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119

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',
	SELECTED_EXPRESSION_UPDATED: 'SelectedExpressionUpdated'
};

export var ServiceEvents = {
	STATE_CHANGED: 'StateChanged'
};

export var SessionEvents = {
	INITIALIZED: 'initialized',
	STOPPED: 'stopped',
	DEBUGEE_TERMINATED: 'terminated',
	SERVER_EXIT: 'exit',
	CONTINUED: 'continued',
	THREAD: 'thread',
	OUTPUT: 'output'
};

I
isidor 已提交
120
// model interfaces
E
Erich Gamma 已提交
121 122 123 124 125 126 127 128 129 130 131 132

export interface IViewModel extends ee.EventEmitter {
	getFocusedStackFrame(): IStackFrame;
	getSelectedExpression(): IExpression;
	getFocusedThreadId(): number;
	setSelectedExpression(expression: IExpression);
}

export interface IModel extends ee.IEventEmitter, ITreeElement {
	getThreads(): { [reference: number]: IThread; };
	getBreakpoints(): IBreakpoint[];
	areBreakpointsActivated(): boolean;
I
isidor 已提交
133
	getFunctionBreakpoints(): IFunctionBreakpoint[];
E
Erich Gamma 已提交
134 135 136 137 138
	getExceptionBreakpoints(): IExceptionBreakpoint[];
	getWatchExpressions(): IExpression[];
	getReplElements(): ITreeElement[];
}

I
isidor 已提交
139
// service enums
E
Erich Gamma 已提交
140 141 142 143 144 145 146 147 148

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

I
isidor 已提交
149
// service interfaces
E
Erich Gamma 已提交
150 151 152

export interface IGlobalConfig {
	version: string;
153
	debugServer?: number;
E
Erich Gamma 已提交
154 155 156 157
	configurations: IConfig[];
}

export interface IConfig {
158
	name?: string;
E
Erich Gamma 已提交
159 160
	type: string;
	request: string;
161 162 163 164 165 166 167 168 169 170 171 172 173 174
	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 已提交
175 176 177
}

export interface IRawEnvAdapter {
I
isidor 已提交
178 179 180 181 182 183
	type?: string;
	label?: string;
	program?: string;
	args?: string[];
	runtime?: string;
	runtimeArgs?: string[];
E
Erich Gamma 已提交
184 185 186
}

export interface IRawAdapter extends IRawEnvAdapter {
I
isidor 已提交
187 188 189 190
	enableBreakpointsFor?: { languageIds: string[] };
	configurationAttributes?: any;
	initialConfigurations?: any[];
	win?: IRawEnvAdapter;
191
	windows?: IRawEnvAdapter;
I
isidor 已提交
192 193
	osx?: IRawEnvAdapter;
	linux?: IRawEnvAdapter;
E
Erich Gamma 已提交
194 195 196
}

export interface IRawDebugSession extends ee.EventEmitter {
I
isidor 已提交
197
	getType(): string;
198
	isAttach: boolean;
199
	disconnect(restart?: boolean, force?: boolean): TPromise<DebugProtocol.DisconnectResponse>;
E
Erich Gamma 已提交
200

201
	next(args: DebugProtocol.NextArguments): TPromise<DebugProtocol.NextResponse>;
E
Erich Gamma 已提交
202 203 204 205 206 207
	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>;
208
	variables(args: DebugProtocol.VariablesArguments): TPromise<DebugProtocol.VariablesResponse>;
E
Erich Gamma 已提交
209 210 211 212 213 214 215 216 217 218
	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;
	canSetBreakpointsIn(model: editor.IModel, lineNumber: number): boolean;

219
	getConfigurationName(): string;
E
Erich Gamma 已提交
220
	setConfiguration(name: string): Promise;
221
	openConfigFile(sideBySide: boolean): TPromise<boolean>;
E
Erich Gamma 已提交
222 223 224 225
	loadLaunchConfig(): TPromise<IGlobalConfig>;

	setFocusedStackFrameAndEvaluate(focusedStackFrame: IStackFrame): void;

226 227
	setBreakpointsForModel(modelUri: uri, data: IRawBreakpoint[]): Promise;
	toggleBreakpoint(IRawBreakpoint): Promise;
E
Erich Gamma 已提交
228 229 230
	enableOrDisableAllBreakpoints(enabled: boolean): Promise;
	toggleEnablement(element: IEnablement): Promise;
	toggleBreakpointsActivated(): Promise;
231
	removeAllBreakpoints(): Promise;
E
Erich Gamma 已提交
232
	sendAllBreakpoints(): Promise;
233
	editBreakpoint(breakpoint?: IBreakpoint): Promise;
I
isidor 已提交
234

235
	addFunctionBreakpoint(functionName?: string): Promise;
I
isidor 已提交
236
	renameFunctionBreakpoint(id: string, newFunctionName: string): Promise;
237
	removeFunctionBreakpoints(id?: string): Promise;
E
Erich Gamma 已提交
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252

	addReplExpression(name: string): Promise;
	clearReplExpressions(): void;

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

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

	addWatchExpression(name?: string): Promise;
	renameWatchExpression(id: string, newName: string): Promise;
	clearWatchExpressions(id?: string): void;

	createSession(): Promise;
	restartSession(): Promise;
253
	rawAttach(port: number): Promise;
E
Erich Gamma 已提交
254 255 256 257 258 259 260 261 262
	getActiveSession(): IRawDebugSession;

	getModel(): IModel;
	getViewModel(): IViewModel;

	openOrRevealEditor(source: Source, lineNumber: number, preserveFocus: boolean, sideBySide: boolean): Promise;
	revealRepl(inBackground?:boolean): Promise;
}

I
isidor 已提交
263
// utils
E
Erich Gamma 已提交
264

I
isidor 已提交
265
const _formatPIIRegexp = /{([^}]+)}/g;
E
Erich Gamma 已提交
266 267 268 269 270 271 272 273 274 275 276 277

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