debug.ts 13.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';
J
Johannes Rieken 已提交
7
import { TPromise } from 'vs/base/common/winjs.base';
8
import Event from 'vs/base/common/event';
E
Erich Gamma 已提交
9
import severity from 'vs/base/common/severity';
J
Johannes Rieken 已提交
10
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
E
Erich Gamma 已提交
11
import editor = require('vs/editor/common/editorCommon');
J
Johannes Rieken 已提交
12 13 14 15 16
import { Position } from 'vs/editor/common/core/position';
import { ISuggestion } from 'vs/editor/common/modes';
import { Source } from 'vs/workbench/parts/debug/common/debugSource';
import { Range } from 'vs/editor/common/core/range';
import { RawContextKey, ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
E
Erich Gamma 已提交
17

I
isidor 已提交
18 19 20
export const VIEWLET_ID = 'workbench.view.debug';
export const REPL_ID = 'workbench.panel.repl';
export const DEBUG_SERVICE_ID = 'debugService';
A
Alex Dima 已提交
21
export const CONTEXT_IN_DEBUG_MODE = new RawContextKey<boolean>('inDebugMode', false);
22 23 24
export const CONTEXT_NOT_IN_DEBUG_MODE: ContextKeyExpr = CONTEXT_IN_DEBUG_MODE.toNegated();
export const CONTEXT_IN_DEBUG_REPL = new RawContextKey<boolean>('inDebugRepl', false);
export const CONTEXT_NOT_IN_DEBUG_REPL: ContextKeyExpr = CONTEXT_IN_DEBUG_REPL.toNegated();
25 26
export const CONTEXT_ON_FIRST_DEBUG_REPL_LINE = new RawContextKey<boolean>('onFirsteDebugReplLine', false);
export const CONTEXT_ON_LAST_DEBUG_REPL_LINE = new RawContextKey<boolean>('onLastDebugReplLine', false);
I
isidor 已提交
27
export const EDITOR_CONTRIBUTION_ID = 'editor.contrib.debug';
I
isidor 已提交
28
export const DEBUG_SCHEME = 'debug';
E
Erich Gamma 已提交
29

I
isidor 已提交
30
// raw
E
Erich Gamma 已提交
31 32 33

export interface IRawModelUpdate {
	threadId: number;
I
isidor 已提交
34
	rawSession: ISession & ITreeElement;
E
Erich Gamma 已提交
35 36
	thread?: DebugProtocol.Thread;
	callStack?: DebugProtocol.StackFrame[];
I
isidor 已提交
37
	stoppedDetails?: IRawStoppedDetails;
38
	allThreadsStopped?: boolean;
I
isidor 已提交
39 40 41 42 43 44
}

export interface IRawStoppedDetails {
	reason: string;
	threadId?: number;
	text?: string;
I
isidor 已提交
45
	totalFrames?: number;
46
	framesErrorMessage?: string;
E
Erich Gamma 已提交
47 48
}

I
isidor 已提交
49
// model
E
Erich Gamma 已提交
50 51 52 53 54 55 56

export interface ITreeElement {
	getId(): string;
}

export interface IExpressionContainer extends ITreeElement {
	reference: number;
57
	stackFrame: IStackFrame;
E
Erich Gamma 已提交
58 59 60 61 62 63
	getChildren(debugService: IDebugService): TPromise<IExpression[]>;
}

export interface IExpression extends ITreeElement, IExpressionContainer {
	name: string;
	value: string;
64
	valueChanged: boolean;
65
	type?: string;
E
Erich Gamma 已提交
66 67
}

I
isidor 已提交
68
export interface ISession {
69 70 71 72
	stackTrace(args: DebugProtocol.StackTraceArguments): TPromise<DebugProtocol.StackTraceResponse>;
	scopes(args: DebugProtocol.ScopesArguments): TPromise<DebugProtocol.ScopesResponse>;
	variables(args: DebugProtocol.VariablesArguments): TPromise<DebugProtocol.VariablesResponse>;
	evaluate(args: DebugProtocol.EvaluateArguments): TPromise<DebugProtocol.EvaluateResponse>;
73 74 75 76 77

	configuration: { type: string, capabilities: DebugProtocol.Capabilities };
	disconnect(restart?: boolean, force?: boolean): TPromise<DebugProtocol.DisconnectResponse>;
	custom(request: string, args: any): TPromise<DebugProtocol.Response>;
	onDidEvent: Event<DebugProtocol.Event>;
I
isidor 已提交
78
	restartFrame(args: DebugProtocol.RestartFrameArguments): TPromise<DebugProtocol.RestartFrameResponse>;
79

80
	next(args: DebugProtocol.NextArguments): TPromise<DebugProtocol.NextResponse>;
81 82 83 84 85 86 87
	stepIn(args: DebugProtocol.StepInArguments): TPromise<DebugProtocol.StepInResponse>;
	stepOut(args: DebugProtocol.StepOutArguments): TPromise<DebugProtocol.StepOutResponse>;
	stepBack(args: DebugProtocol.StepBackArguments): TPromise<DebugProtocol.StepBackResponse>;
	continue(args: DebugProtocol.ContinueArguments): TPromise<DebugProtocol.ContinueResponse>;
	pause(args: DebugProtocol.PauseArguments): TPromise<DebugProtocol.PauseResponse>;
}

I
isidor 已提交
88
export interface IProcess extends ITreeElement {
I
isidor 已提交
89 90
	getThread(threadId: number): IThread;
	getAllThreads(): IThread[];
I
isidor 已提交
91
	session: ISession;
92 93
}

E
Erich Gamma 已提交
94
export interface IThread extends ITreeElement {
95 96

	/**
97
	 * Process the thread belongs to
98
	 */
99
	process: IProcess;
100

I
isidor 已提交
101 102 103
	/**
	 * Id of the thread generated by the debug adapter backend.
	 */
E
Erich Gamma 已提交
104
	threadId: number;
I
isidor 已提交
105 106 107 108

	/**
	 * Name of the thread.
	 */
E
Erich Gamma 已提交
109
	name: string;
I
isidor 已提交
110 111 112 113

	/**
	 * Information about the current thread stop event. Null if thread is not stopped.
	 */
I
isidor 已提交
114
	stoppedDetails: IRawStoppedDetails;
115 116 117 118 119

	/**
	 * 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 已提交
120 121
	 * Only gets the first 20 stack frames. Calling this method consecutive times
	 * with getAdditionalStackFrames = true gets the remainder of the call stack.
122
	 */
123
	getCallStack(getAdditionalStackFrames?: boolean): TPromise<IStackFrame[]>;
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140

	/**
	 * 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;
141 142 143 144 145 146 147

	next(): TPromise<any>;
	stepIn(): TPromise<any>;
	stepOut(): TPromise<any>;
	stepBack(): TPromise<any>;
	continue(): TPromise<any>;
	pause(): TPromise<any>;
E
Erich Gamma 已提交
148 149 150 151 152 153 154 155
}

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

export interface IStackFrame extends ITreeElement {
156
	thread: IThread;
E
Erich Gamma 已提交
157 158 159 160 161
	name: string;
	lineNumber: number;
	column: number;
	frameId: number;
	source: Source;
162
	getScopes(): TPromise<IScope[]>;
I
isidor 已提交
163
	restart(): TPromise<any>;
E
Erich Gamma 已提交
164 165 166 167 168 169
}

export interface IEnablement extends ITreeElement {
	enabled: boolean;
}

170 171 172
export interface IRawBreakpoint {
	uri: uri;
	lineNumber: number;
173
	enabled?: boolean;
174
	condition?: string;
175
	hitCondition?: string;
176 177
}

E
Erich Gamma 已提交
178 179 180 181
export interface IBreakpoint extends IEnablement {
	source: Source;
	lineNumber: number;
	desiredLineNumber: number;
I
isidor 已提交
182
	condition: string;
183
	hitCondition: string;
184
	verified: boolean;
185
	idFromAdapter: number;
I
isidor 已提交
186
	message: string;
E
Erich Gamma 已提交
187 188
}

I
isidor 已提交
189
export interface IFunctionBreakpoint extends IEnablement {
190
	name: string;
I
isidor 已提交
191
	verified: boolean;
192
	idFromAdapter: number;
193
	hitCondition: string;
I
isidor 已提交
194 195
}

E
Erich Gamma 已提交
196
export interface IExceptionBreakpoint extends IEnablement {
197 198
	filter: string;
	label: string;
E
Erich Gamma 已提交
199 200
}

I
isidor 已提交
201
// model interfaces
E
Erich Gamma 已提交
202

203
export interface IViewModel extends ITreeElement {
204
	/**
205
	 * Returns the active debug process or null if debug is inactive.
206
	 */
207 208 209
	focusedProcess: IProcess;
	focusedThread: IThread;
	focusedStackFrame: IStackFrame;
E
Erich Gamma 已提交
210
	getSelectedExpression(): IExpression;
I
isidor 已提交
211
	getSelectedFunctionBreakpoint(): IFunctionBreakpoint;
212
	setSelectedExpression(expression: IExpression);
I
isidor 已提交
213
	setSelectedFunctionBreakpoint(functionBreakpoint: IFunctionBreakpoint): void;
214 215 216 217

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

220
export interface IModel extends ITreeElement {
221
	getProcesses(): IProcess[];
E
Erich Gamma 已提交
222 223
	getBreakpoints(): IBreakpoint[];
	areBreakpointsActivated(): boolean;
I
isidor 已提交
224
	getFunctionBreakpoints(): IFunctionBreakpoint[];
E
Erich Gamma 已提交
225 226 227
	getExceptionBreakpoints(): IExceptionBreakpoint[];
	getWatchExpressions(): IExpression[];
	getReplElements(): ITreeElement[];
228 229 230 231

	onDidChangeBreakpoints: Event<void>;
	onDidChangeCallStack: Event<void>;
	onDidChangeWatchExpressions: Event<IExpression>;
232
	onDidChangeReplElements: Event<void>;
233
};
E
Erich Gamma 已提交
234

I
isidor 已提交
235
// service enums
E
Erich Gamma 已提交
236 237 238 239 240 241

export enum State {
	Disabled,
	Inactive,
	Initializing,
	Stopped,
I
isidor 已提交
242 243
	Running,
	RunningNoDebug
E
Erich Gamma 已提交
244 245
}

I
isidor 已提交
246 247 248 249
// Service config

export interface IDebugConfiguration {
	allowBreakpointsEverywhere: boolean;
I
isidor 已提交
250
	openExplorerOnEnd: boolean;
I
isidor 已提交
251 252
}

I
isidor 已提交
253
// service interfaces
E
Erich Gamma 已提交
254 255 256

export interface IGlobalConfig {
	version: string;
257
	debugServer?: number;
E
Erich Gamma 已提交
258 259 260
	configurations: IConfig[];
}

261
export interface IEnvConfig {
262
	name?: string;
E
Erich Gamma 已提交
263 264
	type: string;
	request: string;
265
	internalConsoleOptions?: string;
266 267
	preLaunchTask?: string;
	debugServer?: number;
I
isidor 已提交
268
	noDebug?: boolean;
269
	silentlyAbort?: boolean;
E
Erich Gamma 已提交
270 271
}

I
isidor 已提交
272 273 274 275 276 277
export interface IExtHostConfig extends IEnvConfig {
	port?: number;
	sourceMaps?: boolean;
	outDir?: string;
}

278 279 280 281 282 283
export interface IConfig extends IEnvConfig {
	windows?: IEnvConfig;
	osx?: IEnvConfig;
	linux?: IEnvConfig;
}

E
Erich Gamma 已提交
284
export interface IRawEnvAdapter {
I
isidor 已提交
285 286 287 288 289 290
	type?: string;
	label?: string;
	program?: string;
	args?: string[];
	runtime?: string;
	runtimeArgs?: string[];
E
Erich Gamma 已提交
291 292 293
}

export interface IRawAdapter extends IRawEnvAdapter {
I
isidor 已提交
294 295
	enableBreakpointsFor?: { languageIds: string[] };
	configurationAttributes?: any;
296
	initialConfigurations?: any[] | string;
297
	variables: { [key: string]: string };
I
isidor 已提交
298
	aiKey?: string;
I
isidor 已提交
299
	win?: IRawEnvAdapter;
I
isidor 已提交
300
	winx86?: IRawEnvAdapter;
301
	windows?: IRawEnvAdapter;
I
isidor 已提交
302 303
	osx?: IRawEnvAdapter;
	linux?: IRawEnvAdapter;
E
Erich Gamma 已提交
304 305
}

306 307 308 309
export interface IRawBreakpointContribution {
	language: string;
}

310
export interface IConfigurationManager {
311
	configuration: IConfig;
312 313 314 315 316 317 318 319
	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.
	 */
320
	onDidConfigurationChange: Event<IConfig>;
321 322
}

B
Benjamin Pasero 已提交
323
export const IDebugService = createDecorator<IDebugService>(DEBUG_SERVICE_ID);
E
Erich Gamma 已提交
324

325
export interface IDebugService {
326
	_serviceBrand: any;
327 328 329 330

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

333 334 335 336 337
	/**
	 * Allows to register on debug state changes.
	 */
	onDidChangeState: Event<State>;

338 339 340 341
	/**
	 * Gets the current configuration manager.
	 */
	getConfigurationManager(): IConfigurationManager;
E
Erich Gamma 已提交
342

I
isidor 已提交
343 344 345 346
	/**
	 * Sets the focused stack frame and evaluates all expresions against the newly focused stack frame,
	 */
	setFocusedStackFrameAndEvaluate(focusedStackFrame: IStackFrame): TPromise<void>;
E
Erich Gamma 已提交
347

348
	/**
349
	 * Adds new breakpoints to the model. Notifies debug adapter of breakpoint changes.
350
	 */
I
isidor 已提交
351
	addBreakpoints(rawBreakpoints: IRawBreakpoint[]): TPromise<void>;
352 353 354 355 356 357 358 359 360 361 362

	/**
	 * Enables or disables all breakpoints. If breakpoint is passed only enables or disables the passed breakpoint.
	 * Notifies debug adapter of breakpoint changes.
	 */
	enableOrDisableBreakpoints(enable: boolean, breakpoint?: IEnablement): TPromise<void>;

	/**
	 * Sets the global activated property for all breakpoints.
	 * Notifies debug adapter of breakpoint changes.
	 */
363
	setBreakpointsActivated(activated: boolean): TPromise<void>;
364 365 366 367 368

	/**
	 * Removes all breakpoints. If id is passed only removes the breakpoint associated with that id.
	 * Notifies debug adapter of breakpoint changes.
	 */
369
	removeBreakpoints(id?: string): TPromise<any>;
I
isidor 已提交
370

371
	/**
372
	 * Adds a new no name function breakpoint. The function breakpoint should be renamed once user enters the name.
373
	 */
I
isidor 已提交
374
	addFunctionBreakpoint(): void;
375 376 377 378 379

	/**
	 * Renames an already existing function breakpoint.
	 * Notifies debug adapter of breakpoint changes.
	 */
I
isidor 已提交
380
	renameFunctionBreakpoint(id: string, newFunctionName: string): TPromise<void>;
381 382 383 384 385

	/**
	 * Removes all function breakpoints. If id is passed only removes the function breakpoint with the passed id.
	 * Notifies debug adapter of breakpoint changes.
	 */
I
isidor 已提交
386
	removeFunctionBreakpoints(id?: string): TPromise<void>;
E
Erich Gamma 已提交
387

388
	/**
389
	 * Adds a new expression to the repl.
390
	 */
I
isidor 已提交
391
	addReplExpression(name: string): TPromise<void>;
392 393 394 395

	/**
	 * Removes all repl expressions.
	 */
396
	removeReplExpressions(): void;
397 398 399 400

	/**
	 * Adds a new log to the repl. Either a string value or a dictionary (used to inspect complex objects printed to the repl).
	 */
401
	logToRepl(value: string | { [key: string]: any }, severity?: severity): void;
402 403 404 405

	/**
	 * Appends new output to the repl.
	 */
E
Erich Gamma 已提交
406 407
	appendReplOutput(value: string, severity?: severity): void;

I
isidor 已提交
408 409 410 411 412
	/**
	 * Sets the value for the variable against the debug adapter.
	 */
	setVariable(variable: IExpression, value: string): TPromise<void>;

413
	/**
414
	 * Adds a new watch expression and evaluates it against the debug adapter.
415
	 */
I
isidor 已提交
416
	addWatchExpression(name?: string): TPromise<void>;
417 418 419 420

	/**
	 * Renames a watch expression and evaluates it against the debug adapter.
	 */
I
isidor 已提交
421
	renameWatchExpression(id: string, newName: string): TPromise<void>;
422 423 424 425

	/**
	 * Removes all watch expressions. If id is passed only removes the watch expression with the passed id.
	 */
426
	removeWatchExpressions(id?: string): void;
E
Erich Gamma 已提交
427

I
isidor 已提交
428 429 430
	/**
	 * Creates a new debug session. Depending on the configuration will either 'launch' or 'attach'.
	 */
431
	createSession(noDebug: boolean, configuration?: IConfig): TPromise<any>;
I
isidor 已提交
432 433 434 435

	/**
	 * Restarts an active debug session or creates a new one if there is no active session.
	 */
I
isidor 已提交
436
	restartSession(): TPromise<any>;
I
isidor 已提交
437 438 439 440

	/**
	 * Gets the current debug model.
	 */
E
Erich Gamma 已提交
441
	getModel(): IModel;
I
isidor 已提交
442 443 444 445

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

I
isidor 已提交
448 449 450
	/**
	 * Opens a new or reveals an already visible editor showing the source.
	 */
451
	openOrRevealSource(source: Source, lineNumber: number, preserveFocus: boolean, sideBySide: boolean): TPromise<any>;
452

I
isidor 已提交
453
	completions(text: string, position: Position): TPromise<ISuggestion[]>;
E
Erich Gamma 已提交
454 455
}

I
isidor 已提交
456 457
// Editor interfaces
export interface IDebugEditorContribution extends editor.IEditorContribution {
458
	showHover(range: Range, hoveringOver: string, focus: boolean): TPromise<void>;
I
isidor 已提交
459 460
}

I
isidor 已提交
461
// utils
E
Erich Gamma 已提交
462

I
isidor 已提交
463
const _formatPIIRegexp = /{([^}]+)}/g;
E
Erich Gamma 已提交
464

I
isidor 已提交
465 466
export function formatPII(value: string, excludePII: boolean, args: { [key: string]: string }): string {
	return value.replace(_formatPIIRegexp, function (match, group) {
E
Erich Gamma 已提交
467 468 469 470
		if (excludePII && group.length > 0 && group[0] !== '_') {
			return match;
		}

I
isidor 已提交
471
		return args && args.hasOwnProperty(group) ?
E
Erich Gamma 已提交
472 473
			args[group] :
			match;
I
isidor 已提交
474
	});
E
Erich Gamma 已提交
475
}