debug.ts 14.4 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
	rawSession: ISession;
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
export interface IBaseSession {
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 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103

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

export interface ISession extends IBaseSession, ITreeElement {
	readyForBreakpoints: boolean;
	emittedStopped: boolean;
	getLengthInSeconds(): number;
	attach(args: DebugProtocol.AttachRequestArguments): TPromise<DebugProtocol.AttachResponse>;
	setBreakpoints(args: DebugProtocol.SetBreakpointsArguments): TPromise<DebugProtocol.SetBreakpointsResponse>;
	setFunctionBreakpoints(args: DebugProtocol.SetFunctionBreakpointsArguments): TPromise<DebugProtocol.SetFunctionBreakpointsResponse>;
	setExceptionBreakpoints(args: DebugProtocol.SetExceptionBreakpointsArguments): TPromise<DebugProtocol.SetExceptionBreakpointsResponse>;
	onDidStop: Event<DebugProtocol.StoppedEvent>;
	threads(): TPromise<DebugProtocol.ThreadsResponse>;
	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>;
	setVariable(args: DebugProtocol.SetVariableArguments): TPromise<DebugProtocol.SetVariableResponse>;
	restartFrame(args: DebugProtocol.RestartFrameArguments): TPromise<DebugProtocol.RestartFrameResponse>;
	completions(args: DebugProtocol.CompletionsArguments): TPromise<DebugProtocol.CompletionsResponse>;
	next(args: DebugProtocol.NextArguments): TPromise<DebugProtocol.NextResponse>;
	source(args: DebugProtocol.SourceArguments): TPromise<DebugProtocol.SourceResponse>;
}

export interface IProcess extends IBaseSession, ITreeElement {

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;
E
Erich Gamma 已提交
153 154 155 156 157 158 159 160
}

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

export interface IStackFrame extends ITreeElement {
161
	thread: IThread;
E
Erich Gamma 已提交
162 163 164 165 166
	name: string;
	lineNumber: number;
	column: number;
	frameId: number;
	source: Source;
167
	getScopes(): TPromise<IScope[]>;
E
Erich Gamma 已提交
168 169 170 171 172 173
}

export interface IEnablement extends ITreeElement {
	enabled: boolean;
}

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

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

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

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

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

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

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

224
export interface IModel extends ITreeElement {
225
	getProcesses(): IProcess[];
226
	getThreads(sessionId): { [threadId: number]: IThread; };
E
Erich Gamma 已提交
227 228
	getBreakpoints(): IBreakpoint[];
	areBreakpointsActivated(): boolean;
I
isidor 已提交
229
	getFunctionBreakpoints(): IFunctionBreakpoint[];
E
Erich Gamma 已提交
230 231 232
	getExceptionBreakpoints(): IExceptionBreakpoint[];
	getWatchExpressions(): IExpression[];
	getReplElements(): ITreeElement[];
233 234 235 236

	onDidChangeBreakpoints: Event<void>;
	onDidChangeCallStack: Event<void>;
	onDidChangeWatchExpressions: Event<IExpression>;
237
	onDidChangeReplElements: Event<void>;
238
};
E
Erich Gamma 已提交
239

I
isidor 已提交
240
// service enums
E
Erich Gamma 已提交
241 242 243 244 245 246

export enum State {
	Disabled,
	Inactive,
	Initializing,
	Stopped,
I
isidor 已提交
247 248
	Running,
	RunningNoDebug
E
Erich Gamma 已提交
249 250
}

I
isidor 已提交
251 252 253 254
// Service config

export interface IDebugConfiguration {
	allowBreakpointsEverywhere: boolean;
I
isidor 已提交
255
	openExplorerOnEnd: boolean;
I
isidor 已提交
256 257
}

I
isidor 已提交
258
// service interfaces
E
Erich Gamma 已提交
259 260 261

export interface IGlobalConfig {
	version: string;
262
	debugServer?: number;
E
Erich Gamma 已提交
263 264 265
	configurations: IConfig[];
}

266
export interface IEnvConfig {
267
	name?: string;
E
Erich Gamma 已提交
268 269
	type: string;
	request: string;
270
	internalConsoleOptions?: string;
271 272
	preLaunchTask?: string;
	debugServer?: number;
I
isidor 已提交
273
	noDebug?: boolean;
274
	silentlyAbort?: boolean;
E
Erich Gamma 已提交
275 276
}

I
isidor 已提交
277 278 279 280 281 282
export interface IExtHostConfig extends IEnvConfig {
	port?: number;
	sourceMaps?: boolean;
	outDir?: string;
}

283 284 285 286 287 288
export interface IConfig extends IEnvConfig {
	windows?: IEnvConfig;
	osx?: IEnvConfig;
	linux?: IEnvConfig;
}

E
Erich Gamma 已提交
289
export interface IRawEnvAdapter {
I
isidor 已提交
290 291 292 293 294 295
	type?: string;
	label?: string;
	program?: string;
	args?: string[];
	runtime?: string;
	runtimeArgs?: string[];
E
Erich Gamma 已提交
296 297 298
}

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

311 312 313 314
export interface IRawBreakpointContribution {
	language: string;
}

315
export interface IConfigurationManager {
316
	configuration: IConfig;
317 318 319 320 321 322 323 324
	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.
	 */
325
	onDidConfigurationChange: Event<IConfig>;
326 327
}

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

330
export interface IDebugService {
331
	_serviceBrand: any;
332 333 334 335

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

338 339 340 341 342
	/**
	 * Allows to register on debug state changes.
	 */
	onDidChangeState: Event<State>;

343 344 345 346
	/**
	 * Gets the current configuration manager.
	 */
	getConfigurationManager(): IConfigurationManager;
E
Erich Gamma 已提交
347

I
isidor 已提交
348 349 350 351
	/**
	 * Sets the focused stack frame and evaluates all expresions against the newly focused stack frame,
	 */
	setFocusedStackFrameAndEvaluate(focusedStackFrame: IStackFrame): TPromise<void>;
E
Erich Gamma 已提交
352

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

	/**
	 * 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.
	 */
368
	setBreakpointsActivated(activated: boolean): TPromise<void>;
369 370 371 372 373

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

376
	/**
377
	 * Adds a new no name function breakpoint. The function breakpoint should be renamed once user enters the name.
378
	 */
I
isidor 已提交
379
	addFunctionBreakpoint(): void;
380 381 382 383 384

	/**
	 * Renames an already existing function breakpoint.
	 * Notifies debug adapter of breakpoint changes.
	 */
I
isidor 已提交
385
	renameFunctionBreakpoint(id: string, newFunctionName: string): TPromise<void>;
386 387 388 389 390

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

393
	/**
394
	 * Adds a new expression to the repl.
395
	 */
I
isidor 已提交
396
	addReplExpression(name: string): TPromise<void>;
397 398 399 400

	/**
	 * Removes all repl expressions.
	 */
401
	removeReplExpressions(): void;
402 403 404 405

	/**
	 * Adds a new log to the repl. Either a string value or a dictionary (used to inspect complex objects printed to the repl).
	 */
406
	logToRepl(value: string | { [key: string]: any }, severity?: severity): void;
407 408 409 410

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

I
isidor 已提交
413 414 415 416 417
	/**
	 * Sets the value for the variable against the debug adapter.
	 */
	setVariable(variable: IExpression, value: string): TPromise<void>;

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

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

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

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

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

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

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

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

	next(threadId: number): TPromise<void>;
	stepIn(threadId: number): TPromise<void>;
	stepOut(threadId: number): TPromise<void>;
461
	stepBack(threadId: number): TPromise<void>;
462 463
	continue(threadId: number): TPromise<void>;
	pause(threadId: number): TPromise<any>;
A
Andre Weinand 已提交
464
	restartFrame(frameId: number): TPromise<any>;
I
isidor 已提交
465
	completions(text: string, position: Position): TPromise<ISuggestion[]>;
E
Erich Gamma 已提交
466 467
}

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

I
isidor 已提交
473
// utils
E
Erich Gamma 已提交
474

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

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

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