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();
        }
        public static void ClearBreakpoints(this IDebugControl4 control)
        {
            if (control == null)
            {
                return;
            }

            uint number;
            var  hr = control.GetNumberBreakpoints(out number);

            if (hr != HResult.Ok)
            {
                return;
            }

            for (uint breakpointIndex = 0; breakpointIndex < number; breakpointIndex++)
            {
                IDebugBreakpoint2 breakPoint;
                hr = control.GetBreakpointByIndex2(breakpointIndex, out breakPoint);
                if (hr != HResult.Ok)
                {
                    continue;
                }

                control.RemoveBreakpoint2(breakPoint);
            }
        }
        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;
            }
        }
Exemple #4
0
        public UserDebugger()
        {
            Guid   guid = new Guid("27fe5639-8407-4f47-8364-ee118fb08ac8");
            object obj  = null;

            int hr = DebugCreate(ref guid, out obj);

            if (hr < 0)
            {
                Console.WriteLine("SourceFix: Unable to acquire client interface");
                return;
            }

            _client         = obj as IDebugClient5;
            _control        = _client as IDebugControl4;
            _debugDataSpace = _client as IDebugDataSpaces;
            _client.SetOutputCallbacks(this);
            _client.SetEventCallbacksWide(this);
        }
Exemple #5
0
        public void Dispose()
        {
            if (_debugDataSpace != null)
            {
                Marshal.ReleaseComObject(_debugDataSpace);
                _debugDataSpace = null;
            }

            if (_control != null)
            {
                Marshal.ReleaseComObject(_control);
                _control = null;
            }

            if (_client != null)
            {
                Marshal.ReleaseComObject(_client);
                _client = null;
            }
        }
        public WindowsDebugEngine(string winDbgPath)
        {
            logger.Debug("WindowsDebugEngine");

            object obj   = null;
            Guid   clsid = CLSID(typeof(IDebugClient5));

            this.winDbgPath = winDbgPath;

            hDll  = LoadWin32Library(Path.Combine(winDbgPath, "dbgeng.dll"));
            hProc = GetProcAddress(hDll, "DebugCreate");
            DebugCreate debugCreate = (DebugCreate)Marshal.GetDelegateForFunctionPointer(hProc, typeof(DebugCreate));

            if (debugCreate(ref clsid, out obj) != 0)
            {
                Debugger.Break();
            }

            dbgClient        = (IDebugClient5)obj;
            dbgControl       = (IDebugControl4)obj;
            dbgSymbols       = (IDebugSymbols3)obj;
            dbgSystemObjects = (IDebugSystemObjects)obj;

            // Reset events
            loadModules.Reset();
            exitProcess.Reset();
            handlingException.Reset();
            handledException.Reset();
            exitDebugger.Reset();

            // Reset output
            output = new StringBuilder();

            dbgSymbols.SetSymbolPath(@"SRV*http://msdl.microsoft.com/download/symbols");

            dbgClient.SetOutputCallbacks(new OutputCallbacks(this));
            dbgClient.SetEventCallbacks(new EventCallbacks(this));
        }
 public EventCallbacks(IDebugControl4 control)
 {
     _control = control;
 }