public override void Threads(Response response, dynamic args)
        {
            var threads = new List <VSCodeDebug.Thread>();
            var process = Debugger.ActiveProcess;

            if (process != null)
            {
                Dictionary <int, VSCodeDebug.Thread> d;
                lock (_seenThreads) {
                    d = new Dictionary <int, VSCodeDebug.Thread>(_seenThreads);
                }
                foreach (var t in process.GetThreads())
                {
                    int tid = (int)t.Id;
                    d[tid] = new VSCodeDebug.Thread(tid, t.Name);
                }
                threads = d.Values.ToList();
            }
            SendResponse(response, new ThreadsResponseBody(threads));
        }
        public UnityDebugSession() : base(true)
        {
            _variableHandles = new Handles <ObjectValue[]>();
            _frameHandles    = new Handles <Mono.Debugging.Client.StackFrame>();
            _seenThreads     = new Dictionary <int, VSCodeDebug.Thread>();

            Configuration.Current.MaxConnectionAttempts     = 10;
            Configuration.Current.ConnectionAttemptInterval = 500;

            // install an event handler in SDB
            Debugger.Callback = (type, threadinfo, text) => {
                int tid;
                switch (type)
                {
                case "TargetStopped":
                    Stopped();
                    SendEvent(CreateStoppedEvent("step", threadinfo));
                    break;

                case "TargetHitBreakpoint":
                    Stopped();
                    SendEvent(CreateStoppedEvent("breakpoint", threadinfo));
                    break;

                case "TargetExceptionThrown":
                case "TargetUnhandledException":
                    Stopped();
                    ExceptionInfo ex = Debugger.ActiveException;
                    if (ex != null)
                    {
                        _exception = ex.Instance;
                    }
                    SendEvent(CreateStoppedEvent("exception", threadinfo, Debugger.ActiveException.Message));
                    break;

                case "TargetExited":
                    Terminate("target exited");
                    break;

                case "TargetThreadStarted":
                    tid = (int)threadinfo.Id;
                    lock (_seenThreads) {
                        _seenThreads[tid] = new VSCodeDebug.Thread(tid, threadinfo.Name);
                    }
                    SendEvent(new ThreadEvent("started", tid));
                    break;

                case "TargetThreadStopped":
                    tid = (int)threadinfo.Id;
                    lock (_seenThreads) {
                        _seenThreads.Remove(tid);
                    }
                    SendEvent(new ThreadEvent("exited", tid));
                    break;

                case "Output":
                    SendOutput("stdout", text);
                    break;

                case "ErrorOutput":
                    SendOutput("stderr", text);
                    break;

                default:
                    SendEvent(new Event(type));
                    break;
                }
            };
        }
        public UnityDebugSession()
            : base(true)
        {
            _variableHandles = new Handles<ObjectValue[]>();
            _frameHandles = new Handles<Mono.Debugging.Client.StackFrame>();
            _seenThreads = new Dictionary<int, VSCodeDebug.Thread>();

            Configuration.Current.MaxConnectionAttempts = 10;
            Configuration.Current.ConnectionAttemptInterval = 500;

            // install an event handler in SDB
            Debugger.Callback = (type, threadinfo, text) => {
                int tid;
                switch (type) {
                case "TargetStopped":
                    Stopped();
                    SendEvent(CreateStoppedEvent("step", threadinfo));
                    break;

                case "TargetHitBreakpoint":
                    Stopped();
                    SendEvent(CreateStoppedEvent("breakpoint", threadinfo));
                    break;

                case "TargetExceptionThrown":
                case "TargetUnhandledException":
                    Stopped();
                    ExceptionInfo ex = Debugger.ActiveException;
                    if (ex != null) {
                        _exception = ex.Instance;
                    }
                    SendEvent(CreateStoppedEvent("exception", threadinfo, Debugger.ActiveException.Message));
                    break;

                case "TargetExited":
                    Terminate("target exited");
                    break;

                case "TargetThreadStarted":
                    tid = (int)threadinfo.Id;
                    lock (_seenThreads) {
                        _seenThreads[tid] = new VSCodeDebug.Thread(tid, threadinfo.Name);
                    }
                    SendEvent(new ThreadEvent("started", tid));
                    break;

                case "TargetThreadStopped":
                    tid = (int)threadinfo.Id;
                    lock (_seenThreads) {
                        _seenThreads.Remove(tid);
                    }
                    SendEvent(new ThreadEvent("exited", tid));
                    break;

                case "Output":
                    SendOutput("stdout", text);
                    break;

                case "ErrorOutput":
                    SendOutput("stderr", text);
                    break;

                default:
                    SendEvent(new Event(type));
                    break;
                }
            };
        }
        public UnityDebugSession()
        {
            Log.Write("Constructing UnityDebugSession");
            m_ResumeEvent     = new AutoResetEvent(false);
            m_Breakpoints     = new Dictionary <string, Dictionary <int, Breakpoint> >();
            m_VariableHandles = new Handles <ObjectValue[]>();
            m_FrameHandles    = new Handles <StackFrame>();
            m_SeenThreads     = new Dictionary <int, 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) =>
            {
                SendOutput(isStdErr ? "stderr" : "stdout", 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) =>
            {
                var tid = (int)e.Thread.Id;
                lock (m_SeenThreads)
                {
                    m_SeenThreads[tid] = new Thread(tid, e.Thread.Name);
                }

                SendEvent(new ThreadEvent("started", tid));
            };

            m_Session.TargetThreadStopped += (sender, e) =>
            {
                var 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);
            };

            Log.Write("Done constructing UnityDebugSession");
        }
 public override void Threads(Response response, dynamic args)
 {
     var threads = new List<VSCodeDebug.Thread>();
     var process = Debugger.ActiveProcess;
     if (process != null) {
         Dictionary<int, VSCodeDebug.Thread> d;
         lock (_seenThreads) {
             d = new Dictionary<int, VSCodeDebug.Thread>(_seenThreads);
         }
         foreach (var t in process.GetThreads()) {
             int tid = (int)t.Id;
             d[tid] = new VSCodeDebug.Thread(tid, t.Name);
         }
         threads = d.Values.ToList();
     }
     SendResponse(response, new ThreadsResponseBody(threads));
 }