コード例 #1
0
        protected async Task HandleSetFunctionBreakpointsRequest(
            SetFunctionBreakpointsRequestArguments setBreakpointsParams,
            RequestContext <SetBreakpointsResponseBody> requestContext)
        {
            var breakpointDetails = new CommandBreakpointDetails[setBreakpointsParams.Breakpoints.Length];

            for (int i = 0; i < breakpointDetails.Length; i++)
            {
                FunctionBreakpoint funcBreakpoint = setBreakpointsParams.Breakpoints[i];
                breakpointDetails[i] = CommandBreakpointDetails.Create(
                    funcBreakpoint.Name,
                    funcBreakpoint.Condition);
            }

            // If this is a "run without debugging (Ctrl+F5)" session ignore requests to set breakpoints.
            CommandBreakpointDetails[] updatedBreakpointDetails = breakpointDetails;
            if (!this.noDebug)
            {
                updatedBreakpointDetails =
                    await editorSession.DebugService.SetCommandBreakpoints(
                        breakpointDetails);
            }

            await requestContext.SendResult(
                new SetBreakpointsResponseBody {
                Breakpoints =
                    updatedBreakpointDetails
                    .Select(Protocol.DebugAdapter.Breakpoint.Create)
                    .ToArray()
            });
        }
コード例 #2
0
        // This regression test asserts that `ExecuteScriptWithArgsAsync` works for both script
        // files and, in this case, in-line scripts (commands). The bug was that the cwd was
        // erroneously prepended when the script argument was a command.
        public async Task DebuggerAcceptsInlineScript()
        {
            await this.debugService.SetCommandBreakpointsAsync(
                new[] { CommandBreakpointDetails.Create("Get-Random") }).ConfigureAwait(false);

            Task executeTask =
                this.powerShellContext.ExecuteScriptWithArgsAsync(
                    "Get-Random", string.Join(" ", "-Maximum", "100"));

            await this.AssertDebuggerStopped("", 1).ConfigureAwait(false);

            this.debugService.Continue();
            await executeTask.ConfigureAwait(false);

            StackFrameDetails[] stackFrames = debugService.GetStackFrames();
            Assert.Equal(StackFrameDetails.NoFileScriptPath, stackFrames[0].ScriptPath);

            VariableDetailsBase[] variables =
                debugService.GetVariables(stackFrames[0].LocalVariables.Id);

            var var = variables.FirstOrDefault(v => v.Name == "$Error");

            Assert.NotNull(var);
            Assert.True(var.IsExpandable);
            Assert.Equal("[ArrayList: 0]", var.ValueString);
        }
コード例 #3
0
        public async Task DebuggerSetsAndClearsFunctionBreakpoints()
        {
            CommandBreakpointDetails[] breakpoints =
                await this.debugService.SetCommandBreakpointsAsync(
                    new[] {
                CommandBreakpointDetails.Create("Write-Host"),
                CommandBreakpointDetails.Create("Get-Date")
            }).ConfigureAwait(false);

            Assert.Equal(2, breakpoints.Length);
            Assert.Equal("Write-Host", breakpoints[0].Name);
            Assert.Equal("Get-Date", breakpoints[1].Name);

            breakpoints =
                await this.debugService.SetCommandBreakpointsAsync(
                    new[] { CommandBreakpointDetails.Create("Get-Host") }).ConfigureAwait(false);

            Assert.Single(breakpoints);
            Assert.Equal("Get-Host", breakpoints[0].Name);

            breakpoints =
                await this.debugService.SetCommandBreakpointsAsync(
                    Array.Empty <CommandBreakpointDetails>()).ConfigureAwait(false);

            Assert.Empty(breakpoints);

            // Abort debugger
            this.debugService.Abort();
        }
コード例 #4
0
        public async Task DebuggerSetsAndClearsFunctionBreakpoints()
        {
            CommandBreakpointDetails[] breakpoints =
                await this.debugService.SetCommandBreakpoints(
                    new[] {
                CommandBreakpointDetails.Create("Write-Host"),
                CommandBreakpointDetails.Create("Get-Date")
            });

            Assert.Equal(2, breakpoints.Length);
            Assert.Equal("Write-Host", breakpoints[0].Name);
            Assert.Equal("Get-Date", breakpoints[1].Name);

            breakpoints =
                await this.debugService.SetCommandBreakpoints(
                    new[] { CommandBreakpointDetails.Create("Get-Host") });

            Assert.Equal(1, breakpoints.Length);
            Assert.Equal("Get-Host", breakpoints[0].Name);

            breakpoints =
                await this.debugService.SetCommandBreakpoints(
                    new CommandBreakpointDetails[] {});

            Assert.Equal(0, breakpoints.Length);
        }
コード例 #5
0
        protected async Task HandleSetFunctionBreakpointsRequest(
            SetFunctionBreakpointsRequestArguments setBreakpointsParams,
            RequestContext <SetBreakpointsResponseBody> requestContext)
        {
            var breakpointDetails = new CommandBreakpointDetails[setBreakpointsParams.Breakpoints.Length];

            for (int i = 0; i < breakpointDetails.Length; i++)
            {
                FunctionBreakpoint funcBreakpoint = setBreakpointsParams.Breakpoints[i];
                breakpointDetails[i] = CommandBreakpointDetails.Create(
                    funcBreakpoint.Name,
                    funcBreakpoint.Condition);
            }

            CommandBreakpointDetails[] breakpoints =
                await editorSession.DebugService.SetCommandBreakpoints(
                    breakpointDetails);

            await requestContext.SendResult(
                new SetBreakpointsResponseBody {
                Breakpoints =
                    breakpoints
                    .Select(Protocol.DebugAdapter.Breakpoint.Create)
                    .ToArray()
            });
        }
コード例 #6
0
        public static Breakpoint Create(
            CommandBreakpointDetails breakpointDetails)
        {
            Validate.IsNotNull(nameof(breakpointDetails), breakpointDetails);

            return(new Breakpoint {
                Verified = breakpointDetails.Verified,
                Message = breakpointDetails.Message
            });
        }
コード例 #7
0
        protected async Task HandleSetFunctionBreakpointsRequestAsync(
            SetFunctionBreakpointsRequestArguments setBreakpointsParams,
            RequestContext <SetBreakpointsResponseBody> requestContext)
        {
            var breakpointDetails = new CommandBreakpointDetails[setBreakpointsParams.Breakpoints.Length];

            for (int i = 0; i < breakpointDetails.Length; i++)
            {
                FunctionBreakpoint funcBreakpoint = setBreakpointsParams.Breakpoints[i];
                breakpointDetails[i] = CommandBreakpointDetails.Create(
                    funcBreakpoint.Name,
                    funcBreakpoint.Condition,
                    funcBreakpoint.HitCondition);
            }

            // If this is a "run without debugging (Ctrl+F5)" session ignore requests to set breakpoints.
            CommandBreakpointDetails[] updatedBreakpointDetails = breakpointDetails;
            if (!_noDebug)
            {
                _setBreakpointInProgress = true;

                try
                {
                    updatedBreakpointDetails =
                        await _editorSession.DebugService.SetCommandBreakpointsAsync(
                            breakpointDetails);
                }
                catch (Exception e)
                {
                    // Log whatever the error is
                    Logger.WriteException($"Caught error while setting command breakpoints", e);
                }
                finally
                {
                    _setBreakpointInProgress = false;
                }
            }

            await requestContext.SendResultAsync(
                new SetBreakpointsResponseBody {
                Breakpoints =
                    updatedBreakpointDetails
                    .Select(Protocol.DebugAdapter.Breakpoint.Create)
                    .ToArray()
            });
        }
コード例 #8
0
        public async Task DebuggerStopsOnFunctionBreakpoints()
        {
            CommandBreakpointDetails[] breakpoints =
                await this.debugService.SetCommandBreakpoints(
                    new[] {
                CommandBreakpointDetails.Create("Write-Host")
            });

            await this.AssertStateChange(PowerShellContextState.Ready);

            Task executeTask =
                this.powerShellContext.ExecuteScriptWithArgs(
                    this.debugScriptFile.FilePath);

            // Wait for function breakpoint to hit
            await this.AssertDebuggerStopped(this.debugScriptFile.FilePath, 6);

            StackFrameDetails[]   stackFrames = debugService.GetStackFrames();
            VariableDetailsBase[] variables   =
                debugService.GetVariables(stackFrames[0].LocalVariables.Id);

            // Verify the function breakpoint broke at Write-Host and $i is 1
            var i = variables.FirstOrDefault(v => v.Name == "$i");

            Assert.NotNull(i);
            Assert.False(i.IsExpandable);
            Assert.Equal("1", i.ValueString);

            // The function breakpoint should fire the next time through the loop.
            this.debugService.Continue();
            await this.AssertDebuggerStopped(this.debugScriptFile.FilePath, 6);

            stackFrames = debugService.GetStackFrames();
            variables   = debugService.GetVariables(stackFrames[0].LocalVariables.Id);

            // Verify the function breakpoint broke at Write-Host and $i is 1
            i = variables.FirstOrDefault(v => v.Name == "$i");
            Assert.NotNull(i);
            Assert.False(i.IsExpandable);
            Assert.Equal("2", i.ValueString);

            // Abort script execution early and wait for completion
            this.debugService.Abort();
            await executeTask;
        }
コード例 #9
0
        public async Task <SetFunctionBreakpointsResponse> Handle(SetFunctionBreakpointsArguments request, CancellationToken cancellationToken)
        {
            CommandBreakpointDetails[] breakpointDetails = request.Breakpoints
                                                           .Select((funcBreakpoint) => CommandBreakpointDetails.Create(
                                                                       funcBreakpoint.Name,
                                                                       funcBreakpoint.Condition,
                                                                       funcBreakpoint.HitCondition))
                                                           .ToArray();

            // If this is a "run without debugging (Ctrl+F5)" session ignore requests to set breakpoints.
            CommandBreakpointDetails[] updatedBreakpointDetails = breakpointDetails;
            if (!_debugStateService.NoDebug)
            {
                _debugStateService.SetBreakpointInProgress = true;

                try
                {
                    updatedBreakpointDetails =
                        await _debugService.SetCommandBreakpointsAsync(
                            breakpointDetails);
                }
                catch (Exception e)
                {
                    // Log whatever the error is
                    _logger.LogException($"Caught error while setting command breakpoints", e);
                }
                finally
                {
                    _debugStateService.SetBreakpointInProgress = false;
                }
            }

            return(new SetFunctionBreakpointsResponse
            {
                Breakpoints = updatedBreakpointDetails
                              .Select(LspDebugUtils.CreateBreakpoint)
                              .ToArray()
            });
        }