Example #1
1
        internal void Send(IDebugEvent2 eventObject, string iidEvent, IDebugProgram2 program, IDebugThread2 thread) {
            LiveLogger.WriteLine("AD7Engine Event: {0} ({1})", eventObject.GetType(), iidEvent);

            // Check that events was not disposed
            var events = _events;
            if (events == null) {
                return;
            }

            uint attributes;
            var riidEvent = new Guid(iidEvent);

            EngineUtils.RequireOk(eventObject.GetAttributes(out attributes));

            if ((attributes & (uint)enum_EVENTATTRIBUTES.EVENT_STOPPING) != 0 && thread == null) {
                Debug.Fail("A thread must be provided for a stopping event");
                return;
            }

            try {
                EngineUtils.RequireOk(events.Event(this, null, program, thread, eventObject, ref riidEvent, attributes));
            } catch (InvalidCastException) {
                // COM object has gone away
            }
        }
Example #2
0
    public void Send(IDebugEvent2 eventObject, string iidEvent, IDebugProgram2 program, IDebugThread2 thread) {
      uint attributes;
      var riidEvent = new Guid(iidEvent);

      EngineUtils.RequireOk(eventObject.GetAttributes(out attributes));
      EngineUtils.RequireOk(m_ad7Callback.Event(m_engine, null, program, thread, eventObject, ref riidEvent, attributes));
    }
Example #3
0
        public int Event(IDebugEngine2 engine, IDebugProcess2 process, IDebugProgram2 program, 
			IDebugThread2 thread, IDebugEvent2 debugEvent, ref Guid riidEvent, uint attributes)
        {
            if (!(debugEvent is IDebugProcessCreateEvent2) &&
                !(debugEvent is IDebugProcessDestroyEvent2))
                return VSConstants.S_OK;

            var target = GetTargetFromProcess(process);
            if (target == null)
            {
                _package.Reporter.ReportWarning("Can't find target from process {0} ({1}). Event: {2}.",
                    process.GetName(), process.GetProcessId(), TypeHelper.GetDebugEventTypeName(debugEvent));
                return VSConstants.S_OK;
            }

            if (debugEvent is IDebugProcessCreateEvent2)
            {
                target.IsAttached = true;
                _package.History.Items.AddFirst(target);
                _package.Ui.Update();
            }
            else
            {
                target.IsAttached = false;
                _package.Ui.Update();
            }

            return VSConstants.S_OK;
        }
 public int ContinueFromSynchronousEvent(IDebugEvent2 @event)
 {
     if (@event is MonoProgramDestroyEvent)
     {
         Session.Dispose();
     }
     return(VSConstants.S_OK);
 }
Example #5
0
        public void Send(IDebugEvent2 eventObject, string iidEvent, IDebugProgram2 program, IDebugThread2 thread)
        {
            uint attributes;
            Guid riidEvent = new Guid(iidEvent);

            EngineUtils.RequireOk(eventObject.GetAttributes(out attributes));
            EngineUtils.RequireOk(_eventCallback.Event(_engine, null, program, thread, eventObject, ref riidEvent, attributes));
        }
        void HandleDebugProgramCreated(IDebugEvent2 programCreatedEvent, IDebugProgram3 program)
        {
            var         breakpoints = _bindPendingBreakpoints();
            Func <bool> predicate   = () => breakpoints.All(b => b.Ready);

            _jobQueue.Push(_observeAndNotifyJobFactory.Create(
                               predicate, () => SetProgramAndContinue(programCreatedEvent, program),
                               "Waiting for breakpoints to be bound."));
        }
Example #7
0
        int IDebugEngine2.ContinueFromSynchronousEvent(IDebugEvent2 pEvent)
        {
            if (pEvent is ProgramDestroyEvent evtProgramDestroy)
            {
                evtProgramDestroy.Program.Dispose();
            }

            return(VSConstants.S_OK);
        }
 public ProgramStoppedJob(JoinableTaskContext taskContext, IDebugEngine2 debugEngine,
                          IDebugEvent2 evnt, IDebugSessionContext debugSessionContext, IDebugThread2 thread,
                          IFiredBreakpointSetter firedBreakpointSetter)
     : base(taskContext, debugEngine, evnt)
 {
     _debugSessionContext = debugSessionContext;
     _thread = thread;
     _firedBreakpointSetter = firedBreakpointSetter;
 }
        public static enum_EVENTATTRIBUTES GetAttributes(this IDebugEvent2 debugEvent)
        {
            Contract.Requires <ArgumentNullException>(debugEvent != null, "debugEvent");

            uint attributes;

            ErrorHandler.ThrowOnFailure(debugEvent.GetAttributes(out attributes));
            return((enum_EVENTATTRIBUTES)attributes);
        }
Example #10
0
        /// <summary>
        ///     Called by the SDM to indicate that a synchronous debug event, previously sent by the DE to the SDM,
        ///     was received and processed. The only event the sample engine sends in this fashion is Program Destroy.
        ///     It responds to that event by shutting down the engine.
        /// </summary>
        /// <param name="event">The event.</param>
        /// <returns>If successful, returns S_OK; otherwise, returns an error code.</returns>
        public int ContinueFromSynchronousEvent(IDebugEvent2 @event)
        {
            if (@event is SampSharpDestroyEvent)
            {
                Program.Dispose();
            }

            return(S_OK);
        }
Example #11
0
        public int ContinueFromSynchronousEvent(IDebugEvent2 pEvent)
        {
            if (pEvent is DebugEventProgramDestory)
            {
                _softDebugger.Dispose();
            }

            return(S_OK);
        }
Example #12
0
        public int Event(IDebugEngine2 pEngine, IDebugProcess2 pProcess, IDebugProgram2 pProgram, IDebugThread2 pThread, IDebugEvent2 pEvent, ref Guid riidEvent, uint dwAttrib)
        {
            if (pEvent is IRunspaceRequest)
            {
                var request = pEvent as IRunspaceRequest;
                request.SetRunspace(_runspace, _breakpoints);
            }

            return VSConstants.S_OK;
        }
Example #13
0
        protected virtual void OnDebugEvent(IDebugEvent2 eventObject,
                                            Guid iidEvent,
                                            IDebugProgram2 program = null,
                                            IDebugThread2 thread   = null,
                                            IDebugProcess2 process = null)
        {
            uint attributes;

            eventObject.GetAttributes(out attributes);
            DebugEventCallback.Event(DebugEngineBase, process, program, thread, eventObject, ref iidEvent, attributes);
        }
Example #14
0
        int IDebugEngine2.ContinueFromSynchronousEvent(IDebugEvent2 pEvent)
        {
            ThrowIfDisposed();

            if (pEvent is AD7ProgramDestroyEvent)
            {
                Dispose();
            }

            return(VSConstants.S_OK);
        }
Example #15
0
        int IDebugEngine2.ContinueFromSynchronousEvent(IDebugEvent2 pEvent)
        {
            var evtProgramDestroy = pEvent as ProgramDestroyEvent;

            if (evtProgramDestroy != null)
            {
                evtProgramDestroy.Program.Dispose();
            }

            return(VSConstants.S_OK);
        }
Example #16
0
        // Called by the SDM to indicate that a synchronous debug event, previously sent by the DE to the SDM,
        // was received and processed. The only event the sample engine sends in this fashion is Program Destroy.
        // It responds to that event by shutting down the engine.
        int IDebugEngine2.ContinueFromSynchronousEvent(IDebugEvent2 eventObject)
        {
            AD7ProgramCreateEvent programCreate = eventObject as AD7ProgramCreateEvent;

            if (programCreate != null)
            {
                _programCreateContinued.Set();
            }

            return(VSConstants.S_OK);
        }
Example #17
0
        public void Send(IDebugEvent2 eventObject, string iidEvent, IDebugThread2 thread)
        {
            IDebugProgram2 program = _engine;
            if (!_engine.ProgramCreateEventSent)
            {
                // Any events before programe create shouldn't include the program
                program = null;
            }

            Send(eventObject, iidEvent, program, thread);
        }
Example #18
0
        public int Event(IDebugEngine2 pEngine,
                         IDebugProcess2 pProcess,
                         IDebugProgram2 pProgram,
                         IDebugThread2 pThread,
                         IDebugEvent2 pEvent,
                         ref Guid riidEvent,
                         uint dwAttrib)
        {
            Logger.Debug(string.Empty);

            return(VSConstants.S_OK);
        }
Example #19
0
        public void Send(IDebugEvent2 eventObject, string iidEvent, IDebugThread2 thread)
        {
            IDebugProgram2 program = _engine;

            if (!_engine.ProgramCreateEventSent)
            {
                // Any events before programe create shouldn't include the program
                program = null;
            }

            Send(eventObject, iidEvent, program, thread);
        }
Example #20
0
        public void Send(IDebugEvent2 eventObject, string iidEvent, IDebugProgram2 program, IDebugThread2 thread)
        {
            uint attributes;
            Guid riidEvent = new Guid(iidEvent);

            if (!(eventObject is AD7OutputDebugStringEvent))
            {
                _engine.Logger.WriteLine("Send Event {0}", eventObject.GetType().Name);
            }
            EngineUtils.RequireOk(eventObject.GetAttributes(out attributes));
            EngineUtils.RequireOk(_eventCallback.Event(_engine, null, program, thread, eventObject, ref riidEvent, attributes));
        }
        public int Event( IDebugEngine2 pEngine,
            IDebugProcess2 pProcess,
            IDebugProgram2 pProgram,
            IDebugThread2 pThread,
            IDebugEvent2 pEvent,
            ref Guid riidEvent,
            uint dwAttrib)
        {
            Logger.Debug( string.Empty );

            return VSConstants.S_OK;
        }
Example #22
0
        internal void Send(IDebugEvent2 eventObject, string iidEvent, IDebugProgram2 program, IDebugThread2 thread)
        {
            uint attributes;
            Guid riidEvent = new Guid(iidEvent);

            EngineUtils.RequireOk(eventObject.GetAttributes(out attributes));

            Debug.WriteLine(String.Format("Sending Event: {0} {1}", eventObject.GetType(), iidEvent));
            try {
                EngineUtils.RequireOk(_events.Event(this, null, program, thread, eventObject, ref riidEvent, attributes));
            } catch (InvalidCastException) {
                // COM object has gone away
            }
        }
Example #23
0
        public int Event(IDebugEngine2 pEngine, IDebugProcess2 pProcess, IDebugProgram2 pProgram,
                         IDebugThread2 pThread, IDebugEvent2 pEvent, ref Guid riidEvent, uint dwAttrib)
        {
            _taskContext.ThrowIfNotOnMainThread();

            _logger.Trace($"Note right of VS: <IN> IDebugEventCallback2 {pEvent.GetType()}");

            var result = _callback.Event(pEngine, pProcess, pProgram, pThread, pEvent,
                                         ref riidEvent, dwAttrib);

            _logger.Trace($"Note right of VS: <OUT> IDebugEventCallback2 {pEvent.GetType()}");

            return(result);
        }
Example #24
0
        // Called by the SDM to indicate that a synchronous debug event, previously sent by the DE to the SDM,
        // was received and processed. The only event the sample engine sends in this fashion is Program Destroy.
        // It responds to that event by shutting down the engine.
        public int ContinueFromSynchronousEvent(IDebugEvent2 eventObject)
        {
            try
            {
                if (eventObject is AD7ProgramCreateEvent)
                {
                    Exception exception = null;

                    try
                    {
                        _engineCallback.OnLoadComplete();
                        // At this point breakpoints and exception settings have been sent down, so we can resume the target
                        _pollThread.RunOperation(() =>
                        {
                            return(_debuggedProcess.ResumeFromLaunch());
                        });
                    }
                    catch (Exception e)
                    {
                        exception = e;
                        // Return from the catch block so that we can let the exception unwind - the stack can get kind of big
                    }

                    if (exception != null)
                    {
                        // If something goes wrong, report the error and then stop debugging. The SDM will drop errors
                        // from ContinueFromSynchronousEvent, so we want to deal with them ourself.
                        SendStartDebuggingError(exception);
                        _debuggedProcess.Terminate();
                    }

                    return(Constants.S_OK);
                }
                else if (eventObject is AD7ProgramDestroyEvent)
                {
                    Dispose();
                }
                else
                {
                    Debug.Fail("Unknown syncronious event");
                }
            }
            catch (Exception e)
            {
                return(EngineUtils.UnexpectedException(e));
            }

            return(Constants.S_OK);
        }
Example #25
0
        public int ContinueFromSynchronousEvent(IDebugEvent2 pEvent)
        {
            if (pEvent == null)
            {
                throw new ArgumentNullException("pEvent");
            }
            if (!(pEvent is DebugEvent))
            {
                return(VSConstants.E_INVALIDARG);
            }

            if (pEvent is IDebugEngineCreateEvent2)
            {
                return(VSConstants.S_OK);
            }

            IPropertyOwner propertyOwner = pEvent as IPropertyOwner;

            if (propertyOwner != null)
            {
                bool manualResume;
                propertyOwner.Properties.TryGetProperty("ManualResume", out manualResume);

                SuspendPolicy suspendPolicy;
                if (!manualResume && propertyOwner.Properties.TryGetProperty(typeof(SuspendPolicy), out suspendPolicy))
                {
                    IThreadReference thread = propertyOwner.Properties.GetProperty <IThreadReference>(typeof(IThreadReference));

                    switch (suspendPolicy)
                    {
                    case SuspendPolicy.All:
                        JavaDebugProgram program = propertyOwner.Properties.GetProperty <JavaDebugProgram>(typeof(JavaDebugProgram));
                        JavaDebugThread  debugThread;
                        program.Threads.TryGetValue(thread.GetUniqueId(), out debugThread);
                        program.Continue(debugThread);
                        break;

                    case SuspendPolicy.EventThread:
                        Task.Factory.StartNew(thread.Resume).HandleNonCriticalExceptions();
                        break;

                    case SuspendPolicy.None:
                        break;
                    }
                }
            }

            return(VSConstants.S_OK);
        }
Example #26
0
        public int ContinueFromSynchronousEvent(IDebugEvent2 eventObject)
        {
            if (eventObject is AD7ProgramDestroyEvent)
            {
                _breakpointManager = null;
                _program           = null;
                _callbacks         = null;
            }
            if (eventObject is AD7LoadCompleteEvent)
            {
                _program.Launch();
            }

            return(VSConstants.S_OK);
        }
Example #27
0
        public int ContinueFromSynchronousEvent(IDebugEvent2 eventObject)
        {
            switch (eventObject)
            {
            case AD7ProgramDestroyEvent _:
                _program   = null;
                _callbacks = null;
                TerminationCallback();
                break;

            case AD7LoadCompleteEvent _:
                _program.Continue(thread: null);
                break;
            }
            return(VSConstants.S_OK);
        }
Example #28
0
 int IDebugEventCallback2.Event(
     IDebugEngine2 pEngine,
     IDebugProcess2 pProcess,
     IDebugProgram2 pProgram,
     IDebugThread2 pThread,
     IDebugEvent2 pEvent,
     ref Guid riidEvent,
     uint dwAttrib)
 {
     if (Callback == null)
     {
         return(VSConstants.S_OK);
     }
     return(Callback.Event(pEngine, pProcess,
                           pProgram, pThread, pEvent, ref riidEvent, dwAttrib));
 }
Example #29
0
        int IDebugEventCallback2.Event(
            IDebugEngine2 pEngine,
            IDebugProcess2 pProcess,
            IDebugProgram2 pProgram,
            IDebugThread2 pThread,
            IDebugEvent2 pEvent,
            ref Guid riidEvent,
            uint dwAttrib)
        {
            if (pEngine == Engine)
            {
                return(VSConstants.S_OK);
            }

            if (pProcess == null && pProgram == null)
            {
                return(VSConstants.S_OK);
            }

            if (pProcess == null)
            {
                if (pProgram.GetProcess(out pProcess) != VSConstants.S_OK || pProcess == null)
                {
                    return(VSConstants.S_OK);
                }
            }

            var pProcessId = new AD_PROCESS_ID[1];

            if (pProcess.GetPhysicalProcessId(pProcessId) != VSConstants.S_OK)
            {
                return(VSConstants.S_OK);
            }

            if (pProcessId[0].dwProcessId != NativeProcId)
            {
                return(VSConstants.S_OK);
            }

            if (riidEvent == typeof(IDebugProgramDestroyEvent2).GUID)
            {
                TerminateProcess();
            }

            return(VSConstants.S_OK);
        }
        private void CreateAndRegisterXamarinThread(Client.ThreadInfo threadInfo)
        {
            XamarinThread            thread = new XamarinThread(this, threadInfo.Id, threadInfo.Name, threadInfo.Location, _session);
            uint                     attributes;
            Guid                     riidEvent   = new Guid(XamarinThreadCreateEvent.IID);
            IDebugThreadCreateEvent2 evnt        = new XamarinThreadCreateEvent();
            IDebugEvent2             eventObject = evnt as IDebugEvent2;

            if (eventObject.GetAttributes(out attributes) != VisualStudioExtensionConstants.S_OK)
            {
                throw new InvalidOperationException("Failed to create and register a thread. The event object failed to get its attributes");
            }
            if (_eventCallback.Event(_engine, null, _activeProgram, thread, eventObject, ref riidEvent, attributes) != VisualStudioExtensionConstants.S_OK)
            {
                throw new InvalidOperationException("Failed to create and register a thread. The event has not been sent succesfully");
            }
        }
        public int Event(IDebugEngine2 engine, IDebugProcess2 process, IDebugProgram2 program,
            IDebugThread2 thread, IDebugEvent2 debugEvent, ref Guid riidEvent, uint attributes)
        {
            if (process == null)
                return VSConstants.S_OK;
            string processName;
            if (process.GetName((uint) enum_GETNAME_TYPE.GN_FILENAME, out processName) != VSConstants.S_OK)
                return VSConstants.S_OK;
            if (processName.EndsWith("vshost.exe"))
                return VSConstants.S_OK;

            var shortName = Path.GetFileName(processName);

            if (debugEvent is IDebugProcessCreateEvent2)
            {
                Log.Instance.SetStatus("[attaching...] {0}", shortName);
                Storage.Instance.SubscribeProcess(processName);
            }
            if (debugEvent is IDebugProcessDestroyEvent2)
            {
                Log.Instance.SetStatus("[detached] {0}", shortName);
                Log.Instance.AppendLine("[detached] {0}", shortName);
            }
            if (debugEvent is  IDebugLoadCompleteEvent2)
            {
                if (program != null)
                {
                    string engineName;
                    Guid engineId;
                    if (program.GetEngineInfo(out engineName, out engineId) == VSConstants.S_OK)
                    {
                        var fields = new PROCESS_INFO[1];
                        if (process.GetInfo((uint)enum_PROCESS_INFO_FIELDS.PIF_PROCESS_ID, fields) != VSConstants.S_OK)
                            return VSConstants.S_OK;
                        Storage.Instance.SubscribeEngine(processName, engineId);
                        AttachCenter.Instance.Freeze();

                        Log.Instance.SetStatus("[attached] {0}", shortName);
                        Log.Instance.AppendLine("[attached] {0} ({1}) / {2}", shortName, fields[0].ProcessId.dwProcessId, engineName);
                    }
                }
            }
            return VSConstants.S_OK;
        }
Example #32
0
        public int Event(IDebugEngine2 engine, IDebugProcess2 process, IDebugProgram2 program,
                         IDebugThread2 thread, IDebugEvent2 debugEvent, ref Guid riidEvent, uint attributes)
        {
            // _package.Reporter.ReportTrace(TypeHelper.GetDebugEventTypeName(debugEvent));

            if (!(debugEvent is IDebugProcessCreateEvent2) &&
                !(debugEvent is IDebugProcessDestroyEvent2))
            {
                return(VSConstants.S_OK);
            }

            var target = GetTargetFromProcess(process);

            if (target == null)
            {
                _package.Reporter.ReportWarning("Can't find target from process {0} ({1}). Event: {2}.",
                                                process.GetName(), process.GetProcessId(), TypeHelper.GetDebugEventTypeName(debugEvent));
                return(VSConstants.S_OK);
            }

            if (debugEvent is IDebugProcessCreateEvent2)
            {
                var engines = target.Engines.Where(e => _engines.ContainsKey(e)).Select(e => _engines[e]).ToArray();

                var mode = new DBGMODE[1];
                _debugger.GetMode(mode);
                if (mode[0] == DBGMODE.DBGMODE_Design)
                {
                    return(VSConstants.S_OK);
                }

                target.IsAttached = true;
                _package.History.Items.AddFirst(target);
                _package.Ui.Update();
            }
            else
            {
                target.IsAttached = false;
                _package.Ui.Update();
            }

            return(VSConstants.S_OK);
        }
Example #33
0
        // Note that this method can be called from a thread other than the test main thread.
        public int HandleCallbackEvent(IDebugEngine2 pEngine, IDebugProcess2 pProcess,
                                       IDebugProgram2 pProgram, IDebugThread2 pThread,
                                       IDebugEvent2 pEvent)
        {
            if (pEvent is IDebugBreakpointEvent2 || pEvent is IDebugBreakEvent2 ||
                pEvent is IDebugStepCompleteEvent2)
            {
                _queue.Push(
                    _programStoppedJobFactory.Create(pEngine, pEvent, _debugSessionContext,
                                                     pThread));
            }
            else if (pEvent is IDebugProgramDestroyEvent2)
            {
                _queue.Push(
                    _programTerminatedJobFactory.Create(pEngine, pEvent, _debugSessionContext));
            }

            var pProgram3 = pProgram as IDebugProgram3;

            if (pProgram3 == null)
            {
                // TODO: Ensure program can be cast to IDebugProgram3 without
                // throwing across the COM/interop boundary.
                throw new NotSupportedException(
                          "'pProgram' must be castable to type " +
                          $"{nameof(IDebugProgram3)} but is of type {pProgram.GetType()}");
            }

            _queue.Push(_broadcastDebugEventJobFactory.Create(() =>
            {
                DebugEventHandler handler = DebugEvent;
                handler?.Invoke(new DebugEventArgs
                {
                    DebugEngine = pEngine,
                    Process     = pProcess,
                    Program     = pProgram3,
                    Thread      = pThread,
                    Event       = pEvent
                });
            }, pEvent));

            return(VSConstants.S_OK);
        }
Example #34
0
        // Called by the SDM to indicate that a synchronous debug event, previously sent by the DE to the SDM,
        // was received and processed. The only event we send in this fashion is Program Destroy.
        // It responds to that event by shutting down the engine.
        int IDebugEngine2.ContinueFromSynchronousEvent(IDebugEvent2 eventObject)
        {
            if (!(eventObject is AD7ProgramDestroyEvent))
            {
                Debug.Fail("Unknown syncronious event");
                return(VSConstants.E_FAIL);
            }

            _ad7ProgramId = Guid.Empty;

            _modules.Clear();
            _process.Close();

            _threads = null;
            _events  = null;
            _process = null;

            return(VSConstants.S_OK);
        }
Example #35
0
        // Called by the SDM to indicate that a synchronous debug event, previously sent by the DE to the SDM,
        // was received and processed. The only event the sample engine sends in this fashion is Program Destroy.
        // It responds to that event by shutting down the engine.
        int IDebugEngine2.ContinueFromSynchronousEvent(IDebugEvent2 eventObject)
        {
            // Debug.Assert(Worker.MainThreadId == Worker.CurrentThreadId);

            try
            {
                if (eventObject is AD7ProgramDestroyEvent)
                {
                    //WorkerThread pollThread = m_pollThread;
                    SquirrelProcess _debuggedProcess = debuggedProcess;

                    m_engineCallback = null;
                    debuggedProcess  = null;
                    //m_pollThread = null;
                    m_ad7ProgramId = Guid.Empty;

                    _debuggedProcess.Close();
                    //pollThread.Close();
                }
                else if (eventObject is ErrorEvent)
                {
                    ErrorEvent errorEventObject = eventObject as ErrorEvent;
                    if (errorEventObject != null)
                    {
                        Debug.WriteLine("Debugger received errorevent " + errorEventObject.ErrorMessage + "\n");
                    }

                    return(EngineConstants.E_FAIL);
                    // m_engineCallback.Send(new AD7ProgramDestroyEvent(0), AD7ProgramDestroyEvent.IID, null);
                }
                else
                {
                    Debug.Fail("Debug engine received unknown synchronous event");
                }
            }
            catch (Exception e)
            {
                return(EngineUtils.UnexpectedException(e));
            }

            return(EngineConstants.S_OK);
        }
        public int Event(IDebugEngine2 engine, IDebugProcess2 process, IDebugProgram2 program,
                         IDebugThread2 thread, IDebugEvent2 debugEvent, ref Guid riidEvent, uint attributes)
        {
            System.Diagnostics.Debug.WriteLine(debugEvent.GetType());

            if (debugEvent is IDebugBreakEvent2)
            {
                OnEnterBreakMode(this, thread);
            }
            else if (debugEvent is IDebugBreakpointEvent2)
            {
                OnEnterBreakMode(this, thread);
            }
            else if (debugEvent is IDebugExceptionEvent2)
            {
                OnEnterBreakMode(this, thread);
            }

            return(VSConstants.S_OK);
        }
        public int Event(IDebugEngine2 engine, IDebugProcess2 process, IDebugProgram2 program,
            IDebugThread2 thread, IDebugEvent2 debugEvent, ref Guid riidEvent, uint attributes)
        {
            // Ignore a few events right away.
            if (debugEvent is IDebugModuleLoadEvent2 ||
                debugEvent is IDebugThreadCreateEvent2 ||
                debugEvent is IDebugThreadDestroyEvent2)
                return VSConstants.S_OK;

            if (process == null)
                return VSConstants.S_OK;

            if (debugEvent is IDebugProcessCreateEvent2) {
                State.IsAttached = true;
            }
            else if (debugEvent is IDebugProcessDestroyEvent2) {
                State.IsAttached = false;
            }

            return VSConstants.S_OK;
        }
        // Called by the SDM to indicate that a synchronous debug event, previously sent by the DE to the SDM,
        // was received and processed. The only event the sample engine sends in this fashion is Program Destroy.
        // It responds to that event by shutting down the engine.
        int IDebugEngine2.ContinueFromSynchronousEvent(IDebugEvent2 eventObject)
        {
            try
            {
                if (eventObject is AD7ProgramCreateEvent)
                {
                    try
                    {
                        // At this point breakpoints and exception settings have been sent down, so we can resume the target
                        _pollThread.RunOperation(() =>
                        {
                            return(_debuggedProcess.ResumeFromLaunch());
                        });
                    }
                    catch (Exception e)
                    {
                        // If something goes wrong, report the error and then stop debugging. The SDM will drop errors
                        // from ContinueFromSynchronousEvent, so we want to deal with them ourself.
                        SendStartDebuggingError(e);
                        _debuggedProcess.Terminate();
                    }

                    return(VSConstants.S_OK);
                }
                else if (eventObject is AD7ProgramDestroyEvent)
                {
                    Dispose();
                }
                else
                {
                    Debug.Fail("Unknown syncronious event");
                }
            }
            catch (Exception e)
            {
                //return EngineUtils.UnexpectedException(e);
            }

            return(VSConstants.S_OK);
        }
Example #39
0
        public int Event(IDebugEngine2 engine, IDebugProcess2 process, IDebugProgram2 program, 
			IDebugThread2 thread, IDebugEvent2 debugEvent, ref Guid riidEvent, uint attributes)
        {
            // Ignore a few events right away.
            if (debugEvent is IDebugModuleLoadEvent2 ||
                debugEvent is IDebugThreadCreateEvent2 ||
                debugEvent is IDebugThreadDestroyEvent2)
                return VSConstants.S_OK;

            // Trace.WriteLine(TypeHelper.GetDebugEventTypeName(debugEvent)); // TODO: Remove me.

            if (process == null)
                return VSConstants.S_OK;

            var target = GetTargetFromProcess(process);

            if (target == null)
            {
                _package.Reporter.ReportWarning("Can't find target from process {0} ({1}). Event: {2}.",
                    process.GetName(), process.GetProcessId(), TypeHelper.GetDebugEventTypeName(debugEvent));
                return VSConstants.S_OK;
            }
            if (debugEvent is IDebugProcessCreateEvent2)
            {
                target.IsAttached = true;
                _package.History.Items.AddFirst(target);
                _package.Ui.Update();
                return VSConstants.S_OK;
            }

            if (debugEvent is IDebugProcessDestroyEvent2)
            {
                target.IsAttached = false;
                _package.Ui.Update();
                return VSConstants.S_OK;
            }

            return VSConstants.S_OK;
        }
        public int Event(IDebugEngine2 pEngine, IDebugProcess2 pProcess, IDebugProgram2 pProgram, IDebugThread2 pThread, IDebugEvent2 pEvent, ref Guid riidEvent, uint dwAttrib)
        {
            if (riidEvent == typeof(IDebugOutputStringEvent2).GUID)
            {
                IDebugOutputStringEvent2 ev = pEvent as IDebugOutputStringEvent2;
                if (ev != null)
                {
                    string message;
                    if (ErrorHandler.Succeeded(ev.GetString(out message)))
                    {
                        var lines = message.Split(sp, StringSplitOptions.RemoveEmptyEntries);

                        foreach(var line in lines)
                        {
                            HandleMessage(line);
                        }
                    }
                }
            }

            return VSConstants.S_OK;
        }
        public int Event(IDebugEngine2 engine, IDebugProcess2 process, IDebugProgram2 program, 
			IDebugThread2 thread, IDebugEvent2 debugEvent, ref Guid riidEvent, uint attributes)
        {
            // _package.Reporter.ReportTrace(TypeHelper.GetDebugEventTypeName(debugEvent));

            if (!(debugEvent is IDebugProcessCreateEvent2) &&
                !(debugEvent is IDebugProcessDestroyEvent2))
                return VSConstants.S_OK;

            var target = GetTargetFromProcess(process);
            if (target == null)
            {
                _package.Reporter.ReportWarning("Can't find target from process {0} ({1}). Event: {2}.",
                    process.GetName(), process.GetProcessId(), TypeHelper.GetDebugEventTypeName(debugEvent));
                return VSConstants.S_OK;
            }

            if (debugEvent is IDebugProcessCreateEvent2)
            {
                var engines = target.Engines.Where(e => _engines.ContainsKey(e)).Select(e => _engines[e]).ToArray();

                var mode = new DBGMODE[1];
                _debugger.GetMode(mode);
                if (mode[0] == DBGMODE.DBGMODE_Design)
                    return VSConstants.S_OK;

                target.IsAttached = true;
                _package.History.Items.AddFirst(target);
                _package.Ui.Update();
            }
            else
            {
                target.IsAttached = false;
                _package.Ui.Update();
            }

            return VSConstants.S_OK;
        }
Example #42
0
        public int Event(IDebugEngine2 pEngine, IDebugProcess2 pProcess, IDebugProgram2 pProgram, IDebugThread2 pThread, IDebugEvent2 pEvent, ref Guid riidEvent, uint dwAttrib) {
            if (riidEvent == typeof(IDebugProgramCreateEvent2).GUID) {
                Guid processId;

                // A program was created and attached
                if (pProcess != null) {
                    if (VSConstants.S_OK == pProcess.GetProcessId(out processId)) {
                        DkmProcess dkmProcess = DkmProcess.FindProcess(processId);

                        if (dkmProcess != null) {
                            var debugTrigger = DkmExceptionCodeTrigger.Create(DkmExceptionProcessingStage.Thrown, null, DkmExceptionCategory.Win32, RemoteDebugStartExceptionCode);
                            var attachTrigger = DkmExceptionCodeTrigger.Create(DkmExceptionProcessingStage.Thrown, null, DkmExceptionCategory.Win32, RemoteDebugAttachExceptionCode);

                            // Try to add exception trigger for when a remote debugger server is started for Python
                            dkmProcess.AddExceptionTrigger(RemoteDebugExceptionGuid, debugTrigger);
                            dkmProcess.AddExceptionTrigger(RemoteDebugExceptionGuid, attachTrigger);
                        }
                    }
                }
            }

            return VSConstants.S_OK;
        }
 public int ContinueFromSynchronousEvent(IDebugEvent2 pEvent)
 {
     DebugHelper.TraceEnteringMethod();
     return VSConstants.S_OK;
 }
Example #44
0
 internal void Send(IDebugEvent2 eventObject, string iidEvent)
 {
     Send(eventObject, iidEvent, this);
 }
Example #45
0
        internal void Send(IDebugEvent2 eventObject, string iidEvent, IDebugProgram2 program)
        {
            uint attributes;
            Guid riidEvent = new Guid(iidEvent);

            EngineUtils.RequireOk(eventObject.GetAttributes(out attributes));

            Debug.WriteLine(string.Format("Sending Event: {0} {1}", eventObject.GetType(), iidEvent));
            try
            {
                EngineUtils.RequireOk(events.Event(this, debugProcess, this, debugThread, eventObject, ref riidEvent, attributes));
            }
            catch (InvalidCastException)
            {
                // COM object has gone away
            }
        }
Example #46
0
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    public int ContinueFromSynchronousEvent (IDebugEvent2 eventObject)
    {
      // 
      // Called by the Session Debug Manager (SDM) to indicate that a synchronous event, previously sent by the DebugEngine to the SDM,
      // was received and processed. An example of this is 'Program Destroy', which triggers a shutdown of the DebugEngine.
      // 

      LoggingUtils.PrintFunction ();

      try
      {
        m_broadcastHandleLock.Set ();

        return Constants.S_OK;
      }
      catch (Exception e)
      {
        LoggingUtils.HandleException (e);

        return Constants.E_FAIL;
      }
    }
Example #47
0
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    public void Broadcast (IDebugEvent2 debugEvent, IDebugProgram2 program, IDebugThread2 thread)
    {
      Guid eventGuid = ComUtils.GuidOf (debugEvent);

      if ((m_cLangCallback != null) && (m_cLangCallback.IsRegistered (ref eventGuid)))
      {
        Broadcast (m_cLangCallback, debugEvent, program, thread);
      }
      else if ((m_javaLangCallback != null) && (m_javaLangCallback.IsRegistered (ref eventGuid)))
      {
        Broadcast (m_javaLangCallback, debugEvent, program, thread);
      }
      else
      {
        Broadcast (m_sdmCallback, debugEvent, program, thread);
      }
    }
Example #48
0
        // Called by the SDM to indicate that a synchronous debug event, previously sent by the DE to the SDM,
        // was received and processed. The only event we send in this fashion is Program Destroy.
        // It responds to that event by shutting down the engine.
        int IDebugEngine2.ContinueFromSynchronousEvent(IDebugEvent2 eventObject) {
            DebugWriteCommand("ContinueFromSynchronousEvent");
            AssertMainThread();

            if (eventObject is AD7ProgramDestroyEvent) {
                var debuggedProcess = _process;

                _events = null;
                _process = null;
                _ad7ProgramId = Guid.Empty;
                _threads.Clear();
                _modules.Clear();

                if (_trackFileChanges) {
                    _documentEvents.DocumentSaved -= OnDocumentSaved;
                    _documentEvents = null;
                }

                debuggedProcess.Close();
            } else {
                Debug.Fail("Unknown synchronous event");
            }

            return VSConstants.S_OK;
        }
Example #49
0
 internal void Send(IDebugEvent2 eventObject, string iidEvent, IDebugThread2 thread)
 {
     Send(eventObject, iidEvent, this, thread);
 }
Example #50
0
 public int ContinueFromSynchronousEvent(IDebugEvent2 pEvent)
 {
     DLog.Debug(DContext.VSDebuggerComCall, "IDebugEngine2.ContinueFromSynchronousEvent {0}", pEvent);
     return VSConstants.S_OK;
 }
Example #51
0
        internal void Send(IDebugEvent2 eventObject, string iidEvent, IDebugProgram2 program, IDebugThread2 thread)
        {
            uint attributes;
            Guid riidEvent = new Guid(iidEvent);

            EngineUtils.RequireOk(eventObject.GetAttributes(out attributes));

            var events = _events;
            if (events == null) {
                // Probably racing with the end of the process.
                Debug.Fail("_events is null");
                return;
            }

            Debug.WriteLine(String.Format("Sending Event: {0} {1}", eventObject.GetType(), iidEvent));
            try {
                EngineUtils.RequireOk(events.Event(this, null, program, thread, eventObject, ref riidEvent, attributes));
            } catch (InvalidCastException) {
                // COM object has gone away
            }
        }
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    public int Event (IDebugEngine2 pEngine, IDebugProcess2 pProcess, IDebugProgram2 pProgram, IDebugThread2 pThread, IDebugEvent2 pEvent, ref Guid riidEvent, uint dwAttrib)
    {
      // 
      // Custom event handler.
      // 

      try
      {
        LoggingUtils.Print ("[CLangDebuggerCallback] Event: " + riidEvent.ToString ());

        CLangDebuggerEventDelegate eventCallback;

        if (!m_debuggerCallback.TryGetValue (riidEvent, out eventCallback))
        {
          return Constants.E_NOTIMPL;
        }

        return eventCallback (m_debugEngine.NativeDebugger);
      }
      catch (Exception e)
      {
        LoggingUtils.HandleException (e);

        throw;
      }
    }
Example #53
0
        // Called by the SDM to indicate that a synchronous debug event, previously sent by the DE to the SDM,
        // was received and processed.
        int IDebugEngine2.ContinueFromSynchronousEvent(IDebugEvent2 eventObject)
        {
            if (_mixedMode) {
                return VSConstants.E_NOTIMPL;
            }

            AssertMainThread();

            if (eventObject is AD7ProgramDestroyEvent) {
                var debuggedProcess = _process;

                _events = null;
                _process = null;
                _ad7ProgramId = Guid.Empty;
                foreach (var thread in _threads.Values) {
                    thread.Dispose();
                }
                _threads.Clear();
                _modules.Clear();

                debuggedProcess.Dispose();
            } else if (eventObject is AD7CustomEvent) {
            } else {
                Debug.Fail("Unknown synchronous event");
            }

            return VSConstants.S_OK;
        }
 /// <summary>
 /// Called by the session debug manager (SDM) to indicate that a synchronous debug event, previously sent by the debug DebugEngine (DE) to the SDM, was received and processed.
 /// </summary>
 /// <param name="pEvent">An IDebugEvent2 object that represents the previously sent synchronous event from which the debugger should now continue.</param>
 /// <returns>If successful, returns S_OK; otherwise, returns an error code.</returns>
 /// <remarks>The DE must verify that it was the source of the event represented by the pEvent parameter.</remarks>
 public virtual int ContinueFromSynchronousEvent( IDebugEvent2 pEvent )
 {
     Logger.Debug( string.Empty );
     return VSConstants.E_NOTIMPL;
 }
Example #55
0
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    public void Broadcast (IDebugEvent2 debugEvent, IDebugProgram3 program, IDebugThread3 thread)
    {
      Broadcast (debugEvent, program as IDebugProgram2, thread as IDebugThread2);
    }
Example #56
0
 // Called by the SDM to indicate that a synchronous debug event, previously sent by the DE to the SDM,
 // was received and processed. The only event the sample engine sends in this fashion is Program Destroy.
 // It responds to that event by shutting down the engine.
 int IDebugEngine2.ContinueFromSynchronousEvent(IDebugEvent2 eventObject)
 {
     AD7ProgramCreateEvent programCreate = eventObject as AD7ProgramCreateEvent;
     if (programCreate != null)
     {
         _programCreateContinued.Set();
     }
     
     return VSConstants.S_OK;
 }
Example #57
0
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    public void Broadcast (IDebugEventCallback2 callback, IDebugEvent2 debugEvent, IDebugProgram2 program, IDebugThread2 thread)
    {
      LoggingUtils.PrintFunction ();

      if (callback == null)
      {
        throw new ArgumentNullException ("callback");
      }

      Guid eventGuid = ComUtils.GuidOf (debugEvent);

      uint eventAttributes = 0;

      LoggingUtils.RequireOk (debugEvent.GetAttributes (out eventAttributes));

      if (((eventAttributes & (uint) enum_EVENTATTRIBUTES.EVENT_STOPPING) != 0) && (thread == null))
      {
        throw new ArgumentNullException ("thread", "For stopping events, this parameter cannot be a null value as the stack frame is obtained from this parameter.");
      }

      try
      {
        int handle = callback.Event (this, null, program, thread, debugEvent, ref eventGuid, eventAttributes);

        if (handle != Constants.E_NOTIMPL)
        {
          LoggingUtils.RequireOk (handle);
        }
      }
      catch (Exception e)
      {
        LoggingUtils.HandleException (e);

        throw;
      }
      finally
      {
        if ((eventAttributes & (uint) enum_EVENTATTRIBUTES.EVENT_SYNCHRONOUS) != 0)
        {
          while (!m_broadcastHandleLock.WaitOne (0))
          {
            Thread.Sleep (100);
          }
        }
      }
    }
 protected virtual void OnDebugEvent( IDebugEvent2 eventObject,
     Guid iidEvent,
     IDebugProgram2 program = null,
     IDebugThread2 thread = null,
     IDebugProcess2 process = null)
 {
     uint attributes;
     eventObject.GetAttributes( out attributes );
     DebugEventCallback.Event( DebugEngineBase, process, program, thread, eventObject, ref iidEvent, attributes );
 }
Example #59
0
        // Called by the SDM to indicate that a synchronous debug event, previously sent by the DE to the SDM,
        // was received and processed. The only event the sample engine sends in this fashion is Program Destroy.
        // It responds to that event by shutting down the engine.
        int IDebugEngine2.ContinueFromSynchronousEvent(IDebugEvent2 eventObject)
        {
            try
            {
                if (eventObject is AD7ProgramCreateEvent)
                {
                    Exception exception = null;

                    try
                    {
                        // At this point breakpoints and exception settings have been sent down, so we can resume the target
                        _pollThread.RunOperation(() =>
                        {
                            return _debuggedProcess.ResumeFromLaunch();
                        });
                    }
                    catch (Exception e)
                    {
                        exception = e;
                        // Return from the catch block so that we can let the exception unwind - the stack can get kind of big
                    }

                    if (exception != null)
                    {
                        // If something goes wrong, report the error and then stop debugging. The SDM will drop errors
                        // from ContinueFromSynchronousEvent, so we want to deal with them ourself.
                        SendStartDebuggingError(exception);
                        _debuggedProcess.Terminate();
                    }

                    return Constants.S_OK;
                }
                else if (eventObject is AD7ProgramDestroyEvent)
                {
                    Dispose();
                }
                else
                {
                    Debug.Fail("Unknown syncronious event");
                }
            }
            catch (Exception e)
            {
                return EngineUtils.UnexpectedException(e);
            }

            return Constants.S_OK;
        }
Example #60
0
 // Called by the SDM to indicate that a synchronous debug event, previously sent by the DE to the SDM,
 // was received and processed. The only event the sample engine sends in this fashion is Program Destroy.
 // It responds to that event by shutting down the engine.
 int IDebugEngine2.ContinueFromSynchronousEvent(IDebugEvent2 eventObject)
 {
     return VSConstants.S_OK;
 }