Exemple #1
0
        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 => Tracer.ContinueAsync(ct);
                    }
                }

                if (continueMethod != null)
                {
                    TaskExtensions.RunSynchronouslyOnUIThread(continueMethod);
                }
            }

            return(VSConstants.S_OK);
        }
Exemple #2
0
        int IDebugExpression2.EvaluateSync(enum_EVALFLAGS dwFlags, uint dwTimeout, IDebugEventCallback2 pExprCallback, out IDebugProperty2 ppResult)
        {
            var res = TaskExtensions.RunSynchronouslyOnUIThread(ct => StackFrame.StackFrame.TryEvaluateAndDescribeAsync(_expression, AD7Property.PrefetchedProperties, AD7Property.Repr, ct));

            ppResult = new AD7Property(StackFrame, res);
            return(VSConstants.S_OK);
        }
Exemple #3
0
        public AD7StackFrame(AD7Engine engine, IRStackFrame stackFrame)
        {
            Engine     = engine;
            StackFrame = stackFrame;

            _property = Lazy.Create(() => new AD7Property(this, TaskExtensions.RunSynchronouslyOnUIThread(ct => StackFrame.DescribeEnvironmentAsync(cancellationToken: ct)), isFrameEnvironment: true));
        }
Exemple #4
0
 private void ResetStackFrames()
 {
     _stackFrames = Lazy.Create(() =>
                                (IReadOnlyList <IRStackFrame>)
                                TaskExtensions.RunSynchronouslyOnUIThread(ct => Engine.Tracer.Session.TracebackAsync(cancellationToken: ct))
                                .Reverse()
                                .ToArray());
 }
Exemple #5
0
        int IDebugEngine2.Attach(IDebugProgram2[] rgpPrograms, IDebugProgramNode2[] rgpProgramNodes, uint celtPrograms, IDebugEventCallback2 pCallback, enum_ATTACH_REASON dwReason)
        {
            ThrowIfDisposed();

            if (rgpPrograms.Length != 1)
            {
                throw new ArgumentException("Zero or more than one programs", nameof(rgpPrograms));
            }

            _program = rgpPrograms[0] as RDebugPortSupplier.DebugProgram;
            if (_program == null)
            {
                throw new ArgumentException("rgpPrograms[0] must be an " + nameof(RDebugPortSupplier.DebugProgram), nameof(rgpPrograms));
            }
            Marshal.ThrowExceptionForHR(_program.GetProgramId(out _programId));

            _events     = pCallback;
            Session     = _program.Session;
            Tracer      = TaskExtensions.RunSynchronouslyOnUIThread(ct => Session.TraceExecutionAsync(ct));
            MainThread  = new AD7Thread(this);
            IsConnected = true;

            // Enable breakpoint instrumentation.
            TaskExtensions.RunSynchronouslyOnUIThread(ct => Tracer.EnableBreakpointsAsync(true, ct));

            // Send notification after acquiring the session - we need it in case there were any breakpoints pending before
            // the attach, in which case we'll immediately get breakpoint creation requests as soon as we send these, and
            // we will need the session to process them.
            AD7EngineCreateEvent.Send(this);
            AD7ProgramCreateEvent.Send(this);
            Send(new AD7LoadCompleteEvent(), AD7LoadCompleteEvent.IID);

            var sessionProvider = WorkflowProvider.GetOrCreate().RSessions;

            sessionProvider.BrokerChanged += SessionProvider_BrokerChanged;

            // Register event handlers after notifying VS that debug engine has loaded. This order is important because
            // we may get a Browse event immediately, and we want to raise a breakpoint notification in response to that
            // to pause the debugger - but it will be ignored unless the engine has reported its creation.
            // Also, AfterRequest must be registered before Browse, so that we never get in a situation where we get
            // Browse but not AfterRequest that follows it because of a race between raising and registration.
            Session.AfterRequest += Session_AfterRequest;
            Session.Disconnected += Session_Disconnected;

            // If we're already at the Browse prompt, registering the handler will result in its immediate invocation.
            // We want to handle that fully before we process any following AfterRequest event to avoid concurrency issues
            // where we pause and never resume, so hold the lock while adding the handler.
            lock (_browseLock) {
                Tracer.Browse += Tracer_Browse;
            }

            return(VSConstants.S_OK);
        }
Exemple #6
0
        int IDebugProperty3.SetValueAsStringWithError(string pszValue, uint dwRadix, uint dwTimeout, out string errorString)
        {
            errorString = null;

            // TODO: dwRadix
            try {
                TaskExtensions.RunSynchronouslyOnUIThread(ct => EvaluationResult.AssignAsync(pszValue, ct));
            } catch (RException ex) {
                errorString = ex.Message;
                return(VSConstants.E_FAIL);
            }

            return(VSConstants.S_OK);
        }
        private int SetState(enum_BP_STATE state)
        {
            if (_state == enum_BP_STATE.BPS_ENABLED)
            {
                if (state == enum_BP_STATE.BPS_DISABLED || state == enum_BP_STATE.BPS_DELETED)
                {
                    if (DebugBreakpoint != null)
                    {
                        DebugBreakpoint.BreakpointHit -= DebugBreakpoint_BreakpointHit;
                        if (Engine.IsConnected)
                        {
                            if (Engine.IsProgramDestroyed)
                            {
                                // If engine is shutting down, do not wait for the delete eval to complete, to avoid
                                // blocking debugger detach if a long-running operation is in progress. This way the
                                // engine can just report successful detach right away, and breakpoints are deleted
                                // later, but as soon as it's actually possible.
                                DebugBreakpoint.DeleteAsync()
                                .SilenceException <MessageTransportException>()
                                .DoNotWait();
                            }
                            else
                            {
                                TaskExtensions.RunSynchronouslyOnUIThread(ct => DebugBreakpoint.DeleteAsync(ct));
                            }
                        }
                    }
                }
            }
            else
            {
                if (state == enum_BP_STATE.BPS_ENABLED)
                {
                    if (Engine.IsProgramDestroyed)
                    {
                        // Do not allow enabling breakpoints when engine is shutting down.
                        return(VSConstants.E_ABORT);
                    }

                    DebugBreakpoint = TaskExtensions.RunSynchronouslyOnUIThread(ct => Engine.Tracer.CreateBreakpointAsync(Location, ct));
                    DebugBreakpoint.BreakpointHit += DebugBreakpoint_BreakpointHit;
                }
            }

            _state = state;
            return(VSConstants.S_OK);
        }
Exemple #8
0
        private IReadOnlyList <IREvaluationResultInfo> CreateChildren() =>
        TaskExtensions.RunSynchronouslyOnUIThread(async ct => {
            var valueResult = EvaluationResult as IRValueInfo;
            if (valueResult == null)
            {
                return(new IREvaluationResultInfo[0]);
            }

            var children = await valueResult.DescribeChildrenAsync(PrefetchedProperties, Repr, ChildrenMaxCount, ct);

            // Children of environments do not have any meaningful order, so sort them by name.
            if (valueResult.TypeName == "environment")
            {
                children = children.OrderBy(er => er.Name).ToArray();
            }

            return(children);
        });
Exemple #9
0
        int IDebugProperty2.EnumChildren(enum_DEBUGPROP_INFO_FLAGS dwFields, uint dwRadix, ref Guid guidFilter, enum_DBG_ATTRIB_FLAGS dwAttribFilter, string pszNameFilter, uint dwTimeout, out IEnumDebugPropertyInfo2 ppEnum)
        {
            IEnumerable <IREvaluationResultInfo> children = _children.Value;

            if (!RToolsSettings.Current.ShowDotPrefixedVariables)
            {
                children = children.Where(v => v.Name != null && !v.Name.StartsWithOrdinal("."));
            }

            var infos = children.Select(v => new AD7Property(this, v).GetDebugPropertyInfo(dwRadix, dwFields));

            var valueResult = EvaluationResult as IRValueInfo;

            if (valueResult != null)
            {
                if (valueResult.HasAttributes() == true)
                {
                    string attrExpr   = Invariant($"base::attributes({valueResult.Expression})");
                    var    attrResult = TaskExtensions.RunSynchronouslyOnUIThread(ct => StackFrame.StackFrame.TryEvaluateAndDescribeAsync(attrExpr, "attributes()", PrefetchedProperties, Repr, ct));
                    if (!(attrResult is IRErrorInfo))
                    {
                        var attrInfo = new AD7Property(this, attrResult, isSynthetic: true).GetDebugPropertyInfo(dwRadix, dwFields);
                        infos = new[] { attrInfo }.Concat(infos);
                    }
                }

                if (valueResult.Flags.HasFlag(RValueFlags.HasParentEnvironment))
                {
                    string parentExpr   = Invariant($"base::parent.env({valueResult.Expression})");
                    var    parentResult = TaskExtensions.RunSynchronouslyOnUIThread(ct => StackFrame.StackFrame.TryEvaluateAndDescribeAsync(parentExpr, "parent.env()", PrefetchedProperties, Repr, ct));
                    if (!(parentResult is IRErrorInfo))
                    {
                        var parentInfo = new AD7Property(this, parentResult, isSynthetic: true).GetDebugPropertyInfo(dwRadix, dwFields);
                        infos = new[] { parentInfo }.Concat(infos);
                    }
                }
            }

            ppEnum = new AD7PropertyInfoEnum(infos.ToArray());
            return(VSConstants.S_OK);
        }
Exemple #10
0
        private string GetReprToString()
        {
            var code = Invariant($"rtvs:::repr_toString(eval(quote({EvaluationResult.Expression}), envir = {EvaluationResult.EnvironmentExpression}))");

            return(TaskExtensions.RunSynchronouslyOnUIThread(ct => StackFrame.Engine.Tracer.Session.EvaluateAsync <string>(code, REvaluationKind.Normal, ct)));
        }