debug.ts 13.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';
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;
34
	sessionId: string;
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
}

68 69 70 71 72 73
export enum SessionRequestType {
	LAUNCH,
	ATTACH,
	LAUNCH_NO_DEBUG
}

I
isidor 已提交
74
export interface ISession {
75
	requestType: SessionRequestType;
76 77 78 79
	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>;
80 81 82 83 84

	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 已提交
85
	restartFrame(args: DebugProtocol.RestartFrameArguments): TPromise<DebugProtocol.RestartFrameResponse>;
86

87
	next(args: DebugProtocol.NextArguments): TPromise<DebugProtocol.NextResponse>;
88 89 90 91 92
	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 已提交
93 94

	completions(args: DebugProtocol.CompletionsArguments): TPromise<DebugProtocol.CompletionsResponse>;
95
	setVariable(args: DebugProtocol.SetVariableArguments): TPromise<DebugProtocol.SetVariableResponse>;
96
	source(args: DebugProtocol.SourceArguments): TPromise<DebugProtocol.SourceResponse>;
97 98
}

I
isidor 已提交
99
export interface IProcess extends ITreeElement {
I
isidor 已提交
100
	name: string;
I
isidor 已提交
101 102
	getThread(threadId: number): IThread;
	getAllThreads(): IThread[];
I
isidor 已提交
103
	session: ISession;
104 105
}

E
Erich Gamma 已提交
106
export interface IThread extends ITreeElement {
107 108

	/**
109
	 * Process the thread belongs to
110
	 */
111
	process: IProcess;
112

I
isidor 已提交
113 114 115
	/**
	 * Id of the thread generated by the debug adapter backend.
	 */
E
Erich Gamma 已提交
116
	threadId: number;
I
isidor 已提交
117 118 119 120

	/**
	 * Name of the thread.
	 */
E
Erich Gamma 已提交
121
	name: string;
I
isidor 已提交
122 123 124 125

	/**
	 * Information about the current thread stop event. Null if thread is not stopped.
	 */
I
isidor 已提交
126
	stoppedDetails: IRawStoppedDetails;
127 128 129 130 131

	/**
	 * 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 已提交
132 133
	 * Only gets the first 20 stack frames. Calling this method consecutive times
	 * with getAdditionalStackFrames = true gets the remainder of the call stack.
134
	 */
135
	getCallStack(getAdditionalStackFrames?: boolean): TPromise<IStackFrame[]>;
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152

	/**
	 * 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;
153 154 155 156 157 158 159

	next(): TPromise<any>;
	stepIn(): TPromise<any>;
	stepOut(): TPromise<any>;
	stepBack(): TPromise<any>;
	continue(): TPromise<any>;
	pause(): TPromise<any>;
E
Erich Gamma 已提交
160 161 162 163 164 165 166 167
}

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

export interface IStackFrame extends ITreeElement {
168
	thread: IThread;
E
Erich Gamma 已提交
169 170 171 172 173
	name: string;
	lineNumber: number;
	column: number;
	frameId: number;
	source: Source;
174
	getScopes(): TPromise<IScope[]>;
I
isidor 已提交
175
	restart(): TPromise<any>;
I
isidor 已提交
176
	completions(text: string, position: Position): TPromise<ISuggestion[]>;
E
Erich Gamma 已提交
177 178 179 180 181 182
}

export interface IEnablement extends ITreeElement {
	enabled: boolean;
}

183 184 185
export interface IRawBreakpoint {
	uri: uri;
	lineNumber: number;
186
	enabled?: boolean;
187
	condition?: string;
188
	hitCondition?: string;
189 190
}

E
Erich Gamma 已提交
191 192 193 194
export interface IBreakpoint extends IEnablement {
	source: Source;
	lineNumber: number;
	desiredLineNumber: number;
I
isidor 已提交
195
	condition: string;
196
	hitCondition: string;
197
	verified: boolean;
198
	idFromAdapter: number;
I
isidor 已提交
199
	message: string;
E
Erich Gamma 已提交
200 201
}

I
isidor 已提交
202
export interface IFunctionBreakpoint extends IEnablement {
203
	name: string;
I
isidor 已提交
204
	verified: boolean;
205
	idFromAdapter: number;
206
	hitCondition: string;
I
isidor 已提交
207 208
}

E
Erich Gamma 已提交
209
export interface IExceptionBreakpoint extends IEnablement {
210 211
	filter: string;
	label: string;
E
Erich Gamma 已提交
212 213
}

I
isidor 已提交
214
// model interfaces
E
Erich Gamma 已提交
215

216
export interface IViewModel extends ITreeElement {
217
	/**
218
	 * Returns the focused debug process or null if no process is stopped.
219
	 */
220
	focusedProcess: IProcess;
221 222

	/**
223
	 * Returns the focused thread or null if no thread is stopped.
224
	 */
225
	focusedThread: IThread;
226 227

	/**
228
	 * Returns the focused stack frame or null if there are no stack frames.
229
	 */
230
	focusedStackFrame: IStackFrame;
E
Erich Gamma 已提交
231
	getSelectedExpression(): IExpression;
I
isidor 已提交
232
	getSelectedFunctionBreakpoint(): IFunctionBreakpoint;
233
	setSelectedExpression(expression: IExpression);
I
isidor 已提交
234
	setSelectedFunctionBreakpoint(functionBreakpoint: IFunctionBreakpoint): void;
235

236 237 238
	selectedConfigurationName: string;
	setSelectedConfigurationName(name: string): void;

239 240 241
	onDidFocusStackFrame: Event<IStackFrame>;
	onDidSelectExpression: Event<IExpression>;
	onDidSelectFunctionBreakpoint: Event<IFunctionBreakpoint>;
242 243 244 245
	/**
	 * Allows to register on change of selected debug configuration.
	 */
	onDidSelectConfigurationName: Event<string>;
E
Erich Gamma 已提交
246 247
}

248
export interface IModel extends ITreeElement {
249
	getProcesses(): IProcess[];
E
Erich Gamma 已提交
250 251
	getBreakpoints(): IBreakpoint[];
	areBreakpointsActivated(): boolean;
I
isidor 已提交
252
	getFunctionBreakpoints(): IFunctionBreakpoint[];
E
Erich Gamma 已提交
253 254 255
	getExceptionBreakpoints(): IExceptionBreakpoint[];
	getWatchExpressions(): IExpression[];
	getReplElements(): ITreeElement[];
256 257 258 259

	onDidChangeBreakpoints: Event<void>;
	onDidChangeCallStack: Event<void>;
	onDidChangeWatchExpressions: Event<IExpression>;
260
	onDidChangeReplElements: Event<void>;
261
};
E
Erich Gamma 已提交
262

I
isidor 已提交
263
// service enums
E
Erich Gamma 已提交
264 265 266 267 268 269

export enum State {
	Disabled,
	Inactive,
	Initializing,
	Stopped,
I
isidor 已提交
270 271
	Running,
	RunningNoDebug
E
Erich Gamma 已提交
272 273
}

I
isidor 已提交
274 275 276 277
// Service config

export interface IDebugConfiguration {
	allowBreakpointsEverywhere: boolean;
I
isidor 已提交
278
	openExplorerOnEnd: boolean;
I
isidor 已提交
279 280
}

I
isidor 已提交
281
// service interfaces
E
Erich Gamma 已提交
282 283 284

export interface IGlobalConfig {
	version: string;
285
	debugServer?: number;
E
Erich Gamma 已提交
286 287 288
	configurations: IConfig[];
}

289
export interface IEnvConfig {
290
	name?: string;
E
Erich Gamma 已提交
291 292
	type: string;
	request: string;
293
	internalConsoleOptions?: string;
294 295
	preLaunchTask?: string;
	debugServer?: number;
I
isidor 已提交
296
	noDebug?: boolean;
297
	silentlyAbort?: boolean;
E
Erich Gamma 已提交
298 299
}

I
isidor 已提交
300 301 302 303 304 305
export interface IExtHostConfig extends IEnvConfig {
	port?: number;
	sourceMaps?: boolean;
	outDir?: string;
}

306 307 308 309 310 311
export interface IConfig extends IEnvConfig {
	windows?: IEnvConfig;
	osx?: IEnvConfig;
	linux?: IEnvConfig;
}

E
Erich Gamma 已提交
312
export interface IRawEnvAdapter {
I
isidor 已提交
313 314 315 316 317 318
	type?: string;
	label?: string;
	program?: string;
	args?: string[];
	runtime?: string;
	runtimeArgs?: string[];
E
Erich Gamma 已提交
319 320 321
}

export interface IRawAdapter extends IRawEnvAdapter {
I
isidor 已提交
322 323
	enableBreakpointsFor?: { languageIds: string[] };
	configurationAttributes?: any;
324
	initialConfigurations?: any[] | string;
325
	variables: { [key: string]: string };
I
isidor 已提交
326
	aiKey?: string;
I
isidor 已提交
327
	win?: IRawEnvAdapter;
I
isidor 已提交
328
	winx86?: IRawEnvAdapter;
329
	windows?: IRawEnvAdapter;
I
isidor 已提交
330 331
	osx?: IRawEnvAdapter;
	linux?: IRawEnvAdapter;
E
Erich Gamma 已提交
332 333
}

334 335 336 337
export interface IRawBreakpointContribution {
	language: string;
}

338
export interface IConfigurationManager {
339
	getConfiguration(nameOrConfig: string | IConfig): TPromise<IConfig>;
340 341 342 343 344
	openConfigFile(sideBySide: boolean): TPromise<boolean>;
	loadLaunchConfig(): TPromise<IGlobalConfig>;
	canSetBreakpointsIn(model: editor.IModel): boolean;
}

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

347
export interface IDebugService {
348
	_serviceBrand: any;
349 350 351 352

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

355 356 357 358 359
	/**
	 * Allows to register on debug state changes.
	 */
	onDidChangeState: Event<State>;

360 361 362 363
	/**
	 * Gets the current configuration manager.
	 */
	getConfigurationManager(): IConfigurationManager;
E
Erich Gamma 已提交
364

I
isidor 已提交
365 366 367 368
	/**
	 * Sets the focused stack frame and evaluates all expresions against the newly focused stack frame,
	 */
	setFocusedStackFrameAndEvaluate(focusedStackFrame: IStackFrame): TPromise<void>;
E
Erich Gamma 已提交
369

370
	/**
371
	 * Adds new breakpoints to the model. Notifies debug adapter of breakpoint changes.
372
	 */
I
isidor 已提交
373
	addBreakpoints(rawBreakpoints: IRawBreakpoint[]): TPromise<void>;
374 375 376 377 378 379 380 381 382 383 384

	/**
	 * 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.
	 */
385
	setBreakpointsActivated(activated: boolean): TPromise<void>;
386 387 388 389 390

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

393
	/**
394
	 * Adds a new no name function breakpoint. The function breakpoint should be renamed once user enters the name.
395
	 */
I
isidor 已提交
396
	addFunctionBreakpoint(): void;
397 398 399 400 401

	/**
	 * Renames an already existing function breakpoint.
	 * Notifies debug adapter of breakpoint changes.
	 */
I
isidor 已提交
402
	renameFunctionBreakpoint(id: string, newFunctionName: string): TPromise<void>;
403 404 405 406 407

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

410
	/**
411
	 * Adds a new expression to the repl.
412
	 */
I
isidor 已提交
413
	addReplExpression(name: string): TPromise<void>;
414 415 416 417

	/**
	 * Removes all repl expressions.
	 */
418
	removeReplExpressions(): void;
419 420 421 422

	/**
	 * Adds a new log to the repl. Either a string value or a dictionary (used to inspect complex objects printed to the repl).
	 */
423
	logToRepl(value: string | { [key: string]: any }, severity?: severity): void;
424 425 426 427

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

430
	/**
431
	 * Adds a new watch expression and evaluates it against the debug adapter.
432
	 */
I
isidor 已提交
433
	addWatchExpression(name?: string): TPromise<void>;
434 435 436 437

	/**
	 * Renames a watch expression and evaluates it against the debug adapter.
	 */
I
isidor 已提交
438
	renameWatchExpression(id: string, newName: string): TPromise<void>;
439 440 441 442

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

I
isidor 已提交
445 446 447
	/**
	 * Creates a new debug session. Depending on the configuration will either 'launch' or 'attach'.
	 */
448
	createSession(noDebug: boolean, configuration?: IConfig): TPromise<any>;
I
isidor 已提交
449 450 451 452

	/**
	 * Restarts an active debug session or creates a new one if there is no active session.
	 */
453
	restartSession(session: ISession): TPromise<any>;
I
isidor 已提交
454 455 456 457

	/**
	 * Gets the current debug model.
	 */
E
Erich Gamma 已提交
458
	getModel(): IModel;
I
isidor 已提交
459 460 461 462

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

I
isidor 已提交
465 466 467
	/**
	 * Opens a new or reveals an already visible editor showing the source.
	 */
468
	openOrRevealSource(source: Source, lineNumber: number, preserveFocus: boolean, sideBySide: boolean): TPromise<any>;
E
Erich Gamma 已提交
469 470
}

I
isidor 已提交
471 472
// Editor interfaces
export interface IDebugEditorContribution extends editor.IEditorContribution {
473
	showHover(range: Range, hoveringOver: string, focus: boolean): TPromise<void>;
I
isidor 已提交
474 475
}

I
isidor 已提交
476
// utils
E
Erich Gamma 已提交
477

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

I
isidor 已提交
480 481
export function formatPII(value: string, excludePII: boolean, args: { [key: string]: string }): string {
	return value.replace(_formatPIIRegexp, function (match, group) {
E
Erich Gamma 已提交
482 483 484 485
		if (excludePII && group.length > 0 && group[0] !== '_') {
			return match;
		}

I
isidor 已提交
486
		return args && args.hasOwnProperty(group) ?
E
Erich Gamma 已提交
487 488
			args[group] :
			match;
I
isidor 已提交
489
	});
E
Erich Gamma 已提交
490
}