public void InitializeAfterFork(Inferior inferior)
        {
            Lock();
            try {
                int[] indices = new int [index_hash.Count];
                index_hash.Keys.CopyTo(indices, 0);

                for (int i = 0; i < indices.Length; i++)
                {
                    int              idx   = indices [i];
                    BreakpointEntry  entry = (BreakpointEntry)index_hash [idx];
                    SourceBreakpoint bpt   = entry.Handle.Breakpoint as SourceBreakpoint;

                    if (!entry.Handle.Breakpoint.ThreadGroup.IsGlobal)
                    {
                        try {
                            inferior.RemoveBreakpoint(idx);
                        } catch (Exception ex) {
                            Report.Error("Removing breakpoint {0} failed: {1}",
                                         idx, ex);
                        }
                    }
                }
            } finally {
                Unlock();
            }
        }
Beispiel #2
0
        protected async Task HandleSetBreakpointsRequest(
            SetBreakpointsRequestArguments setBreakpointsParams,
            RequestContext <SetBreakpointsResponseBody> requestContext)
        {
            ScriptFile scriptFile;

            // Fix for issue #195 - user can change name of file outside of VSCode in which case
            // VSCode sends breakpoint requests with the original filename that doesn't exist anymore.
            try
            {
                scriptFile = editorSession.Workspace.GetFile(setBreakpointsParams.Source.Path);
            }
            catch (FileNotFoundException)
            {
                Logger.Write(
                    LogLevel.Warning,
                    $"Attempted to set breakpoints on a non-existing file: {setBreakpointsParams.Source.Path}");

                var srcBreakpoints = setBreakpointsParams.Breakpoints
                                     .Select(srcBkpt => Protocol.DebugAdapter.Breakpoint.Create(
                                                 srcBkpt, setBreakpointsParams.Source.Path, "Source does not exist, breakpoint not set."));

                // Return non-verified breakpoint message.
                await requestContext.SendResult(
                    new SetBreakpointsResponseBody {
                    Breakpoints = srcBreakpoints.ToArray()
                });

                return;
            }

            var breakpointDetails = new BreakpointDetails[setBreakpointsParams.Breakpoints.Length];

            for (int i = 0; i < breakpointDetails.Length; i++)
            {
                SourceBreakpoint srcBreakpoint = setBreakpointsParams.Breakpoints[i];
                breakpointDetails[i] = BreakpointDetails.Create(
                    scriptFile.FilePath,
                    srcBreakpoint.Line,
                    srcBreakpoint.Column,
                    srcBreakpoint.Condition);
            }

            BreakpointDetails[] breakpoints =
                await editorSession.DebugService.SetLineBreakpoints(
                    scriptFile,
                    breakpointDetails);

            await requestContext.SendResult(
                new SetBreakpointsResponseBody
            {
                Breakpoints =
                    breakpoints
                    .Select(Protocol.DebugAdapter.Breakpoint.Create)
                    .ToArray()
            });
        }
Beispiel #3
0
        void RemoveBreakpoint(SourceBreakpoint breakpoint)
        {
            RemoteTreeNode node = (RemoteTreeNode)breakpointToTreeNode[breakpoint];

            if (node != null)
            {
                node.Remove();
            }

            breakpointToTreeNode.Remove(breakpoint);
        }
Beispiel #4
0
        void UpdateBreakpoint(SourceBreakpoint breakpoint)
        {
            RemoteTreeNode node = (RemoteTreeNode)breakpointToTreeNode[breakpoint];

            if (node == null)
            {
                node = RootNode.AppendNode();
                breakpointToTreeNode.Add(breakpoint, node);
            }

            node.SetValue(ColumnLocation, new SourceCodeLocation(breakpoint.Location));
            node.SetValue(ColumnImage, breakpoint.IsEnabled && breakpoint.IsActivated ? Pixmaps.Breakpoint : Pixmaps.BreakpointDisabled);
            node.SetValue(ColumnID, breakpoint.Index);
            node.SetValue(ColumnEnabled, breakpoint.IsEnabled ? "Yes" : "No");
            node.SetValue(ColumnActivated, breakpoint.IsActivated ? "Yes" : "No");
            node.SetValue(ColumnThreadGroup, breakpoint.ThreadGroup != null ? breakpoint.ThreadGroup.Name : "global");
            node.SetValue(ColumnName, breakpoint.Name);
        }
Beispiel #5
0
        public static Breakpoint CreateBreakpoint(
            SourceBreakpoint sourceBreakpoint,
            string source,
            string message,
            bool verified = false)
        {
            Validate.IsNotNull(nameof(sourceBreakpoint), sourceBreakpoint);
            Validate.IsNotNull(nameof(source), source);
            Validate.IsNotNull(nameof(message), message);

            return new Breakpoint
            {
                Verified = verified,
                Message = message,
                Source = new Source { Path = source },
                Line = sourceBreakpoint.Line,
                Column = sourceBreakpoint.Column
            };
        }
        protected async Task HandleSetBreakpointsRequestAsync(
            SetBreakpointsRequestArguments setBreakpointsParams,
            RequestContext <SetBreakpointsResponseBody> requestContext)
        {
            ScriptFile scriptFile = null;

            // When you set a breakpoint in the right pane of a Git diff window on a PS1 file,
            // the Source.Path comes through as Untitled-X. That's why we check for IsUntitledPath.
            if (!ScriptFile.IsUntitledPath(setBreakpointsParams.Source.Path) &&
                !_editorSession.Workspace.TryGetFile(
                    setBreakpointsParams.Source.Path,
                    out scriptFile))
            {
                string message        = _noDebug ? string.Empty : "Source file could not be accessed, breakpoint not set.";
                var    srcBreakpoints = setBreakpointsParams.Breakpoints
                                        .Select(srcBkpt => Protocol.DebugAdapter.Breakpoint.Create(
                                                    srcBkpt, setBreakpointsParams.Source.Path, message, verified: _noDebug));

                // Return non-verified breakpoint message.
                await requestContext.SendResultAsync(
                    new SetBreakpointsResponseBody {
                    Breakpoints = srcBreakpoints.ToArray()
                });

                return;
            }

            // Verify source file is a PowerShell script file.
            string fileExtension = Path.GetExtension(scriptFile?.FilePath ?? "")?.ToLower();

            if (string.IsNullOrEmpty(fileExtension) || ((fileExtension != ".ps1") && (fileExtension != ".psm1")))
            {
                Logger.Write(
                    LogLevel.Warning,
                    $"Attempted to set breakpoints on a non-PowerShell file: {setBreakpointsParams.Source.Path}");

                string message = _noDebug ? string.Empty : "Source is not a PowerShell script, breakpoint not set.";

                var srcBreakpoints = setBreakpointsParams.Breakpoints
                                     .Select(srcBkpt => Protocol.DebugAdapter.Breakpoint.Create(
                                                 srcBkpt, setBreakpointsParams.Source.Path, message, verified: _noDebug));

                // Return non-verified breakpoint message.
                await requestContext.SendResultAsync(
                    new SetBreakpointsResponseBody
                {
                    Breakpoints = srcBreakpoints.ToArray()
                });

                return;
            }

            // At this point, the source file has been verified as a PowerShell script.
            var breakpointDetails = new BreakpointDetails[setBreakpointsParams.Breakpoints.Length];

            for (int i = 0; i < breakpointDetails.Length; i++)
            {
                SourceBreakpoint srcBreakpoint = setBreakpointsParams.Breakpoints[i];
                breakpointDetails[i] = BreakpointDetails.Create(
                    scriptFile.FilePath,
                    srcBreakpoint.Line,
                    srcBreakpoint.Column,
                    srcBreakpoint.Condition,
                    srcBreakpoint.HitCondition);
            }

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

                try
                {
                    updatedBreakpointDetails =
                        await _editorSession.DebugService.SetLineBreakpointsAsync(
                            scriptFile,
                            breakpointDetails);
                }
                catch (Exception e)
                {
                    // Log whatever the error is
                    Logger.WriteException($"Caught error while setting breakpoints in SetBreakpoints handler for file {scriptFile?.FilePath}", e);
                }
                finally
                {
                    _setBreakpointInProgress = false;
                }
            }

            await requestContext.SendResultAsync(
                new SetBreakpointsResponseBody {
                Breakpoints =
                    updatedBreakpointDetails
                    .Select(Protocol.DebugAdapter.Breakpoint.Create)
                    .ToArray()
            });
        }
        protected async Task HandleSetBreakpointsRequest(
            SetBreakpointsRequestArguments setBreakpointsParams,
            RequestContext <SetBreakpointsResponseBody> requestContext)
        {
            ScriptFile scriptFile = null;

            // Fix for issue #195 - user can change name of file outside of VSCode in which case
            // VSCode sends breakpoint requests with the original filename that doesn't exist anymore.
            try
            {
                // When you set a breakpoint in the right pane of a Git diff window on a PS1 file,
                // the Source.Path comes through as Untitled-X.
                if (!ScriptFile.IsUntitledPath(setBreakpointsParams.Source.Path))
                {
                    scriptFile = editorSession.Workspace.GetFile(setBreakpointsParams.Source.Path);
                }
            }
            catch (Exception e) when(
                e is FileNotFoundException ||
                e is DirectoryNotFoundException ||
                e is IOException ||
                e is NotSupportedException ||
                e is PathTooLongException ||
                e is SecurityException ||
                e is UnauthorizedAccessException)
            {
                Logger.WriteException(
                    $"Failed to set breakpoint on file: {setBreakpointsParams.Source.Path}",
                    e);

                string message        = this.noDebug ? string.Empty : "Source file could not be accessed, breakpoint not set - " + e.Message;
                var    srcBreakpoints = setBreakpointsParams.Breakpoints
                                        .Select(srcBkpt => Protocol.DebugAdapter.Breakpoint.Create(
                                                    srcBkpt, setBreakpointsParams.Source.Path, message, verified: this.noDebug));

                // Return non-verified breakpoint message.
                await requestContext.SendResult(
                    new SetBreakpointsResponseBody {
                    Breakpoints = srcBreakpoints.ToArray()
                });

                return;
            }

            // Verify source file is a PowerShell script file.
            string fileExtension = Path.GetExtension(scriptFile?.FilePath ?? "")?.ToLower();

            if (string.IsNullOrEmpty(fileExtension) || ((fileExtension != ".ps1") && (fileExtension != ".psm1")))
            {
                Logger.Write(
                    LogLevel.Warning,
                    $"Attempted to set breakpoints on a non-PowerShell file: {setBreakpointsParams.Source.Path}");

                string message = this.noDebug ? string.Empty : "Source is not a PowerShell script, breakpoint not set.";

                var srcBreakpoints = setBreakpointsParams.Breakpoints
                                     .Select(srcBkpt => Protocol.DebugAdapter.Breakpoint.Create(
                                                 srcBkpt, setBreakpointsParams.Source.Path, message, verified: this.noDebug));

                // Return non-verified breakpoint message.
                await requestContext.SendResult(
                    new SetBreakpointsResponseBody
                {
                    Breakpoints = srcBreakpoints.ToArray()
                });

                return;
            }

            // At this point, the source file has been verified as a PowerShell script.
            var breakpointDetails = new BreakpointDetails[setBreakpointsParams.Breakpoints.Length];

            for (int i = 0; i < breakpointDetails.Length; i++)
            {
                SourceBreakpoint srcBreakpoint = setBreakpointsParams.Breakpoints[i];
                breakpointDetails[i] = BreakpointDetails.Create(
                    scriptFile.FilePath,
                    srcBreakpoint.Line,
                    srcBreakpoint.Column,
                    srcBreakpoint.Condition,
                    srcBreakpoint.HitCondition);
            }

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

                try
                {
                    updatedBreakpointDetails =
                        await editorSession.DebugService.SetLineBreakpoints(
                            scriptFile,
                            breakpointDetails);
                }
                catch (Exception e)
                {
                    // Log whatever the error is
                    Logger.WriteException($"Caught error while setting breakpoints in SetBreakpoints handler for file {scriptFile?.FilePath}", e);
                }
                finally
                {
                    this.setBreakpointInProgress = false;
                }
            }

            await requestContext.SendResult(
                new SetBreakpointsResponseBody {
                Breakpoints =
                    updatedBreakpointDetails
                    .Select(Protocol.DebugAdapter.Breakpoint.Create)
                    .ToArray()
            });
        }
Beispiel #8
0
        protected async Task HandleSetBreakpointsRequest(
            SetBreakpointsRequestArguments setBreakpointsParams,
            RequestContext <SetBreakpointsResponseBody> requestContext)
        {
            ScriptFile scriptFile = null;

            // Fix for issue #195 - user can change name of file outside of VSCode in which case
            // VSCode sends breakpoint requests with the original filename that doesn't exist anymore.
            try
            {
                scriptFile = editorSession.Workspace.GetFile(setBreakpointsParams.Source.Path);
            }
            catch (Exception e) when(e is FileNotFoundException || e is DirectoryNotFoundException)
            {
                Logger.Write(
                    LogLevel.Warning,
                    $"Attempted to set breakpoints on a non-existing file: {setBreakpointsParams.Source.Path}");

                string message = this.noDebug ? string.Empty : "Source does not exist, breakpoint not set.";

                var srcBreakpoints = setBreakpointsParams.Breakpoints
                                     .Select(srcBkpt => Protocol.DebugAdapter.Breakpoint.Create(
                                                 srcBkpt, setBreakpointsParams.Source.Path, message, verified: this.noDebug));

                // Return non-verified breakpoint message.
                await requestContext.SendResult(
                    new SetBreakpointsResponseBody {
                    Breakpoints = srcBreakpoints.ToArray()
                });

                return;
            }

            var breakpointDetails = new BreakpointDetails[setBreakpointsParams.Breakpoints.Length];

            for (int i = 0; i < breakpointDetails.Length; i++)
            {
                SourceBreakpoint srcBreakpoint = setBreakpointsParams.Breakpoints[i];
                breakpointDetails[i] = BreakpointDetails.Create(
                    scriptFile.FilePath,
                    srcBreakpoint.Line,
                    srcBreakpoint.Column,
                    srcBreakpoint.Condition,
                    srcBreakpoint.HitCondition);
            }

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

                try
                {
                    updatedBreakpointDetails =
                        await editorSession.DebugService.SetLineBreakpoints(
                            scriptFile,
                            breakpointDetails);
                }
                catch (Exception e)
                {
                    // Log whatever the error is
                    Logger.WriteException("Caught error while setting breakpoints in SetBreakpoints handler", e);
                }
                finally
                {
                    this.setBreakpointInProgress = false;
                }
            }

            await requestContext.SendResult(
                new SetBreakpointsResponseBody {
                Breakpoints =
                    updatedBreakpointDetails
                    .Select(Protocol.DebugAdapter.Breakpoint.Create)
                    .ToArray()
            });
        }
 public Row(Source source, SourceBreakpoint sourceBreakpoint)
 {
     Source           = source;
     SourceBreakpoint = sourceBreakpoint;
 }