コード例 #1
0
ファイル: ExceptionManager.cs プロジェクト: haise0/reAtomizer
 void DnDebugger_DebugCallbackEvent(DnDebugger dbg, DebugCallbackEventArgs e)
 {
     if (e.Kind == DebugCallbackKind.Exception2)
     {
         OnException((Exception2DebugCallbackEventArgs)e);
     }
 }
コード例 #2
0
ファイル: ExceptionManager.cs プロジェクト: imanadib/dnSpy
 void DnDebugger_DebugCallbackEvent(DnDebugger dbg, DebugCallbackEventArgs e)
 {
     if (e.Type == DebugCallbackType.Exception2)
     {
         OnException((Exception2DebugCallbackEventArgs)e);
     }
 }
コード例 #3
0
ファイル: BreakpointsVM.cs プロジェクト: imanadib/dnSpy
 void DnDebugger_DebugCallbackEvent(DnDebugger dbg, DebugCallbackEventArgs e)
 {
     if (nameErrorCounter != 0 && e.Type == DebugCallbackType.LoadClass)
     {
         var lcArgs = (LoadClassDebugCallbackEventArgs)e;
         var module = dbg.TryGetModule(lcArgs.CorAppDomain, lcArgs.CorClass);
         Debug.Assert(module != null);
         if (module != null && module.IsDynamic)
         {
             pendingModules.Add(module.SerializedDnModule);
         }
     }
 }
コード例 #4
0
 void DnDebugger_DebugCallbackEvent(DnDebugger dbg, DebugCallbackEventArgs e)
 {
     if (e.Type == DebugCallbackType.LoadClass)
     {
         var lc       = (LoadClassDebugCallbackEventArgs)e;
         var cls      = lc.CorClass;
         var dnModule = dbg.TryGetModule(lc.CorAppDomain, cls);
         OnLoadClass(dnModule, cls);
     }
     else if (e.Type == DebugCallbackType.UnloadClass)
     {
         var uc       = (UnloadClassDebugCallbackEventArgs)e;
         var cls      = uc.CorClass;
         var dnModule = dbg.TryGetModule(uc.CorAppDomain, cls);
         OnUnloadClass(dnModule, cls);
     }
 }
コード例 #5
0
        public static DebugEventBreakpointType?GetDebugEventBreakpointType(DebugCallbackEventArgs e)
        {
            switch (e.Type)
            {
            case DebugCallbackType.CreateProcess:           return(DebugEventBreakpointType.CreateProcess);

            case DebugCallbackType.ExitProcess:                     return(DebugEventBreakpointType.ExitProcess);

            case DebugCallbackType.CreateThread:            return(DebugEventBreakpointType.CreateThread);

            case DebugCallbackType.ExitThread:                      return(DebugEventBreakpointType.ExitThread);

            case DebugCallbackType.LoadModule:                      return(DebugEventBreakpointType.LoadModule);

            case DebugCallbackType.UnloadModule:            return(DebugEventBreakpointType.UnloadModule);

            case DebugCallbackType.LoadClass:                       return(DebugEventBreakpointType.LoadClass);

            case DebugCallbackType.UnloadClass:                     return(DebugEventBreakpointType.UnloadClass);

            case DebugCallbackType.LogMessage:                      return(DebugEventBreakpointType.LogMessage);

            case DebugCallbackType.LogSwitch:                       return(DebugEventBreakpointType.LogSwitch);

            case DebugCallbackType.CreateAppDomain:         return(DebugEventBreakpointType.CreateAppDomain);

            case DebugCallbackType.ExitAppDomain:           return(DebugEventBreakpointType.ExitAppDomain);

            case DebugCallbackType.LoadAssembly:            return(DebugEventBreakpointType.LoadAssembly);

            case DebugCallbackType.UnloadAssembly:          return(DebugEventBreakpointType.UnloadAssembly);

            case DebugCallbackType.ControlCTrap:            return(DebugEventBreakpointType.ControlCTrap);

            case DebugCallbackType.NameChange:                      return(DebugEventBreakpointType.NameChange);

            case DebugCallbackType.UpdateModuleSymbols:     return(DebugEventBreakpointType.UpdateModuleSymbols);

            case DebugCallbackType.MDANotification:         return(DebugEventBreakpointType.MDANotification);

            case DebugCallbackType.CustomNotification:      return(DebugEventBreakpointType.CustomNotification);

            default: return(null);
            }
        }
コード例 #6
0
		public static DebugEventBreakpointType? GetDebugEventBreakpointType(DebugCallbackEventArgs e) {
			switch (e.Type) {
			case DebugCallbackType.CreateProcess:		return DebugEventBreakpointType.CreateProcess;
			case DebugCallbackType.ExitProcess:			return DebugEventBreakpointType.ExitProcess;
			case DebugCallbackType.CreateThread:		return DebugEventBreakpointType.CreateThread;
			case DebugCallbackType.ExitThread:			return DebugEventBreakpointType.ExitThread;
			case DebugCallbackType.LoadModule:			return DebugEventBreakpointType.LoadModule;
			case DebugCallbackType.UnloadModule:		return DebugEventBreakpointType.UnloadModule;
			case DebugCallbackType.LoadClass:			return DebugEventBreakpointType.LoadClass;
			case DebugCallbackType.UnloadClass:			return DebugEventBreakpointType.UnloadClass;
			case DebugCallbackType.LogMessage:			return DebugEventBreakpointType.LogMessage;
			case DebugCallbackType.LogSwitch:			return DebugEventBreakpointType.LogSwitch;
			case DebugCallbackType.CreateAppDomain:		return DebugEventBreakpointType.CreateAppDomain;
			case DebugCallbackType.ExitAppDomain:		return DebugEventBreakpointType.ExitAppDomain;
			case DebugCallbackType.LoadAssembly:		return DebugEventBreakpointType.LoadAssembly;
			case DebugCallbackType.UnloadAssembly:		return DebugEventBreakpointType.UnloadAssembly;
			case DebugCallbackType.ControlCTrap:		return DebugEventBreakpointType.ControlCTrap;
			case DebugCallbackType.NameChange:			return DebugEventBreakpointType.NameChange;
			case DebugCallbackType.UpdateModuleSymbols:	return DebugEventBreakpointType.UpdateModuleSymbols;
			case DebugCallbackType.MDANotification:		return DebugEventBreakpointType.MDANotification;
			case DebugCallbackType.CustomNotification:	return DebugEventBreakpointType.CustomNotification;
			default: return null;
			}
		}
コード例 #7
0
		public AnyDebugEventBreakpointConditionContext(DnDebugger debugger, DnAnyDebugEventBreakpoint bp, DebugCallbackEventArgs e)
			: base(debugger) {
			this.bp = bp;
			this.e = e;
		}
コード例 #8
0
        void DnDebugger_DebugCallbackEvent(DnDebugger dbg, DebugCallbackEventArgs e)
        {
            if (debugState?.dbg != dbg)
            {
                return;
            }

            switch (e.Kind)
            {
            case DebugCallbackKind.Breakpoint:
            case DebugCallbackKind.StepComplete:
            case DebugCallbackKind.Break:
            case DebugCallbackKind.Exception:
            case DebugCallbackKind.EvalComplete:
            case DebugCallbackKind.EvalException:
            case DebugCallbackKind.CreateProcess:
            case DebugCallbackKind.ExitProcess:
            case DebugCallbackKind.CreateThread:
            case DebugCallbackKind.LoadClass:
            case DebugCallbackKind.UnloadClass:
            case DebugCallbackKind.DebuggerError:
            case DebugCallbackKind.LogSwitch:
            case DebugCallbackKind.CreateAppDomain:
            case DebugCallbackKind.ExitAppDomain:
            case DebugCallbackKind.LoadAssembly:
            case DebugCallbackKind.UnloadAssembly:
            case DebugCallbackKind.ControlCTrap:
            case DebugCallbackKind.NameChange:
            case DebugCallbackKind.UpdateModuleSymbols:
            case DebugCallbackKind.EditAndContinueRemap:
            case DebugCallbackKind.BreakpointSetError:
            case DebugCallbackKind.FunctionRemapOpportunity:
            case DebugCallbackKind.CreateConnection:
            case DebugCallbackKind.ChangeConnection:
            case DebugCallbackKind.DestroyConnection:
            case DebugCallbackKind.ExceptionUnwind:
            case DebugCallbackKind.FunctionRemapComplete:
            case DebugCallbackKind.CustomNotification:
                break;

            case DebugCallbackKind.ExitThread:
                if (outputLoggerSettings.ShowThreadExitMessages)
                {
                    var etArgs = (ExitThreadDebugCallbackEventArgs)e;
                    int threadExitCode;
                    if (!NativeMethods.GetExitCodeThread(etArgs.CorThread?.Handle ?? IntPtr.Zero, out threadExitCode))
                    {
                        threadExitCode = -1;
                    }
                    textPane.WriteLine(BoxedTextColor.DebugLogExitThread,
                                       string.Format(dnSpy_Debugger_Resources.DebugLogExitThread,
                                                     etArgs.CorThread?.ThreadId ?? 0,
                                                     threadExitCode));
                }
                break;

            case DebugCallbackKind.LoadModule:
                if (outputLoggerSettings.ShowModuleLoadMessages)
                {
                    var lmArgs = (LoadModuleDebugCallbackEventArgs)e;
                    var module = dbg.Modules.FirstOrDefault(a => a.CorModule == lmArgs.CorModule);
                    Debug.Assert(module != null);
                    textPane.WriteLine(BoxedTextColor.DebugLogLoadModule,
                                       string.Format(dnSpy_Debugger_Resources.DebugLogLoadModule,
                                                     GetProcessName(module?.Process),
                                                     GetRuntimeVersion(dbg),
                                                     module?.AppDomain?.Name ?? "???",
                                                     module?.Name));
                }
                break;

            case DebugCallbackKind.UnloadModule:
                if (outputLoggerSettings.ShowModuleUnloadMessages)
                {
                    var ulmArgs = (UnloadModuleDebugCallbackEventArgs)e;
                    var module  = dbg.Modules.FirstOrDefault(a => a.CorModule == ulmArgs.CorModule);
                    Debug.Assert(module != null);
                    textPane.WriteLine(BoxedTextColor.DebugLogUnloadModule,
                                       string.Format(dnSpy_Debugger_Resources.DebugLogUnloadModule,
                                                     GetProcessName(module?.Process),
                                                     GetRuntimeVersion(dbg),
                                                     module?.AppDomain?.Name ?? "???",
                                                     module?.Name));
                }
                break;

            case DebugCallbackKind.LogMessage:
                if (outputLoggerSettings.ShowProgramOutputMessages)
                {
                    var lmsgArgs = (LogMessageDebugCallbackEventArgs)e;
                    var msg      = FilterUserMessage(lmsgArgs.Message);
                    textPane.Write(BoxedTextColor.DebugLogProgramOutput, msg);
                }
                break;

            case DebugCallbackKind.Exception2:
                if (outputLoggerSettings.ShowExceptionMessages)
                {
                    var       ex2Args = (Exception2DebugCallbackEventArgs)e;
                    CorValue  exValue;
                    DnModule  exModule;
                    CorModule module;
                    string    exMsg;

                    switch (ex2Args.EventType)
                    {
                    case CorDebugExceptionCallbackType.DEBUG_EXCEPTION_FIRST_CHANCE:
                    case CorDebugExceptionCallbackType.DEBUG_EXCEPTION_USER_FIRST_CHANCE:
                        break;

                    case CorDebugExceptionCallbackType.DEBUG_EXCEPTION_CATCH_HANDLER_FOUND:
                        exValue  = ex2Args.CorThread?.CurrentException;
                        module   = ex2Args.CorFrame?.Function?.Module;
                        exModule = dbg.Modules.FirstOrDefault(a => a.CorModule == module);
                        textPane.WriteLine(BoxedTextColor.DebugLogExceptionHandled,
                                           string.Format(dnSpy_Debugger_Resources.DebugLogExceptionHandled,
                                                         exValue?.ExactType?.ToString() ?? "???",
                                                         GetModuleName(exModule)));
                        exMsg = FilterUserMessage(GetExceptionMessage(exValue));
                        textPane.WriteLine(BoxedTextColor.DebugLogExceptionHandled,
                                           string.Format(dnSpy_Debugger_Resources.DebugLogAdditionalInformation, exMsg));
                        break;

                    case CorDebugExceptionCallbackType.DEBUG_EXCEPTION_UNHANDLED:
                        exValue = ex2Args.CorThread?.CurrentException;
                        // CorFrame could be null so try to find another one, eg. top frame
                        var frame = ex2Args.CorFrame ?? ex2Args.CorThread?.ActiveFrame ?? ex2Args.CorThread?.AllFrames.FirstOrDefault();
                        module   = frame?.Function?.Module;
                        exModule = dbg.Modules.FirstOrDefault(a => a.CorModule == module);
                        textPane.WriteLine(BoxedTextColor.DebugLogExceptionUnhandled,
                                           string.Format(dnSpy_Debugger_Resources.DebugLogExceptionUnhandled,
                                                         exValue?.ExactType?.ToString() ?? "???",
                                                         GetModuleName(exModule)));
                        exMsg = FilterUserMessage(GetExceptionMessage(exValue));
                        textPane.WriteLine(BoxedTextColor.DebugLogExceptionUnhandled,
                                           string.Format(dnSpy_Debugger_Resources.DebugLogAdditionalInformation, exMsg));
                        break;

                    default:
                        Debug.Fail("Unknown exception event type: " + ex2Args.EventType);
                        break;
                    }
                }
                break;

            case DebugCallbackKind.MDANotification:
                if (outputLoggerSettings.ShowMDAMessages)
                {
                    var mdaArgs    = (MDANotificationDebugCallbackEventArgs)e;
                    var mda        = mdaArgs.CorMDA;
                    var corProcess = mdaArgs.CorProcess ?? mdaArgs.CorThread?.Process;
                    var process    = dbg.Processes.FirstOrDefault(a => a.CorProcess == corProcess);
                    textPane.WriteLine(BoxedTextColor.DebugLogMDA,
                                       string.Format(dnSpy_Debugger_Resources.DebugLogMDA,
                                                     mda.Name ?? "???",
                                                     GetProcessFullPath(process)));
                    textPane.WriteLine(BoxedTextColor.DebugLogMDA,
                                       string.Format(dnSpy_Debugger_Resources.DebugLogAdditionalInformation, mda.Description ?? "???"));
                }
                break;
            }
        }
コード例 #9
0
ファイル: DbgEngineImpl.cs プロジェクト: kalinathalie/dnSpy
        void DnDebugger_DebugCallbackEvent(DnDebugger dbg, DebugCallbackEventArgs e)
        {
            string msg;

            switch (e.Kind)
            {
            case DebugCallbackKind.CreateProcess:
                var cp = (CreateProcessDebugCallbackEventArgs)e;
                hProcess_debuggee = Native.NativeMethods.OpenProcess(Native.NativeMethods.PROCESS_QUERY_LIMITED_INFORMATION, false, (uint)(cp.CorProcess?.ProcessId ?? -1));
                SendMessage(new DbgMessageConnected((uint)cp.CorProcess.ProcessId, GetMessageFlags()));
                e.AddPauseReason(DebuggerPauseReason.Other);
                break;

            case DebugCallbackKind.CreateAppDomain:
                // CreateProcess is too early, we must do this when the AppDomain gets created
                if (!clrDacInitd)
                {
                    clrDacInitd = true;
                    var p = dnDebugger.Processes.FirstOrDefault();
                    if (p != null)
                    {
                        clrDac = clrDacProvider.Create(p.ProcessId, dnDebugger.CLRPath, this);
                    }
                }
                break;

            case DebugCallbackKind.Exception2:
                var e2 = (Exception2DebugCallbackEventArgs)e;
                DbgExceptionEventFlags exFlags;
                if (e2.EventType == CorDebugExceptionCallbackType.DEBUG_EXCEPTION_FIRST_CHANCE)
                {
                    exFlags = DbgExceptionEventFlags.FirstChance;
                }
                else if (e2.EventType == CorDebugExceptionCallbackType.DEBUG_EXCEPTION_UNHANDLED)
                {
                    exFlags = DbgExceptionEventFlags.SecondChance | DbgExceptionEventFlags.Unhandled;
                    isUnhandledException = true;
                }
                else
                {
                    break;
                }

                // Ignore exceptions when evaluating except if it's an unhandled exception, those must always be reported
                if (dbg.IsEvaluating && e2.EventType != CorDebugExceptionCallbackType.DEBUG_EXCEPTION_UNHANDLED)
                {
                    break;
                }

                var exObj = e2.CorThread?.CurrentException;
                objectFactory.CreateException(new DbgExceptionId(PredefinedExceptionCategories.DotNet, TryGetExceptionName(exObj) ?? "???"), exFlags, TryGetExceptionMessage(exObj), TryGetThread(e2.CorThread), TryGetModule(e2.CorFrame, e2.CorThread), GetMessageFlags());
                e.AddPauseReason(DebuggerPauseReason.Other);
                break;

            case DebugCallbackKind.MDANotification:
                if (dbg.IsEvaluating)
                {
                    break;
                }
                var mdan = (MDANotificationDebugCallbackEventArgs)e;
                objectFactory.CreateException(new DbgExceptionId(PredefinedExceptionCategories.MDA, mdan.CorMDA?.Name ?? "???"), DbgExceptionEventFlags.FirstChance, mdan.CorMDA?.Description, TryGetThread(mdan.CorThread), TryGetModule(null, mdan.CorThread), GetMessageFlags());
                e.AddPauseReason(DebuggerPauseReason.Other);
                break;

            case DebugCallbackKind.LogMessage:
                if (dbg.IsEvaluating)
                {
                    break;
                }
                var lmsgArgs = (LogMessageDebugCallbackEventArgs)e;
                msg = lmsgArgs.Message;
                if (msg != null)
                {
                    e.AddPauseReason(DebuggerPauseReason.Other);
                    var thread = TryGetThread(lmsgArgs.CorThread);
                    SendMessage(new DbgMessageProgramMessage(msg, thread, GetMessageFlags()));
                }
                break;

            case DebugCallbackKind.LoadClass:
                var lcArgs = (LoadClassDebugCallbackEventArgs)e;
                var cls    = lcArgs.CorClass;
                Debug.Assert(cls != null);
                if (cls != null)
                {
                    var dnModule = dbg.TryGetModule(lcArgs.CorAppDomain, cls);
                    if (dnModule.IsDynamic)
                    {
                        UpdateDynamicModuleIds(dnModule);
                        var module = TryGetModule(dnModule.CorModule);
                        Debug.Assert(module != null);
                        if (module != null)
                        {
                            dbgModuleMemoryRefreshedNotifier.RaiseModulesRefreshed(new[] { module });
                        }
                        if (dnModule?.CorModuleDef != null && module != null)
                        {
                            if (TryGetModuleData(module, out var data))
                            {
                                data.OnLoadClass();
                            }
                            ClassLoaded?.Invoke(this, new ClassLoadedEventArgs(module, cls.Token));
                        }
                        GetDynamicModuleHelper(dnModule).RaiseTypeLoaded(new DmdTypeLoadedEventArgs((int)cls.Token));
                    }
                }
                break;

            case DebugCallbackKind.DebuggerError:
                var deArgs = (DebuggerErrorDebugCallbackEventArgs)e;
                if (deArgs.HError == CordbgErrors.CORDBG_E_UNCOMPATIBLE_PLATFORMS)
                {
                    msg = GetIncompatiblePlatformErrorMessage();
                }
                else
                {
                    msg = string.Format(dnSpy_Debugger_DotNet_CorDebug_Resources.Error_CLRDebuggerErrorOccurred, deArgs.HError, deArgs.ErrorCode);
                }
                SendMessage(new DbgMessageBreak(msg, GetMessageFlags(pause: true)));
                break;
            }
        }
コード例 #10
0
 public DebugEventBreakpointConditionContext(DnDebugger debugger, DnDebugEventBreakpoint bp, DebugCallbackEventArgs e)
     : base(debugger)
 {
     this.bp = bp;
     this.e  = e;
 }