internal void DispatchEvent(ManagedCallbackType callback, CorEventArgs e) { try { if (m_callbackAttachedEvent != null) { m_callbackAttachedEvent.WaitOne(); // waits till callbacks are enabled } var d = m_callbacksArray[callback]; d(this, e); } catch (Exception ex) { CorExceptionInCallbackEventArgs e2 = new CorExceptionInCallbackEventArgs(e.Controller, ex); Debug.Assert(false, "Exception in callback: " + ex.ToString()); try { // we need to dispatch the exceptin in callback error, but we cannot // use DispatchEvent since throwing exception in ExceptionInCallback // would lead to infinite recursion. Debug.Assert(m_callbackAttachedEvent == null); var d = m_callbacksArray[ManagedCallbackType.OnExceptionInCallback]; d(this, e2); } catch (Exception ex2) { Debug.Assert(false, "Exception in Exception notification callback: " + ex2.ToString()); // ignore it -- there is nothing we can do. } e.Continue = e2.Continue; } }
/// <summary> /// Expose direct dispatch logic so that other event dispatchers can /// use CorProcess's event handlers. /// </summary> /// <param name="callback">callback type to dispatch</param> /// <param name="e">event arguments used to dispatch</param> public void DirectDispatchEvent(ManagedCallbackType callback, CorEventArgs e) { Debug.Assert(callback == e.CallbackType); if (m_callbackAttachedEvent != null) { m_callbackAttachedEvent.Set(); } DispatchEvent(callback, e); }
internal void DispatchEvent(ManagedCallbackType callback, CorEventArgs e) { try { // CorProcess.Continue has an extra abstraction layer. // - The fist call just sets m_callbackAttachedEvent // - future calls go to ICorDebugProcess::Continue. // This ensures that we don't dispatch any callbacks until // after CorProcess.Continue() is called. if (m_callbackAttachedEvent != null) { m_callbackAttachedEvent.WaitOne(); // waits till callbacks are enabled } Debug.Assert((int)callback >= 0 && (int)callback < m_callbacksArray.Length); Delegate d = m_callbacksArray[(int)callback]; if (d != null) { d.DynamicInvoke(new Object[] { this, e }); } } catch (Exception ex) { CorExceptionInCallbackEventArgs e2 = new CorExceptionInCallbackEventArgs(e.Controller, ex); Debug.Assert(false, "Exception in callback: " + ex.ToString()); try { // we need to dispatch the exception in callback error, but we cannot // use DispatchEvent since throwing exception in ExceptionInCallback // would lead to infinite recursion. Debug.Assert(m_callbackAttachedEvent == null); Delegate d = m_callbacksArray[(int)ManagedCallbackType.OnExceptionInCallback]; if (d != null) { d.DynamicInvoke(new Object[] { this, e2 }); } } catch (Exception ex2) { Debug.Assert(false, "Exception in Exception notification callback: " + ex2.ToString()); // ignore it -- there is nothing we can do. } e.Continue = e2.Continue; } }
// when process is first created wait till callbacks are enabled. internal void DispatchEvent(ManagedCallbackType callback, CorEventArgs e) { try { if (m_callbackAttachedEvent != null) { m_callbackAttachedEvent.WaitOne(); // waits till callbacks are enabled } Debug.Assert((int)callback >= 0 && (int)callback < m_callbacksArray.Length); Delegate d = m_callbacksArray[(int)callback]; if (d != null) { d.DynamicInvoke(new Object[] { this, e }); } } catch (Exception ex) { var e2 = new CorExceptionInCallbackEventArgs(e.Controller, ex); OriginalMDbgMessages.WriteLine("Exception in callback: " + ex); // DC Debug.Assert(false,"Exception in callback: "+ex.ToString()); try { // we need to dispatch the exceptin in callback error, but we cannot // use DispatchEvent since throwing exception in ExceptionInCallback // would lead to infinite recursion. Debug.Assert(m_callbackAttachedEvent == null); Delegate d = m_callbacksArray[(int)ManagedCallbackType.OnExceptionInCallback]; if (d != null) { d.DynamicInvoke(new Object[] { this, e2 }); } } catch (Exception ex2) { OriginalMDbgMessages.WriteLine("Exception in Exception notification callback: " + ex2); // DC Debug.Assert(false,"Exception in Exception notification callback: "+ex2.ToString()); // ignore it -- there is nothing we can do. } e.Continue = e2.Continue; } }
/*private void CorProcess_OnStepComplete(object sender, CorStepCompleteEventArgs e) * { * // if (iCount++ % 100 == 0 && logOnBreakpoint) * DI.log.info("[{0}] CorProcess_OnStepComplete {1}", iStepCount++, getActiveFrameFunctionName(e)); * e.Continue = handleDebugFlowAction(); * } * * private void CorProcess_OnBreakpointSetError(object sender, CorBreakpointEventArgs e) * { * if (logOnBreakpoint) * DI.log.info("CorProcess_OnBreakpointSetError {0}", getActiveFrameFunctionName(e)); * e.Continue = true; * } * * private void CorProcess_OnBreakpoint(object sender, CorBreakpointEventArgs e) * { * DI.log.info("in CorProcess_OnBreakpoint"); * /*( if (handleBreakpoints) * { * if (logOnBreakpoint) * log.info("Breakpoint on {0}", getActiveFrameFunctionName(e)); * e.Continue = handleDebugFlowAction(); * }* / * e.Continue = true; * } * * private bool handleDebugFlowAction() * { * switch (onBreakPointAction) * { * case OnBreakPointAction.StepOut: * o2MDbgOLD.mdbgProcess.StepOut(); * break; * case OnBreakPointAction.StepInto: * o2MDbgOLD.mdbgProcess.StepInto(false); * break; * case OnBreakPointAction.StepOver: * o2MDbgOLD.mdbgProcess.StepOver(false); * break; * * case OnBreakPointAction.Stop: * return false; * case OnBreakPointAction.Continue: * return true; * } * return true; * } */ public static string getActiveFrameFunctionName(CorEventArgs e) { try { if (e.Thread.ActiveFrame == null) { return("e.Thread.ActiveFrame == null"); } //var corFunctionBreakpoint = (CorFunctionBreakpoint)e.Breakpoint; var corMetadataImport = new CorMetadataImport(e.Thread.ActiveFrame.Function.Class.Module); MethodInfo methodInfo = corMetadataImport.GetMethodInfo(e.Thread.ActiveFrame.Function.Token); return((methodInfo.DeclaringType.FullName ?? "(null)") + " :: " + (methodInfo.Name ?? "(null)")); } catch (Exception ex) { DI.log.ex(ex, "getActiveFrameFunctionName"); return(""); } }
/// <summary> /// Acts on the current callback, based on the current debugger behavior for this stop /// option policy. /// </summary> /// <param name="currentProcess">Current MDbgProcess.</param> /// <param name="args">Callback arguments.</param> public override void ActOnCallback(MDbgProcess currentProcess, CustomPostCallbackEventArgs args) { CorEventArgs eventArgs = args.CallbackArgs as CorEventArgs; switch (m_behavior) { case DebuggerBehavior.Stop: args.Controller.Stop(eventArgs.Thread, MDbgUtil.CreateStopReasonFromEventArgs(eventArgs, currentProcess)); break; case DebuggerBehavior.Log: CommandBase.WriteOutput(eventArgs.ToString() + "\n"); break; case DebuggerBehavior.Notify: CommandBase.WriteOutput(eventArgs.ToString() + "\n"); MDbgThread currentThread = currentProcess.Threads.GetThreadFromThreadId((args.CallbackArgs as CorThreadEventArgs).Thread.Id); try { // Getting the current notification may not be implemented. MDbgValue notification = currentThread.CurrentNotification; if (notification != null) { CommandBase.WriteOutput(notification.GetStringValue(true, "-", null)); } else { CommandBase.WriteOutput("custom notification is null\n"); } } catch (NotImplementedException) { Trace.WriteLine("Custom Notifications Not Implemented"); } break; } }
/// <summary> /// Given a CorEventArgs object, returns a corresponding StopReason. /// </summary> /// <param name="args">Callback Arguments.</param> /// <param name="currentProcess">Current MDbgProcess.</param> /// <returns>A stop reason corresponsing to the given callback arguments. This /// function currently creates StopReason objects for CorEventArgs with the following /// callback types: OnCreateThread, OnExceptionUnwind2, OnModuleLoad, OnMDANotification. /// For all other callback types, this function returns args.ToString().</returns> public static Object CreateStopReasonFromEventArgs(CorEventArgs args, MDbgProcess currentProcess) { if (args.CallbackType == ManagedCallbackType.OnCreateThread) { return(new ThreadCreatedStopReason(currentProcess.Threads.GetThreadFromThreadId(args.Thread.Id))); } if (args.CallbackType == ManagedCallbackType.OnExceptionUnwind2) { var ea = args as CorExceptionUnwind2EventArgs; return(new ExceptionUnwindStopReason(ea.AppDomain, ea.Thread, ea.EventType, ea.Flags)); } if (args.CallbackType == ManagedCallbackType.OnModuleLoad) { var ea = args as CorModuleEventArgs; return(new ModuleLoadedStopReason(currentProcess.Modules.Lookup(ea.Module))); } if (args.CallbackType == ManagedCallbackType.OnMDANotification) { var ea = args as CorMDAEventArgs; return(new MDANotificationStopReason(ea.MDA)); } return(args.ToString()); }
internal RawModeStopReason(ManagedCallbackType callbackType, CorEventArgs callbackArgs) { Debug.Assert(callbackArgs != null); m_callbackType = callbackType; m_callbackArgs = callbackArgs; }