private void DebugService_DebuggerStopped(object sender, DebuggerStoppedEventArgs e)
        {
            // Provide the reason for why the debugger has stopped script execution.
            // See https://github.com/Microsoft/vscode/issues/3648
            // The reason is displayed in the breakpoints viewlet.  Some recommended reasons are:
            // "step", "breakpoint", "function breakpoint", "exception" and "pause".
            // We don't support exception breakpoints and for "pause", we can't distinguish
            // between stepping and the user pressing the pause/break button in the debug toolbar.
            string debuggerStoppedReason = "step";

            if (e.OriginalEvent.Breakpoints.Count > 0)
            {
                debuggerStoppedReason =
                    e.OriginalEvent.Breakpoints[0] is CommandBreakpoint
                        ? "function breakpoint"
                        : "breakpoint";
            }

            _debugAdapterServer.SendNotification(EventNames.Stopped,
                                                 new StoppedEvent
            {
                ThreadId = 1,
                Reason   = debuggerStoppedReason
            });
        }
        async void DebugService_DebuggerStoppedAsync(object sender, DebuggerStoppedEventArgs e)
        {
            // Provide the reason for why the debugger has stopped script execution.
            // See https://github.com/Microsoft/vscode/issues/3648
            // The reason is displayed in the breakpoints viewlet.  Some recommended reasons are:
            // "step", "breakpoint", "function breakpoint", "exception" and "pause".
            // We don't support exception breakpoints and for "pause", we can't distinguish
            // between stepping and the user pressing the pause/break button in the debug toolbar.
            string debuggerStoppedReason = "step";

            if (e.OriginalEvent.Breakpoints.Count > 0)
            {
                debuggerStoppedReason =
                    e.OriginalEvent.Breakpoints[0] is CommandBreakpoint
                        ? "function breakpoint"
                        : "breakpoint";
            }

            await _messageSender.SendEventAsync(
                StoppedEvent.Type,
                new StoppedEventBody
            {
                Source = new Source
                {
                    Path = e.ScriptPath,
                },
                ThreadId = 1,
                Reason   = debuggerStoppedReason
            });
        }
 void debugService_DebuggerStopped(object sender, DebuggerStoppedEventArgs e)
 {
     // We need to ensure this is run on a different thread than the one it's
     // called on because it can cause PowerShellContext.OnDebuggerStopped to
     // never hit the while loop.
     Task.Run(() => this.debuggerStoppedQueue.Enqueue(e));
 }
        private async Task AssertDebuggerPaused()
        {
            DebuggerStoppedEventArgs eventArgs =
                await this.debuggerStoppedQueue.DequeueAsync(new CancellationTokenSource(10000).Token).ConfigureAwait(false);

            Assert.Empty(eventArgs.OriginalEvent.Breakpoints);
        }
        public async Task AssertDebuggerPaused()
        {
            SynchronizationContext syncContext = SynchronizationContext.Current;

            DebuggerStoppedEventArgs eventArgs =
                await this.debuggerStoppedQueue.DequeueAsync(new CancellationTokenSource(5000).Token);

            Assert.Empty(eventArgs.OriginalEvent.Breakpoints);
        }
Ejemplo n.º 6
0
        public async Task AssertDebuggerPaused()
        {
            SynchronizationContext syncContext = SynchronizationContext.Current;

            DebuggerStoppedEventArgs eventArgs =
                await this.debuggerStoppedQueue.DequeueAsync();

            Assert.Equal(0, eventArgs.OriginalEvent.Breakpoints.Count);
        }
        private async Task AssertDebuggerStopped(
            string scriptPath,
            int lineNumber = -1)
        {
            DebuggerStoppedEventArgs eventArgs =
                await this.debuggerStoppedQueue.DequeueAsync(new CancellationTokenSource(10000).Token).ConfigureAwait(false);

            // TODO: Why does the casing of the path change? Specifically the Drive letter on Windows.
            Assert.Equal(scriptPath.ToLower(), eventArgs.ScriptPath.ToLower());
            if (lineNumber > -1)
            {
                Assert.Equal(lineNumber, eventArgs.LineNumber);
            }
        }
Ejemplo n.º 8
0
        public async Task AssertDebuggerStopped(
            string scriptPath,
            int lineNumber = -1)
        {
            SynchronizationContext syncContext = SynchronizationContext.Current;

            DebuggerStoppedEventArgs eventArgs =
                await this.debuggerStoppedQueue.DequeueAsync();

            Assert.Equal(scriptPath, eventArgs.ScriptPath);
            if (lineNumber > -1)
            {
                Assert.Equal(lineNumber, eventArgs.LineNumber);
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Debugger stopped handler
        /// </summary>
        /// <param name="e"></param>
        public void DebuggerStop(DebuggerStoppedEventArgs e)
        {
            Log.InfoFormat("Debugger stopped");
            try
            {
                if (e.OpenScript)
                {
                    OpenFileInVS(e.ScriptFullPath);
                }

                RefreshScopedVariables();
                RefreshCallStack();

                if (!BreakpointManager.ProcessLineBreakpoints(e.ScriptFullPath, e.Line, e.Column))
                {
                    if (DebuggerPaused != null)
                    {
                        var scriptLocation = new ScriptLocation(e.ScriptFullPath, e.Line, 0);

                        DebuggerPaused(this, new EventArgs <ScriptLocation>(scriptLocation));
                    }
                }
            }
            catch (DebugEngineInternalException dbgEx)
            {
                Log.Debug(dbgEx.Message);
                DebuggingService.SetDebuggerResumeAction(DebugEngineConstants.Debugger_Stop);

                IsDebuggingCommandReady = false;
            }
            catch (Exception ex)
            {
                Log.Debug(ex.Message);
                DebuggingService.SetDebuggerResumeAction(DebugEngineConstants.Debugger_Stop);

                IsDebuggingCommandReady = false;
                throw;
            }
            finally
            {
                Log.Debug("Waiting for debuggee to resume.");

                IsDebuggingCommandReady = true;
                RefreshPrompt();
            }
        }
 internal void TriggerDebuggerStopped(DebuggerStoppedEventArgs e)
 {
     DebugService_DebuggerStopped(null, e);
 }
Ejemplo n.º 11
0
 private void OnDebuggerResumed(object sender, DebuggerResumeAction e)
 {
     this.CurrentDebuggerStoppedEventArgs = null;
 }
Ejemplo n.º 12
0
        internal async void OnDebuggerStopAsync(object sender, DebuggerStopEventArgs e)
        {
            bool   noScriptName    = false;
            string localScriptPath = e.InvocationInfo.ScriptName;

            // If there's no ScriptName, get the "list" of the current source
            if (this.remoteFileManager != null && string.IsNullOrEmpty(localScriptPath))
            {
                // Get the current script listing and create the buffer
                PSCommand command = new PSCommand();
                command.AddScript($"list 1 {int.MaxValue}");

                IEnumerable <PSObject> scriptListingLines =
                    await this.powerShellContext.ExecuteCommandAsync <PSObject>(
                        command, false, false).ConfigureAwait(false);

                if (scriptListingLines != null)
                {
                    int linePrefixLength = 0;

                    string scriptListing =
                        string.Join(
                            Environment.NewLine,
                            scriptListingLines
                            .Select(o => DebugService.TrimScriptListingLine(o, ref linePrefixLength))
                            .Where(s => s != null));

                    this.temporaryScriptListingPath =
                        this.remoteFileManager.CreateTemporaryFile(
                            $"[{this.powerShellContext.CurrentRunspace.SessionDetails.ComputerName}] {TemporaryScriptFileName}",
                            scriptListing,
                            this.powerShellContext.CurrentRunspace);

                    localScriptPath =
                        this.temporaryScriptListingPath
                        ?? StackFrameDetails.NoFileScriptPath;

                    noScriptName = localScriptPath != null;
                }
                else
                {
                    this.logger.LogWarning($"Could not load script context");
                }
            }

            // Get call stack and variables.
            await this.FetchStackFramesAndVariablesAsync(
                noScriptName?localScriptPath : null).ConfigureAwait(false);

            // If this is a remote connection and the debugger stopped at a line
            // in a script file, get the file contents
            if (this.powerShellContext.CurrentRunspace.Location == RunspaceLocation.Remote &&
                this.remoteFileManager != null &&
                !noScriptName)
            {
                localScriptPath =
                    await this.remoteFileManager.FetchRemoteFileAsync(
                        e.InvocationInfo.ScriptName,
                        powerShellContext.CurrentRunspace).ConfigureAwait(false);
            }

            if (this.stackFrameDetails.Length > 0)
            {
                // Augment the top stack frame with details from the stop event

                if (this.invocationTypeScriptPositionProperty
                    .GetValue(e.InvocationInfo) is IScriptExtent scriptExtent)
                {
                    this.stackFrameDetails[0].StartLineNumber   = scriptExtent.StartLineNumber;
                    this.stackFrameDetails[0].EndLineNumber     = scriptExtent.EndLineNumber;
                    this.stackFrameDetails[0].StartColumnNumber = scriptExtent.StartColumnNumber;
                    this.stackFrameDetails[0].EndColumnNumber   = scriptExtent.EndColumnNumber;
                }
            }

            this.CurrentDebuggerStoppedEventArgs =
                new DebuggerStoppedEventArgs(
                    e,
                    this.powerShellContext.CurrentRunspace,
                    localScriptPath);

            // Notify the host that the debugger is stopped
            this.DebuggerStopped?.Invoke(
                sender,
                this.CurrentDebuggerStoppedEventArgs);
        }
Ejemplo n.º 13
0
 async void debugService_DebuggerStopped(object sender, DebuggerStoppedEventArgs e)
 {
     await this.debuggerStoppedQueue.EnqueueAsync(e);
 }
 internal void TriggerDebuggerStopped(DebuggerStoppedEventArgs e) => OnDebuggerStopped(null, e);
 /// <summary>
 /// Debugger stopped
 /// </summary>
 /// <param name="e">DebuggerStoppedEventArgs</param>
 public void DebuggerStopped(DebuggerStoppedEventArgs e)
 {
     Debugger.DebuggerStop(e);
 }