public async Task OverlappingBreakpoints() { const string code = @"f <- function() { 1 }"; using (var debugSession = new DebugSession(_session)) using (var sf = new SourceFile(code)) { await debugSession.EnableBreakpointsAsync(true); await sf.Source(_session); var bp1 = await debugSession.CreateBreakpointAsync(sf, 1); var bp2 = await debugSession.CreateBreakpointAsync(sf, 1); bp1.Should().BeSameAs(bp2); debugSession.Breakpoints.Should().HaveCount(1); var bp1Hit = new BreakpointHitDetector(bp1); var bp2Hit = new BreakpointHitDetector(bp2); using (var inter = await _session.BeginInteractionAsync()) { await inter.RespondAsync("f()\n"); } await bp1Hit.ShouldBeHitAtNextPromptAsync(); bp2Hit.WasHit.Should().BeTrue(); await bp1.DeleteAsync(); debugSession.Breakpoints.Should().HaveCount(1); debugSession.Breakpoints.Should().Contain(bp2); await debugSession.ContinueAsync(); using (var inter = await _session.BeginInteractionAsync()) { await inter.RespondAsync("f()\n"); } await bp2Hit.ShouldBeHitAtNextPromptAsync(); await bp2.DeleteAsync(); debugSession.Breakpoints.Should().HaveCount(0); await debugSession.ContinueAsync(); using (var inter = await _session.BeginInteractionAsync()) { await inter.RespondAsync("f()\n"); } using (var inter = await _session.BeginInteractionAsync()) { inter.Contexts.IsBrowser().Should().BeFalse(); } } }
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 } }); } }
private int Continue(IDebugThread2 pThread) { ThrowIfDisposed(); if (_firstContinue) { _firstContinue = false; } else { // If _sentContinue is true, then this is a dummy Continue issued to notify the // debugger that user has explicitly entered something at the Browse prompt, and // we don't actually need to issue the command to R debugger. Func <CancellationToken, Task> continueMethod = null; lock (_browseLock) { if (_sentContinue != true) { _sentContinue = true; continueMethod = ct => DebugSession.ContinueAsync(ct); } } if (continueMethod != null) { TaskExtensions.RunSynchronouslyOnUIThread(continueMethod); } } return(VSConstants.S_OK); }
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 } }); } }
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); } }
public async Task BreakpointsInDifferentFiles() { using (var debugSession = new DebugSession(_session)) using (var sf1 = new SourceFile("1")) using (var sf2 = new SourceFile($"eval(parse({sf1.FilePath.ToRStringLiteral()}))")) { await debugSession.EnableBreakpointsAsync(true); var bp1Loc = new DebugBreakpointLocation(sf1.FilePath, 1); var bp1 = await debugSession.CreateBreakpointAsync(bp1Loc); bp1.Location.Should().Be(bp1Loc); var bp2Loc = new DebugBreakpointLocation(sf2.FilePath, 1); var bp2 = await debugSession.CreateBreakpointAsync(bp2Loc); bp2.Location.Should().Be(bp2Loc); debugSession.Breakpoints.Should().HaveCount(2); var bp1Hit = new BreakpointHitDetector(bp1); var bp2Hit = new BreakpointHitDetector(bp2); await sf2.Source(_session); await bp2Hit.ShouldBeHitAtNextPromptAsync(); bp1Hit.WasHit.Should().BeFalse(); bp2Hit.Reset(); await debugSession.ContinueAsync(); await bp1Hit.ShouldBeHitAtNextPromptAsync(); bp2Hit.WasHit.Should().BeFalse(); } }
public async Task RemovedBreakpointNotHit() { const string code = @"f <- function() { 0 }"; using (var debugSession = new DebugSession(_session)) using (var sf = new SourceFile(code)) { await debugSession.EnableBreakpointsAsync(true); await sf.Source(_session); var bp = await debugSession.CreateBreakpointAsync(new DebugBreakpointLocation(sf.FilePath, 2)); var bpHit = new BreakpointHitDetector(bp); using (var inter = await _session.BeginInteractionAsync()) { await inter.RespondAsync("f()\n"); } await bpHit.ShouldBeHitAtNextPromptAsync(); await bp.DeleteAsync(); await debugSession.ContinueAsync(); using (var inter = await _session.BeginInteractionAsync()) { await inter.RespondAsync("f()\n"); } using (var inter = await _session.BeginInteractionAsync()) { inter.Contexts.IsBrowser().Should().BeFalse(); } } }
public async Task OverlappingBreakpoints() { const string code = @"f <- function() { 1 }"; using (var debugSession = new DebugSession(_session)) using (var sf = new SourceFile(code)) { await debugSession.EnableBreakpointsAsync(true); await sf.Source(_session); var bp1 = await debugSession.CreateBreakpointAsync(sf, 1); var bp2 = await debugSession.CreateBreakpointAsync(sf, 1); bp1.Should().BeSameAs(bp2); debugSession.Breakpoints.Should().HaveCount(1); var bp1Hit = new BreakpointHitDetector(bp1); var bp2Hit = new BreakpointHitDetector(bp2); using (var inter = await _session.BeginInteractionAsync()) { await inter.RespondAsync("f()\n"); } await bp1Hit.ShouldBeHitAtNextPromptAsync(); bp2Hit.WasHit.Should().BeTrue(); await debugSession.ContinueAsync(); await bp1.DeleteAsync(); debugSession.Breakpoints.Should().HaveCount(1); debugSession.Breakpoints.Should().Contain(bp2); using (var inter = await _session.BeginInteractionAsync()) { await inter.RespondAsync("f()\n"); } await bp2Hit.ShouldBeHitAtNextPromptAsync(); await debugSession.ContinueAsync(); await bp2.DeleteAsync(); debugSession.Breakpoints.Should().HaveCount(0); using (var inter = await _session.BeginInteractionAsync()) { await inter.RespondAsync("f()\n"); } using (var inter = await _session.BeginInteractionAsync()) { inter.Contexts.IsBrowser().Should().BeFalse(); } } }