コード例 #1
0
 public OutputEventArgs(NodeThread thread, string output) {
     _thread = thread;
     _output = output;
 }
コード例 #2
0
 public BreakpointHitEventArgs(NodeBreakpointBinding breakpoint, NodeThread thread) {
     _breakpointBinding = breakpoint;
     _thread = thread;
 }
コード例 #3
0
        /// <summary>
        /// Starts listening for debugger communication.  Can be called after Start
        /// to give time to attach to debugger events.
        /// </summary>
        public void StartListening() {
            _connection.Connect(_debuggerEndpointUri);

            var mainThread = new NodeThread(this, MainThreadId, false);
            _threads[mainThread.Id] = mainThread;

            if (!GetScriptsAsync().Wait((int)_timeout.TotalMilliseconds)) {
                throw new TimeoutException("Timed out while retrieving scripts from debuggee.");
            }

            if (!SetExceptionBreakAsync().Wait((int)_timeout.TotalMilliseconds)) {
                throw new TimeoutException("Timed out while setting up exception handling in debuggee.");
            }

            var backTraceTask = PerformBacktraceAsync();
            if (!backTraceTask.Wait((int)_timeout.TotalMilliseconds)) {
                throw new TimeoutException("Timed out while performing initial backtrace.");
            }

            // At this point we can fire events
            EventHandler<ThreadEventArgs> newThread = ThreadCreated;
            if (newThread != null) {
                newThread(this, new ThreadEventArgs(mainThread));
            }
            EventHandler<ThreadEventArgs> procLoaded = ProcessLoaded;
            if (procLoaded != null) {
                procLoaded(this, new ThreadEventArgs(MainThread));
            }

        }
コード例 #4
0
        /// <summary>
        /// Starts listening for debugger communication.  Can be called after Start
        /// to give time to attach to debugger events.
        /// </summary>
        public void StartListening() {
            LiveLogger.WriteLine("NodeDebugger start listening");

            _connection.Connect(_debuggerEndpointUri);

            var mainThread = new NodeThread(this, MainThreadId, false);
            _threads[mainThread.Id] = mainThread;

            if (!GetScriptsAsync().Wait((int)_timeout.TotalMilliseconds)) {
                LiveLogger.WriteLine("NodeDebugger GetScripts timeout");
                throw new TimeoutException("Timed out while retrieving scripts from debuggee.");
            }

            if (!SetExceptionBreakAsync().Wait((int)_timeout.TotalMilliseconds)) {
                LiveLogger.WriteLine("NodeDebugger SetException timeout");
                throw new TimeoutException("Timed out while setting up exception handling in debuggee.");
            }

            var backTraceTask = PerformBacktraceAsync();
            if (!backTraceTask.Wait((int)_timeout.TotalMilliseconds)) {
                LiveLogger.WriteLine("NodeDebugger backtrace timeout");
                throw new TimeoutException("Timed out while performing initial backtrace.");
            }

            // At this point we can fire events
            ThreadCreated?.Invoke(this, new ThreadEventArgs(mainThread));
            ProcessLoaded?.Invoke(this, new ThreadEventArgs(MainThread));
        }
コード例 #5
0
 public BreakpointHitEventArgs(NodeBreakpointBinding breakpoint, NodeThread thread)
 {
     _breakpointBinding = breakpoint;
     _thread            = thread;
 }
コード例 #6
0
 public OutputEventArgs(NodeThread thread, string output)
 {
     this.Thread = thread;
     this.Output = output;
 }
コード例 #7
0
 public BreakpointHitEventArgs(NodeBreakpointBinding breakpoint, NodeThread thread)
 {
     this.BreakpointBinding = breakpoint;
     this.Thread            = thread;
 }
コード例 #8
0
 public ProcessLoadedEventArgs(NodeThread thread, bool running) : base(thread) {
     _running = running;
 }
コード例 #9
0
        internal void ExecTest(
            NodeThread thread,
            int frameIndex = 0,
            string expression = null,
            string expectedType = null,
            string expectedValue = null,
            string expectedException = null,
            string expectedFrame = null
        ) {
            var frame = thread.Frames[frameIndex];
            NodeEvaluationResult evaluationResult = null;
            Exception exception = null;

            try {
                evaluationResult = frame.ExecuteTextAsync(expression).WaitAndUnwrapExceptions();
            } catch (Exception ex) {
                exception = ex;
            }

            if (expectedType != null) {
                Assert.IsNotNull(evaluationResult);
                Assert.AreEqual(expectedType, evaluationResult.TypeName);
            }
            if (expectedValue != null) {
                Assert.IsNotNull(evaluationResult);
                Assert.AreEqual(expectedValue, evaluationResult.StringValue);
            }
            if (expectedException != null) {
                Assert.IsNotNull(exception);
                Assert.AreEqual(expectedException, exception.Message);
            }
            if (expectedFrame != null) {
                Assert.AreEqual(expectedFrame, frame.FunctionName);
            }
        }
コード例 #10
0
        internal void TestDebuggerSteps(
            NodeDebugger process,
            NodeThread thread,
            string filename,
            IEnumerable<TestStep> steps,
            ExceptionHitTreatment? defaultExceptionTreatment = null,
            ICollection<KeyValuePair<string, ExceptionHitTreatment>> exceptionTreatments = null,
            bool waitForExit = false
        ) {
            if (!Path.IsPathRooted(filename)) {
                filename = DebuggerTestPath + filename;
            }

            // Since Alpha does not support break on unhandled, and the commonly used Express module has handled SyntaxError exceptions,
            // for alpha we have SyntaxErrors set to BreakNever by default.  Here we set it to BreakAlways so unit tests can run
            // assuming BreakAlways is the default.            
            // TODO: Remove once exception treatment is updated for just my code support when it is added after Alpha
            process.SetExceptionTreatment(null, CollectExceptionTreatments(ExceptionHitTreatment.BreakAlways, "SyntaxError"));

            if (defaultExceptionTreatment != null || exceptionTreatments != null) {
                process.SetExceptionTreatment(defaultExceptionTreatment, exceptionTreatments);
            }

            Dictionary<Breakpoint, NodeBreakpoint> breakpoints = new Dictionary<Breakpoint, NodeBreakpoint>();

            AutoResetEvent entryPointHit = new AutoResetEvent(false);
            process.EntryPointHit += (sender, e) => {
                Console.WriteLine("EntryPointHit");
                Assert.AreEqual(e.Thread, thread);
                entryPointHit.Set();
            };

            AutoResetEvent breakpointBound = new AutoResetEvent(false);
            process.BreakpointBound += (sender, e) => {
                Console.WriteLine("BreakpointBound {0} {1}", e.BreakpointBinding.Position.FileName, e.BreakpointBinding.Position.Line);
                breakpointBound.Set();
            };

            AutoResetEvent breakpointUnbound = new AutoResetEvent(false);
            process.BreakpointUnbound += (sender, e) => {
                Console.WriteLine("BreakpointUnbound");
                breakpointUnbound.Set();
            };

            AutoResetEvent breakpointBindFailure = new AutoResetEvent(false);
            process.BreakpointBindFailure += (sender, e) => {
                Console.WriteLine("BreakpointBindFailure");
                breakpointBindFailure.Set();
            };

            AutoResetEvent breakpointHit = new AutoResetEvent(false);
            process.BreakpointHit += (sender, e) => {
                Console.WriteLine("BreakpointHit {0}", e.BreakpointBinding.Target.Line);
                Assert.AreEqual(e.Thread, thread);
                Assert.AreEqual(e.BreakpointBinding.Target.Line, thread.Frames.First().Line);
                breakpointHit.Set();
            };

            AutoResetEvent stepComplete = new AutoResetEvent(false);
            process.StepComplete += (sender, e) => {
                Console.WriteLine("StepComplete");
                Assert.AreEqual(e.Thread, thread);
                stepComplete.Set();
            };

            AutoResetEvent exceptionRaised = new AutoResetEvent(false);
            NodeException exception = null;
            process.ExceptionRaised += (sender, e) => {
                Console.WriteLine("ExceptionRaised");
                Assert.AreEqual(e.Thread, thread);
                exception = e.Exception;
                exceptionRaised.Set();
            };

            AutoResetEvent processExited = new AutoResetEvent(false);
            int exitCode = 0;
            process.ProcessExited += (sender, e) => {
                Console.WriteLine("ProcessExited {0}", e.ExitCode);
                exitCode = e.ExitCode;
                processExited.Set();
            };

            Console.WriteLine("-----------------------------------------");
            Console.WriteLine("Begin debugger step test");
            foreach (var step in steps) {
                Console.WriteLine("Step: {0}", step._action);
                Assert.IsFalse(
                    ((step._expectedEntryPointHit != null ? 1 : 0) +
                     (step._expectedBreakpointHit != null ? 1 : 0) +
                     (step._expectedStepComplete != null ? 1 : 0) +
                     (step._expectedExceptionRaised != null ? 1 : 0)) > 1);
                bool wait = false;
                NodeBreakpoint nodeBreakpoint;
                switch (step._action) {
                    case TestAction.None:
                        break;
                    case TestAction.Wait:
                        wait = true;
                        break;
                    case TestAction.ResumeThread:
                        thread.Resume();
                        wait = true;
                        break;
                    case TestAction.ResumeProcess:
                        process.Resume();
                        wait = true;
                        break;
                    case TestAction.StepOver:
                        thread.StepOver();
                        wait = true;
                        break;
                    case TestAction.StepInto:
                        thread.StepInto();
                        wait = true;
                        break;
                    case TestAction.StepOut:
                        thread.StepOut();
                        wait = true;
                        break;
                    case TestAction.AddBreakpoint:
                        string breakpointFileName = step._targetBreakpointFile;
                        if (breakpointFileName != null) {
                            if (!step._builtin && !Path.IsPathRooted(breakpointFileName)) {
                                breakpointFileName = DebuggerTestPath + breakpointFileName;
                            }
                        } else {
                            breakpointFileName = filename;
                        }
                        int breakpointLine = step._targetBreakpoint.Value;
                        int breakpointColumn = step._targetBreakpointColumn.HasValue ? step._targetBreakpointColumn.Value : 0;
                        Breakpoint breakpoint = new Breakpoint(breakpointFileName, breakpointLine, breakpointColumn);
                        Assert.IsFalse(breakpoints.TryGetValue(breakpoint, out nodeBreakpoint));
                        breakpoints[breakpoint] =
                            AddBreakPoint(
                                process,
                                breakpointFileName,
                                breakpointLine,
                                breakpointColumn,
                                step._enabled ?? true,
                                step._breakOn ?? new BreakOn(),
                                step._condition
                            );
                        if (step._expectFailure) {
                            AssertWaited(breakpointBindFailure);
                            AssertNotSet(breakpointBound);
                            breakpointBindFailure.Reset();
                        } else {
                            AssertWaited(breakpointBound);
                            AssertNotSet(breakpointBindFailure);
                            breakpointBound.Reset();
                        }
                        break;
                    case TestAction.RemoveBreakpoint:
                        breakpointFileName = step._targetBreakpointFile ?? filename;
                        breakpointLine = step._targetBreakpoint.Value;
                        breakpointColumn = step._targetBreakpointColumn.HasValue ? step._targetBreakpointColumn.Value : 0;
                        breakpoint = new Breakpoint(breakpointFileName, breakpointLine, breakpointColumn);
                        breakpoints[breakpoint].Remove().WaitAndUnwrapExceptions();
                        breakpoints.Remove(breakpoint);
                        AssertWaited(breakpointUnbound);
                        breakpointUnbound.Reset();
                        break;
                    case TestAction.UpdateBreakpoint:
                        breakpointFileName = step._targetBreakpointFile ?? filename;
                        breakpointLine = step._targetBreakpoint.Value;
                        breakpointColumn = step._targetBreakpointColumn.HasValue ? step._targetBreakpointColumn.Value : 0;
                        breakpoint = new Breakpoint(breakpointFileName, breakpointLine, breakpointColumn);
                        nodeBreakpoint = breakpoints[breakpoint];
                        foreach (var breakpointBinding in nodeBreakpoint.GetBindings()) {
                            if (step._hitCount != null) {
                                Assert.IsTrue(breakpointBinding.SetHitCountAsync(step._hitCount.Value).WaitAndUnwrapExceptions());
                            }
                            if (step._enabled != null) {
                                Assert.IsTrue(breakpointBinding.SetEnabledAsync(step._enabled.Value).WaitAndUnwrapExceptions());
                            }
                            if (step._breakOn != null) {
                                Assert.IsTrue(breakpointBinding.SetBreakOnAsync(step._breakOn.Value).WaitAndUnwrapExceptions());
                            }
                            if (step._condition != null) {
                                Assert.IsTrue(breakpointBinding.SetConditionAsync(step._condition).WaitAndUnwrapExceptions());
                            }
                        }
                        break;
                    case TestAction.KillProcess:
                        process.Terminate();
                        break;
                    case TestAction.Detach:
                        process.Detach();
                        break;
                }

                if (wait) {
                    if (step._expectedEntryPointHit != null) {
                        AssertWaited(entryPointHit);
                        AssertNotSet(breakpointHit);
                        AssertNotSet(stepComplete);
                        AssertNotSet(exceptionRaised);
                        Assert.IsNull(exception);
                        entryPointHit.Reset();
                    } else if (step._expectedBreakpointHit != null) {
                        if (step._expectReBind) {
                            AssertWaited(breakpointUnbound);
                            AssertWaited(breakpointBound);
                            breakpointUnbound.Reset();
                            breakpointBound.Reset();
                        }
                        AssertWaited(breakpointHit);
                        AssertNotSet(entryPointHit);
                        AssertNotSet(stepComplete);
                        AssertNotSet(exceptionRaised);
                        Assert.IsNull(exception);
                        breakpointHit.Reset();
                    } else if (step._expectedStepComplete != null) {
                        AssertWaited(stepComplete);
                        AssertNotSet(entryPointHit);
                        AssertNotSet(breakpointHit);
                        AssertNotSet(exceptionRaised);
                        Assert.IsNull(exception);
                        stepComplete.Reset();
                    } else if (step._expectedExceptionRaised != null) {
                        AssertWaited(exceptionRaised);
                        AssertNotSet(entryPointHit);
                        AssertNotSet(breakpointHit);
                        AssertNotSet(stepComplete);
                        exceptionRaised.Reset();
                    } else {
                        AssertNotSet(entryPointHit);
                        AssertNotSet(breakpointHit);
                        AssertNotSet(stepComplete);
                        AssertNotSet(exceptionRaised);
                        Assert.IsNull(exception);
                    }
                }

                if (step._expectedEntryPointHit != null) {
                    Assert.AreEqual(step._expectedEntryPointHit.Value, thread.Frames.First().Line);
                } else if (step._expectedBreakpointHit != null) {
                    Assert.AreEqual(step._expectedBreakpointHit.Value, thread.Frames.First().Line);
                } else if (step._expectedStepComplete != null) {
                    Assert.AreEqual(step._expectedStepComplete.Value, thread.Frames.First().Line);
                } else if (step._expectedExceptionRaised != null) {
                    Assert.AreEqual(step._expectedExceptionRaised.TypeName, exception.TypeName);
                    Assert.AreEqual(step._expectedExceptionRaised.Description, exception.Description);
                    if (step._expectedExceptionRaised.LineNo != null) {
                        Assert.AreEqual(step._expectedExceptionRaised.LineNo.Value, thread.Frames[0].Line);
                    }
                    exception = null;
                }
                var expectedBreakFile = step._expectedBreakFile;
                if (expectedBreakFile != null) {
                    if (!step._builtin && !Path.IsPathRooted(expectedBreakFile)) {
                        expectedBreakFile = DebuggerTestPath + expectedBreakFile;
                    }
                    Assert.AreEqual(expectedBreakFile, thread.Frames.First().FileName);
                }
                var expectedBreakFunction = step._expectedBreakFunction;
                if (expectedBreakFunction != null) {
                    Assert.AreEqual(expectedBreakFunction, thread.Frames.First().FunctionName);
                }

                if (step._expectedHitCount != null) {
                    string breakpointFileName = step._targetBreakpointFile ?? filename;
                    if (!step._builtin && !Path.IsPathRooted(breakpointFileName)) {
                        breakpointFileName = DebuggerTestPath + breakpointFileName;
                    }
                    int breakpointLine = step._targetBreakpoint.Value;
                    int breakpointColumn = step._targetBreakpointColumn.HasValue ? step._targetBreakpointColumn.Value : 0;
                    var breakpoint = new Breakpoint(breakpointFileName, breakpointLine, breakpointColumn);
                    nodeBreakpoint = breakpoints[breakpoint];
                    foreach (var breakpointBinding in nodeBreakpoint.GetBindings()) {
                        Assert.AreEqual(step._expectedHitCount.Value, breakpointBinding.GetHitCount());
                    }
                }

                if (step._validation != null) {
                    step._validation(process, thread);
                }

                if (step._expectedExitCode != null) {
                    AssertWaited(processExited);
                    Assert.AreEqual(step._expectedExitCode.Value, exitCode);
                }
            }

            if (waitForExit) {
                process.WaitForExit(10000);
            }

            AssertNotSet(entryPointHit);
            AssertNotSet(breakpointHit);
            AssertNotSet(stepComplete);
            AssertNotSet(exceptionRaised);
            Assert.IsNull(exception);
        }
コード例 #11
0
 public ThreadEventArgs(NodeThread thread) {
     _thread = thread;
 }
 public ExceptionRaisedEventArgs(NodeThread thread, NodeException exception, bool isUnhandled) {
     _thread = thread;
     _exception = exception;
     _isUnhandled = isUnhandled;
 }
コード例 #13
0
 public ProcessLoadedEventArgs(NodeThread thread, bool running) : base(thread)
 {
     _running = running;
 }
コード例 #14
0
 public ThreadEventArgs(NodeThread thread)
 {
     Thread = thread;
 }
コード例 #15
0
ファイル: OutputEventArgs.cs プロジェクト: tbscer/nodejstools
 public OutputEventArgs(NodeThread thread, string output)
 {
     _thread = thread;
     _output = output;
 }
コード例 #16
0
 public ExceptionRaisedEventArgs(NodeThread thread, NodeException exception, bool isUnhandled)
 {
     this.Thread      = thread;
     this.Exception   = exception;
     this.IsUnhandled = isUnhandled;
 }
コード例 #17
0
 public ExceptionRaisedEventArgs(NodeThread thread, NodeException exception, bool isUnhandled)
 {
     _thread      = thread;
     _exception   = exception;
     _isUnhandled = isUnhandled;
 }