/*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 "";
            }
        }
Esempio n. 2
0
        // returns true if the CustomPostCallback requested stop.
        private bool HandleCustomPostCallback(ManagedCallbackType callbackType, CorEventArgs callbackArgs)
        {
            bool stopRequested = false;
            bool needAsyncStopCall = false;
            if (!needAsyncStopCall)
            {
                Threads.RefreshStack();
            }


            using (var psc = new MDbgProcessStopController(this, callbackArgs, needAsyncStopCall))
            {
                if (PostDebugEvent != null)
                {
                    PostDebugEvent(this, new CustomPostCallbackEventArgs(psc, callbackType, callbackArgs));
                    stopRequested = psc.CustomStopRequested;
                }
            } // end using

            return stopRequested;
        }
Esempio n. 3
0
 public MDbgProcessStopController(MDbgProcess process, CorEventArgs eventArgs, bool needAsyncStopCall)
 {
     Debug.Assert(process != null);
     Debug.Assert(eventArgs != null);
     this.process = process;
     this.eventArgs = eventArgs;
     this.needAsyncStopCall = needAsyncStopCall;
 }
Esempio n. 4
0
 internal RawModeStopReason(ManagedCallbackType callbackType, CorEventArgs callbackArgs)
 {
     Debug.Assert(callbackArgs != null);
     m_callbackType = callbackType;
     m_callbackArgs = callbackArgs;
 }
Esempio n. 5
0
 private bool InternalHandleRawMode(ManagedCallbackType callbackType, CorEventArgs callbackArgs)
 {
     lock (this)
     {
         switch (RawModeType)
         {
             case RawMode.None:
                 return false;
             case RawMode.AlwaysStop:
                 callbackArgs.Continue = false;
                 m_stopReason = new RawModeStopReason(callbackType, callbackArgs);
                 ++m_stopCount;
                 Debug.Assert(m_stopCount == 1, "StopCount=" + m_stopCount);
                 // we should be stopped just by this event
                 m_stopCounter = g_stopCounter++;
                 m_stopEvent.Set();
                 return true;
             case RawMode.NeverStop:
                 return true;
             default:
                 Debug.Assert(false);
                 return false;
         }
     }
 }
 protected override void HandleEvent(ManagedCallbackType eventId, CorEventArgs args)
 {
     m_outer.InternalFireEvent(eventId, args);
 }
        /**
         * Helper for invoking events.  Checks to make sure that handlers
         * are hooked up to a handler before the handler is invoked.
         *
         * We want to allow maximum flexibility by our callers.  As such,
         * we don't require that they call <code>e.Controller.Continue</code>,
         * nor do we require that this class call it.  <b>Someone</b> needs
         * to call it, however.
         *
         * Consequently, if an exception is thrown and the process is stopped,
         * the process is continued automatically.
         */

        private void InternalFireEvent(ManagedCallbackType callbackType, CorEventArgs e)
        {
            CorProcess owner;
            CorController c = e.Controller;
            Debug.Assert(c != null);
            if (c is CorProcess)
                owner = (CorProcess) c;
            else
            {
                Debug.Assert(c is CorAppDomain);
                owner = (c as CorAppDomain).Process;
            }
            Debug.Assert(owner != null);
            try
            {
                owner.DispatchEvent(callbackType, e);
            }
            finally
            {
                if (e.Continue)
                {
                    e.Controller.Continue(false);
                }
            }
        }
 protected abstract void HandleEvent(ManagedCallbackType eventId, CorEventArgs args);
        // 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;
            }
        }
Esempio n. 10
0
 /// <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();
 }