Exemple #1
0
 void DbgEngineImpl_ClassLoaded(object?sender, ClassLoadedEventArgs e) => ClassLoaded?.Invoke(this, e);
Exemple #2
0
        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;
            }
        }