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 } }
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)); }
public void Send(IDebugEvent2 eventObject, string iidEvent, IDebugProgram2 program, IDebugThread2 thread) { uint attributes; Guid riidEvent = new Guid(iidEvent); if (initialized) { int hr = 0; try { EngineUtils.RequireOk(eventObject.GetAttributes(out attributes)); EngineUtils.RequireOk(hr = m_ad7Callback.Event(m_engine, null, program, thread, eventObject, ref riidEvent, attributes)); } catch (Exception) { if (m_ad7Callback == null) { Debug.WriteLine("m_ad7Callback is null#####################################################"); } else if (hr != 0) { Debug.WriteLine("EngineCallback::Send -> m_ad7Callback.Event failed: " + hr); } else { Debug.WriteLine("EngineCallback::Send ############################# unknown exception"); } } } else { Debug.WriteLine("m_ad7Callback is null#####################################################"); } }
/// <summary> /// Send events to the debugger. /// </summary> /// <param name="eventObject"> Event object to be sent to the debugger. </param> /// <param name="iidEvent"> ID of the event. </param> /// <param name="program"> A program that is running in a process. </param> /// <param name="thread"> A thread running in a program. </param> public void Send(IDebugEvent2 eventObject, string iidEvent, IDebugProgram2 program, IDebugThread2 thread) { uint attributes; Guid riidEvent = new Guid(iidEvent); EngineUtils.RequireOk(eventObject.GetAttributes(out attributes)); if ((thread == null) && (m_engine != null) && (m_engine.thread != null) && (program != null) && (eventObject != null) && (riidEvent != null) && (attributes != null)) { if (m_engine._currentThreadIndex != -1) { EngineUtils.RequireOk(m_ad7Callback.Event(m_engine, null, program, m_engine.thread[m_engine._currentThreadIndex], eventObject, ref riidEvent, attributes)); } else { if (m_engine.thread != null) { EngineUtils.RequireOk(m_ad7Callback.Event(m_engine, null, program, m_engine.thread[0], eventObject, ref riidEvent, attributes)); } else { EngineUtils.RequireOk(m_ad7Callback.Event(m_engine, null, program, null, eventObject, ref riidEvent, attributes)); } } } else { EngineUtils.RequireOk(m_ad7Callback.Event(m_engine, null, program, thread, eventObject, ref riidEvent, attributes)); } }
// This method evaluates the expression asynchronously. // This method should return immediately after it has started the expression evaluation. // When the expression is successfully evaluated, an IDebugExpressionEvaluationCompleteEvent2 // must be sent to the IDebugEventCallback2 event callback int IDebugExpression2.EvaluateAsync(enum_EVALFLAGS dwFlags, IDebugEventCallback2 pExprCallback) { if (pExprCallback == null) { return(VisualStudioExtensionConstants.S_FALSE); } if (_asyncEval == null || _asyncEval.ThreadState != System.Threading.ThreadState.Running) { _asyncEval = new System.Threading.Thread(() => { uint attributes; Guid riidEvent = new Guid(XamarinExpressionEvaluationCompleteEvent.IID); IDebugExpressionEvaluationCompleteEvent2 evnt = new XamarinExpressionEvaluationCompleteEvent(this, new XamarinProperty(_var)); 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 (pExprCallback.Event(_engine.MonoEngine, null, _engine.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"); } }); _asyncEval.Start(); return(VisualStudioExtensionConstants.S_OK); } return(VisualStudioExtensionConstants.S_FALSE); }
internal void Send(IDebugEvent2 eventObject, string iidEvent, IDebugProgram2 program, IDebugThread2 thread) { var events = _events; if (events == null) { return; } uint attributes; var riidEvent = new Guid(iidEvent); Marshal.ThrowExceptionForHR(eventObject.GetAttributes(out attributes)); if ((attributes & (uint)enum_EVENTATTRIBUTES.EVENT_STOPPING) != 0 && thread == null) { throw new InvalidOperationException("A thread must be provided for a stopping event"); } try { Marshal.ThrowExceptionForHR(events.Event(this, null, program, thread, eventObject, ref riidEvent, attributes)); } catch (InvalidCastException) { // COM object has gone away. } }
private void Send(IDebugEvent2 eventObject, string iidEvent) { uint attributes; Guid riidEvent = new Guid(iidEvent); EngineUtils.RequireOk(eventObject.GetAttributes(out attributes)); EngineUtils.RequireOk(_ad7Callback.Event(_engine, _process, _program, _program, eventObject, ref riidEvent, attributes)); }
public void Send(IDebugEvent2 eventObject, string eventId, IDebugProgram2 program, IDebugThread2 thread) { uint attributes; var @event = new Guid(eventId); eventObject.GetAttributes(out attributes); Callback.Event(_engine, null, program, thread, eventObject, ref @event, attributes); }
public static void Send(this IDebugEventCallback2 callback, MonoEngine engine, IDebugEvent2 eventObject, string iidEvent, IDebugProgram2 program, IDebugThread2 thread) { uint attributes; var riidEvent = new Guid(iidEvent); eventObject.GetAttributes(out attributes); callback.Event(engine, null, program, thread, eventObject, ref riidEvent, attributes); }
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)); }
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); }
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); }
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)); }
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 } }
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"); } }
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) { try { string threadName = null; if (pThread != null && pEvent != null) { uint attributes; pEvent.GetAttributes(out attributes); if ( (uint)enum_EVENTATTRIBUTES.EVENT_SYNC_STOP == attributes) { //HandleException.PrintFrames(pThread); } pThread.GetName(out threadName); //ExtractFrameContent(pThread); //IEnumDebugFrameInfo2 ppEnum = null; } Trace.WriteLine(string.Format("Event {0} Thread {1}", riidEvent, threadName )); if (typeof(IDebugInterceptExceptionCompleteEvent2).GUID == riidEvent) { var interactionEvent = pEvent as IDebugInterceptExceptionCompleteEvent2; ulong cookie; interactionEvent.GetInterceptCookie(out cookie); // another way to get code path: //pProgram.EnumCodePaths( var exceptionInfo = HandleException.PrintFrames(pThread); if (exceptionInfo != null) { if (exceptionInfo.ExceptionKind == null) { exceptionInfo.ExceptionKind = LastExceptionType; } if (exceptionInfo.ExceptionMessage == null) { exceptionInfo.ExceptionMessage = LastExceptionMessage; } SaveToDb(exceptionInfo); } } //HandleException.ProcessEvent(riidEvent, pThread); if (typeof(IDebugProgramCreateEvent2).GUID == riidEvent) { // Add handle } //if (typeof(IDebugBreakEvent2).GUID == riidEvent) if(typeof(IDebugBreakpointEvent2).GUID == riidEvent) { // Might be interesting to get the statement line number here and emit. //var ev = pEvent as IDebugBreakEvent2; var ev = pEvent as IDebugBreakpointEvent2; var info = HandleException.ProcessEvent(riidEvent, pThread); if (info != null) { SaveToDb(info); } } if (riidEvent == typeof(IDebugEntryPointEvent2).GUID) { // This is when execution is just about to the start. // I can't get the reference to the engine, pEngine is always null, and // there doesn't seem to be an interface to fetch it (there is a query interface in docs, but not in dll!) //string engineStr; Guid engineGuid; //pProgram.GetEngineInfo(out engineStr, out engineGuid); //var superEngine = pEngine as IDebugEngine3; //if (superEngine != null) //{ // superEngine.SetAllExceptions(enum_EXCEPTION_STATE.EXCEPTION_STOP_FIRST_CHANCE); //} } else if (riidEvent == typeof(IDebugMessageEvent2).GUID) { var ev = pEvent as IDebugMessageEvent2; var str = ""; uint type; string helpFile; uint helpId; var suc = ev.GetMessage(new enum_MESSAGETYPE[] { enum_MESSAGETYPE.MT_REASON_EXCEPTION }, out str, out type, out helpFile, out helpId); //uint messageType; //var suc = ev.GetMessage( out messageType, out str, out type, out helpFile, out helpId); if (suc == VSConstants.S_OK) { if (str.StartsWith("A first chance exception of type")) { if (pThread != null) { //ExtractFrameContent(pThread); //HandleException.PrintFrames(pThread); LastExceptionMessage = str; LastExceptionType = str; } // First chance exception thrown...but can't figure out how to get stack trace :( } } } // This interface is sent by the debug engine (DE) to the session debug manager (SDM) when a thread is created in a program being debugged. //if (riidEvent == Guid.Parse("{2090ccfc-70c5-491d-a5e8-bad2dd9ee3ea}")) { if (pThread != null) { // ExtractFrameContent(pThread); } } // Process of exception handling. // http://msdn.microsoft.com/es-es/library/bb146610.aspx if (riidEvent == typeof(IDebugExceptionEvent2).GUID || riidEvent == Guid.Parse("{51A94113-8788-4A54-AE15-08B74FF922D0}") ) { IDebugExceptionEvent2 ev = pEvent as IDebugExceptionEvent2; if (ev != null) { var info = new EXCEPTION_INFO[1]; ev.GetException(info); var name = info[0].bstrExceptionName; var state = info[0].dwState; //state == enum_EXCEPTION_STATE.EXCEPTION_STOP_SECOND_CHANCE //ExtractFrameContent(pThread); } } } catch (Exception ex) { Trace.WriteLine(ex.Message); } if (pEngine != null) { Marshal.ReleaseComObject(pEngine); } if (pProcess != null) { Marshal.ReleaseComObject(pProcess); } if (pProgram != null) { Marshal.ReleaseComObject(pProgram); } if (pThread != null) { Marshal.ReleaseComObject(pThread); } if (pEvent != null) { Marshal.ReleaseComObject(pEvent); } return VSConstants.S_OK; }
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 } }
public int Event(IDebugEngine2 pEngine, IDebugProcess2 pProcess, IDebugProgram2 pProgram, IDebugThread2 pThread, IDebugEvent2 pEvent, ref Guid riidEvent, uint dwAttrib) { try { string threadName = null; if (pThread != null && pEvent != null) { uint attributes; pEvent.GetAttributes(out attributes); if ((uint)enum_EVENTATTRIBUTES.EVENT_SYNC_STOP == attributes) { //HandleException.PrintFrames(pThread); } pThread.GetName(out threadName); //ExtractFrameContent(pThread); //IEnumDebugFrameInfo2 ppEnum = null; } Trace.WriteLine(string.Format("Event {0} Thread {1}", riidEvent, threadName)); if (typeof(IDebugInterceptExceptionCompleteEvent2).GUID == riidEvent) { var interactionEvent = pEvent as IDebugInterceptExceptionCompleteEvent2; ulong cookie; interactionEvent.GetInterceptCookie(out cookie); // another way to get code path: //pProgram.EnumCodePaths( var exceptionInfo = HandleException.PrintFrames(pThread); if (exceptionInfo != null) { if (exceptionInfo.ExceptionKind == null) { exceptionInfo.ExceptionKind = LastExceptionType; } if (exceptionInfo.ExceptionMessage == null) { exceptionInfo.ExceptionMessage = LastExceptionMessage; } SaveToDb(exceptionInfo); } } //HandleException.ProcessEvent(riidEvent, pThread); if (typeof(IDebugProgramCreateEvent2).GUID == riidEvent) { // Add handle } //if (typeof(IDebugBreakEvent2).GUID == riidEvent) if (typeof(IDebugBreakpointEvent2).GUID == riidEvent) { // Might be interesting to get the statement line number here and emit. //var ev = pEvent as IDebugBreakEvent2; var ev = pEvent as IDebugBreakpointEvent2; var info = HandleException.ProcessEvent(riidEvent, pThread); if (info != null) { SaveToDb(info); } } if (riidEvent == typeof(IDebugEntryPointEvent2).GUID) { // This is when execution is just about to the start. // I can't get the reference to the engine, pEngine is always null, and // there doesn't seem to be an interface to fetch it (there is a query interface in docs, but not in dll!) //string engineStr; Guid engineGuid; //pProgram.GetEngineInfo(out engineStr, out engineGuid); //var superEngine = pEngine as IDebugEngine3; //if (superEngine != null) //{ // superEngine.SetAllExceptions(enum_EXCEPTION_STATE.EXCEPTION_STOP_FIRST_CHANCE); //} } else if (riidEvent == typeof(IDebugMessageEvent2).GUID) { var ev = pEvent as IDebugMessageEvent2; var str = ""; uint type; string helpFile; uint helpId; var suc = ev.GetMessage(new enum_MESSAGETYPE[] { enum_MESSAGETYPE.MT_REASON_EXCEPTION }, out str, out type, out helpFile, out helpId); //uint messageType; //var suc = ev.GetMessage( out messageType, out str, out type, out helpFile, out helpId); if (suc == VSConstants.S_OK) { if (str.StartsWith("A first chance exception of type")) { if (pThread != null) { //ExtractFrameContent(pThread); //HandleException.PrintFrames(pThread); LastExceptionMessage = str; LastExceptionType = str; } // First chance exception thrown...but can't figure out how to get stack trace :( } } } // This interface is sent by the debug engine (DE) to the session debug manager (SDM) when a thread is created in a program being debugged. //if (riidEvent == Guid.Parse("{2090ccfc-70c5-491d-a5e8-bad2dd9ee3ea}")) { if (pThread != null) { // ExtractFrameContent(pThread); } } // Process of exception handling. // http://msdn.microsoft.com/es-es/library/bb146610.aspx if (riidEvent == typeof(IDebugExceptionEvent2).GUID || riidEvent == Guid.Parse("{51A94113-8788-4A54-AE15-08B74FF922D0}") ) { IDebugExceptionEvent2 ev = pEvent as IDebugExceptionEvent2; if (ev != null) { var info = new EXCEPTION_INFO[1]; ev.GetException(info); var name = info[0].bstrExceptionName; var state = info[0].dwState; //state == enum_EXCEPTION_STATE.EXCEPTION_STOP_SECOND_CHANCE //ExtractFrameContent(pThread); } } } catch (Exception ex) { Trace.WriteLine(ex.Message); } if (pEngine != null) { Marshal.ReleaseComObject(pEngine); } if (pProcess != null) { Marshal.ReleaseComObject(pProcess); } if (pProgram != null) { Marshal.ReleaseComObject(pProgram); } if (pThread != null) { Marshal.ReleaseComObject(pThread); } if (pEvent != null) { Marshal.ReleaseComObject(pEvent); } return(VSConstants.S_OK); }
/// <summary> /// Send events to the debugger. /// </summary> /// <param name="eventObject"> Event object to be sent to the debugger. </param> /// <param name="iidEvent"> ID of the event. </param> /// <param name="program"> A program that is running in a process. </param> /// <param name="thread"> A thread running in a program. </param> public void Send(IDebugEvent2 eventObject, string iidEvent, IDebugProgram2 program, IDebugThread2 thread) { uint attributes; Guid riidEvent = new Guid(iidEvent); EngineUtils.RequireOk(eventObject.GetAttributes(out attributes)); if ((thread == null) && (m_engine != null) && (m_engine.thread != null) && (program != null) && (eventObject != null) && (riidEvent != null) && (attributes != null)) { if (m_engine._currentThreadIndex != -1) { EngineUtils.RequireOk(m_ad7Callback.Event(m_engine, null, program, m_engine.thread[m_engine._currentThreadIndex], eventObject, ref riidEvent, attributes)); } else { if (m_engine.thread != null) EngineUtils.RequireOk(m_ad7Callback.Event(m_engine, null, program, m_engine.thread[0], eventObject, ref riidEvent, attributes)); else EngineUtils.RequireOk(m_ad7Callback.Event(m_engine, null, program, null, eventObject, ref riidEvent, attributes)); } } else EngineUtils.RequireOk(m_ad7Callback.Event(m_engine, null, program, thread, eventObject, ref riidEvent, attributes)); }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 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 ); }