public MonoDebugSession() : base()
        {
            _variableHandles = new Handles <ObjectValue[]>();
            _frameHandles    = new Handles <Mono.Debugging.Client.StackFrame>();
            _seenThreads     = new Dictionary <int, Thread>();

            _debuggerSessionOptions = new DebuggerSessionOptions {
                EvaluationOptions = EvaluationOptions.DefaultOptions
            };

            _session             = new XamarinDebuggerSession();
            _session.Breakpoints = new BreakpointStore();

            _breakpoints = new SortedDictionary <long, BreakEvent>();
            _catchpoints = new List <Catchpoint>();

            DebuggerLoggingService.CustomLogger = new CustomLogger();

            _session.ExceptionHandler = ex => {
                return(true);
            };

            _session.LogWriter = (isStdErr, text) => {
            };

            _session.TargetStopped += (sender, e) => {
                Stopped();
                SendEvent(CreateStoppedEvent("step", e.Thread));
                _resumeEvent.Set();
            };

            _session.TargetHitBreakpoint += (sender, e) => {
                Stopped();
                SendEvent(CreateStoppedEvent("breakpoint", e.Thread));
                _resumeEvent.Set();
            };

            _session.TargetExceptionThrown += (sender, e) => {
                Stopped();
                var ex = DebuggerActiveException();
                if (ex != null)
                {
                    _exception = ex.Instance;
                    SendEvent(CreateStoppedEvent("exception", e.Thread, ex.Message));
                }
                _resumeEvent.Set();
            };

            _session.TargetUnhandledException += (sender, e) => {
                Stopped();
                var ex = DebuggerActiveException();
                if (ex != null)
                {
                    _exception = ex.Instance;
                    SendEvent(CreateStoppedEvent("exception", e.Thread, ex.Message));
                }
                _resumeEvent.Set();
            };

            _session.TargetStarted += (sender, e) => {
                _activeFrame = null;
            };

            _session.TargetReady += (sender, e) => {
                _activeProcess = _session.GetProcesses().SingleOrDefault();
            };

            _session.TargetExited += (sender, e) => {
                DebuggerKill();

                _debuggeeKilled = true;

                Terminate("target exited");

                _resumeEvent.Set();
            };

            _session.TargetInterrupted += (sender, e) => {
                _resumeEvent.Set();
            };

            _session.TargetEvent += (sender, e) => {
            };

            _session.TargetThreadStarted += (sender, e) => {
                int tid = (int)e.Thread.Id;
                lock (_seenThreads) {
                    _seenThreads[tid] = new Thread(tid, e.Thread.Name);
                }
                SendEvent(new ThreadEvent("started", tid));
            };

            _session.TargetThreadStopped += (sender, e) => {
                int tid = (int)e.Thread.Id;
                lock (_seenThreads) {
                    _seenThreads.Remove(tid);
                }
                SendEvent(new ThreadEvent("exited", tid));
            };

            _session.OutputWriter = (isStdErr, text) => {
                SendOutput(isStdErr ? "stderr" : "stdout", text);
            };
        }
Beispiel #2
0
        public UnityDebugSession() : base()
        {
            m_VariableHandles = new Handles <ObjectValue[]>();
            m_FrameHandles    = new Handles <Mono.Debugging.Client.StackFrame>();
            m_SeenThreads     = new Dictionary <int, VSCodeDebug.Thread>();

            m_DebuggerSessionOptions = new DebuggerSessionOptions {
                EvaluationOptions = EvaluationOptions.DefaultOptions
            };

            m_Session             = new UnityDebuggerSession();
            m_Session.Breakpoints = new BreakpointStore();

            m_Catchpoints = new List <Catchpoint>();

            DebuggerLoggingService.CustomLogger = new CustomLogger();

            m_Session.ExceptionHandler = ex => {
                return(true);
            };

            m_Session.LogWriter = (isStdErr, text) => {
            };

            m_Session.TargetStopped += (sender, e) => {
                if (e.Backtrace != null)
                {
                    Frame = e.Backtrace.GetFrame(0);
                }
                else
                {
                    SendOutput("stdout", "e.Bracktrace is null");
                }
                Stopped();
                SendEvent(CreateStoppedEvent("step", e.Thread));
                m_ResumeEvent.Set();
            };

            m_Session.TargetHitBreakpoint += (sender, e) => {
                Frame = e.Backtrace.GetFrame(0);
                Stopped();
                SendEvent(CreateStoppedEvent("breakpoint", e.Thread));
                m_ResumeEvent.Set();
            };

            m_Session.TargetExceptionThrown += (sender, e) => {
                Frame = e.Backtrace.GetFrame(0);
                for (var i = 0; i < e.Backtrace.FrameCount; i++)
                {
                    if (!e.Backtrace.GetFrame(i).IsExternalCode)
                    {
                        Frame = e.Backtrace.GetFrame(i);
                        break;
                    }
                }
                Stopped();
                var ex = DebuggerActiveException();
                if (ex != null)
                {
                    m_Exception = ex.Instance;
                    SendEvent(CreateStoppedEvent("exception", e.Thread, ex.Message));
                }
                m_ResumeEvent.Set();
            };

            m_Session.TargetUnhandledException += (sender, e) => {
                Stopped();
                var ex = DebuggerActiveException();
                if (ex != null)
                {
                    m_Exception = ex.Instance;
                    SendEvent(CreateStoppedEvent("exception", e.Thread, ex.Message));
                }
                m_ResumeEvent.Set();
            };

            m_Session.TargetStarted += (sender, e) => {
            };

            m_Session.TargetReady += (sender, e) => {
                m_ActiveProcess = m_Session.GetProcesses().SingleOrDefault();
            };

            m_Session.TargetExited += (sender, e) => {
                DebuggerKill();

                Terminate("target exited");

                m_ResumeEvent.Set();
            };

            m_Session.TargetInterrupted += (sender, e) => {
                m_ResumeEvent.Set();
            };

            m_Session.TargetEvent += (sender, e) => {
            };

            m_Session.TargetThreadStarted += (sender, e) => {
                int tid = (int)e.Thread.Id;
                lock (m_SeenThreads) {
                    m_SeenThreads[tid] = new VSCodeDebug.Thread(tid, e.Thread.Name);
                }
                SendEvent(new ThreadEvent("started", tid));
            };

            m_Session.TargetThreadStopped += (sender, e) => {
                int tid = (int)e.Thread.Id;
                lock (m_SeenThreads) {
                    m_SeenThreads.Remove(tid);
                }
                SendEvent(new ThreadEvent("exited", tid));
            };

            m_Session.OutputWriter = (isStdErr, text) => {
                SendOutput(isStdErr ? "stderr" : "stdout", text);
            };
        }