Path: blob/main/src/vs/workbench/contrib/debug/test/common/mockDebug.ts
3296 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import { DeferredPromise } from '../../../../../base/common/async.js';6import { CancellationToken } from '../../../../../base/common/cancellation.js';7import { Event } from '../../../../../base/common/event.js';8import { URI as uri } from '../../../../../base/common/uri.js';9import { IPosition, Position } from '../../../../../editor/common/core/position.js';10import { ITextModel } from '../../../../../editor/common/model.js';11import { NullLogService } from '../../../../../platform/log/common/log.js';12import { IStorageService } from '../../../../../platform/storage/common/storage.js';13import { IWorkspaceFolder } from '../../../../../platform/workspace/common/workspace.js';14import { AbstractDebugAdapter } from '../../common/abstractDebugAdapter.js';15import { AdapterEndEvent, IAdapterManager, IBreakpoint, IBreakpointData, IBreakpointUpdateData, IConfig, IConfigurationManager, IDataBreakpoint, IDataBreakpointInfoResponse, IDebugLocationReferenced, IDebugModel, IDebugService, IDebugSession, IDebugSessionOptions, IDebugger, IExceptionBreakpoint, IExceptionInfo, IFunctionBreakpoint, IInstructionBreakpoint, ILaunch, IMemoryRegion, INewReplElementData, IRawModelUpdate, IRawStoppedDetails, IReplElement, IStackFrame, IThread, IViewModel, LoadedSourceEvent, State } from '../../common/debug.js';16import { DebugCompoundRoot } from '../../common/debugCompoundRoot.js';17import { IInstructionBreakpointOptions } from '../../common/debugModel.js';18import { Source } from '../../common/debugSource.js';19import { DebugStorage } from '../../common/debugStorage.js';2021export class MockDebugService implements IDebugService {22_serviceBrand: undefined;2324get state(): State {25throw new Error('not implemented');26}2728get onWillNewSession(): Event<IDebugSession> {29throw new Error('not implemented');30}3132get onDidNewSession(): Event<IDebugSession> {33throw new Error('not implemented');34}3536get onDidEndSession(): Event<{ session: IDebugSession; restart: boolean }> {37throw new Error('not implemented');38}3940get onDidChangeState(): Event<State> {41throw new Error('not implemented');42}4344getConfigurationManager(): IConfigurationManager {45throw new Error('not implemented');46}4748getAdapterManager(): IAdapterManager {49throw new Error('Method not implemented.');50}5152canSetBreakpointsIn(model: ITextModel): boolean {53throw new Error('Method not implemented.');54}5556focusStackFrame(focusedStackFrame: IStackFrame): Promise<void> {57throw new Error('not implemented');58}5960sendAllBreakpoints(session?: IDebugSession): Promise<any> {61throw new Error('not implemented');62}6364sendBreakpoints(modelUri: uri, sourceModified?: boolean | undefined, session?: IDebugSession | undefined): Promise<any> {65throw new Error('not implemented');66}6768addBreakpoints(uri: uri, rawBreakpoints: IBreakpointData[]): Promise<IBreakpoint[]> {69throw new Error('not implemented');70}7172updateBreakpoints(uri: uri, data: Map<string, IBreakpointUpdateData>, sendOnResourceSaved: boolean): Promise<void> {73throw new Error('not implemented');74}7576enableOrDisableBreakpoints(enabled: boolean): Promise<void> {77throw new Error('not implemented');78}7980setBreakpointsActivated(): Promise<void> {81throw new Error('not implemented');82}8384removeBreakpoints(): Promise<any> {85throw new Error('not implemented');86}8788addInstructionBreakpoint(opts: IInstructionBreakpointOptions): Promise<void> {89throw new Error('Method not implemented.');90}9192removeInstructionBreakpoints(address?: string): Promise<void> {93throw new Error('Method not implemented.');94}9596setExceptionBreakpointCondition(breakpoint: IExceptionBreakpoint, condition: string): Promise<void> {97throw new Error('Method not implemented.');98}99100setExceptionBreakpointsForSession(session: IDebugSession, data: DebugProtocol.ExceptionBreakpointsFilter[]): void {101throw new Error('Method not implemented.');102}103104addFunctionBreakpoint(): void { }105106moveWatchExpression(id: string, position: number): void { }107108updateFunctionBreakpoint(id: string, update: { name?: string; hitCondition?: string; condition?: string }): Promise<void> {109throw new Error('not implemented');110}111112removeFunctionBreakpoints(id?: string): Promise<void> {113throw new Error('not implemented');114}115116addDataBreakpoint(): Promise<void> {117throw new Error('Method not implemented.');118}119120updateDataBreakpoint(id: string, update: { hitCondition?: string; condition?: string }): Promise<void> {121throw new Error('not implemented');122}123124removeDataBreakpoints(id?: string | undefined): Promise<void> {125throw new Error('Method not implemented.');126}127128addReplExpression(name: string): Promise<void> {129throw new Error('not implemented');130}131132removeReplExpressions(): void { }133134addWatchExpression(name?: string): Promise<void> {135throw new Error('not implemented');136}137138renameWatchExpression(id: string, newName: string): Promise<void> {139throw new Error('not implemented');140}141142removeWatchExpressions(id?: string): void { }143144startDebugging(launch: ILaunch, configOrName?: IConfig | string, options?: IDebugSessionOptions): Promise<boolean> {145return Promise.resolve(true);146}147148restartSession(): Promise<any> {149throw new Error('not implemented');150}151152stopSession(): Promise<any> {153throw new Error('not implemented');154}155156getModel(): IDebugModel {157throw new Error('not implemented');158}159160getViewModel(): IViewModel {161throw new Error('not implemented');162}163164sourceIsNotAvailable(uri: uri): void { }165166tryToAutoFocusStackFrame(thread: IThread): Promise<any> {167throw new Error('not implemented');168}169170runTo(uri: uri, lineNumber: number, column?: number): Promise<void> {171throw new Error('Method not implemented.');172}173}174175export class MockSession implements IDebugSession {176readonly suppressDebugToolbar = false;177readonly suppressDebugStatusbar = false;178readonly suppressDebugView = false;179readonly autoExpandLazyVariables = false;180181dispose(): void {182183}184185getMemory(memoryReference: string): IMemoryRegion {186throw new Error('Method not implemented.');187}188189get onDidInvalidateMemory(): Event<DebugProtocol.MemoryEvent> {190throw new Error('Not implemented');191}192193readMemory(memoryReference: string, offset: number, count: number): Promise<DebugProtocol.ReadMemoryResponse | undefined> {194throw new Error('Method not implemented.');195}196197writeMemory(memoryReference: string, offset: number, data: string, allowPartial?: boolean): Promise<DebugProtocol.WriteMemoryResponse | undefined> {198throw new Error('Method not implemented.');199}200201cancelCorrelatedTestRun(): void {202203}204205get compoundRoot(): DebugCompoundRoot | undefined {206return undefined;207}208209get saveBeforeRestart(): boolean {210return true;211}212213get isSimpleUI(): boolean {214return false;215}216217get lifecycleManagedByParent(): boolean {218return false;219}220221stepInTargets(frameId: number): Promise<{ id: number; label: string }[]> {222throw new Error('Method not implemented.');223}224225cancel(_progressId: string): Promise<DebugProtocol.CancelResponse> {226throw new Error('Method not implemented.');227}228229breakpointsLocations(uri: uri, lineNumber: number): Promise<IPosition[]> {230throw new Error('Method not implemented.');231}232233dataBytesBreakpointInfo(address: string, bytes: number): Promise<IDataBreakpointInfoResponse | undefined> {234throw new Error('Method not implemented.');235}236237dataBreakpointInfo(name: string, variablesReference?: number | undefined): Promise<{ dataId: string | null; description: string; canPersist?: boolean | undefined } | undefined> {238throw new Error('Method not implemented.');239}240241sendDataBreakpoints(dbps: IDataBreakpoint[]): Promise<void> {242throw new Error('Method not implemented.');243}244245subId: string | undefined;246247get compact(): boolean {248return false;249}250251setSubId(subId: string | undefined): void {252throw new Error('Method not implemented.');253}254255get parentSession(): IDebugSession | undefined {256return undefined;257}258259getReplElements(): IReplElement[] {260return [];261}262263hasSeparateRepl(): boolean {264return true;265}266267removeReplExpressions(): void { }268get onDidChangeReplElements(): Event<IReplElement | undefined> {269throw new Error('not implemented');270}271272addReplExpression(stackFrame: IStackFrame, name: string): Promise<void> {273return Promise.resolve(undefined);274}275276appendToRepl(data: INewReplElementData): void { }277278configuration: IConfig = { type: 'mock', name: 'mock', request: 'launch' };279unresolvedConfiguration: IConfig = { type: 'mock', name: 'mock', request: 'launch' };280state = State.Stopped;281root!: IWorkspaceFolder;282capabilities: DebugProtocol.Capabilities = {};283284getId(): string {285return 'mock';286}287288getLabel(): string {289return 'mockname';290}291292get name(): string {293return 'mockname';294}295296setName(name: string): void {297throw new Error('not implemented');298}299300getSourceForUri(modelUri: uri): Source {301throw new Error('not implemented');302}303304getThread(threadId: number): IThread {305throw new Error('not implemented');306}307308getStoppedDetails(): IRawStoppedDetails {309throw new Error('not implemented');310}311312get onDidCustomEvent(): Event<DebugProtocol.Event> {313throw new Error('not implemented');314}315316get onDidLoadedSource(): Event<LoadedSourceEvent> {317throw new Error('not implemented');318}319320get onDidChangeState(): Event<void> {321throw new Error('not implemented');322}323324get onDidEndAdapter(): Event<AdapterEndEvent | undefined> {325throw new Error('not implemented');326}327328get onDidChangeName(): Event<string> {329throw new Error('not implemented');330}331332get onDidProgressStart(): Event<DebugProtocol.ProgressStartEvent> {333throw new Error('not implemented');334}335336get onDidProgressUpdate(): Event<DebugProtocol.ProgressUpdateEvent> {337throw new Error('not implemented');338}339340get onDidProgressEnd(): Event<DebugProtocol.ProgressEndEvent> {341throw new Error('not implemented');342}343344setConfiguration(configuration: { resolved: IConfig; unresolved: IConfig }) { }345346getAllThreads(): IThread[] {347return [];348}349350getSource(raw: DebugProtocol.Source): Source {351throw new Error('not implemented');352}353354getLoadedSources(): Promise<Source[]> {355return Promise.resolve([]);356}357358completions(frameId: number, threadId: number, text: string, position: Position): Promise<DebugProtocol.CompletionsResponse> {359throw new Error('not implemented');360}361362clearThreads(removeThreads: boolean, reference?: number): void { }363364rawUpdate(data: IRawModelUpdate): void { }365366initialize(dbgr: IDebugger): Promise<void> {367throw new Error('Method not implemented.');368}369launchOrAttach(config: IConfig): Promise<void> {370throw new Error('Method not implemented.');371}372restart(): Promise<void> {373throw new Error('Method not implemented.');374}375sendBreakpoints(modelUri: uri, bpts: IBreakpoint[], sourceModified: boolean): Promise<void> {376throw new Error('Method not implemented.');377}378sendFunctionBreakpoints(fbps: IFunctionBreakpoint[]): Promise<void> {379throw new Error('Method not implemented.');380}381sendExceptionBreakpoints(exbpts: IExceptionBreakpoint[]): Promise<void> {382throw new Error('Method not implemented.');383}384sendInstructionBreakpoints(dbps: IInstructionBreakpoint[]): Promise<void> {385throw new Error('Method not implemented.');386}387getDebugProtocolBreakpoint(breakpointId: string): DebugProtocol.Breakpoint | undefined {388throw new Error('Method not implemented.');389}390customRequest(request: string, args: any): Promise<DebugProtocol.Response> {391throw new Error('Method not implemented.');392}393stackTrace(threadId: number, startFrame: number, levels: number, token: CancellationToken): Promise<DebugProtocol.StackTraceResponse> {394throw new Error('Method not implemented.');395}396exceptionInfo(threadId: number): Promise<IExceptionInfo> {397throw new Error('Method not implemented.');398}399scopes(frameId: number): Promise<DebugProtocol.ScopesResponse> {400throw new Error('Method not implemented.');401}402variables(variablesReference: number, threadId: number | undefined, filter: 'indexed' | 'named', start: number, count: number): Promise<DebugProtocol.VariablesResponse> {403throw new Error('Method not implemented.');404}405evaluate(expression: string, frameId: number, context?: string): Promise<DebugProtocol.EvaluateResponse> {406throw new Error('Method not implemented.');407}408restartFrame(frameId: number, threadId: number): Promise<void> {409throw new Error('Method not implemented.');410}411next(threadId: number, granularity?: DebugProtocol.SteppingGranularity): Promise<void> {412throw new Error('Method not implemented.');413}414stepIn(threadId: number, targetId?: number, granularity?: DebugProtocol.SteppingGranularity): Promise<void> {415throw new Error('Method not implemented.');416}417stepOut(threadId: number, granularity?: DebugProtocol.SteppingGranularity): Promise<void> {418throw new Error('Method not implemented.');419}420stepBack(threadId: number, granularity?: DebugProtocol.SteppingGranularity): Promise<void> {421throw new Error('Method not implemented.');422}423continue(threadId: number): Promise<void> {424throw new Error('Method not implemented.');425}426reverseContinue(threadId: number): Promise<void> {427throw new Error('Method not implemented.');428}429pause(threadId: number): Promise<void> {430throw new Error('Method not implemented.');431}432terminateThreads(threadIds: number[]): Promise<void> {433throw new Error('Method not implemented.');434}435setVariable(variablesReference: number, name: string, value: string): Promise<DebugProtocol.SetVariableResponse> {436throw new Error('Method not implemented.');437}438setExpression(frameId: number, expression: string, value: string): Promise<DebugProtocol.SetExpressionResponse | undefined> {439throw new Error('Method not implemented.');440}441loadSource(resource: uri): Promise<DebugProtocol.SourceResponse> {442throw new Error('Method not implemented.');443}444disassemble(memoryReference: string, offset: number, instructionOffset: number, instructionCount: number): Promise<DebugProtocol.DisassembledInstruction[] | undefined> {445throw new Error('Method not implemented.');446}447448terminate(restart = false): Promise<void> {449throw new Error('Method not implemented.');450}451disconnect(restart = false): Promise<void> {452throw new Error('Method not implemented.');453}454455gotoTargets(source: DebugProtocol.Source, line: number, column?: number | undefined): Promise<DebugProtocol.GotoTargetsResponse> {456throw new Error('Method not implemented.');457}458goto(threadId: number, targetId: number): Promise<DebugProtocol.GotoResponse> {459throw new Error('Method not implemented.');460}461resolveLocationReference(locationReference: number): Promise<IDebugLocationReferenced> {462throw new Error('Method not implemented.');463}464}465466export class MockRawSession {467468capabilities: DebugProtocol.Capabilities = {};469disconnected = false;470sessionLengthInSeconds: number = 0;471472readyForBreakpoints = true;473emittedStopped = true;474475getLengthInSeconds(): number {476return 100;477}478479stackTrace(args: DebugProtocol.StackTraceArguments): Promise<DebugProtocol.StackTraceResponse> {480return Promise.resolve({481seq: 1,482type: 'response',483request_seq: 1,484success: true,485command: 'stackTrace',486body: {487stackFrames: [{488id: 1,489name: 'mock',490line: 5,491column: 6492}]493}494});495}496497exceptionInfo(args: DebugProtocol.ExceptionInfoArguments): Promise<DebugProtocol.ExceptionInfoResponse> {498throw new Error('not implemented');499}500501launchOrAttach(args: IConfig): Promise<DebugProtocol.Response> {502throw new Error('not implemented');503}504505scopes(args: DebugProtocol.ScopesArguments): Promise<DebugProtocol.ScopesResponse> {506throw new Error('not implemented');507}508509variables(args: DebugProtocol.VariablesArguments): Promise<DebugProtocol.VariablesResponse> {510throw new Error('not implemented');511}512513evaluate(args: DebugProtocol.EvaluateArguments): Promise<DebugProtocol.EvaluateResponse> {514return Promise.resolve(null!);515}516517custom(request: string, args: any): Promise<DebugProtocol.Response> {518throw new Error('not implemented');519}520521terminate(restart = false): Promise<DebugProtocol.TerminateResponse> {522throw new Error('not implemented');523}524525disconnect(restart?: boolean): Promise<any> {526throw new Error('not implemented');527}528529threads(): Promise<DebugProtocol.ThreadsResponse> {530throw new Error('not implemented');531}532533stepIn(args: DebugProtocol.StepInArguments): Promise<DebugProtocol.StepInResponse> {534throw new Error('not implemented');535}536537stepOut(args: DebugProtocol.StepOutArguments): Promise<DebugProtocol.StepOutResponse> {538throw new Error('not implemented');539}540541stepBack(args: DebugProtocol.StepBackArguments): Promise<DebugProtocol.StepBackResponse> {542throw new Error('not implemented');543}544545continue(args: DebugProtocol.ContinueArguments): Promise<DebugProtocol.ContinueResponse> {546throw new Error('not implemented');547}548549reverseContinue(args: DebugProtocol.ReverseContinueArguments): Promise<DebugProtocol.ReverseContinueResponse> {550throw new Error('not implemented');551}552553pause(args: DebugProtocol.PauseArguments): Promise<DebugProtocol.PauseResponse> {554throw new Error('not implemented');555}556557terminateThreads(args: DebugProtocol.TerminateThreadsArguments): Promise<DebugProtocol.TerminateThreadsResponse> {558throw new Error('not implemented');559}560561setVariable(args: DebugProtocol.SetVariableArguments): Promise<DebugProtocol.SetVariableResponse> {562throw new Error('not implemented');563}564565restartFrame(args: DebugProtocol.RestartFrameArguments): Promise<DebugProtocol.RestartFrameResponse> {566throw new Error('not implemented');567}568569completions(args: DebugProtocol.CompletionsArguments): Promise<DebugProtocol.CompletionsResponse> {570throw new Error('not implemented');571}572573next(args: DebugProtocol.NextArguments): Promise<DebugProtocol.NextResponse> {574throw new Error('not implemented');575}576577source(args: DebugProtocol.SourceArguments): Promise<DebugProtocol.SourceResponse> {578throw new Error('not implemented');579}580581loadedSources(args: DebugProtocol.LoadedSourcesArguments): Promise<DebugProtocol.LoadedSourcesResponse> {582throw new Error('not implemented');583}584585setBreakpoints(args: DebugProtocol.SetBreakpointsArguments): Promise<DebugProtocol.SetBreakpointsResponse> {586throw new Error('not implemented');587}588589setFunctionBreakpoints(args: DebugProtocol.SetFunctionBreakpointsArguments): Promise<DebugProtocol.SetFunctionBreakpointsResponse> {590throw new Error('not implemented');591}592593setExceptionBreakpoints(args: DebugProtocol.SetExceptionBreakpointsArguments): Promise<DebugProtocol.SetExceptionBreakpointsResponse> {594throw new Error('not implemented');595}596597readonly onDidStop: Event<DebugProtocol.StoppedEvent> = null!;598}599600export class MockDebugAdapter extends AbstractDebugAdapter {601private seq = 0;602603private pendingResponses = new Map<string, DeferredPromise<DebugProtocol.Response>>();604605startSession(): Promise<void> {606return Promise.resolve();607}608609stopSession(): Promise<void> {610return Promise.resolve();611}612613sendMessage(message: DebugProtocol.ProtocolMessage): void {614if (message.type === 'request') {615setTimeout(() => {616const request = message as DebugProtocol.Request;617switch (request.command) {618case 'evaluate':619this.evaluate(request, request.arguments);620return;621}622this.sendResponseBody(request, {});623return;624}, 0);625} else if (message.type === 'response') {626const response = message as DebugProtocol.Response;627if (this.pendingResponses.has(response.command)) {628this.pendingResponses.get(response.command)!.complete(response);629}630}631}632633sendResponseBody(request: DebugProtocol.Request, body: any) {634const response: DebugProtocol.Response = {635seq: ++this.seq,636type: 'response',637request_seq: request.seq,638command: request.command,639success: true,640body641};642this.acceptMessage(response);643}644645sendEventBody(event: string, body: any) {646const response: DebugProtocol.Event = {647seq: ++this.seq,648type: 'event',649event,650body651};652this.acceptMessage(response);653}654655waitForResponseFromClient(command: string): Promise<DebugProtocol.Response> {656const deferred = new DeferredPromise<DebugProtocol.Response>();657if (this.pendingResponses.has(command)) {658return this.pendingResponses.get(command)!.p;659}660661this.pendingResponses.set(command, deferred);662return deferred.p;663}664665sendRequestBody(command: string, args: any) {666const response: DebugProtocol.Request = {667seq: ++this.seq,668type: 'request',669command,670arguments: args671};672this.acceptMessage(response);673}674675evaluate(request: DebugProtocol.Request, args: DebugProtocol.EvaluateArguments) {676if (args.expression.indexOf('before.') === 0) {677this.sendEventBody('output', { output: args.expression });678}679680this.sendResponseBody(request, {681result: '=' + args.expression,682variablesReference: 0683});684685if (args.expression.indexOf('after.') === 0) {686this.sendEventBody('output', { output: args.expression });687}688}689}690691export class MockDebugStorage extends DebugStorage {692693constructor(storageService: IStorageService) {694super(storageService, undefined as any, undefined as any, new NullLogService());695}696}697698699