コード例 #1
0
        public void OnBreakpointChanged(BreakpointEventType eventType)
        {
            IPendingBreakpoint[] breakpoints =
            {
                GetBreakpointSubstitute(1), GetBreakpointSubstitute(2),
                GetBreakpointSubstitute(3)
            };
            _breakpointManager.GetPendingBreakpointById(Arg.Any <int>(), out IPendingBreakpoint _)
            .Returns(x =>
            {
                x[1] = breakpoints.First(b => b.GetId() == (int)x[0]);
                return(true);
            });
            SbEvent evnt = Substitute.For <SbEvent>();
            IEventBreakpointData breakpointData = Substitute.For <IEventBreakpointData>();

            evnt.IsBreakpointEvent.Returns(true);
            evnt.BreakpointData.Returns(breakpointData);
            breakpointData.BreakpointId.Returns(2);
            breakpointData.EventType.Returns(eventType);

            _attachedProgram.Start(Substitute.For <IDebugEngine2>());
            _listenerSubscriber.BreakpointChanged +=
                Raise.EventWith(null, new BreakpointChangedEventArgs(evnt));

            breakpoints[0].DidNotReceive().UpdateLocations();
            breakpoints[1].Received(1).UpdateLocations();
            breakpoints[2].DidNotReceive().UpdateLocations();
        }
コード例 #2
0
 void MockListener(SbEvent sbEvent, bool waitForEventResult)
 {
     _mockSbListener.WaitForEvent(Arg.Any <uint>(), out SbEvent _).Returns(x => {
         x[1] = sbEvent;
         return(waitForEventResult);
     });
 }
コード例 #3
0
        public void HandleEventNoEvent()
        {
            _mockSbEvent = null;

            RaiseSingleStateChanged();

            _mockDebugEngineHandler.DidNotReceive().SendEvent(Arg.Any <DebugEvent>(), _mockProgram,
                                                              Arg.Any <RemoteThread>());
            _mockDebugEngineHandler.DidNotReceive().SendEvent(Arg.Any <DebugEvent>(), _mockProgram,
                                                              Arg.Any <IDebugThread2>());
        }
コード例 #4
0
        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();
        }
コード例 #5
0
        public bool WaitForEvent(uint numSeconds, out SbEvent evnt)
        {
            WaitForEventResponse response = null;

            if (connection.InvokeRpc(() =>
            {
                response = client.WaitForEvent(
                    new WaitForEventRequest
                {
                    Listener = grpcListener,
                    NumSeconds = numSeconds,
                });
            }))
            {
                if (response.Result)
                {
                    evnt = eventFactory.Create(response.Event);
                    return(true);
                }
            }
            evnt = null;
            return(false);
        }
コード例 #6
0
 public bool WaitForEvent(uint numSeconds, out SbEvent evnt)
 {
     Interlocked.Increment(ref _waitForEventCallCount);
     evnt = null;
     return(false);
 }
コード例 #7
0
 public BreakpointChangedEventArgs(SbEvent evt)
 {
     Event = evt;
 }
コード例 #8
0
 public StateChangedEventArgs(SbEvent sbEvent)
 {
     Event = sbEvent;
 }
コード例 #9
0
        // Called when we receive a state changed LLDB event.
        void OnStateChangedEvent(SbEvent sbEvent)
        {
            if (sbEvent == null)
            {
                return;
            }

            var type = sbEvent.GetStateType();

            Debug.WriteLine("Received LLDB event: " + Enum.GetName(type.GetType(), type));
            switch (type)
            {
            case StateType.STOPPED:
                if (sbEvent.GetProcessRestarted())
                {
                    break;
                }

                var currentThread     = _lldbProcess.GetSelectedThread();
                var currentStopReason = StopReason.INVALID;
                if (currentThread != null)
                {
                    currentStopReason = currentThread.GetStopReason();
                }

                // When stopping pick the most relevant thread based on the stop reason.
                if (currentThread == null || currentStopReason == StopReason.INVALID ||
                    currentStopReason == StopReason.NONE)
                {
                    int          numThreads  = _lldbProcess.GetNumThreads();
                    RemoteThread planThread  = null;
                    RemoteThread otherThread = null;
                    for (int i = 0; i < numThreads; ++i)
                    {
                        RemoteThread thread = _lldbProcess.GetThreadAtIndex(i);
                        switch (thread.GetStopReason())
                        {
                        case StopReason.INVALID:
                        // fall-through
                        case StopReason.NONE:
                            break;

                        case StopReason.SIGNAL:
                            if (otherThread == null)
                            {
                                var signalNumber = thread.GetStopReasonDataAtIndex(0);
                                var unixSignals  = _lldbProcess.GetUnixSignals();
                                if (unixSignals != null &&
                                    unixSignals.GetShouldStop((int)signalNumber))
                                {
                                    otherThread = thread;
                                }
                            }
                            break;

                        case StopReason.TRACE:
                        // fall-through
                        case StopReason.BREAKPOINT:
                        // fall-through
                        case StopReason.WATCHPOINT:
                        // fall-through
                        case StopReason.EXCEPTION:
                        // fall-through
                        case StopReason.EXEC:
                        // fall-through
                        case StopReason.EXITING:
                        // fall-through
                        case StopReason.INSTRUMENTATION:
                            if (otherThread == null)
                            {
                                otherThread = thread;
                            }
                            break;

                        case StopReason.PLAN_COMPLETE:
                            if (planThread == null)
                            {
                                planThread = thread;
                            }
                            break;
                        }
                    }
                    if (planThread != null)
                    {
                        currentThread = planThread;
                    }
                    else if (otherThread != null)
                    {
                        currentThread = otherThread;
                    }
                    else if (currentThread == null)
                    {
                        currentThread = _lldbProcess.GetThreadAtIndex(0);
                    }
                    if (currentThread == null)
                    {
                        Trace.WriteLine("Error: Cannot handle event. No thread found.");
                        return;
                    }
                    _lldbProcess.SetSelectedThreadById(currentThread.GetThreadId());
                    currentStopReason = currentThread.GetStopReason();
                }

                // Log specific information about the stop event.
                string message = "Received stop event.  Reason: " + currentStopReason;

                var stopReasonDataCount = currentThread.GetStopReasonDataCount();
                if (stopReasonDataCount > 0)
                {
                    message += " Data:";
                    for (uint i = 0; i < stopReasonDataCount; i++)
                    {
                        message += " " + currentThread.GetStopReasonDataAtIndex(i);
                    }
                }
                Trace.WriteLine(message);

                _taskContext.Factory.Run(async() => {
                    // We run the event resolution on the main thread to make sure
                    // we do not race with concurrent modifications in the breakpoint
                    // manager class (we could just have hit breakpoint that is being
                    // added by the main thread!).
                    await _taskContext.Factory.SwitchToMainThreadAsync();
                    DebugEvent eventToSend = null;
                    switch (currentStopReason)
                    {
                    case StopReason.BREAKPOINT:
                        eventToSend = HandleBreakpointStop(currentThread);
                        break;

                    case StopReason.WATCHPOINT:
                        eventToSend = HandleWatchpointStop(currentThread);
                        break;

                    case StopReason.SIGNAL:
                        eventToSend = HandleSignalStop(currentThread);
                        break;

                    case StopReason.PLAN_COMPLETE:
                        eventToSend = new StepCompleteEvent();
                        break;

                    default:
                        break;
                    }
                    if (eventToSend == null)
                    {
                        eventToSend = new BreakEvent();
                    }
                    _debugEngineHandler.SendEvent(eventToSend,_program,currentThread);
                });
                break;

            case StateType.EXITED:
            {
                // There are two ways to exit a debug session without an error:
                //   - We call program.Terminate, which causes LLDB to send this event.
                //   - Program exits by itself, resulting in this event.
                // We distinguish these events by checking if we called Terminate.
                ExitReason exitReason = _program.TerminationRequested
                                                    ? ExitReason.DebuggerTerminated
                                                    : ExitReason.ProcessExited;
                _debugEngineHandler.Abort(_program,ExitInfo.Normal(exitReason));
            }
            break;

            case StateType.DETACHED:
            {
                // Normally the only way to detach the process is by program.Detach.
                // However, this check was retained to mirror the EXITED case and to
                // record unexpected instances of detaching through some other path.
                ExitReason exitReason = _program.DetachRequested
                                                    ? ExitReason.DebuggerDetached
                                                    : ExitReason.ProcessDetached;
                _debugEngineHandler.Abort(_program,ExitInfo.Normal(exitReason));
            }
            break;
            }
        }