コード例 #1
0
        public override void VisitInvocationExpression(InvocationExpressionSyntax node)
        {
            string fileName = Path.GetFileName(node.SyntaxTree.FilePath);
            FileLinePositionSpan lineSpan = node.SyntaxTree.GetLineSpan(node.Span);
            int numLine = lineSpan.StartLinePosition.Line + 1;

            switch (node.Expression.ToString())
            {
            case "Label.Breakpoint":
                string name = node.ArgumentList.Arguments[0].Expression.ToString();
                // "name" -> name
                name = name.Trim(new char[] { '\"' });

                LineBreakpoint lbp = (LineBreakpoint)Activator.CreateInstance(TypeClassBP,
                                                                              name, fileName, numLine);

                TestLabelsInfo.Breakpoints.Add(name, lbp);
                break;

            case "Label.Checkpoint":
                string id      = node.ArgumentList.Arguments[0].Expression.ToString();
                string next_id = node.ArgumentList.Arguments[1].Expression.ToString();
                // "id" -> id
                id      = id.Trim(new char[] { '\"' });
                next_id = next_id.Trim(new char[] { '\"' });

                TestLabelsInfo.CheckPointInvokes.Add(
                    id, new Tuple <string, InvocationExpressionSyntax>(next_id, node));
                break;
            }
        }
コード例 #2
0
        public static bool WasStep(LineBreakpoint lbp)
        {
            Func <MIOutOfBandRecord, bool> filter = (record) => {
                if (!IsStoppedEvent(record))
                {
                    return(false);
                }

                var output = ((MIAsyncRecord)record).Output;
                var reason = (MIConst)output["reason"];
                if (reason.CString != "end-stepping-range")
                {
                    return(false);
                }

                var frame = (MITuple)output["frame"];
                var line  = ((MIConst)frame["line"]).Int;
                if (lbp.NumLine == line)
                {
                    return(true);
                }

                return(false);
            };

            return(MIDebugger.IsEventReceived(filter));
        }
コード例 #3
0
        /// <summary>
        /// Creates an instance of the BreakpointDetails class from a
        /// PowerShell Breakpoint object.
        /// </summary>
        /// <param name="breakpoint">The Breakpoint instance from which details will be taken.</param>
        /// <returns>A new instance of the BreakpointDetails class.</returns>
        public static BreakpointDetails Create(Breakpoint breakpoint)
        {
            Validate.IsNotNull("breakpoint", breakpoint);

            LineBreakpoint lineBreakpoint = breakpoint as LineBreakpoint;

            if (lineBreakpoint == null)
            {
                throw new ArgumentException(
                          "Unexpected breakpoint type: " + breakpoint.GetType().Name);
            }

            var breakpointDetails = new BreakpointDetails
            {
                Verified   = true,
                Source     = lineBreakpoint.Script,
                LineNumber = lineBreakpoint.Line,
                Condition  = lineBreakpoint.Action?.ToString()
            };

            if (lineBreakpoint.Column > 0)
            {
                breakpointDetails.ColumnNumber = lineBreakpoint.Column;
            }

            return(breakpointDetails);
        }
コード例 #4
0
ファイル: DebuggerMenu.cs プロジェクト: zertyuiop/FarNet
        void OnEdit(object sender, MenuEventArgs e)
        {
            if (!(_menu.SelectedData is Breakpoint bp) || string.IsNullOrEmpty(bp.Script))
            {
                e.Ignore = true;
                return;
            }

            _toStop = true;
            IEditor        editor = _editor;
            LineBreakpoint lbp    = bp as LineBreakpoint;

            // the target script is opened now
            if (editor != null && Kit.Equals(editor.FileName, bp.Script))
            {
                // it is a line breakpoint, go to line
                if (lbp != null)
                {
                    editor.GoToLine(lbp.Line - 1);
                    return;
                }

                return;
            }

            editor          = Far.Api.CreateEditor();
            editor.FileName = bp.Script;
            if (lbp != null)
            {
                editor.GoToLine(lbp.Line - 1);
            }

            editor.Open();
        }
コード例 #5
0
        /// <summary>
        /// Analyzes the text using each of the analyzers and returns
        /// their results as a series of runs.
        /// </summary>
        public void GenerateResults(TextAnalyzer textAnalyzer, out Run[] runs, out LineBreakpoint[] breakpoints)
        {
            // Initially start out with one result that covers the entire range.
            // This result will be subdivided by the analysis processes.
            LinkedRun initialRun = new LinkedRun()
            {
                nextRunIndex = 0,
                textStart    = 0,
                textLength   = text_.Length,
                bidiLevel    = (readingDirection_ == ReadingDirection.RightToLeft) ? 1 : 0
            };

            runs_ = new List <LinkedRun>();
            runs_.Add(initialRun);

            breakpoints_ = new List <LineBreakpoint>();

            textAnalyzer.AnalyzeLineBreakpoints(this, 0, text_.Length, this);
            textAnalyzer.AnalyzeBidi(this, 0, text_.Length, this);
            textAnalyzer.AnalyzeScript(this, 0, text_.Length, this);
            textAnalyzer.AnalyzeNumberSubstitution(this, 0, text_.Length, this);
            //Call each of the analyzers in sequence, recording their results.
            breakpoints = new LineBreakpoint[breakpoints_.Count];
            breakpoints_.CopyTo(breakpoints);

            // Resequence the resulting runs in order before returning to caller.
            runs = new Run[runs_.Count];
            int nextRunIndex = 0;

            for (int i = 0; i < runs_.Count; i++)
            {
                runs[i]      = runs_[nextRunIndex].AsRun;
                nextRunIndex = runs_[nextRunIndex].nextRunIndex;
            }
        }
コード例 #6
0
ファイル: Program.cs プロジェクト: viewizard/netcoredbg
        static void Main(string[] args)
        {
            Label.Checkpoint("init", "eval_test", () => {
                Context.Prepare();

                Context.WasEntryPointHit();

                LineBreakpoint lbp = (LineBreakpoint)DebuggeeInfo.Breakpoints["BREAK"];

                Assert.Equal(MIResultClass.Done,
                             Context.MIDebugger.Request("-break-insert -f " + lbp.FileName
                                                        + ":" + lbp.NumLine).Class);

                Assert.Equal(MIResultClass.Running,
                             Context.MIDebugger.Request("-exec-continue").Class);
            });

            Console.WriteLine("영어 출력이 아닌 테스트.");
            Console.WriteLine("测试非英语输出。");

            int 당신 = 1;

            당신++;                                                      Label.Breakpoint("BREAK");

            Label.Checkpoint("eval_test", "finish", () => {
                Context.WasBreakpointHit(DebuggeeInfo.Breakpoints["BREAK"]);

                var notDeclaredVariable =
                    Context.MIDebugger.Request(String.Format("-var-create - * \"{0}\"", "你"));
                Assert.Equal(MIResultClass.Error, notDeclaredVariable.Class);

                notDeclaredVariable =
                    Context.MIDebugger.Request(String.Format("-var-create - * \"{0}\"", "你 + 1"));
                Assert.Equal(MIResultClass.Error, notDeclaredVariable.Class);


                var notEnglishVariable =
                    Context.MIDebugger.Request(String.Format("-var-create - * \"{0}\"", "당신"));
                Assert.Equal(MIResultClass.Done, notEnglishVariable.Class);
                Assert.Equal("1", ((MIConst)notEnglishVariable["value"]).CString);

                notEnglishVariable =
                    Context.MIDebugger.Request(String.Format("-var-create - * \"{0}\"", "당신 + 11"));
                Assert.Equal(MIResultClass.Done, notEnglishVariable.Class);
                Assert.Equal("12", ((MIConst)notEnglishVariable["value"]).CString);

                Assert.Equal(MIResultClass.Running,
                             Context.MIDebugger.Request("-exec-continue").Class);
            });

            Label.Checkpoint("finish", "", () => {
                Context.WasExit();
                Context.DebuggerExit();
            });
        }
コード例 #7
0
        public void RemoveBreakpoint(int lineNumber)
        {
            var lineBreakpoint = new LineBreakpoint(lineNumber);

            if (!_breakpoints.Contains(lineBreakpoint))
            {
                return;
            }

            _breakpoints.Remove(lineBreakpoint);
        }
コード例 #8
0
        public void AddBreakpoint(int lineNumber)
        {
            if (_cachedScriptPath == null)
            {
                CacheRunbook();
            }

            var lineBreakpoint = new LineBreakpoint(lineNumber);

            // We can only have one breakpoint per line
            if (_breakpoints.Contains(lineBreakpoint))
            {
                return;
            }

            _breakpoints.Add(lineBreakpoint);
        }
コード例 #9
0
        /// <summary>
        /// Creates an instance of the BreakpointDetails class from a
        /// PowerShell Breakpoint object.
        /// </summary>
        /// <param name="breakpoint">The Breakpoint instance from which details will be taken.</param>
        /// <returns>A new instance of the BreakpointDetails class.</returns>
        public static BreakpointDetails Create(Breakpoint breakpoint)
        {
            Validate.IsNotNull("breakpoint", breakpoint);

            LineBreakpoint lineBreakpoint = breakpoint as LineBreakpoint;

            if (lineBreakpoint != null)
            {
                return(new BreakpointDetails
                {
                    LineNumber = lineBreakpoint.Line
                });
            }
            else
            {
                throw new ArgumentException(
                          "Expected breakpoint type:" + breakpoint.GetType().Name);
            }
        }
コード例 #10
0
        private void OnBreakpointUpdated(object sender, BreakpointUpdatedEventArgs e)
        {
            // This event callback also gets called when a CommandBreakpoint is modified.
            // Only execute the following code for LineBreakpoint so we can keep track
            // of which line breakpoints exist per script file.  We use this later when
            // we need to clear all breakpoints in a script file.  We do not need to do
            // this for CommandBreakpoint, as those span all script files.
            LineBreakpoint lineBreakpoint = e.Breakpoint as LineBreakpoint;

            if (lineBreakpoint != null)
            {
                List <Breakpoint> breakpoints;

                // Normalize the script filename for proper indexing
                string normalizedScriptName = lineBreakpoint.Script.ToLower();

                // Get the list of breakpoints for this file
                if (!this.breakpointsPerFile.TryGetValue(normalizedScriptName, out breakpoints))
                {
                    breakpoints = new List <Breakpoint>();
                    this.breakpointsPerFile.Add(
                        normalizedScriptName,
                        breakpoints);
                }

                // Add or remove the breakpoint based on the update type
                if (e.UpdateType == BreakpointUpdateType.Set)
                {
                    breakpoints.Add(e.Breakpoint);
                }
                else if (e.UpdateType == BreakpointUpdateType.Removed)
                {
                    breakpoints.Remove(e.Breakpoint);
                }
                else
                {
                    // TODO: Do I need to switch out instances for updated breakpoints?
                }
            }

            this.BreakpointUpdated?.Invoke(sender, e);
        }
コード例 #11
0
        private void ProcessRemoteDebuggingCommandResults(PSDataCollection <PSObject> output)
        {
            var pobj = output.FirstOrDefault();

            if (pobj != null && pobj.BaseObject is string)
            {
                _debugCommandOutput = (string)pobj.BaseObject;
            }
            else if (pobj != null && pobj.BaseObject is LineBreakpoint)
            {
                LineBreakpoint bp = (LineBreakpoint)pobj.BaseObject;
                if (bp != null)
                {
                    _psBreakpointTable.Add(
                        new PowerShellBreakpointRecord(
                            new PowerShellBreakpoint(bp.Script, bp.Line, bp.Column),
                            bp.Id));
                }
            }
        }
コード例 #12
0
        private void ProcessDebuggingCommandResults(Collection <PSObject> output)
        {
            if (output != null && output.Count > 0)
            {
                StringBuilder outputString = new StringBuilder();
                foreach (PSObject obj in output)
                {
                    if (obj != null)
                    {
                        outputString.AppendLine(obj.ToString());
                    }
                }

                if (_debugOutput)
                {
                    NotifyOutputString(outputString.ToString());
                }

                var pobj = output.FirstOrDefault();

                if (pobj != null && pobj.BaseObject is string)
                {
                    _debugCommandOutput = (string)pobj.BaseObject;
                }
                else if (pobj != null && pobj.BaseObject is LineBreakpoint)
                {
                    LineBreakpoint bp = (LineBreakpoint)pobj.BaseObject;
                    if (bp != null)
                    {
                        _psBreakpointTable.Add(
                            new PowerShellBreakpointRecord(
                                new PowerShellBreakpoint(bp.Script, bp.Line, bp.Column),
                                bp.Id));
                    }
                }
            }
        }
コード例 #13
0
ファイル: DebuggerMenu.cs プロジェクト: zertyuiop/FarNet
        void OnLineBreakpoint(object sender, EventArgs e)
        {
            if (_menu.Key.VirtualKeyCode != 0)
            {
                return;
            }

            string file = null;
            int    line = 0;

            LineBreakpoint bpFound = null;

            if (_editor != null)
            {
                // location
                file = _editor.FileName;
                line = _editor.Caret.Y + 1;

                // find
                foreach (PSObject o in _breakpoints)
                {
                    if (o.BaseObject is LineBreakpoint lbp && lbp.Action == null && line == lbp.Line && Kit.Equals(file, lbp.Script))
                    {
                        bpFound = lbp;
                        break;
                    }
                }

                // found?
                if (bpFound != null)
                {
                    switch (Far.Api.Message("Breakpoint exists",
                                            "Line breakpoint",
                                            MessageOptions.None,
                                            new string[] {
                        "&Remove",
                        bpFound.Enabled ? "&Disable" : "&Enable",
                        "&Modify",
                        "&Add",
                        "&Cancel"
                    }))
                    {
                    case 0:
                        A.RemoveBreakpoint(bpFound);
                        return;

                    case 1:
                        if (bpFound.Enabled)
                        {
                            A.DisableBreakpoint(bpFound);
                        }
                        else
                        {
                            A.InvokeCode("Enable-PSBreakpoint -Breakpoint $args[0]", bpFound);
                        }
                        return;

                    case 2:
                        break;

                    case 3:
                        bpFound = null;
                        break;

                    default:
                        return;
                    }
                }
            }

            // go
            BreakpointDialog ui = new BreakpointDialog(0, file, line);

            if (!ui.Show())
            {
                return;
            }

            // remove old
            if (bpFound != null)
            {
                A.RemoveBreakpoint(bpFound);
            }

            // set new
            A.SetBreakpoint(ui.Script, int.Parse(ui.Matter, null), ui.Action);
        }
コード例 #14
0
        protected bool FitText(ref ClusterPosition clusterStart, int textEnd, float maxWidth, out ClusterPosition clusterEnd)
        {
            // Fits as much text as possible into the given width,
            // using the clusters and advances returned by DWrite.

            ////////////////////////////////////////
            // Set the starting cluster to the starting text position,
            // and continue until we exceed the maximum width or hit
            // a hard break.
            ClusterPosition cluster            = clusterStart;
            ClusterPosition nextCluster        = clusterStart;
            int             validBreakPosition = cluster.textPosition;
            int             bestBreakPosition  = cluster.textPosition;
            float           textWidth          = 0;

            while (cluster.textPosition < textEnd)
            {
                // Use breakpoint information to find where we can safely break words.
                AdvanceClusterPosition(ref nextCluster);
                LineBreakpoint breakpoint = breakpoints_[nextCluster.textPosition - 1];

                // Check whether we exceeded the amount of text that can fit,
                // unless it's whitespace, which we allow to flow beyond the end.

                textWidth += GetClusterRangeWidth(ref cluster, ref nextCluster);
                if (textWidth > maxWidth && !breakpoint.IsWhitespace)
                {
                    // Want a minimum of one cluster.
                    if (validBreakPosition > clusterStart.textPosition)
                    {
                        break;
                    }
                }

                validBreakPosition = nextCluster.textPosition;

                // See if we can break after this character cluster, and if so,
                // mark it as the new potential break point.
                if (breakpoint.BreakConditionAfter != BreakCondition.MayNotBreak)
                {
                    bestBreakPosition = validBreakPosition;
                    if (breakpoint.BreakConditionAfter == BreakCondition.MustBreak)
                    {
                        break; // we have a hard return, so we've fit all we can.
                    }
                }
                cluster = nextCluster;
            }

            ////////////////////////////////////////
            // Want last best position that didn't break a word, but if that's not available,
            // fit at least one cluster (emergency line breaking).
            if (bestBreakPosition == clusterStart.textPosition)
            {
                bestBreakPosition = validBreakPosition;
            }

            SetClusterPosition(ref cluster, bestBreakPosition);

            clusterEnd = cluster;

            return(true);
        }
コード例 #15
0
ファイル: Program.cs プロジェクト: viewizard/netcoredbg
        static void Main(string[] args)
        {
            Label.Checkpoint("init", "values_test", () => {
                Context.Prepare();

                Context.WasEntryPointHit();

                LineBreakpoint lbp = (LineBreakpoint)DebuggeeInfo.Breakpoints["BREAK"];

                Assert.Equal(MIResultClass.Done,
                             Context.MIDebugger.Request("4-break-insert -f " + lbp.FileName
                                                        + ":" + lbp.NumLine).Class);

                Assert.Equal(MIResultClass.Running,
                             Context.MIDebugger.Request("5-exec-continue").Class);
            });

            decimal d              = 12345678901234567890123456m;
            decimal long_zero_dec  = 0.00000000000000000017M;
            decimal short_zero_dec = 0.17M;
            int     x              = 1; Label.Breakpoint("BREAK");

            Label.Checkpoint("values_test", "finish", () => {
                Context.WasBreakpointHit(DebuggeeInfo.Breakpoints["BREAK"]);

                var createDResult =
                    Context.MIDebugger.Request(String.Format("6-var-create - * \"{0}\"", "d"));
                Assert.Equal(MIResultClass.Done, createDResult.Class);

                string d_varName = ((MIConst)createDResult["name"]).CString;
                Assert.Equal("12345678901234567890123456", ((MIConst)createDResult["value"]).CString);
                Assert.Equal("d", ((MIConst)createDResult["exp"]).CString);
                Assert.Equal("0", ((MIConst)createDResult["numchild"]).CString);
                Assert.Equal("decimal", ((MIConst)createDResult["type"]).CString);


                var createLongZeroDecResult =
                    Context.MIDebugger.Request(String.Format("7-var-create 8 * \"{0}\"", "long_zero_dec"));
                Assert.Equal(MIResultClass.Done, createLongZeroDecResult.Class);

                Assert.Equal("0.00000000000000000017", ((MIConst)createLongZeroDecResult["value"]).CString);


                var createShortZeroDecResult =
                    Context.MIDebugger.Request(String.Format("8-var-create 8 * \"{0}\"", "short_zero_dec"));
                Assert.Equal(MIResultClass.Done, createShortZeroDecResult.Class);

                Assert.Equal("0.17", ((MIConst)createShortZeroDecResult["value"]).CString);


                var notDeclaredVariable =
                    Context.MIDebugger.Request(String.Format("-var-create - * \"{0}\"", "not_declared_variable"));
                Assert.Equal(MIResultClass.Error, notDeclaredVariable.Class);

                notDeclaredVariable =
                    Context.MIDebugger.Request(String.Format("-var-create - * \"{0}\"", "not_declared_variable + 1"));
                Assert.Equal(MIResultClass.Error, notDeclaredVariable.Class);


                var attrDResult = Context.MIDebugger.Request("9-var-show-attributes " + d_varName);
                Assert.Equal(MIResultClass.Done, attrDResult.Class);
                Assert.Equal("editable", ((MIConst)attrDResult["status"]).CString);

                Assert.Equal(MIResultClass.Done,
                             Context.MIDebugger.Request("10-var-delete " + d_varName).Class);

                Assert.Equal(MIResultClass.Error,
                             Context.MIDebugger.Request("11-var-show-attributes " + d_varName).Class);


                Assert.Equal(MIResultClass.Running,
                             Context.MIDebugger.Request("12-exec-continue").Class);
            });

            Label.Checkpoint("finish", "", () => {
                Context.WasExit();
                Context.DebuggerExit();
            });
        }
コード例 #16
0
ファイル: MyTextSource.cs プロジェクト: eugeniomiro/Terrarium
 protected override void OnSetLineBreakpoints(uint textPosition, uint textLength, LineBreakpoint lineBreakPoints)
 {
     base.OnSetLineBreakpoints(textPosition, textLength, lineBreakPoints);
 }
コード例 #17
0
ファイル: MyTextSource.cs プロジェクト: morelli690/Terrarium
 protected override void OnSetLineBreakpoints(uint textPosition, uint textLength, LineBreakpoint lineBreakPoints)
 {
     base.OnSetLineBreakpoints(textPosition, textLength, lineBreakPoints);
 }
コード例 #18
0
        /// <summary>
        /// PS debugger stopped event handler
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Debugger_DebuggerStop(object sender, DebuggerStopEventArgs e)
        {
            ServiceCommon.Log("Debugger stopped ...");
            DebugScenario currScenario = GetDebugScenario();

            if (_installedPowerShellVersion < RequiredPowerShellVersionForRemoteSessionDebugging)
            {
                RefreshScopedVariable();
                RefreshCallStack();
            }
            else
            {
                RefreshScopedVariable40();
                RefreshCallStack40();
            }

            ServiceCommon.LogCallbackEvent("Callback to client, and wait for debuggee to resume");
            if (e.Breakpoints.Count > 0)
            {
                LineBreakpoint bp = (LineBreakpoint)e.Breakpoints[0];
                if (_callback != null)
                {
                    string file = bp.Script;
                    if (currScenario != DebugScenario.Local && _mapRemoteToLocal.ContainsKey(bp.Script))
                    {
                        file = _mapRemoteToLocal[bp.Script];
                    }

                    // breakpoint is always hit for this case
                    _callback.DebuggerStopped(new DebuggerStoppedEventArgs(file, bp.Line, bp.Column, true, false));
                }
            }
            else
            {
                if (_callback != null)
                {
                    string file;
                    int    lineNum, column;

                    switch (currScenario)
                    {
                    case DebugScenario.LocalAttach:
                        file    = e.InvocationInfo.ScriptName;
                        lineNum = e.InvocationInfo.ScriptLineNumber;
                        column  = e.InvocationInfo.OffsetInLine;

                        // the stop which occurs after attaching is not associated with a breakpoint and should result in the process' script being opened
                        _callback.DebuggerStopped(new DebuggerStoppedEventArgs(file, lineNum, column, false, true));
                        break;

                    case DebugScenario.RemoteAttach:
                        // copy the remote file over to host machine
                        file    = OpenRemoteAttachedFile(e.InvocationInfo.ScriptName);
                        lineNum = e.InvocationInfo.ScriptLineNumber;
                        column  = e.InvocationInfo.OffsetInLine;

                        // the stop which occurs after attaching is not associated with a breakpoint and should result in the remote process' script being opened
                        _callback.DebuggerStopped(new DebuggerStoppedEventArgs(file, lineNum, column, false, true));
                        _needToCopyRemoteScript = false;
                        break;

                    default:
                        _callback.DebuggerStopped(new DebuggerStoppedEventArgs());
                        break;
                    }
                }
            }

            bool resumed = false;

            while (!resumed)
            {
                _pausedEvent.WaitOne();

                try
                {
                    currScenario = GetDebugScenario();
                    if (!string.IsNullOrEmpty(_debuggingCommand))
                    {
                        if (currScenario == DebugScenario.Local)
                        {
                            // local debugging
                            var output = new Collection <PSObject>();

                            using (var pipeline = (_runspace.CreateNestedPipeline()))
                            {
                                pipeline.Commands.AddScript(_debuggingCommand);
                                pipeline.Commands[0].MergeMyResults(PipelineResultTypes.Error, PipelineResultTypes.Output);
                                output = pipeline.Invoke();
                            }

                            ProcessDebuggingCommandResults(output);
                        }
                        else
                        {
                            // remote session and local attach debugging
                            ProcessRemoteDebuggingCommandResults(ExecuteDebuggingCommand());
                        }
                    }
                    else
                    {
                        ServiceCommon.Log(string.Format("Debuggee resume action is {0}", _resumeAction));
                        e.ResumeAction = _resumeAction;
                        resumed        = true; // debugger resumed executing
                    }
                }
                catch (Exception ex)
                {
                    NotifyOutputString(ex.Message);
                }

                // Notify the debugging command execution call that debugging command was complete.
                _debugCommandEvent.Set();
            }
        }