示例#1
0
        public async Task StepOver() {
            const string code =
@"f <- function(x) {
    x + 1
  }
  x <- f(1)
  print(x)";

            using (var debugSession = new DebugSession(_session))
            using (var sf = new SourceFile(code)) {
                await debugSession.EnableBreakpointsAsync(true);

                var bp = await debugSession.CreateBreakpointAsync(sf, 4);
                var bpHit = new BreakpointHitDetector(bp);

                await sf.Source(_session);
                await bpHit.ShouldBeHitAtNextPromptAsync();
                (await debugSession.GetStackFramesAsync()).Should().HaveTail(new MatchDebugStackFrames {
                    { bp.Location }
                });

                (await debugSession.StepOverAsync()).Should().Be(true);
                (await debugSession.GetStackFramesAsync()).Should().HaveTail(new MatchDebugStackFrames {
                    { bp.Location, +1 }
                });
            }
        }
示例#2
0
        public async Task StepOver()
        {
            const string code =
                @"f <- function(x) {
    x + 1
  }
  x <- f(1)
  print(x)";

            using (var debugSession = new DebugSession(_session))
                using (var sf = new SourceFile(code)) {
                    await debugSession.EnableBreakpointsAsync(true);

                    var bp = await debugSession.CreateBreakpointAsync(sf, 4);

                    var bpHit = new BreakpointHitDetector(bp);

                    await sf.Source(_session);

                    await bpHit.ShouldBeHitAtNextPromptAsync();

                    (await debugSession.GetStackFramesAsync()).Should().HaveTail(new MatchDebugStackFrames {
                        { bp.Location }
                    });

                    (await debugSession.StepOverAsync()).Should().Be(true);
                    (await debugSession.GetStackFramesAsync()).Should().HaveTail(new MatchDebugStackFrames {
                        { bp.Location, +1 }
                    });
                }
        }
示例#3
0
        public async Task StepOutFromGlobal()
        {
            const string code =
                @"x <- 1
  y <- 2";

            using (var debugSession = new DebugSession(_session))
                using (var sf = new SourceFile(code)) {
                    await debugSession.EnableBreakpointsAsync(true);

                    var bp1 = await debugSession.CreateBreakpointAsync(sf, 1);

                    var bp2 = await debugSession.CreateBreakpointAsync(sf, 2);

                    var bp1Hit = new BreakpointHitDetector(bp1);

                    await sf.Source(_session);

                    await bp1Hit.ShouldBeHitAtNextPromptAsync();

                    (await debugSession.GetStackFramesAsync()).Should().HaveTail(new MatchDebugStackFrames {
                        { bp1.Location }
                    });

                    (await debugSession.StepOutAsync()).Should().Be(false);
                    (await debugSession.GetStackFramesAsync()).Should().HaveTail(new MatchDebugStackFrames {
                        { bp2.Location }
                    });
                }
        }
示例#4
0
        public async Task MultilinePromise()
        {
            const string code = @"
f <- function(p, d) {
    force(d)
    browser()
}
x <- quote({{{}}})
eval(substitute(f(P, x), list(P = x)))
";

            using (var debugSession = new DebugSession(_session))
                using (var sf = new SourceFile(code)) {
                    await debugSession.EnableBreakpointsAsync(true);

                    var browseTask = EventTaskSources.DebugSession.Browse.Create(debugSession);

                    await sf.Source(_session);

                    await browseTask;

                    var stackFrames = (await debugSession.GetStackFramesAsync()).ToArray();
                    stackFrames.Should().NotBeEmpty();

                    var frame    = (await stackFrames.Last().GetEnvironmentAsync()).As <DebugValueEvaluationResult>();
                    var children = (await frame.GetChildrenAsync(DebugEvaluationResultFields.ReprDeparse)).ToDictionary(er => er.Name);

                    var p = children.Should().ContainKey("p").WhichValue.As <DebugPromiseEvaluationResult>();
                    var d = children.Should().ContainKey("d").WhichValue.As <DebugValueEvaluationResult>();

                    p.Code.Should().Be(d.GetRepresentation().Deparse);
                }
        }
示例#5
0
        public async Task SetBreakpointWhileRunning()
        {
            const string code =
                @"browser()
  f <- function() {
    NULL
  }
  while (TRUE) f()";

            using (var debugSession = new DebugSession(_session))
                using (var sf = new SourceFile(code)) {
                    await debugSession.EnableBreakpointsAsync(true);

                    await sf.Source(_session);

                    await debugSession.NextPromptShouldBeBrowseAsync();

                    await debugSession.ContinueAsync();

                    await Task.Delay(100);

                    var bp = await debugSession.CreateBreakpointAsync(sf, 3);

                    await debugSession.NextPromptShouldBeBrowseAsync();

                    (await debugSession.GetStackFramesAsync()).Should().HaveTail(new MatchDebugStackFrames {
                        { bp.Location }
                    });
                }
        }
示例#6
0
        public async Task MultilinePromise() {
            const string code = @"
f <- function(p, d) {
    force(d)
    browser()
}
x <- quote({{{}}})
eval(substitute(f(P, x), list(P = x)))
";

            using (var debugSession = new DebugSession(_session))
            using (var sf = new SourceFile(code)) {
                await debugSession.EnableBreakpointsAsync(true);

                var browseTask = EventTaskSources.DebugSession.Browse.Create(debugSession);

                await sf.Source(_session);
                await browseTask;

                var stackFrames = (await debugSession.GetStackFramesAsync()).ToArray();
                stackFrames.Should().NotBeEmpty();

                var frame = (await stackFrames.Last().GetEnvironmentAsync()).As<DebugValueEvaluationResult>();
                var children = (await frame.GetChildrenAsync()).ToDictionary(er => er.Name);

                var p = children.Should().ContainKey("p").WhichValue.As<DebugPromiseEvaluationResult>();
                var d = children.Should().ContainKey("d").WhichValue.As<DebugValueEvaluationResult>();

                p.Code.Should().Be(d.GetRepresentation(DebugValueRepresentationKind.Raw).Deparse);
            }
        }
示例#7
0
        public async Task MultilinePromise() {
            const string code = @"
f <- function(p, d) {
    force(d)
    browser()
}
x <- quote({{{}}})
eval(substitute(f(P, x), list(P = x)))
";

            using (var sessionProvider = new RSessionProvider()) {
                var session = sessionProvider.GetOrCreate(Guid.NewGuid(), new RHostClientTestApp());
                await session.StartHostAsync(new RHostStartupInfo {
                    Name = _testMethod.Name,
                    RBasePath = RUtilities.FindExistingRBasePath()
                }, 50000);

                using (var debugSession = new DebugSession(session)) {
                    using (var sf = new SourceFile(code)) {
                        await debugSession.EnableBreakpointsAsync(true);

                        var paused = new TaskCompletionSource<bool>();
                        debugSession.Browse += delegate {
                            paused.SetResult(true);
                        };

                        await sf.Source(session);
                        await paused.Task;

                        var stackFrames = (await debugSession.GetStackFramesAsync()).Reverse().ToArray();
                        stackFrames.Should().NotBeEmpty();

                        var evalResult = await stackFrames[0].GetEnvironmentAsync();
                        evalResult.Should().BeAssignableTo<DebugValueEvaluationResult>();

                        var frame = (DebugValueEvaluationResult)evalResult;
                        var children = (await frame.GetChildrenAsync()).ToDictionary(er => er.Name);

                        children.Should().ContainKey("p");
                        children["p"].Should().BeAssignableTo<DebugPromiseEvaluationResult>();
                        var p = (DebugPromiseEvaluationResult)children["p"];

                        children.Should().ContainKey("d");
                        children["d"].Should().BeAssignableTo<DebugValueEvaluationResult>();
                        var d = (DebugValueEvaluationResult)children["d"];

                        p.Code.Should().Be(d.GetRepresentation(DebugValueRepresentationKind.Raw).Deparse);
                    }
                }

                await session.StopHostAsync();
            }
        }
示例#8
0
        public async Task BreakContinue()
        {
            const string code =
                @"browser()
  x <- 0
  while (x >= 0) {
    x <- x + 1
  }
  browser()";

            using (var debugSession = new DebugSession(_session))
                using (var sf = new SourceFile(code)) {
                    await sf.Source(_session);

                    await debugSession.NextPromptShouldBeBrowseAsync();

                    await debugSession.ContinueAsync();

                    await Task.Delay(100);

                    await debugSession.BreakAsync();

                    await debugSession.NextPromptShouldBeBrowseAsync();

                    (await debugSession.GetStackFramesAsync()).Should().HaveTail(new MatchDebugStackFrames {
                        { sf, new MatchRange <int>(1, 3) }
                    });

                    await _session.EvaluateAsync("x <- -42", REvaluationKind.Mutating);

                    await debugSession.ContinueAsync();

                    await debugSession.NextPromptShouldBeBrowseAsync();

                    (await debugSession.GetStackFramesAsync()).Should().HaveTail(new MatchDebugStackFrames {
                        { sf, 6 }
                    });
                }
        }
示例#9
0
        public async Task StepOutToFunction()
        {
            const string code =
                @"f <- function() {
    1
  }
  g <- function() {
    f()
    1
  }
  g()";

            using (var debugSession = new DebugSession(_session))
                using (var sf = new SourceFile(code)) {
                    await debugSession.EnableBreakpointsAsync(true);

                    var bp = await debugSession.CreateBreakpointAsync(sf, 2);

                    var bpHit = new BreakpointHitDetector(bp);

                    await sf.Source(_session);

                    await bpHit.ShouldBeHitAtNextPromptAsync();

                    (await debugSession.GetStackFramesAsync()).Should().HaveTail(new MatchDebugStackFrames {
                        { sf, 8, "g()" },
                        { sf, 5, "f()" },
                        { bp.Location },
                    });

                    (await debugSession.StepOutAsync()).Should().Be(true);
                    (await debugSession.GetStackFramesAsync()).Should().HaveTail(new MatchDebugStackFrames {
                        { sf, 8, "g()" },
                        { sf, 6, MatchAny <string> .Instance },
                    });
                }
        }
示例#10
0
        public async Task CallStack()
        {
            using (var debugSession = new DebugSession(_session)) {
                const string code1 =
                    @"f <- function(n) {
     if (n > 0) {
        g(n - 1)
     } else {
        return()
     }
  }";

                const string code2 =
                    @"g <- function(n) {
     if (n > 0) {
        f(n - 1)
     } else {
        return()
     }
  }";

                using (var sf1 = new SourceFile(code1))
                    using (var sf2 = new SourceFile(code2)) {
                        await debugSession.EnableBreakpointsAsync(true);

                        await sf1.Source(_session);

                        await sf2.Source(_session);

                        var bp = await debugSession.CreateBreakpointAsync(sf1, 5);

                        var bpHit = new BreakpointHitDetector(bp);

                        using (var inter = await _session.BeginInteractionAsync()) {
                            await inter.RespondAsync("f(4)\n");
                        }
                        await bpHit.ShouldBeHitAtNextPromptAsync();

                        (await debugSession.GetStackFramesAsync()).Should().HaveTail(new MatchDebugStackFrames {
                            { (string)null, null, "f(4)" },
                            { sf1, 3, "g(n - 1)" },
                            { sf2, 3, "f(n - 1)" },
                            { sf1, 3, "g(n - 1)" },
                            { sf2, 3, "f(n - 1)" },
                            { sf1, 5, MatchAny <string> .Instance },
                        });
                    }
            }
        }
示例#11
0
        public async Task CallStack() {
            using (var debugSession = new DebugSession(_session)) {
                const string code1 =
@"f <- function(n) {
     if (n > 0) {
        g(n - 1)
     } else {
        return()
     }
  }";

                const string code2 =
@"g <- function(n) {
     if (n > 0) {
        f(n - 1)
     } else {
        return()
     }
  }";

                using (var sf1 = new SourceFile(code1))
                using (var sf2 = new SourceFile(code2)) {
                    await debugSession.EnableBreakpointsAsync(true);

                    await sf1.Source(_session);
                    await sf2.Source(_session);

                    var bp = await debugSession.CreateBreakpointAsync(sf1, 5);
                    var bpHit = new BreakpointHitDetector(bp);

                    using (var inter = await _session.BeginInteractionAsync()) {
                        await inter.RespondAsync("f(4)\n");
                    }
                    await bpHit.ShouldBeHitAtNextPromptAsync();

                    (await debugSession.GetStackFramesAsync()).Should().HaveTail(new MatchDebugStackFrames {
                        { (string)null, null, "f(4)" },
                        { sf1, 3, "g(n - 1)" },
                        { sf2, 3, "f(n - 1)" },
                        { sf1, 3, "g(n - 1)" },
                        { sf2, 3, "f(n - 1)" },
                        { sf1, 5, MatchAny<string>.Instance },
                    });
                }
            }
        }
示例#12
0
        public async Task RemoveBreakpointWhileRunning()
        {
            const string code =
                @"browser()
  f <- function() {
    NULL
    browser()
  }
  b <- FALSE;
  while (TRUE) if (b) f()";

            using (var debugSession = new DebugSession(_session))
                using (var sf = new SourceFile(code)) {
                    await debugSession.EnableBreakpointsAsync(true);

                    await sf.Source(_session);

                    await debugSession.NextPromptShouldBeBrowseAsync();

                    var bp = await debugSession.CreateBreakpointAsync(sf, 3);

                    int hitCount = 0;
                    bp.BreakpointHit += delegate { ++hitCount; };

                    await debugSession.ContinueAsync();

                    await Task.Delay(100);

                    await bp.DeleteAsync();

                    await _session.EvaluateAsync("b <- TRUE", REvaluationKind.Mutating);

                    await debugSession.NextPromptShouldBeBrowseAsync();

                    (await debugSession.GetStackFramesAsync()).Should().HaveTail(new MatchDebugStackFrames {
                        { sf, 4 }
                    });
                    hitCount.Should().Be(0);
                }
        }
示例#13
0
        private async Task PublishAsync(VariableSubscriptionToken token, IList <VariableSubscription> subscriptions)
        {
            if (subscriptions.Count == 0)
            {
                return;
            }

            Debug.Assert(_debugSession != null);

            var stackFrames = await _debugSession.GetStackFramesAsync();

            var stackFrame = stackFrames.FirstOrDefault(f => f.Index == token.FrameIndex);

            if (stackFrame != null)
            {
                const DebugEvaluationResultFields fields = DebugEvaluationResultFields.Classes
                                                           | DebugEvaluationResultFields.Expression
                                                           | DebugEvaluationResultFields.TypeName
                                                           | (DebugEvaluationResultFields.Repr | DebugEvaluationResultFields.ReprStr)
                                                           | DebugEvaluationResultFields.Dim
                                                           | DebugEvaluationResultFields.Length;

                DebugEvaluationResult evaluation = await stackFrame.EvaluateAsync(token.Expression, fields : fields);

                foreach (var sub in subscriptions)
                {
                    try {
                        var action = sub.GetExecuteAction();
                        if (action != null)
                        {
                            action(evaluation);
                        }
                    } catch (Exception e) {
                        Debug.Fail(e.ToString());
                        // swallow exception and continue
                    }
                }
            }
        }
示例#14
0
        public async Task StepOutToGlobal() {
            const string code =
@"f <- function(x) {
    x + 1
  }
  x <- f(1)
  print(x)";

            using (var debugSession = new DebugSession(_session))
            using (var sf = new SourceFile(code)) {
                await debugSession.EnableBreakpointsAsync(true);

                var bp = await debugSession.CreateBreakpointAsync(sf, 2);
                var bpHit = new BreakpointHitDetector(bp);

                await sf.Source(_session);
                await bpHit.ShouldBeHitAtNextPromptAsync();
                (await debugSession.GetStackFramesAsync()).Should().BeAt(bp.Location, "f(1)");

                (await debugSession.StepOutAsync()).Should().Be(true);
                (await debugSession.GetStackFramesAsync()).Should().BeAt(sf, 5);
            }
        }
示例#15
0
        public async Task StepOutFromGlobal() {
            const string code =
@"x <- 1
  y <- 2";

            using (var debugSession = new DebugSession(_session))
            using (var sf = new SourceFile(code)) {
                await debugSession.EnableBreakpointsAsync(true);

                var bp1 = await debugSession.CreateBreakpointAsync(sf, 1);
                var bp2 = await debugSession.CreateBreakpointAsync(sf, 2);

                var bp1Hit = new BreakpointHitDetector(bp1);

                await sf.Source(_session);
                await bp1Hit.ShouldBeHitAtNextPromptAsync();
                (await debugSession.GetStackFramesAsync()).Should().BeAt(bp1.Location);

                (await debugSession.StepOutAsync()).Should().Be(false);
                (await debugSession.GetStackFramesAsync()).Should().BeAt(bp2.Location);
            }
        }
示例#16
0
        public async Task StepOutToFunction() {
            const string code =
@"f <- function() {
    1
  }
  g <- function() {
    f()
    1
  }
  g()";

            using (var debugSession = new DebugSession(_session))
            using (var sf = new SourceFile(code)) {
                await debugSession.EnableBreakpointsAsync(true);

                var bp = await debugSession.CreateBreakpointAsync(sf, 2);
                var bpHit = new BreakpointHitDetector(bp);

                await sf.Source(_session);
                await bpHit.ShouldBeHitAtNextPromptAsync();
                (await debugSession.GetStackFramesAsync()).Should().HaveTail(new MatchDebugStackFrames {
                    { sf, 8, "g()" },
                    { sf, 5, "f()" },
                    { bp.Location },
                });

                (await debugSession.StepOutAsync()).Should().Be(true);
                (await debugSession.GetStackFramesAsync()).Should().HaveTail(new MatchDebugStackFrames {
                    { sf, 8, "g()" },
                    { sf, 6, MatchAny<string>.Instance },
                });
            }
        }