debug.ts 11.6 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';
I
isidor 已提交
7
import { TPromise } from 'vs/base/common/winjs.base';
8
import Event from 'vs/base/common/event';
E
Erich Gamma 已提交
9 10 11
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';
13
import { Range } from 'vs/editor/common/core/range';
E
Erich Gamma 已提交
14

I
isidor 已提交
15 16 17 18
export const VIEWLET_ID = 'workbench.view.debug';
export const REPL_ID = 'workbench.panel.repl';
export const DEBUG_SERVICE_ID = 'debugService';
export const CONTEXT_IN_DEBUG_MODE = 'inDebugMode';
I
isidor 已提交
19
export const EDITOR_CONTRIBUTION_ID = 'editor.contrib.debug';
E
Erich Gamma 已提交
20

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

export interface IRawModelUpdate {
	threadId: number;
	thread?: DebugProtocol.Thread;
	callStack?: DebugProtocol.StackFrame[];
I
isidor 已提交
27
	stoppedDetails?: IRawStoppedDetails;
28
	allThreadsStopped?: boolean;
I
isidor 已提交
29 30 31 32 33 34
}

export interface IRawStoppedDetails {
	reason: string;
	threadId?: number;
	text?: string;
I
isidor 已提交
35
	totalFrames?: number;
36
	framesErrorMessage?: string;
E
Erich Gamma 已提交
37 38
}

I
isidor 已提交
39
// model
E
Erich Gamma 已提交
40 41 42 43 44 45 46 47 48 49 50 51 52

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;
53
	valueChanged: boolean;
E
Erich Gamma 已提交
54 55 56
}

export interface IThread extends ITreeElement {
I
isidor 已提交
57 58 59
	/**
	 * Id of the thread generated by the debug adapter backend.
	 */
E
Erich Gamma 已提交
60
	threadId: number;
I
isidor 已提交
61 62 63 64

	/**
	 * Name of the thread.
	 */
E
Erich Gamma 已提交
65
	name: string;
I
isidor 已提交
66 67 68 69

	/**
	 * Information about the current thread stop event. Null if thread is not stopped.
	 */
I
isidor 已提交
70
	stoppedDetails: IRawStoppedDetails;
71 72 73 74 75

	/**
	 * 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 已提交
76 77
	 * Only gets the first 20 stack frames. Calling this method consecutive times
	 * with getAdditionalStackFrames = true gets the remainder of the call stack.
78
	 */
I
isidor 已提交
79
	getCallStack(debugService: IDebugService, getAdditionalStackFrames?: boolean): TPromise<IStackFrame[]>;
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96

	/**
	 * 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 已提交
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
}

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

118 119 120
export interface IRawBreakpoint {
	uri: uri;
	lineNumber: number;
121
	enabled?: boolean;
122 123 124
	condition?: string;
}

E
Erich Gamma 已提交
125 126 127 128
export interface IBreakpoint extends IEnablement {
	source: Source;
	lineNumber: number;
	desiredLineNumber: number;
I
isidor 已提交
129
	condition: string;
130
	verified: boolean;
131
	idFromAdapter: number;
I
isidor 已提交
132
	message: string;
E
Erich Gamma 已提交
133 134
}

I
isidor 已提交
135
export interface IFunctionBreakpoint extends IEnablement {
136
	name: string;
I
isidor 已提交
137
	verified: boolean;
138
	idFromAdapter: number;
I
isidor 已提交
139 140
}

E
Erich Gamma 已提交
141
export interface IExceptionBreakpoint extends IEnablement {
142 143
	filter: string;
	label: string;
E
Erich Gamma 已提交
144 145
}

I
isidor 已提交
146
// model interfaces
E
Erich Gamma 已提交
147

148
export interface IViewModel extends ITreeElement {
E
Erich Gamma 已提交
149 150 151 152
	getFocusedStackFrame(): IStackFrame;
	getSelectedExpression(): IExpression;
	getFocusedThreadId(): number;
	setSelectedExpression(expression: IExpression);
I
isidor 已提交
153 154
	getSelectedFunctionBreakpoint(): IFunctionBreakpoint;
	setSelectedFunctionBreakpoint(functionBreakpoint: IFunctionBreakpoint): void;
155 156 157 158

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

161
export interface IModel extends ITreeElement {
162
	getThreads(): { [threadId: number]: IThread; };
E
Erich Gamma 已提交
163 164
	getBreakpoints(): IBreakpoint[];
	areBreakpointsActivated(): boolean;
I
isidor 已提交
165
	getFunctionBreakpoints(): IFunctionBreakpoint[];
E
Erich Gamma 已提交
166 167 168
	getExceptionBreakpoints(): IExceptionBreakpoint[];
	getWatchExpressions(): IExpression[];
	getReplElements(): ITreeElement[];
169 170 171 172

	onDidChangeBreakpoints: Event<void>;
	onDidChangeCallStack: Event<void>;
	onDidChangeWatchExpressions: Event<IExpression>;
173
	onDidChangeReplElements: Event<void>;
174
};
E
Erich Gamma 已提交
175

I
isidor 已提交
176
// service enums
E
Erich Gamma 已提交
177 178 179 180 181 182

export enum State {
	Disabled,
	Inactive,
	Initializing,
	Stopped,
I
isidor 已提交
183 184
	Running,
	RunningNoDebug
E
Erich Gamma 已提交
185 186
}

I
isidor 已提交
187
// service interfaces
E
Erich Gamma 已提交
188 189 190

export interface IGlobalConfig {
	version: string;
191
	debugServer?: number;
E
Erich Gamma 已提交
192 193 194
	configurations: IConfig[];
}

195
export interface IEnvConfig {
196
	name?: string;
E
Erich Gamma 已提交
197 198
	type: string;
	request: string;
199
	internalConsoleOptions?: string;
200 201
	preLaunchTask?: string;
	debugServer?: number;
I
isidor 已提交
202
	noDebug?: boolean;
203
	silentlyAbort?: boolean;
E
Erich Gamma 已提交
204 205
}

I
isidor 已提交
206 207 208 209 210 211
export interface IExtHostConfig extends IEnvConfig {
	port?: number;
	sourceMaps?: boolean;
	outDir?: string;
}

212 213 214 215 216 217
export interface IConfig extends IEnvConfig {
	windows?: IEnvConfig;
	osx?: IEnvConfig;
	linux?: IEnvConfig;
}

E
Erich Gamma 已提交
218
export interface IRawEnvAdapter {
I
isidor 已提交
219 220 221 222 223 224
	type?: string;
	label?: string;
	program?: string;
	args?: string[];
	runtime?: string;
	runtimeArgs?: string[];
E
Erich Gamma 已提交
225 226 227
}

export interface IRawAdapter extends IRawEnvAdapter {
I
isidor 已提交
228 229 230
	enableBreakpointsFor?: { languageIds: string[] };
	configurationAttributes?: any;
	initialConfigurations?: any[];
231
	variables: { [key: string]: string };
I
isidor 已提交
232
	aiKey?: string;
I
isidor 已提交
233
	win?: IRawEnvAdapter;
I
isidor 已提交
234
	winx86?: IRawEnvAdapter;
235
	windows?: IRawEnvAdapter;
I
isidor 已提交
236 237
	osx?: IRawEnvAdapter;
	linux?: IRawEnvAdapter;
E
Erich Gamma 已提交
238 239
}

240
export interface IRawDebugSession {
I
isidor 已提交
241 242
	configuration: { type: string, isAttach: boolean, capabilities: DebugProtocol.Capabilites };

243
	disconnect(restart?: boolean, force?: boolean): TPromise<DebugProtocol.DisconnectResponse>;
E
Erich Gamma 已提交
244

245
	stackTrace(args: DebugProtocol.StackTraceArguments): TPromise<DebugProtocol.StackTraceResponse>;
E
Erich Gamma 已提交
246
	scopes(args: DebugProtocol.ScopesArguments): TPromise<DebugProtocol.ScopesResponse>;
247
	variables(args: DebugProtocol.VariablesArguments): TPromise<DebugProtocol.VariablesResponse>;
E
Erich Gamma 已提交
248
	evaluate(args: DebugProtocol.EvaluateArguments): TPromise<DebugProtocol.EvaluateResponse>;
249

250 251 252
	custom(request: string, args: any): TPromise<DebugProtocol.Response>;

	onDidEvent: Event<DebugProtocol.Event>;
E
Erich Gamma 已提交
253 254
}

255 256 257 258 259 260 261 262 263 264 265 266 267
export interface IConfigurationManager {
	configurationName: string;
	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.
	 */
	onDidConfigurationChange: Event<string>;
}

E
Erich Gamma 已提交
268 269
export var IDebugService = createDecorator<IDebugService>(DEBUG_SERVICE_ID);

270
export interface IDebugService {
E
Erich Gamma 已提交
271
	serviceId: ServiceIdentifier<any>;
272 273 274 275

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

278 279 280 281 282
	/**
	 * Allows to register on debug state changes.
	 */
	onDidChangeState: Event<State>;

283 284 285 286
	/**
	 * Gets the current configuration manager.
	 */
	getConfigurationManager(): IConfigurationManager;
E
Erich Gamma 已提交
287

I
isidor 已提交
288 289 290 291
	/**
	 * Sets the focused stack frame and evaluates all expresions against the newly focused stack frame,
	 */
	setFocusedStackFrameAndEvaluate(focusedStackFrame: IStackFrame): TPromise<void>;
E
Erich Gamma 已提交
292

293
	/**
294
	 * Adds new breakpoints to the model. Notifies debug adapter of breakpoint changes.
295
	 */
296
	addBreakpoints(rawBreakpoints: IRawBreakpoint[]): TPromise<void[]>;
297 298 299 300 301 302 303 304 305 306 307

	/**
	 * 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.
	 */
308
	setBreakpointsActivated(activated: boolean): TPromise<void>;
309 310 311 312 313

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

316
	/**
317
	 * Adds a new no name function breakpoint. The function breakpoint should be renamed once user enters the name.
318
	 */
I
isidor 已提交
319
	addFunctionBreakpoint(): void;
320 321 322 323 324

	/**
	 * Renames an already existing function breakpoint.
	 * Notifies debug adapter of breakpoint changes.
	 */
I
isidor 已提交
325
	renameFunctionBreakpoint(id: string, newFunctionName: string): TPromise<void>;
326 327 328 329 330

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

333
	/**
334
	 * Adds a new expression to the repl.
335
	 */
I
isidor 已提交
336
	addReplExpression(name: string): TPromise<void>;
337 338 339 340

	/**
	 * Removes all repl expressions.
	 */
341
	removeReplExpressions(): void;
342 343 344 345

	/**
	 * Adds a new log to the repl. Either a string value or a dictionary (used to inspect complex objects printed to the repl).
	 */
346
	logToRepl(value: string | { [key: string]: any }, severity?: severity): void;
347 348 349 350

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

I
isidor 已提交
353 354 355 356 357
	/**
	 * Sets the value for the variable against the debug adapter.
	 */
	setVariable(variable: IExpression, value: string): TPromise<void>;

358
	/**
359
	 * Adds a new watch expression and evaluates it against the debug adapter.
360
	 */
I
isidor 已提交
361
	addWatchExpression(name?: string): TPromise<void>;
362 363 364 365

	/**
	 * Renames a watch expression and evaluates it against the debug adapter.
	 */
I
isidor 已提交
366
	renameWatchExpression(id: string, newName: string): TPromise<void>;
367 368 369 370

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

I
isidor 已提交
373 374 375
	/**
	 * Creates a new debug session. Depending on the configuration will either 'launch' or 'attach'.
	 */
376
	createSession(noDebug: boolean, configuration?: IConfig): TPromise<any>;
I
isidor 已提交
377 378 379 380

	/**
	 * Restarts an active debug session or creates a new one if there is no active session.
	 */
I
isidor 已提交
381
	restartSession(): TPromise<any>;
I
isidor 已提交
382 383 384 385

	/**
	 * Returns the active debug session or null if debug is inactive.
	 */
E
Erich Gamma 已提交
386 387
	getActiveSession(): IRawDebugSession;

I
isidor 已提交
388 389 390
	/**
	 * Gets the current debug model.
	 */
E
Erich Gamma 已提交
391
	getModel(): IModel;
I
isidor 已提交
392 393 394 395

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

I
isidor 已提交
398 399 400
	/**
	 * Opens a new or reveals an already visible editor showing the source.
	 */
401
	openOrRevealSource(source: Source, lineNumber: number, preserveFocus: boolean, sideBySide: boolean): TPromise<any>;
402 403 404 405

	next(threadId: number): TPromise<void>;
	stepIn(threadId: number): TPromise<void>;
	stepOut(threadId: number): TPromise<void>;
406
	stepBack(threadId: number): TPromise<void>;
407 408
	continue(threadId: number): TPromise<void>;
	pause(threadId: number): TPromise<any>;
E
Erich Gamma 已提交
409 410
}

I
isidor 已提交
411 412
// Editor interfaces
export interface IDebugEditorContribution extends editor.IEditorContribution {
413
	showHover(range: Range, hoveringOver: string, focus: boolean): TPromise<void>;
I
isidor 已提交
414 415
}

I
isidor 已提交
416
// utils
E
Erich Gamma 已提交
417

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

I
isidor 已提交
420 421
export function formatPII(value: string, excludePII: boolean, args: { [key: string]: string }): string {
	return value.replace(_formatPIIRegexp, function (match, group) {
E
Erich Gamma 已提交
422 423 424 425
		if (excludePII && group.length > 0 && group[0] !== '_') {
			return match;
		}

I
isidor 已提交
426
		return args && args.hasOwnProperty(group) ?
E
Erich Gamma 已提交
427 428
			args[group] :
			match;
I
isidor 已提交
429
	});
E
Erich Gamma 已提交
430
}