Example #1
0
        private void CreateClient(IDebugClient client)
        {
            DebuggerInterface = client;

            _spaces    = (IDebugDataSpaces)DebuggerInterface;
            _spacesPtr = (IDebugDataSpacesPtr)DebuggerInterface;
            _symbols   = (IDebugSymbols)DebuggerInterface;
            _control   = (IDebugControl2)DebuggerInterface;

            // These interfaces may not be present in older DbgEng dlls.
            _spaces2        = DebuggerInterface as IDebugDataSpaces2;
            _symbols3       = DebuggerInterface as IDebugSymbols3;
            _advanced       = DebuggerInterface as IDebugAdvanced;
            _systemObjects  = DebuggerInterface as IDebugSystemObjects;
            _systemObjects3 = DebuggerInterface as IDebugSystemObjects3;

            Interlocked.Increment(ref s_totalInstanceCount);

            if (_systemObjects3 == null && s_totalInstanceCount > 1)
            {
                throw new ClrDiagnosticsException("This version of DbgEng is too old to create multiple instances of DataTarget.", ClrDiagnosticsExceptionKind.DebuggerError);
            }

            if (_systemObjects3 != null)
            {
                _systemObjects3.GetCurrentSystemId(out _instance);
            }
        }
Example #2
0
        private void Initialize()
        {
            _debugger = CreateDebuggerClient();
            _control = _debugger as IDebugControl4;
            _symbols = _debugger as IDebugSymbols4;
            _systemObjects = _debugger as IDebugSystemObjects3;
            _advanced = _debugger as IDebugAdvanced3;
            _spaces = _debugger as IDebugDataSpaces4;

            // in case previous debugging session hasn't finished correctly
            // some leftover breakpoints may exist (even if debugging target has changed)
            _control.ClearBreakpoints();
            _requestHelper = new RequestHelper(_advanced, _spaces, _symbols);
            _commandExecutor = new CommandExecutor(_control);
            _output = new OutputCallbacks();

            _callbacks = new EventCallbacks(_control);
            _callbacks.BreakpointHit += OnBreakpoint;
            _callbacks.ExceptionHit += OnException;
            _callbacks.BreakHappened += OnBreak;
            _callbacks.ThreadStarted += OnThreadStarted;
            _callbacks.ThreadFinished += OnThreadFinished;
            _callbacks.ProcessExited += OnProcessExited;

            _debugger.SetEventCallbacks(_callbacks);
            _debugger.SetOutputCallbacks(_output);
            _debugger.SetInputCallbacks(new InputCallbacks());

            _visualizers = new VisualizerRegistry(new DefaultVisualizer(_requestHelper, _symbols, _output));
            InitializeHandlers();
        }
Example #3
0
        private void Dispose(bool disposing)
        {
            if (!_isDisposed)
            {
                if (disposing)
                {
                    _cancel.Cancel();

                    if (_debuggerThread != null)
                        _debuggerThread.Join(TimeSpan.FromMilliseconds(100));

                    if (_callbacks != null)
                    {
                        _callbacks.BreakpointHit -= OnBreakpoint;
                        _callbacks.ExceptionHit -= OnException;
                        _callbacks.BreakHappened -= OnBreak;
                        _callbacks.ThreadFinished -= OnThreadFinished;
                        _callbacks.ThreadStarted -= OnThreadStarted;
                        _callbacks.ProcessExited -= OnProcessExited;
                    }

                    if (_debugger != null)
                    {
                        _debugger.EndSession(DEBUG_END.ACTIVE_TERMINATE);
                        _debugger.SetEventCallbacks(null);
                        _debugger.SetOutputCallbacks(null);
                        _debugger.SetInputCallbacks(null);
                    }

                    _callbacks = null;
                    _messages.Dispose();
                }

                if (_debugger != null)
                {
                    while (Marshal.ReleaseComObject(_debugger) > 0)
                    {
                    }
                }

                _debugger = null;
                _control = null;
                _symbols = null;
                _spaces = null;
                _systemObjects = null;

                _advanced = null;
                _requestHelper = null;

                _isDisposed = true;
            }
        }
Example #4
0
        public override bool Generate(CommandExecutionContext context)
        {
            var managedThreadNames = GetManagedThreadNames(context.Heap);

            var target = context.NativeDbgEngTarget;
            IDebugSystemObjects3 sysObjects = (IDebugSystemObjects3)target.DebuggerInterface;

            sysObjects.GetCurrentProcessUpTime(out _processUpTimeInSeconds);

            var debugAdvanced = (IDebugAdvanced2)target.DebuggerInterface;
            var stackTraces   = new UnifiedStackTraces(target.DebuggerInterface, context);

            foreach (var thread in stackTraces.Threads)
            {
                var stackTrace = stackTraces.GetStackTrace(thread.Index);
                var threadInfo = new ThreadInfo
                {
                    EngineThreadId     = thread.EngineThreadId,
                    OSThreadId         = thread.OSThreadId,
                    ManagedThreadId    = thread.ManagedThread?.ManagedThreadId ?? -1,
                    SpecialDescription = thread.ManagedThread?.SpecialDescription()
                };

                string threadName;
                if (managedThreadNames.TryGetValue(threadInfo.ManagedThreadId, out threadName))
                {
                    threadInfo.ThreadName = threadName;
                }

                threadInfo.Fill(debugAdvanced);
                foreach (var frame in stackTrace)
                {
                    threadInfo.StackFrames.Add(new StackFrame
                    {
                        Module           = frame.Module,
                        Method           = frame.Method,
                        SourceFileName   = frame.SourceFileName,
                        SourceLineNumber = frame.SourceLineNumber
                    });
                }
                Threads.Add(threadInfo);
            }

            RecommendFinalizerThreadHighCPU(context);
            RecommendHighNumberOfThreads();

            return(true);
        }
Example #5
0
        private void CreateClient(IDebugClient client)
        {
            _client = client;

            _spaces = (IDebugDataSpaces)_client;
            _spacesPtr = (IDebugDataSpacesPtr)_client;
            _symbols = (IDebugSymbols)_client;
            _control = (IDebugControl2)_client;

            // These interfaces may not be present in older DbgEng dlls.
            _spaces2 = _client as IDebugDataSpaces2;
            _symbols3 = _client as IDebugSymbols3;
            _advanced = _client as IDebugAdvanced;
            _systemObjects = _client as IDebugSystemObjects;
            _systemObjects3 = _client as IDebugSystemObjects3;

            Interlocked.Increment(ref s_totalInstanceCount);

            if (_systemObjects3 == null && s_totalInstanceCount > 1)
                throw new ClrDiagnosticsException("This version of DbgEng is too old to create multiple instances of DataTarget.", ClrDiagnosticsException.HR.DebuggerError);

            if (_systemObjects3 != null)
                _systemObjects3.GetCurrentSystemId(out _instance);
        }