Exemple #1
0
 /// <summary>
 /// Acts on debugger callback based on the contained stop option policies matching
 /// the callback type.
 /// </summary>
 /// <param name="currentProcess">Current MDbgProcess.</param>
 /// <param name="args">Debugger callback arguments.</param>
 public void ActOnCallback(MDbgProcess currentProcess, CustomPostCallbackEventArgs args)
 {
     if (m_stopOptions[(int)args.CallbackType] != null)
     {
         foreach (MDbgStopOptionPolicy sop in m_stopOptions[(int)args.CallbackType])
         {
             sop.ActOnCallback(currentProcess, args);
         }
     }
 }
        /// <summary>
        /// Acts on the debugger callback, based on the stop option policy settings and the
        /// type of exception thrown.
        /// </summary>
        /// <param name="currentProcess">Current MDbgProcess.</param>
        /// <param name="args">Callback arguments.</param>
        public override void ActOnCallback(MDbgProcess currentProcess, CustomPostCallbackEventArgs args)
        {
            var  ea          = args.CallbackArgs as CorException2EventArgs;
            var  ua          = args.CallbackArgs as CorExceptionUnwind2EventArgs;
            bool bException2 = (ea != null);

            if (m_exceptionEnhancedOn ||
                (bException2 && (ea.EventType == CorDebugExceptionCallbackType.DEBUG_EXCEPTION_FIRST_CHANCE)))
            {
                MDbgThread currentThread = null;
                currentThread =
                    currentProcess.Threads.GetThreadFromThreadId((args.CallbackArgs as CorThreadEventArgs).Thread.Id);

                string exceptionType = currentThread.CurrentException.TypeName;

                switch (DetermineBehavior(exceptionType))
                {
                case DebuggerBehavior.Stop:
                    if (bException2)
                    {
                        args.Controller.Stop(ea.Thread, new ExceptionThrownStopReason(ea.AppDomain,
                                                                                      ea.Thread, ea.Frame, ea.Offset,
                                                                                      ea.EventType, ea.Flags,
                                                                                      m_exceptionEnhancedOn));
                    }
                    else
                    {
                        args.Controller.Stop(ua.Thread, new ExceptionUnwindStopReason(ua.AppDomain,
                                                                                      ua.Thread, ua.EventType,
                                                                                      ua.Flags));
                    }
                    break;

                case DebuggerBehavior.Log:
                    CommandBase.WriteOutput("Exception thrown: " + currentThread.CurrentException.TypeName +
                                            " at function " + currentThread.CurrentFrame.Function.FullName +
                                            " in source file " + currentThread.CurrentSourcePosition.Path +
                                            ":" + currentThread.CurrentSourcePosition.Line);
                    if (m_exceptionEnhancedOn)
                    {
                        if (bException2)
                        {
                            CommandBase.WriteOutput("Event type: " + ea.EventType);
                        }
                        else
                        {
                            CommandBase.WriteOutput("Event type: " + ua.EventType);
                        }
                    }
                    CommandBase.WriteOutput("");
                    break;
                }
            }
        }
Exemple #3
0
        void OnPostDebugEvent(object sender, CustomPostCallbackEventArgs e)
        {
            if (e.CallbackType == ManagedCallbackType.OnProcessExit)
            {
                ReportDebugTermination();
            }

            if (e.CallbackType == ManagedCallbackType.OnBreakpoint || e.CallbackType == ManagedCallbackType.OnBreak || e.CallbackType == ManagedCallbackType.OnStepComplete)
            {
                if (GetCurrentSourcePosition() == null)
                {
                    MessageQueue.AddNotification(NppCategory.State + "NOSOURCEBREAK"); //can be caused by 'Debugger.Break();'
                }
            }

            if (e.CallbackType == ManagedCallbackType.OnLogMessage)
            {
                var args = e.CallbackArgs as CorLogMessageEventArgs;
                ReportLogMessage(args.Message);
            }

            if (breakOnException && e.CallbackType == ManagedCallbackType.OnException)
            {
                string position = GetCurrentSourcePosition();

                CorExceptionEventArgs args = (CorExceptionEventArgs)e.CallbackArgs;

                string info = SerializeException(args.Thread.CurrentException).Replace("\r\n", "\n").Replace("\n", "{$NL}");

                if (position != null)
                {
                    if (!position.Contains("css_dbg.cs|")) //If it is a script launcher then just ignore it.
                    {
                        bool isDifferentThread = SwitchToThread(args.Thread);
                        if (!isDifferentThread)
                        {
                            BreakAndReport();
                            MessageQueue.AddNotification(NppCategory.Exception + "user+:User code Exception.{$NL}Location: " + position + "{$NL}" + info);
                        }
                    }
                }
                else
                {
                    MessageQueue.AddNotification(NppCategory.Exception + "user-:Non-user code Exception." + "{$NL}" + info);
                    BreakAndReport();
                }
            }

            WriteOutput("meta=>", e.CallbackType.ToString());
            ReportBreakMode();
        }
        /// <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)
        {
            var 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 + "\n");
                break;
            }
        }
        /// <summary>
        /// Handle the Debug Event of the MDbgProcess.
        /// </summary>
        void MDbgProcess_PostDebugEvent(object sender, CustomPostCallbackEventArgs e)
        {
            this.stopReason = e.CallbackType;

            switch (this.stopReason)
            {
            case ManagedCallbackType.OnException:
                CorExceptionEventArgs exceptionEventArgs =
                    e.CallbackArgs as CorExceptionEventArgs;
                this.isExceptionUnhandled =
                    exceptionEventArgs != null && exceptionEventArgs.Unhandled;
                break;

            default:
                break;
            }
        }
Exemple #6
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;
            }
        }
 /// <summary>
 /// Acts on debugger callback.
 /// </summary>
 /// <param name="currentProcess">The current MDbgProcess. </param>
 /// <param name="args">The callback arguments.</param>
 public abstract void ActOnCallback(MDbgProcess currentProcess, CustomPostCallbackEventArgs args);
 /// <summary>
 /// Does nothing - an ExceptionEnhancedStopOptionPolicy object  is only meant to control the
 /// ExceptionEnhanced switch in an ExceptionStopOptionPolicy object, not to directly stop the
 /// debugger or to log a callback.
 /// </summary>
 /// <param name="currentProcess">Current MDbgProcess.</param>
 /// <param name="args">Callback arguments.</param>
 public override void ActOnCallback(MDbgProcess currentProcess, CustomPostCallbackEventArgs args)
 {
 }
Exemple #9
0
        /// <summary>
        /// Acts on the debugger callback, based on the stop option policy settings and the
        /// type of exception thrown.
        /// </summary>
        /// <param name="currentProcess">Current MDbgProcess.</param>
        /// <param name="args">Callback arguments.</param>
        public override void ActOnCallback(MDbgProcess currentProcess, CustomPostCallbackEventArgs args)
        {
            CorException2EventArgs       ea = args.CallbackArgs as CorException2EventArgs;
            CorExceptionUnwind2EventArgs ua = args.CallbackArgs as CorExceptionUnwind2EventArgs;
            bool bException2 = (ea != null);

            if (m_exceptionEnhancedOn ||
                (bException2 && (ea.EventType == CorDebugExceptionCallbackType.DEBUG_EXCEPTION_FIRST_CHANCE)))
            {
                MDbgThread currentThread = null;
                currentThread = currentProcess.Threads.GetThreadFromThreadId((args.CallbackArgs as CorThreadEventArgs).Thread.Id);

                string           exceptionType = null;
                DebuggerBehavior behavior;
                try
                {
                    // Getting the current exception may not be implemented.
                    exceptionType = currentThread.CurrentException.TypeName;
                    behavior      = DetermineBehavior(exceptionType);
                }
                catch (NotImplementedException)
                {
                    behavior = this.m_default;
                }

                switch (behavior)
                {
                case DebuggerBehavior.Stop:
                    if (bException2)
                    {
                        args.Controller.Stop(ea.Thread, new ExceptionThrownStopReason(ea.AppDomain,
                                                                                      ea.Thread, ea.Frame, ea.Offset, ea.EventType, ea.Flags, m_exceptionEnhancedOn));
                    }
                    else
                    {
                        args.Controller.Stop(ua.Thread, new ExceptionUnwindStopReason(ua.AppDomain,
                                                                                      ua.Thread, ua.EventType, ua.Flags));
                    }
                    break;

                case DebuggerBehavior.Log:
                    string output = "Exception thrown: " + currentThread.CurrentException.TypeName +
                                    " at function " + currentThread.CurrentFrame.Function.FullName;
                    if (currentThread.CurrentSourcePosition != null)
                    {
                        output += " in source file " + currentThread.CurrentSourcePosition.Path +
                                  ":" + currentThread.CurrentSourcePosition.Line;
                    }
                    CommandBase.WriteOutput(output);
                    if (m_exceptionEnhancedOn)
                    {
                        if (bException2)
                        {
                            CommandBase.WriteOutput("Event type: " + ea.EventType);
                        }
                        else
                        {
                            CommandBase.WriteOutput("Event type: " + ua.EventType);
                        }
                    }
                    CommandBase.WriteOutput("");
                    break;
                }
            }
        }