debug.ts 13.7 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
	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 已提交
86 87

	completions(args: DebugProtocol.CompletionsArguments): TPromise<DebugProtocol.CompletionsResponse>;
88
	setVariable(args: DebugProtocol.SetVariableArguments): TPromise<DebugProtocol.SetVariableResponse>;
89
	source(args: DebugProtocol.SourceArguments): TPromise<DebugProtocol.SourceResponse>;
90 91
}

I
isidor 已提交
92
export interface IProcess extends ITreeElement {
I
isidor 已提交
93 94
	getThread(threadId: number): IThread;
	getAllThreads(): IThread[];
I
isidor 已提交
95
	session: ISession;
96 97
}

E
Erich Gamma 已提交
98
export interface IThread extends ITreeElement {
99 100

	/**
101
	 * Process the thread belongs to
102
	 */
103
	process: IProcess;
104

I
isidor 已提交
105 106 107
	/**
	 * Id of the thread generated by the debug adapter backend.
	 */
E
Erich Gamma 已提交
108
	threadId: number;
I
isidor 已提交
109 110 111 112

	/**
	 * Name of the thread.
	 */
E
Erich Gamma 已提交
113
	name: string;
I
isidor 已提交
114 115 116 117

	/**
	 * Information about the current thread stop event. Null if thread is not stopped.
	 */
I
isidor 已提交
118
	stoppedDetails: IRawStoppedDetails;
119 120 121 122 123

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

	/**
	 * 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;
145 146 147 148 149 150 151

	next(): TPromise<any>;
	stepIn(): TPromise<any>;
	stepOut(): TPromise<any>;
	stepBack(): TPromise<any>;
	continue(): TPromise<any>;
	pause(): TPromise<any>;
E
Erich Gamma 已提交
152 153 154 155 156 157 158 159
}

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

export interface IStackFrame extends ITreeElement {
160
	thread: IThread;
E
Erich Gamma 已提交
161 162 163 164 165
	name: string;
	lineNumber: number;
	column: number;
	frameId: number;
	source: Source;
166
	getScopes(): TPromise<IScope[]>;
I
isidor 已提交
167
	restart(): TPromise<any>;
I
isidor 已提交
168
	completions(text: string, position: Position): TPromise<ISuggestion[]>;
E
Erich Gamma 已提交
169 170 171 172 173 174
}

export interface IEnablement extends ITreeElement {
	enabled: boolean;
}

175 176 177
export interface IRawBreakpoint {
	uri: uri;
	lineNumber: number;
178
	enabled?: boolean;
179
	condition?: string;
180
	hitCondition?: string;
181 182
}

E
Erich Gamma 已提交
183 184 185 186
export interface IBreakpoint extends IEnablement {
	source: Source;
	lineNumber: number;
	desiredLineNumber: number;
I
isidor 已提交
187
	condition: string;
188
	hitCondition: string;
189
	verified: boolean;
190
	idFromAdapter: number;
I
isidor 已提交
191
	message: string;
E
Erich Gamma 已提交
192 193
}

I
isidor 已提交
194
export interface IFunctionBreakpoint extends IEnablement {
195
	name: string;
I
isidor 已提交
196
	verified: boolean;
197
	idFromAdapter: number;
198
	hitCondition: string;
I
isidor 已提交
199 200
}

E
Erich Gamma 已提交
201
export interface IExceptionBreakpoint extends IEnablement {
202 203
	filter: string;
	label: string;
E
Erich Gamma 已提交
204 205
}

I
isidor 已提交
206
// model interfaces
E
Erich Gamma 已提交
207

208
export interface IViewModel extends ITreeElement {
209
	/**
210
	 * Returns the focused debug process or null if there are no processes.
211
	 */
212
	focusedProcess: IProcess;
213 214 215 216

	/**
	 * Returns the focused thread or null if there are no threads.
	 */
217
	focusedThread: IThread;
218 219 220 221

	/**
	 * Returns the focused stack frame or null if there are no stack frames (debug inactive).
	 */
222
	focusedStackFrame: IStackFrame;
E
Erich Gamma 已提交
223
	getSelectedExpression(): IExpression;
I
isidor 已提交
224
	getSelectedFunctionBreakpoint(): IFunctionBreakpoint;
225
	setSelectedExpression(expression: IExpression);
I
isidor 已提交
226
	setSelectedFunctionBreakpoint(functionBreakpoint: IFunctionBreakpoint): void;
227 228 229 230

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

233
export interface IModel extends ITreeElement {
234
	getProcesses(): IProcess[];
E
Erich Gamma 已提交
235 236
	getBreakpoints(): IBreakpoint[];
	areBreakpointsActivated(): boolean;
I
isidor 已提交
237
	getFunctionBreakpoints(): IFunctionBreakpoint[];
E
Erich Gamma 已提交
238 239 240
	getExceptionBreakpoints(): IExceptionBreakpoint[];
	getWatchExpressions(): IExpression[];
	getReplElements(): ITreeElement[];
241 242 243 244

	onDidChangeBreakpoints: Event<void>;
	onDidChangeCallStack: Event<void>;
	onDidChangeWatchExpressions: Event<IExpression>;
245
	onDidChangeReplElements: Event<void>;
246
};
E
Erich Gamma 已提交
247

I
isidor 已提交
248
// service enums
E
Erich Gamma 已提交
249 250 251 252 253 254

export enum State {
	Disabled,
	Inactive,
	Initializing,
	Stopped,
I
isidor 已提交
255 256
	Running,
	RunningNoDebug
E
Erich Gamma 已提交
257 258
}

I
isidor 已提交
259 260 261 262
// Service config

export interface IDebugConfiguration {
	allowBreakpointsEverywhere: boolean;
I
isidor 已提交
263
	openExplorerOnEnd: boolean;
I
isidor 已提交
264 265
}

I
isidor 已提交
266
// service interfaces
E
Erich Gamma 已提交
267 268 269

export interface IGlobalConfig {
	version: string;
270
	debugServer?: number;
E
Erich Gamma 已提交
271 272 273
	configurations: IConfig[];
}

274
export interface IEnvConfig {
275
	name?: string;
E
Erich Gamma 已提交
276 277
	type: string;
	request: string;
278
	internalConsoleOptions?: string;
279 280
	preLaunchTask?: string;
	debugServer?: number;
I
isidor 已提交
281
	noDebug?: boolean;
282
	silentlyAbort?: boolean;
E
Erich Gamma 已提交
283 284
}

I
isidor 已提交
285 286 287 288 289 290
export interface IExtHostConfig extends IEnvConfig {
	port?: number;
	sourceMaps?: boolean;
	outDir?: string;
}

291 292 293 294 295 296
export interface IConfig extends IEnvConfig {
	windows?: IEnvConfig;
	osx?: IEnvConfig;
	linux?: IEnvConfig;
}

E
Erich Gamma 已提交
297
export interface IRawEnvAdapter {
I
isidor 已提交
298 299 300 301 302 303
	type?: string;
	label?: string;
	program?: string;
	args?: string[];
	runtime?: string;
	runtimeArgs?: string[];
E
Erich Gamma 已提交
304 305 306
}

export interface IRawAdapter extends IRawEnvAdapter {
I
isidor 已提交
307 308
	enableBreakpointsFor?: { languageIds: string[] };
	configurationAttributes?: any;
309
	initialConfigurations?: any[] | string;
310
	variables: { [key: string]: string };
I
isidor 已提交
311
	aiKey?: string;
I
isidor 已提交
312
	win?: IRawEnvAdapter;
I
isidor 已提交
313
	winx86?: IRawEnvAdapter;
314
	windows?: IRawEnvAdapter;
I
isidor 已提交
315 316
	osx?: IRawEnvAdapter;
	linux?: IRawEnvAdapter;
E
Erich Gamma 已提交
317 318
}

319 320 321 322
export interface IRawBreakpointContribution {
	language: string;
}

323
export interface IConfigurationManager {
324
	configuration: IConfig;
325 326 327 328 329 330 331 332
	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.
	 */
333
	onDidConfigurationChange: Event<IConfig>;
334 335
}

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

338
export interface IDebugService {
339
	_serviceBrand: any;
340 341 342 343

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

346 347 348 349 350
	/**
	 * Allows to register on debug state changes.
	 */
	onDidChangeState: Event<State>;

351 352 353 354
	/**
	 * Gets the current configuration manager.
	 */
	getConfigurationManager(): IConfigurationManager;
E
Erich Gamma 已提交
355

I
isidor 已提交
356 357 358 359
	/**
	 * Sets the focused stack frame and evaluates all expresions against the newly focused stack frame,
	 */
	setFocusedStackFrameAndEvaluate(focusedStackFrame: IStackFrame): TPromise<void>;
E
Erich Gamma 已提交
360

361
	/**
362
	 * Adds new breakpoints to the model. Notifies debug adapter of breakpoint changes.
363
	 */
I
isidor 已提交
364
	addBreakpoints(rawBreakpoints: IRawBreakpoint[]): TPromise<void>;
365 366 367 368 369 370 371 372 373 374 375

	/**
	 * 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.
	 */
376
	setBreakpointsActivated(activated: boolean): TPromise<void>;
377 378 379 380 381

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

384
	/**
385
	 * Adds a new no name function breakpoint. The function breakpoint should be renamed once user enters the name.
386
	 */
I
isidor 已提交
387
	addFunctionBreakpoint(): void;
388 389 390 391 392

	/**
	 * Renames an already existing function breakpoint.
	 * Notifies debug adapter of breakpoint changes.
	 */
I
isidor 已提交
393
	renameFunctionBreakpoint(id: string, newFunctionName: string): TPromise<void>;
394 395 396 397 398

	/**
	 * 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 已提交
399
	removeFunctionBreakpoints(id?: string): TPromise<void>;
E
Erich Gamma 已提交
400

401
	/**
402
	 * Adds a new expression to the repl.
403
	 */
I
isidor 已提交
404
	addReplExpression(name: string): TPromise<void>;
405 406 407 408

	/**
	 * Removes all repl expressions.
	 */
409
	removeReplExpressions(): void;
410 411 412 413

	/**
	 * Adds a new log to the repl. Either a string value or a dictionary (used to inspect complex objects printed to the repl).
	 */
414
	logToRepl(value: string | { [key: string]: any }, severity?: severity): void;
415 416 417 418

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

421
	/**
422
	 * Adds a new watch expression and evaluates it against the debug adapter.
423
	 */
I
isidor 已提交
424
	addWatchExpression(name?: string): TPromise<void>;
425 426 427 428

	/**
	 * Renames a watch expression and evaluates it against the debug adapter.
	 */
I
isidor 已提交
429
	renameWatchExpression(id: string, newName: string): TPromise<void>;
430 431 432 433

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

I
isidor 已提交
436 437 438
	/**
	 * Creates a new debug session. Depending on the configuration will either 'launch' or 'attach'.
	 */
439
	createSession(noDebug: boolean, configuration?: IConfig): TPromise<any>;
I
isidor 已提交
440 441 442 443

	/**
	 * Restarts an active debug session or creates a new one if there is no active session.
	 */
444
	restartSession(session: ISession): TPromise<any>;
I
isidor 已提交
445 446 447 448

	/**
	 * Gets the current debug model.
	 */
E
Erich Gamma 已提交
449
	getModel(): IModel;
I
isidor 已提交
450 451 452 453

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

I
isidor 已提交
456 457 458
	/**
	 * Opens a new or reveals an already visible editor showing the source.
	 */
459
	openOrRevealSource(source: Source, lineNumber: number, preserveFocus: boolean, sideBySide: boolean): TPromise<any>;
E
Erich Gamma 已提交
460 461
}

I
isidor 已提交
462 463
// Editor interfaces
export interface IDebugEditorContribution extends editor.IEditorContribution {
464
	showHover(range: Range, hoveringOver: string, focus: boolean): TPromise<void>;
I
isidor 已提交
465 466
}

I
isidor 已提交
467
// utils
E
Erich Gamma 已提交
468

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

I
isidor 已提交
471 472
export function formatPII(value: string, excludePII: boolean, args: { [key: string]: string }): string {
	return value.replace(_formatPIIRegexp, function (match, group) {
E
Erich Gamma 已提交
473 474 475 476
		if (excludePII && group.length > 0 && group[0] !== '_') {
			return match;
		}

I
isidor 已提交
477
		return args && args.hasOwnProperty(group) ?
E
Erich Gamma 已提交
478 479
			args[group] :
			match;
I
isidor 已提交
480
	});
E
Erich Gamma 已提交
481
}