public async Task BeginEvaluationAsync_DisconnectedFromTheStart()
 {
     using (var session = new RSession(0, _brokerConnector, () => { })) {
         // ReSharper disable once AccessToDisposedClosure
         Func <Task> f = () => session.BeginEvaluationAsync();
         await f.ShouldThrowAsync <RHostDisconnectedException>();
     }
 }
Пример #2
0
        public async Task EnableBreakpointsAsync(bool enable, CancellationToken ct = default(CancellationToken))
        {
            ThrowIfDisposed();
            await TaskUtilities.SwitchToBackgroundThread();

            using (var eval = await RSession.BeginEvaluationAsync(ct)) {
                await eval.EvaluateAsync($"rtvs:::enable_breakpoints({(enable ? "TRUE" : "FALSE")})", REvaluationKind.Mutating);
            }
        }
            public async Task ExclusiveEvaluation()
            {
                var interactionTasks = ParallelTools.Invoke(4, i => _session.BeginEvaluationAsync());
                IList <Task <IRSessionEvaluation> > runningTasks = interactionTasks.ToList();

                while (runningTasks.Count > 0)
                {
                    await Task.WhenAny(runningTasks);

                    IList <Task <IRSessionEvaluation> > completedTasks;
                    runningTasks.Split(t => t.Status == TaskStatus.RanToCompletion, out completedTasks, out runningTasks);
                    completedTasks.Should().ContainSingle();
                    completedTasks.Single().Result.Dispose();
                }
            }
Пример #4
0
        internal async Task <REvaluationResult> InvokeDebugHelperAsync(string expression, CancellationToken cancellationToken, bool json = false)
        {
            TaskUtilities.AssertIsOnBackgroundThread();
            ThrowIfDisposed();

            REvaluationResult res;

            using (var eval = await RSession.BeginEvaluationAsync(false, cancellationToken)) {
                res = await eval.EvaluateAsync(expression, json?REvaluationKind.Json : REvaluationKind.Normal);

                if (res.ParseStatus != RParseStatus.OK || res.Error != null || (json && res.JsonResult == null))
                {
                    Trace.Fail(Invariant($"Internal debugger evaluation {expression} failed: {res}"));
                    throw new REvaluationException(res);
                }
            }

            return(res);
        }
Пример #5
0
        public Task <bool> StepOutAsync(CancellationToken cancellationToken = default(CancellationToken))
        {
            return(StepAsync(cancellationToken, "c", async inter => {
                using (var eval = await RSession.BeginEvaluationAsync(false, cancellationToken)) {
                    // EvaluateAsync will push a new toplevel context on the context stack before
                    // evaluating the expression, so tell browser_set_debug to skip 1 toplevel context
                    // before locating the target context for step-out.
                    var res = await eval.EvaluateAsync("rtvs:::browser_set_debug(1, 1)");
                    Trace.Assert(res.ParseStatus == RParseStatus.OK);

                    if (res.ParseStatus != RParseStatus.OK || res.Error != null)
                    {
                        _stepTcs.TrySetResult(false);
                        return false;
                    }

                    return true;
                }
            }));
        }
Пример #6
0
        private async Task InitializeWorkerAsync(CancellationToken cancellationToken = default(CancellationToken))
        {
            ThrowIfDisposed();
            await TaskUtilities.SwitchToBackgroundThread();

            try {
                using (var eval = await RSession.BeginEvaluationAsync(cancellationToken: cancellationToken)) {
                    // Re-initialize the breakpoint table.
                    foreach (var bp in _breakpoints.Values)
                    {
                        await eval.EvaluateAsync(bp.GetAddBreakpointExpression(false)); // TODO: mark breakpoint as invalid if this fails.
                    }

                    await eval.EvaluateAsync("rtvs:::reapply_breakpoints()"); // TODO: mark all breakpoints as invalid if this fails.
                }

                // Attach might happen when session is already at the Browse prompt, in which case we have
                // missed the corresponding BeginRequest event, but we want to raise Browse anyway. So
                // grab an interaction and check the prompt.
                RSession.BeginInteractionAsync(cancellationToken: cancellationToken).ContinueWith(async t => {
                    using (var inter = await t) {
                        // If we got AfterRequest before we got here, then that has already taken care of
                        // the prompt; or if it's not a Browse prompt, will do so in a future event. Bail out.'
                        if (_initialPromptCts.IsCancellationRequested)
                        {
                            return;
                        }

                        // Otherwise, treat it the same as if AfterRequest just happened.
                        ProcessBrowsePrompt(inter.Contexts);
                    }
                }, cancellationToken).DoNotWait();
            } catch (Exception ex) when(!ex.IsCriticalException())
            {
                Dispose();
                throw;
            }
        }