コード例 #1
0
        void DebuggerTask()
        {
            try
            {
                Util.LogMemoryUsageStatistics("Inside debugger task thread");

                lock (_statusLock)
                {
                    _status.State      = DebuggerState.NotStarted;
                    _status.ExitReason = "The session terminated before it could attach to the debuggee.";
                    _status.Fatal      = true;
                }

                lock (_statusLock)
                {
                    _status.State = DebuggerState.Running;
                    _status.Fatal = false;
                }

                Stopwatch sw = new Stopwatch();
                sw.Start();

                DebuggerStatus lastStatus = DebuggerStatus.TimedOut;
#if DEBUG
                int numTicks = 0;
#endif

                while (_status.State == DebuggerState.Running)
                {
                    DebuggerStatus dbgStatus = _debuggee.Update();
                    long           now       = sw.ElapsedMilliseconds;

#if DEBUG
                    if (numTicks % 100 == 0)
                    {
                        Util.LogMemoryUsageStatistics("Tick" + numTicks);
                    }
                    ++numTicks;
#endif

                    if (_status.State != DebuggerState.ExitPending)
                    {
                        if (dbgStatus != DebuggerStatus.Ok && dbgStatus != DebuggerStatus.TimedOut)
                        {
                            if (_sessionStatus == SessionStatusFlags.SessionActive)
                            {
                                TriggerExit("The debug session terminated due to a debuggee system shutdown.");
                            }
                            else
                            {
                                // If we're waiting for an attach, we don't want to bang the COM+ server with RPC traffic.
                                // Add a bit of stabilization time.
                                _debuggerUpdatedEvent.WaitOne(PollTime);
                            }
                        }
                    }

                    lastStatus = dbgStatus;
                    _debuggerUpdatedEvent.Set();
                }

                if (!_debugKernel)
                {
                    _debuggee.DetachProcesses();
                }
            }
            catch (Exception ex)
            {
                lock (_statusLock)
                {
                    _status.ExitReason = "The debugger encountered a fatal error: " + ex.ToString();
                    _status.State      = DebuggerState.Exited;
                }

                throw;
            }
            finally
            {
                lock (_statusLock)
                {
                    _status.State = DebuggerState.Exited;
                }
            }

            Util.LogMemoryUsageStatistics("Debugger task complete");

            if (_status.Fatal)
            {
                throw new DebugMonitorException(_status.ExitReason);
            }
        }