public void SetUp()
        {
            var taskContext = new JoinableTaskContext();

            mockBreakpointManager = Substitute.For <IBreakpointManager>();
            mockBreakpointRequest = Substitute.For <IDebugBreakpointRequest2>();
            mockTarget            = Substitute.For <RemoteTarget>();
            mockProgram           = Substitute.For <IDebugProgram2>();
            mockMarshal           = Substitute.For <Marshal>();
            mockLldbBreakpoint    = Substitute.For <RemoteBreakpoint>();
            requestInfo           = new BP_REQUEST_INFO();
            mockBreakpointRequest.GetRequestInfo(Arg.Any <enum_BPREQI_FIELDS>(),
                                                 Arg.Any <BP_REQUEST_INFO[]>()).Returns(x =>
            {
                enum_BPREQI_FIELDS fields = (enum_BPREQI_FIELDS)x[0];
                BP_REQUEST_INFO[] breakpointRequestInfo = (BP_REQUEST_INFO[])x[1];
                if (breakpointRequestInfo == null || breakpointRequestInfo.Length == 0)
                {
                    return(1);
                }
                return(BuildBreakpointRequestInfo(fields, out breakpointRequestInfo[0]));
            });
            mockLldbBreakpoint.GetId().Returns(EXPECTED_ID);
            SetBreakpointType(enum_BP_LOCATION_TYPE.BPLT_CODE_FILE_LINE);

            mockBoundBreakpointFactory = Substitute.For <DebugBoundBreakpoint.Factory>();

            debugPendingBreakpointFactory = new DebugPendingBreakpoint.Factory(taskContext,
                                                                               mockBoundBreakpointFactory, new BreakpointErrorEnumFactory(),
                                                                               new BoundBreakpointEnumFactory());

            pendingBreakpoint = debugPendingBreakpointFactory.Create(
                mockBreakpointManager, mockProgram, mockBreakpointRequest, mockTarget,
                mockMarshal);
        }
        public void BindPassCount()
        {
            // Set a pass count on the request, and create a new pending breakpoint.
            const uint PASS_COUNT = 3u;

            SetPassCount(enum_BP_PASSCOUNT_STYLE.BP_PASSCOUNT_EQUAL, PASS_COUNT);
            pendingBreakpoint = debugPendingBreakpointFactory.Create(
                mockBreakpointManager, mockProgram, mockBreakpointRequest, mockTarget,
                mockMarshal);
            List <SbBreakpointLocation> mockBreakpointLocations =
                CreateMockBreakpointLocations(1);

            MockBreakpoint(mockBreakpointLocations);
            MockDocumentPosition(TEST_FILE_NAME, LINE_NUMBER, COLUMN_NUMBER);

            var mockBoundBreakpoint = Substitute.For <IBoundBreakpoint>();

            mockBoundBreakpointFactory.Create(pendingBreakpoint, mockBreakpointLocations[0],
                                              mockProgram, Guid.Empty).Returns(mockBoundBreakpoint);

            var result = pendingBreakpoint.Bind();
            IDebugErrorBreakpoint2 breakpointError = GetBreakpointError();

            var boundBreakpoints = GetBoundBreakpoints();

            Assert.AreEqual(1, boundBreakpoints.Count);
            Assert.AreSame(mockBoundBreakpoint, boundBreakpoints[0]);
            mockBoundBreakpoint.Received().SetPassCount(requestInfo.bpPassCount);

            mockBreakpointManager.Received().RegisterPendingBreakpoint(pendingBreakpoint);
            Assert.AreEqual(null, breakpointError);
            Assert.AreEqual(VSConstants.S_OK, result);
        }
        public void BindFunctionBreakpointWithOffset()
        {
            SetBreakpointType(enum_BP_LOCATION_TYPE.BPLT_CODE_FUNC_OFFSET);
            pendingBreakpoint = debugPendingBreakpointFactory.Create(
                mockBreakpointManager, mockProgram, mockBreakpointRequest, mockTarget,
                mockMarshal);

            MockFunctionBreakpoint(1);
            MockFunctionPosition(TEST_FUNCTION_NAME_WITH_OFFSET);

            uint offset = 10;

            mockTarget.CreateFunctionOffsetBreakpoint(TEST_FUNCTION_NAME, offset).Returns(
                new BreakpointErrorPair(mockLldbBreakpoint, BreakpointError.Success));

            var result = pendingBreakpoint.Bind();
            IDebugErrorBreakpoint2 breakpointError = GetBreakpointError();
            var boundBreakpoints = GetBoundBreakpoints();

            Assert.AreEqual(1, boundBreakpoints.Count);
            mockBreakpointManager.Received().RegisterPendingBreakpoint(pendingBreakpoint);

            Assert.AreEqual(null, breakpointError);
            Assert.AreEqual(VSConstants.S_OK, result);
        }
        public void RegisterBreakpointWithLocations(int id, uint locations)
        {
            IPendingBreakpoint pendingBreakpoint = Substitute.For <IPendingBreakpoint>();

            pendingBreakpoint.GetId().Returns(id);
            pendingBreakpoint.GetNumLocations().Returns(locations);
            breakpointManager.RegisterPendingBreakpoint(pendingBreakpoint);
        }
 /// <summary>
 /// Send a breakpoint bound event to the SDM.
 /// </summary>
 public static void OnBreakpointBound(
     this IDebugEngineHandler handler, IPendingBreakpoint pendingBreakpoint,
     IEnumerable <IDebugBoundBreakpoint2> newlyBoundBreakpoints,
     BoundBreakpointEnumFactory breakpointBoundEnumFactory,
     IGgpDebugProgram program) =>
 handler.SendEvent(
     new BreakpointBoundEvent(pendingBreakpoint, newlyBoundBreakpoints,
                              breakpointBoundEnumFactory), program);
示例#6
0
 public void EmitBreakpointBoundEvent(
     IPendingBreakpoint breakpoint,
     IEnumerable <IDebugBoundBreakpoint2> newlyBoundBreakpoints,
     BoundBreakpointEnumFactory breakpointBoundEnumFactory)
 {
     if (breakpoint.GetId() != -1)
     {
         debugEngineHandler.OnBreakpointBound(
             breakpoint, newlyBoundBreakpoints,
             breakpointBoundEnumFactory, debugProgram);
     }
 }
示例#7
0
        public void RemovePendingBreakpoint(IPendingBreakpoint breakpoint)
        {
            int id = breakpoint.GetId();

            if (id != -1)
            {
                pendingBreakpoints.Remove(id);
            }
            else
            {
                Trace.WriteLine(
                    "Failed to remove PendingBreakpoint: breakpoint does not have an ID.");
            }
        }
示例#8
0
        public void RegisterPendingBreakpoint(IPendingBreakpoint pendingBreakpoint)
        {
            int id = pendingBreakpoint.GetId();

            if (id != -1)
            {
                pendingBreakpoints[id] = pendingBreakpoint;
            }
            else
            {
                Trace.WriteLine(
                    "Failed to register PendingBreakpoint: breakpoint does not have an ID.");
            }
        }
        public void CanBindUnsupportedType()
        {
            // Set a unsupported breakpoint type and create a new pending breakpoint.
            SetBreakpointType(enum_BP_LOCATION_TYPE.BPLT_NONE);
            pendingBreakpoint = debugPendingBreakpointFactory.Create(
                mockBreakpointManager, mockProgram, mockBreakpointRequest, mockTarget,
                mockMarshal);

            IEnumDebugErrorBreakpoints2 errorBreakpointsEnum;
            var result = pendingBreakpoint.CanBind(out errorBreakpointsEnum);

            Assert.AreNotEqual(null, errorBreakpointsEnum);
            Assert.AreEqual(VSConstants.S_FALSE, result);
        }
        public void CanBindFunctionBreakpoint()
        {
            // Set a function breakpoint type and create a new pending breakpoint.
            SetBreakpointType(enum_BP_LOCATION_TYPE.BPLT_CODE_FUNC_OFFSET);
            pendingBreakpoint = debugPendingBreakpointFactory.Create(
                mockBreakpointManager, mockProgram, mockBreakpointRequest, mockTarget,
                mockMarshal);

            IEnumDebugErrorBreakpoints2 errorBreakpointsEnum;
            var result = pendingBreakpoint.CanBind(out errorBreakpointsEnum);

            Assert.AreEqual(null, errorBreakpointsEnum);
            Assert.AreEqual(VSConstants.S_OK, result);
        }
        public void SetUp()
        {
            var taskContext = new JoinableTaskContext();
            IDebugBreakpointRequest2 mockBreakpointRequest =
                Substitute.For <IDebugBreakpointRequest2>();

            mockBreakpointRequest.GetRequestInfo(Arg.Any <enum_BPREQI_FIELDS>(),
                                                 Arg.Any <BP_REQUEST_INFO[]>()).Returns(x =>
            {
                return(VSConstants.S_OK);
            });

            pendingBreakpoint = new DebugPendingBreakpoint.Factory(taskContext, null, null, null)
                                .Create(null, null, mockBreakpointRequest, null);
            pendingBreakpoint.Delete();
        }
        public void BindUnsupportedType()
        {
            // Set a unsupported breakpoint type and create a new pending breakpoint.
            SetBreakpointType(enum_BP_LOCATION_TYPE.BPLT_NONE);
            pendingBreakpoint = debugPendingBreakpointFactory.Create(
                mockBreakpointManager, mockProgram, mockBreakpointRequest, mockTarget,
                mockMarshal);

            var result = pendingBreakpoint.Bind();
            IDebugErrorBreakpoint2 breakpointError = GetBreakpointError();

            mockBreakpointManager.Received().ReportBreakpointError(
                Arg.Any <DebugBreakpointError>());
            Assert.AreNotEqual(null, breakpointError);
            Assert.AreEqual(VSConstants.S_FALSE, result);
        }
        public void BindInvalidFunction()
        {
            // Set a function breakpoint type and create a new pending breakpoint.
            SetBreakpointType(enum_BP_LOCATION_TYPE.BPLT_CODE_FUNC_OFFSET);
            pendingBreakpoint = debugPendingBreakpointFactory.Create(
                mockBreakpointManager, mockProgram, mockBreakpointRequest, mockTarget,
                mockMarshal);

            MockFunctionBreakpoint(1);
            MockFunctionPosition(null);

            var result = pendingBreakpoint.Bind();
            IDebugErrorBreakpoint2 breakpointError = GetBreakpointError();

            mockBreakpointManager.Received().ReportBreakpointError(
                Arg.Any <DebugBreakpointError>());
            Assert.AreNotEqual(null, breakpointError);
            Assert.AreEqual(VSConstants.S_FALSE, result);
        }
        public void GetNumLocations()
        {
            int numLocations = 8;

            // Set a function breakpoint type and create a new pending breakpoint.
            SetBreakpointType(enum_BP_LOCATION_TYPE.BPLT_CODE_FUNC_OFFSET);
            pendingBreakpoint = debugPendingBreakpointFactory.Create(
                mockBreakpointManager, mockProgram, mockBreakpointRequest, mockTarget,
                mockMarshal);

            MockFunctionBreakpoint(numLocations);
            MockFunctionPosition(TEST_FUNCTION_NAME);

            var result = pendingBreakpoint.Bind();
            IDebugErrorBreakpoint2 breakpointError = GetBreakpointError();

            Assert.AreEqual(null, breakpointError);
            Assert.AreEqual(VSConstants.S_OK, result);
            Assert.AreEqual(numLocations, pendingBreakpoint.GetNumLocations());
        }
        public void BindFunctionBreakpoint()
        {
            // Set a function breakpoint type and create a new pending breakpoint.
            SetBreakpointType(enum_BP_LOCATION_TYPE.BPLT_CODE_FUNC_OFFSET);
            pendingBreakpoint = debugPendingBreakpointFactory.Create(
                mockBreakpointManager, mockProgram, mockBreakpointRequest, mockTarget,
                mockMarshal);

            MockFunctionBreakpoint(1);
            MockFunctionPosition(TEST_FUNCTION_NAME);

            var result = pendingBreakpoint.Bind();
            IDebugErrorBreakpoint2 breakpointError = GetBreakpointError();
            var boundBreakpoints = GetBoundBreakpoints();

            Assert.AreEqual(1, boundBreakpoints.Count);
            mockBreakpointManager.Received().RegisterPendingBreakpoint(pendingBreakpoint);
            Assert.AreEqual(null, breakpointError);
            Assert.AreEqual(VSConstants.S_OK, result);
        }
        public void BindCodeAddressBreakpoint()
        {
            // Set code address breakpoint type and create a new pending breakpoint.
            SetBreakpointType(enum_BP_LOCATION_TYPE.BPLT_CODE_ADDRESS);
            pendingBreakpoint = debugPendingBreakpointFactory.Create(
                mockBreakpointManager, mockProgram, mockBreakpointRequest, mockTarget,
                mockMarshal);

            MockAssemblyBreakpoint(1);
            MockCodeAddress(STR_TEST_ADDRESS);

            var result = pendingBreakpoint.Bind();

            mockTarget.Received(1).BreakpointCreateByAddress(TEST_ADDRESS);
            IDebugErrorBreakpoint2 breakpointError = GetBreakpointError();
            var boundBreakpoints = GetBoundBreakpoints();

            Assert.AreEqual(1, boundBreakpoints.Count);
            mockBreakpointManager.Received().RegisterPendingBreakpoint(pendingBreakpoint);
            Assert.AreEqual(null, breakpointError);
            Assert.AreEqual(VSConstants.S_OK, result);
        }
        public void SetUp()
        {
            _mockSbListener         = Substitute.For <SbListener>();
            _mockSbProcess          = Substitute.For <SbProcess>();
            _mockSbEvent            = Substitute.For <SbEvent>();
            _mockRemoteThread       = Substitute.For <RemoteThread>();
            _mockBreakpointManager  = Substitute.For <IBreakpointManager>();
            _mockDebugEngineHandler = Substitute.For <IDebugEngineHandler>();

            _mockPendingBreakpoint1 = Substitute.For <IPendingBreakpoint>();
            _mockPendingBreakpoint2 = Substitute.For <IPendingBreakpoint>();
            _mockBoundBreakpoint1   = Substitute.For <IBoundBreakpoint>();
            _mockBoundBreakpoint2   = Substitute.For <IBoundBreakpoint>();
            _mockBoundBreakpoint3   = Substitute.For <IBoundBreakpoint>();
            _mockWatchpoint         = Substitute.For <IWatchpoint>();
            _mockProgram            = Substitute.For <IGgpDebugProgram>();

            MockEvent(EventType.STATE_CHANGED, StateType.STOPPED, false);
            MockListener(_mockSbEvent, true);
            MockThread(_mockRemoteThread, StopReason.BREAKPOINT, _breakpointStopData);
            MockProcess(new List <RemoteThread> {
                _mockRemoteThread
            });
            MockBreakpointManager();

            _mockListenerSubscriber = Substitute.For <LldbListenerSubscriber>(_mockSbListener);

            var threadContext = new FakeMainThreadContext();

            _eventManager =
                new LldbEventManager
                .Factory(new BoundBreakpointEnumFactory(), threadContext.JoinableTaskContext)
                .Create(_mockDebugEngineHandler, _mockBreakpointManager, _mockProgram,
                        _mockSbProcess, _mockListenerSubscriber);

            var lldbEventManager = _eventManager as LldbEventManager;

            lldbEventManager?.SubscribeToChanges();
        }
        public void BindFunctionBreakpointWithoutOffset()
        {
            SetBreakpointType(enum_BP_LOCATION_TYPE.BPLT_CODE_FUNC_OFFSET);
            pendingBreakpoint = debugPendingBreakpointFactory.Create(
                mockBreakpointManager, mockProgram, mockBreakpointRequest, mockTarget,
                mockMarshal);

            MockFunctionBreakpoint(1);
            MockFunctionPosition(TEST_FUNCTION_NAME_WITHOUT_OFFSET);

            var result = pendingBreakpoint.Bind();
            IDebugErrorBreakpoint2 breakpointError = GetBreakpointError();
            var boundBreakpoints = GetBoundBreakpoints();

            mockTarget.Received().BreakpointCreateByName(TEST_FUNCTION_NAME);
            Assert.AreEqual(1, boundBreakpoints.Count);
            mockBreakpointManager.Received().RegisterPendingBreakpoint(pendingBreakpoint);

            mockTarget.DidNotReceive().BreakpointDelete(Arg.Any <int>());
            Assert.AreEqual(null, breakpointError);
            Assert.AreEqual(VSConstants.S_OK, result);
        }
        public void SetUp()
        {
            taskContext           = new JoinableTaskContext();
            mockBreakpointRequest = Substitute.For <IDebugBreakpointRequest2>();
            mockTarget            = Substitute.For <RemoteTarget>();
            mockProgram           = Substitute.For <IGgpDebugProgram>();
            mockPendingBreakpoint = Substitute.For <IPendingBreakpoint>();
            mockPendingBreakpoint.GetId().Returns(ID);
            mockWatchpoint = Substitute.For <IWatchpoint>();
            mockWatchpoint.GetId().Returns(ID);
            mockPendingBreakpointFactory = Substitute.For <DebugPendingBreakpoint.Factory>();
            mockWatchpointFactory        = Substitute.For <DebugWatchpoint.Factory>();
            var mockDebugEngineHandler = Substitute.For <IDebugEngineHandler>();

            breakpointManager = new LldbBreakpointManager.Factory(taskContext,
                                                                  mockPendingBreakpointFactory, mockWatchpointFactory).Create(mockDebugEngineHandler,
                                                                                                                              mockProgram);

            mockPendingBreakpointFactory.Create(breakpointManager, mockProgram,
                                                mockBreakpointRequest, mockTarget).ReturnsForAnyArgs(mockPendingBreakpoint);
            mockWatchpointFactory.Create(breakpointManager, mockBreakpointRequest, mockTarget,
                                         mockProgram).ReturnsForAnyArgs(mockWatchpoint);
        }
        public void BindInvalidFunctionBreakpointWithOffset()
        {
            SetBreakpointType(enum_BP_LOCATION_TYPE.BPLT_CODE_FUNC_OFFSET);
            pendingBreakpoint = debugPendingBreakpointFactory.Create(
                mockBreakpointManager, mockProgram, mockBreakpointRequest, mockTarget,
                mockMarshal);

            MockFunctionBreakpoint(1);
            MockFunctionPosition(TEST_FUNCTION_NAME_WITH_OFFSET);

            // OffsetBreakpoint returns null when it fails
            //mockLldbBreakpoint.OffsetBreakpoint(offset).Returns((RemoteBreakpoint)null);

            var result = pendingBreakpoint.Bind();
            IDebugErrorBreakpoint2 breakpointError = GetBreakpointError();
            var boundBreakpoints = GetBoundBreakpoints();

            Assert.AreEqual(0, boundBreakpoints.Count);
            mockBreakpointManager.DidNotReceive().RegisterPendingBreakpoint(pendingBreakpoint);

            Assert.AreNotEqual(null, breakpointError);
            Assert.AreEqual(VSConstants.S_FALSE, result);
        }
示例#21
0
 public bool GetPendingBreakpointById(int id, out IPendingBreakpoint pendingBreakpoint)
 {
     return(pendingBreakpoints.TryGetValue(id, out pendingBreakpoint));
 }