Example #1
0
        public void GetCurrentState(IVariableEntryInternal child,
                                    Action <DEBUG_PROPERTY_INFO> callback)
        {
            int index = _childToIndex[child];

            if (index != _currentBatchIndex)
            {
                HResultChecker.Check(_childEnum.Reset());
                HResultChecker.Check(_childEnum.Skip((uint)index));
                _currentBatchIndex = index;
            }

            if (_currentBatch.Count == 0)
            {
                int toFetch =
                    Math.Max(0, Math.Min(_batchSize, _totalChildCount - _currentBatchIndex));
                var  propertyInfos = new DEBUG_PROPERTY_INFO[toFetch];
                uint numFetched;
                HResultChecker.Check(
                    _childEnum.Next((uint)toFetch, propertyInfos, out numFetched));
                propertyInfos.ForEach(info => _currentBatch.Enqueue(info));
            }

            _currentBatchIndex++;
            callback(_currentBatch.Dequeue());
        }
        IEnumerable <IDebugBoundBreakpoint2> GetBoundBreakpointsFired()
        {
            var breakpointEvent = evnt as IDebugBreakpointEvent2;

            if (breakpointEvent == null)
            {
                return(Enumerable.Empty <IDebugBoundBreakpoint2>());
            }

            IEnumDebugBoundBreakpoints2 boundBreakpointsEnum;

            HResultChecker.Check(breakpointEvent.EnumBreakpoints(out boundBreakpointsEnum));
            HResultChecker.Check(boundBreakpointsEnum.Reset());
            uint count;

            HResultChecker.Check(boundBreakpointsEnum.GetCount(out count));
            var  boundBreakpoints = new IDebugBoundBreakpoint2[count];
            uint actual           = 0;

            HResultChecker.Check(boundBreakpointsEnum.Next(count, boundBreakpoints, ref actual));
            if (actual != count)
            {
                throw new VSFakeException("Could not fetch all bound breakpoints. " +
                                          $"Expected: {count}, got: {actual}");
            }
            return(boundBreakpoints);
        }
Example #3
0
        IDebugExpressionContext2 GetExpressionContext()
        {
            IDebugExpressionContext2 expressionContext;

            HResultChecker.Check(_debugSessionContext.SelectedStackFrame.GetExpressionContext(
                                     out expressionContext));
            return(expressionContext);
        }
Example #4
0
        DEBUG_PROPERTY_INFO GetPropertyInfo(IDebugProperty2 debugProperty)
        {
            var infos = new DEBUG_PROPERTY_INFO[1];

            HResultChecker.Check(debugProperty.GetPropertyInfo(
                                     enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_ALL, Radix, 0, null, 0, infos));
            return(infos[0]);
        }
Example #5
0
        IDebugProperty2 EvaluateExpression(IDebugExpression2 debugExpression)
        {
            IDebugProperty2 debugProperty;

            // TODO: Provide proper eval flags to IDebugExpression2.EvaluateSync.
            HResultChecker.Check(debugExpression.EvaluateSync(0, 0, null, out debugProperty));
            return(debugProperty);
        }
Example #6
0
 protected void ContinueFromSynchronousEvent()
 {
     taskContext.Factory.Run(async() =>
     {
         await taskContext.Factory.SwitchToMainThreadAsync();
         var result = debugEngine.ContinueFromSynchronousEvent(evnt);
         HResultChecker.Check(result);
     });
 }
Example #7
0
        public void Continue()
        {
            EnsureProgramIsSelected();
            EnsureThreadIsSelected();
            var curThread = _debugSessionContext.SelectedThread;

            SetRunningState();
            // TODO: Figure out if we need to unwrap interop values passed back
            // to the debug engine.
            HResultChecker.Check(_debugSessionContext.DebugProgram.ExecuteOnThread(curThread));
        }
Example #8
0
        void HandleBoundEvent(IDebugBreakpointBoundEvent2 evnt)
        {
            IDebugPendingBreakpoint2 pendingBreakpoint;

            HResultChecker.Check(evnt.GetPendingBreakpoint(out pendingBreakpoint));
            var state = new PENDING_BP_STATE_INFO[1];

            HResultChecker.Check(pendingBreakpoint.GetState(state));
            var breakpoint = _pendingToBreakpoint[pendingBreakpoint];

            breakpoint.State = ToBreakpointState(state[0].state);
        }
Example #9
0
        void Step(enum_STEPKIND stepKind, enum_STEPUNIT stepUnit)
        {
            EnsureProgramIsSelected();
            EnsureThreadIsSelected();
            var curThread = _debugSessionContext.SelectedThread;

            SetRunningState();
            // TODO: Figure out if we need to unwrap interop values passed back
            // to the debug engine.
            HResultChecker.Check(
                _debugSessionContext.DebugProgram.Step(curThread, stepKind, stepUnit));
        }
Example #10
0
        public void Set(IEnumerable <IDebugBoundBreakpoint2> boundBreakpoints)
        {
            if (!boundBreakpoints.Any())
            {
                FiredBreakpoint = null;
                return;
            }

            IDebugPendingBreakpoint2 pendingBreakpoint;

            HResultChecker.Check(
                boundBreakpoints.First().GetPendingBreakpoint(out pendingBreakpoint));
            FiredBreakpoint = _pendingToBreakpoint[pendingBreakpoint];
        }
Example #11
0
        IDebugExpression2 ParseExpression(string expression)
        {
            IDebugExpression2 debugExpression;
            string            errorString;
            uint error;

            HResultChecker.Check(
                GetExpressionContext().ParseText(expression, enum_PARSEFLAGS.PARSE_EXPRESSION,
                                                 Radix, out debugExpression, out errorString, out error));
            if (!string.IsNullOrEmpty(errorString) || error != 0)
            {
                throw new NotSupportedException(
                          $"VSFake doesn't know how to handle the error: ({errorString}, {error})");
            }
            return(debugExpression);
        }
Example #12
0
        public int AddProgramNode(IDebugProgramNode2 programNode)
        {
            programNodes.Add(programNode);
            var port = defaultPortFactory.Create(this);
            // TODO: Should this synchronously call IDebugEngine2.Attach() or should it
            // add a job to the job queue?
            var result = debugEngine.Attach(
                new IDebugProgram2[]
            {
                debugProgramFactory.Create(processFactory.Create("Game Process", port))
            },
                new IDebugProgramNode2[] { programNode }, 1, callback,
                enum_ATTACH_REASON.ATTACH_REASON_LAUNCH);

            HResultChecker.Check(result);
            return(VSConstants.S_OK);
        }
Example #13
0
        public void UpdateDebugProperty(IDebugProperty3 debugProperty)
        {
            if (_debugProperty == debugProperty)
            {
                return;
            }
            _debugProperty = debugProperty;

            int prevTotalChildCount = _totalChildCount;

            if (_debugProperty != null)
            {
                Guid guidFilter = Guid.Empty;
                _childEnum = null;
                HResultChecker.Check(
                    debugProperty.EnumChildren(
                        enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_ALL, Radix, ref guidFilter,
                        enum_DBG_ATTRIB_FLAGS.DBG_ATTRIB_NONE, null, 0, out _childEnum));

                uint totalChildCount;
                HResultChecker.Check(_childEnum.GetCount(out totalChildCount));
                _totalChildCount = (int)totalChildCount;
            }
            else
            {
                _childEnum       = null;
                _totalChildCount = 0;
            }

            _currentBatch.Clear();
            _currentBatchIndex = 0;

            // Emulate Visual Studio:
            // If the number of children changed, collapse (delete) them. Otherwise, refresh them.
            if (prevTotalChildCount != _totalChildCount)
            {
                DeleteChildren();
            }
            else
            {
                _childToIndex.Keys.ForEach(child => child.Refresh());
            }
        }
Example #14
0
 void Bind(Breakpoint breakpoint)
 {
     using (var breakpointRequest = breakpoint.CreateRequest())
     {
         IDebugPendingBreakpoint2 pendingBreakpoint = null;
         _taskContext.RunOnMainThread(() => HResultChecker.Check(
                                          _debugSessionContext.DebugEngine.CreatePendingBreakpoint(
                                              breakpointRequest, out pendingBreakpoint)));
         breakpoint.PendingBreakpoint            = pendingBreakpoint;
         _pendingToBreakpoint[pendingBreakpoint] = breakpoint;
         HResultChecker.Check(pendingBreakpoint.Enable(1));
         if (pendingBreakpoint.Virtualize(1) != VSConstants.E_NOTIMPL)
         {
             throw new InvalidOperationException("VSFake should be updated to handle " +
                                                 $"{nameof(pendingBreakpoint.Virtualize)}.");
         }
         pendingBreakpoint.Bind();
     }
 }
        IEnumerable <IDebugStackFrame2> GetFrames()
        {
            IEnumDebugFrameInfo2 enumFrames;
            var result = _thread.EnumFrameInfo(enum_FRAMEINFO_FLAGS.FIF_FRAME, 0, out enumFrames);

            HResultChecker.Check(result);

            uint count;

            result = enumFrames.GetCount(out count);
            HResultChecker.Check(result);

            var  frames     = new FRAMEINFO[count];
            uint numFetched = 0;

            result = enumFrames.Next(count, frames, ref numFetched);
            HResultChecker.Check(result);
            return(frames.Select(f => f.m_pFrame));
        }
Example #16
0
        void HandleErrorEvent(IDebugBreakpointErrorEvent2 evnt)
        {
            IDebugErrorBreakpoint2 errorBreakpoint;

            HResultChecker.Check(evnt.GetErrorBreakpoint(out errorBreakpoint));
            IDebugErrorBreakpointResolution2 errorBreakpointResolution;

            HResultChecker.Check(
                errorBreakpoint.GetBreakpointResolution(out errorBreakpointResolution));
            var errorResolutionInfo = new BP_ERROR_RESOLUTION_INFO[1];

            HResultChecker.Check(errorBreakpointResolution.GetResolutionInfo(
                                     enum_BPERESI_FIELDS.BPERESI_MESSAGE, errorResolutionInfo));
            IDebugPendingBreakpoint2 pendingBreakpoint;

            HResultChecker.Check(errorBreakpoint.GetPendingBreakpoint(out pendingBreakpoint));
            var breakpoint = _pendingToBreakpoint[pendingBreakpoint];

            breakpoint.Error = errorResolutionInfo[0].bstrMessage;
            breakpoint.State = BreakpointState.Error;
        }
Example #17
0
        void DeleteAll(Breakpoint breakpoint)
        {
            if (breakpoint.State == BreakpointState.Pending ||
                breakpoint.State == BreakpointState.Deleted)
            {
                throw new InvalidOperationException(
                          $"Cannot delete breakpoint ({breakpoint}); state = {breakpoint.State}.");
            }

            bool shouldDeleteInteropBreakpoint =
                breakpoint.State == BreakpointState.Disabled ||
                breakpoint.State == BreakpointState.Enabled;

            breakpoint.State = BreakpointState.Pending;
            _jobQueue.Push(_breakpointDeleteJobFactory.Create(() =>
            {
                if (shouldDeleteInteropBreakpoint)
                {
                    HResultChecker.Check(breakpoint.PendingBreakpoint.Delete());
                }
                breakpoint.State = BreakpointState.Deleted;
                _breakpoints.Remove(breakpoint);
            }, $"{{{breakpoint}}}"));
        }
        void Launch(bool resume)
        {
            IDebugEngine2 debugEngine = null;

            _taskContext.RunOnMainThread(() => debugEngine = _createDebugEngine());
            _debugSessionContext.DebugEngine  = debugEngine;
            _debugSessionContext.ProgramState = ProgramState.NotStarted;

            IDebugEngineLaunch2 debugEngineLauncher = (IDebugEngineLaunch2)debugEngine;

            // TODO: Use the correct DebugLaunchOptions value.
            var launchSettings =
                _targetAdapter.QueryDebugTargets(_projectAdapter.Project, 0).First();

            var port = _targetAdapter.InitializePort(_debugEventCallback, debugEngine);

            HResultChecker.Check(debugEngineLauncher.LaunchSuspended("", // server
                                                                     port,
                                                                     launchSettings.Executable,
                                                                     launchSettings.Arguments,
                                                                     "", // dir,
                                                                     "", // env
                                                                     launchSettings.Options,
                                                                     default(enum_LAUNCH_FLAGS),
                                                                     0, // stdinput,
                                                                     0, // stdoutput,
                                                                     0, // stderr,
                                                                     _debugEventCallback,
                                                                     out IDebugProcess2 process));
            _debugSessionContext.Process      = process;
            _debugSessionContext.ProgramState = ProgramState.LaunchSuspended;
            if (resume)
            {
                HResultChecker.Check(debugEngineLauncher.ResumeProcess(process));
            }
        }
Example #19
0
 public void Stop()
 {
     EnsureProgramIsSelected();
     HResultChecker.Check(_debugSessionContext.DebugProgram.Terminate());
 }
Example #20
0
 public void Pause()
 {
     EnsureProgramIsSelected();
     HResultChecker.Check(_debugSessionContext.DebugProgram.CauseBreak());
 }