예제 #1
0
        /// <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;
            }
        }
예제 #2
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());
 }