public DebuggerState(DebugCallbackEventArgs e, DnProcess process, DnAppDomain appDomain, DnThread thread) { this.EventArgs = e; this.PauseStates = null; this.Process = process; this.AppDomain = appDomain; this.Thread = thread; }
public DebuggerState(DebugCallbackEventArgs e, DnProcess process, DnAppDomain appDomain, DnThread thread) { this.EventArgs = e; this.StopStates = null; this.Process = process; this.AppDomain = appDomain; this.Thread = thread; }
public DebuggerState(DebugCallbackEventArgs e, DnProcess process, DnAppDomain appDomain, DnThread thread) { EventArgs = e; PauseStates = null; Process = process; AppDomain = appDomain; Thread = thread; }
void DnDebugger_DebugCallbackEvent(DnDebugger dbg, DebugCallbackEventArgs e) { if (e.Type == DebugCallbackType.CreateProcess) { dbg.DebugCallbackEvent -= DnDebugger_DebugCallbackEvent; var cpArgs = (CreateProcessDebugCallbackEventArgs)e; bool b = Initialize(cpArgs.CorProcess, dbg.DebuggeeVersion); Debug.Assert(b); } }
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); } }
void DnDebugger_DebugCallbackEvent(DnDebugger dbg, DebugCallbackEventArgs e) { if (e.Kind == DebugCallbackKind.CreateProcess) { dbg.DebugCallbackEvent -= DnDebugger_DebugCallbackEvent; var cpArgs = (CreateProcessDebugCallbackEventArgs)e; bool b = Initialize(cpArgs.CorProcess, dbg.DebuggeeVersion, dbg.CLRPath); Debug.Assert(b); } }
public static DebugEventContext TryCreateDebugEventContext(this DBG.DebugCallbackEventArgs e, Debugger debugger) { Debug.Assert(debugger.Dispatcher.CheckAccess()); switch (e.Kind) { case DBG.DebugCallbackKind.CreateProcess: case DBG.DebugCallbackKind.ExitProcess: return(new ProcessEventContext(debugger, (DBG.ProcessDebugCallbackEventArgs)e)); case DBG.DebugCallbackKind.CreateThread: case DBG.DebugCallbackKind.ExitThread: return(new ThreadEventContext(debugger, (DBG.ThreadDebugCallbackEventArgs)e)); case DBG.DebugCallbackKind.LoadModule: case DBG.DebugCallbackKind.UnloadModule: return(new ModuleEventContext(debugger, (DBG.ModuleDebugCallbackEventArgs)e)); case DBG.DebugCallbackKind.LoadClass: case DBG.DebugCallbackKind.UnloadClass: return(new ClassEventContext(debugger, (DBG.ClassDebugCallbackEventArgs)e)); case DBG.DebugCallbackKind.LogMessage: return(new LogMessageEventContext(debugger, (DBG.LogMessageDebugCallbackEventArgs)e)); case DBG.DebugCallbackKind.LogSwitch: return(new LogSwitchEventContext(debugger, (DBG.LogSwitchDebugCallbackEventArgs)e)); case DBG.DebugCallbackKind.CreateAppDomain: case DBG.DebugCallbackKind.ExitAppDomain: return(new AppDomainEventContext(debugger, (DBG.AppDomainDebugCallbackEventArgs)e)); case DBG.DebugCallbackKind.LoadAssembly: case DBG.DebugCallbackKind.UnloadAssembly: return(new AssemblyEventContext(debugger, (DBG.AssemblyDebugCallbackEventArgs)e)); case DBG.DebugCallbackKind.ControlCTrap: return(new ControlCTrapEventContext(debugger, (DBG.ControlCTrapDebugCallbackEventArgs)e)); case DBG.DebugCallbackKind.NameChange: return(new NameChangeEventContext(debugger, (DBG.NameChangeDebugCallbackEventArgs)e)); case DBG.DebugCallbackKind.UpdateModuleSymbols: return(new UpdateModuleSymbolsEventContext(debugger, (DBG.UpdateModuleSymbolsDebugCallbackEventArgs)e)); case DBG.DebugCallbackKind.MDANotification: return(new MDANotificationEventContext(debugger, (DBG.MDANotificationDebugCallbackEventArgs)e)); case DBG.DebugCallbackKind.CustomNotification: return(new CustomNotificationEventContext(debugger, (DBG.CustomNotificationDebugCallbackEventArgs)e)); default: Debug.Fail("Invalid event kind: " + e.Kind); return(null); } }
void Debugger_DebugCallbackEvent(DnDebugger dbg, DebugCallbackEventArgs e) { var ee = e as EvalDebugCallbackEventArgs; if (ee == null) { return; } if (ee.Eval == eval.RawObject) { debugger.DebugCallbackEvent -= Debugger_DebugCallbackEvent; e.AddStopReason(DebuggerStopReason.Eval); debugMessageDispatcher.CancelDispatchQueue(ee.WasException); return; } }
public static DebugEventBreakpointKind?GetDebugEventBreakpointKind(DebugCallbackEventArgs e) { switch (e.Kind) { case DebugCallbackKind.CreateProcess: return(DebugEventBreakpointKind.CreateProcess); case DebugCallbackKind.ExitProcess: return(DebugEventBreakpointKind.ExitProcess); case DebugCallbackKind.CreateThread: return(DebugEventBreakpointKind.CreateThread); case DebugCallbackKind.ExitThread: return(DebugEventBreakpointKind.ExitThread); case DebugCallbackKind.LoadModule: return(DebugEventBreakpointKind.LoadModule); case DebugCallbackKind.UnloadModule: return(DebugEventBreakpointKind.UnloadModule); case DebugCallbackKind.LoadClass: return(DebugEventBreakpointKind.LoadClass); case DebugCallbackKind.UnloadClass: return(DebugEventBreakpointKind.UnloadClass); case DebugCallbackKind.LogMessage: return(DebugEventBreakpointKind.LogMessage); case DebugCallbackKind.LogSwitch: return(DebugEventBreakpointKind.LogSwitch); case DebugCallbackKind.CreateAppDomain: return(DebugEventBreakpointKind.CreateAppDomain); case DebugCallbackKind.ExitAppDomain: return(DebugEventBreakpointKind.ExitAppDomain); case DebugCallbackKind.LoadAssembly: return(DebugEventBreakpointKind.LoadAssembly); case DebugCallbackKind.UnloadAssembly: return(DebugEventBreakpointKind.UnloadAssembly); case DebugCallbackKind.ControlCTrap: return(DebugEventBreakpointKind.ControlCTrap); case DebugCallbackKind.NameChange: return(DebugEventBreakpointKind.NameChange); case DebugCallbackKind.UpdateModuleSymbols: return(DebugEventBreakpointKind.UpdateModuleSymbols); case DebugCallbackKind.MDANotification: return(DebugEventBreakpointKind.MDANotification); case DebugCallbackKind.CustomNotification: return(DebugEventBreakpointKind.CustomNotification); default: return(null); } }
public static DebugEventBreakpointKind? GetDebugEventBreakpointKind(DebugCallbackEventArgs e) { switch (e.Kind) { case DebugCallbackKind.CreateProcess: return DebugEventBreakpointKind.CreateProcess; case DebugCallbackKind.ExitProcess: return DebugEventBreakpointKind.ExitProcess; case DebugCallbackKind.CreateThread: return DebugEventBreakpointKind.CreateThread; case DebugCallbackKind.ExitThread: return DebugEventBreakpointKind.ExitThread; case DebugCallbackKind.LoadModule: return DebugEventBreakpointKind.LoadModule; case DebugCallbackKind.UnloadModule: return DebugEventBreakpointKind.UnloadModule; case DebugCallbackKind.LoadClass: return DebugEventBreakpointKind.LoadClass; case DebugCallbackKind.UnloadClass: return DebugEventBreakpointKind.UnloadClass; case DebugCallbackKind.LogMessage: return DebugEventBreakpointKind.LogMessage; case DebugCallbackKind.LogSwitch: return DebugEventBreakpointKind.LogSwitch; case DebugCallbackKind.CreateAppDomain: return DebugEventBreakpointKind.CreateAppDomain; case DebugCallbackKind.ExitAppDomain: return DebugEventBreakpointKind.ExitAppDomain; case DebugCallbackKind.LoadAssembly: return DebugEventBreakpointKind.LoadAssembly; case DebugCallbackKind.UnloadAssembly: return DebugEventBreakpointKind.UnloadAssembly; case DebugCallbackKind.ControlCTrap: return DebugEventBreakpointKind.ControlCTrap; case DebugCallbackKind.NameChange: return DebugEventBreakpointKind.NameChange; case DebugCallbackKind.UpdateModuleSymbols: return DebugEventBreakpointKind.UpdateModuleSymbols; case DebugCallbackKind.MDANotification: return DebugEventBreakpointKind.MDANotification; case DebugCallbackKind.CustomNotification: return DebugEventBreakpointKind.CustomNotification; default: return null; } }
public AnyDebugEventBreakpointConditionContext(DnDebugger debugger, DnAnyDebugEventBreakpoint bp, DebugCallbackEventArgs e) : base(debugger) { AnyDebugEventBreakpoint = bp; EventArgs = e; }
void ContinueAndDecrementCounter(DebugCallbackEventArgs e) { if (e.Type != DebugCallbackType.ExitProcess) { if (Continue(e.CorDebugController)) managedCallbackCounter--; } else managedCallbackCounter--; }
void Debugger_DebugCallbackEvent(DnDebugger dbg, DebugCallbackEventArgs e) { var ee = e as EvalDebugCallbackEventArgs; if (ee == null) return; if (ee.Eval == eval.RawObject) { debugger.DebugCallbackEvent -= Debugger_DebugCallbackEvent; e.AddStopReason(DebuggerStopReason.Eval); debugMessageDispatcher.CancelDispatchQueue(ee.WasException); return; } }
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; } }
void SetDefaultCurrentProcess(DebugCallbackEventArgs e) { var ps = Processes; AddDebuggerState(new DebuggerState(e, ps.Length == 0 ? null : ps[0], null, null)); }
// Called in our dndbg thread void OnManagedCallbackInDebuggerThread(DebugCallbackEventArgs e) { DebugVerifyThread(); if (hasTerminated) return; managedCallbackCounter++; try { HandleManagedCallback(e); CheckBreakpoints(e); if (DebugCallbackEvent != null) DebugCallbackEvent(this, e); } catch (Exception ex) { Debug.WriteLine(string.Format("dndbg: EX:\n\n{0}", ex)); ResetDebuggerStates(); throw; } Current.StopStates = e.StopStates; if (HasQueuedCallbacks(e)) ContinueAndDecrementCounter(e); else if (ShouldStopQueued()) CallOnProcessStateChanged(); else { ResetDebuggerStates(); ContinueAndDecrementCounter(e); } }
// This method must be called just before returning to the caller. No fields can be accessed // and no methods can be called because the CLR debugger could call us before this method // returns. void ContinueAndDecrementCounter(DebugCallbackEventArgs e) { if (e.Type != DebugCallbackType.ExitProcess) Continue(e.CorDebugController, false); // Also decrements managedCallbackCounter else managedCallbackCounter--; }
string GetEventDescription(DebugCallbackEventArgs e) { CorModule mod; switch (e.Kind) { case DebugCallbackKind.Exception: var ex1Args = (ExceptionDebugCallbackEventArgs)e; return ex1Args.Unhandled ? dnSpy_Debugger_Resources.Debug_EventDescription_UnhandledException : dnSpy_Debugger_Resources.Debug_EventDescription_Exception; case DebugCallbackKind.CreateProcess: var cpArgs = (CreateProcessDebugCallbackEventArgs)e; var p = cpArgs.CorProcess; if (p == null) break; return string.Format(dnSpy_Debugger_Resources.Debug_EventDescription_CreateProcess, p.ProcessId, p.CLRVersion); case DebugCallbackKind.CreateThread: var ctArgs = (CreateThreadDebugCallbackEventArgs)e; var t = ctArgs.CorThread; if (t == null) break; return string.Format(dnSpy_Debugger_Resources.Debug_EventDescription_CreateThread, t.ThreadId, t.VolatileThreadId); case DebugCallbackKind.LoadModule: var lmArgs = (LoadModuleDebugCallbackEventArgs)e; mod = lmArgs.CorModule; if (mod == null) break; if (mod.IsDynamic || mod.IsInMemory) return string.Format(dnSpy_Debugger_Resources.Debug_EventDescription_LoadModule1, mod.IsDynamic ? 1 : 0, mod.IsInMemory ? 1 : 0, mod.Address, mod.Size, mod.Name); return string.Format(dnSpy_Debugger_Resources.Debug_EventDescription_LoadModule2, mod.Address, mod.Size, mod.Name); case DebugCallbackKind.LoadClass: var lcArgs = (LoadClassDebugCallbackEventArgs)e; var cls = lcArgs.CorClass; mod = cls?.Module; if (mod == null) break; return string.Format(dnSpy_Debugger_Resources.Debug_EventDescription_LoadClass, cls.Token, FilterLongName(cls.ToString()), mod.Name); case DebugCallbackKind.DebuggerError: var deArgs = (DebuggerErrorDebugCallbackEventArgs)e; return string.Format(dnSpy_Debugger_Resources.Debug_EventDescription_DebuggerError, deArgs.HError, deArgs.ErrorCode); case DebugCallbackKind.CreateAppDomain: var cadArgs = (CreateAppDomainDebugCallbackEventArgs)e; var ad = cadArgs.CorAppDomain; if (ad == null) break; return string.Format(dnSpy_Debugger_Resources.Debug_EventDescription_CreateAppDomain, ad.Id, ad.Name); case DebugCallbackKind.LoadAssembly: var laArgs = (LoadAssemblyDebugCallbackEventArgs)e; var asm = laArgs.CorAssembly; if (asm == null) break; return string.Format(dnSpy_Debugger_Resources.Debug_EventDescription_LoadAssembly, asm.Name); case DebugCallbackKind.ControlCTrap: return dnSpy_Debugger_Resources.Debug_EventDescription_ControlCPressed; case DebugCallbackKind.BreakpointSetError: var bpseArgs = (BreakpointSetErrorDebugCallbackEventArgs)e; return string.Format(dnSpy_Debugger_Resources.Debug_EventDescription_BreakpointSetError, bpseArgs.Error); case DebugCallbackKind.Exception2: var ex2Args = (Exception2DebugCallbackEventArgs)e; var sb = new StringBuilder(); sb.Append(string.Format(dnSpy_Debugger_Resources.Debug_EventDescription_Exception2 + " ", ex2Args.Offset)); switch (ex2Args.EventType) { case CorDebugExceptionCallbackType.DEBUG_EXCEPTION_FIRST_CHANCE: sb.Append(dnSpy_Debugger_Resources.Debug_EventDescription_Exception2_FirstChance); break; case CorDebugExceptionCallbackType.DEBUG_EXCEPTION_USER_FIRST_CHANCE: sb.Append(dnSpy_Debugger_Resources.Debug_EventDescription_Exception2_UserFirstChance); break; case CorDebugExceptionCallbackType.DEBUG_EXCEPTION_CATCH_HANDLER_FOUND: sb.Append(dnSpy_Debugger_Resources.Debug_EventDescription_Exception2_CatchHandlerFound); break; case CorDebugExceptionCallbackType.DEBUG_EXCEPTION_UNHANDLED: sb.Append(dnSpy_Debugger_Resources.Debug_EventDescription_Exception2_Unhandled); break; default: sb.Append(dnSpy_Debugger_Resources.Debug_EventDescription_Exception2_Unknown); break; } return sb.ToString(); case DebugCallbackKind.MDANotification: var mdan = (MDANotificationDebugCallbackEventArgs)e; var mda = mdan.CorMDA; if (mda == null) return dnSpy_Debugger_Resources.Debug_EventDescription_MDA_Notification; return string.Format(dnSpy_Debugger_Resources.Debug_EventDescription_MDA_Notification2, mda.OSThreadId, mda.Name, mda.Description); } return e.Kind.ToString(); }
string GetEventDescription(DebugCallbackEventArgs e) { CorModule mod; switch (e.Type) { case DebugCallbackType.Exception: var ex1Args = (ExceptionDebugCallbackEventArgs)e; return ex1Args.Unhandled ? "Unhandled Exception" : "Exception"; case DebugCallbackType.CreateProcess: var cpArgs = (CreateProcessDebugCallbackEventArgs)e; var p = cpArgs.CorProcess; if (p == null) break; return string.Format("CreateProcess PID={0} CLR v{1}", p.ProcessId, p.CLRVersion); case DebugCallbackType.CreateThread: var ctArgs = (CreateThreadDebugCallbackEventArgs)e; var t = ctArgs.CorThread; if (t == null) break; return string.Format("CreateThread TID={0} VTID={1}", t.ThreadId, t.VolatileThreadId); case DebugCallbackType.LoadModule: var lmArgs = (LoadModuleDebugCallbackEventArgs)e; mod = lmArgs.CorModule; if (mod == null) break; if (mod.IsDynamic || mod.IsInMemory) return string.Format("LoadModule DYN={0} MEM={1} {2:X8} {3:X8} {4}", mod.IsDynamic ? 1 : 0, mod.IsInMemory ? 1 : 0, mod.Address, mod.Size, mod.Name); return string.Format("LoadModule A={0:X8} S={1:X8} {2}", mod.Address, mod.Size, mod.Name); case DebugCallbackType.LoadClass: var lcArgs = (LoadClassDebugCallbackEventArgs)e; var cls = lcArgs.CorClass; mod = cls == null ? null : cls.Module; if (mod == null) break; return string.Format("LoadClass 0x{0:X8} {1} {2}", cls.Token, FilterLongName(cls.ToString()), mod.Name); case DebugCallbackType.DebuggerError: var deArgs = (DebuggerErrorDebugCallbackEventArgs)e; return string.Format("DebuggerError hr=0x{0:X8} error=0x{1:X8}", deArgs.HError, deArgs.ErrorCode); case DebugCallbackType.CreateAppDomain: var cadArgs = (CreateAppDomainDebugCallbackEventArgs)e; var ad = cadArgs.CorAppDomain; if (ad == null) break; return string.Format("CreateAppDomain {0} {1}", ad.Id, ad.Name); case DebugCallbackType.LoadAssembly: var laArgs = (LoadAssemblyDebugCallbackEventArgs)e; var asm = laArgs.CorAssembly; if (asm == null) break; return string.Format("LoadAssembly {0}", asm.Name); case DebugCallbackType.ControlCTrap: return "Ctrl+C"; case DebugCallbackType.BreakpointSetError: var bpseArgs = (BreakpointSetErrorDebugCallbackEventArgs)e; return string.Format("BreakpointSetError error=0x{0:X8}", bpseArgs.Error); case DebugCallbackType.Exception2: var ex2Args = (Exception2DebugCallbackEventArgs)e; var sb = new StringBuilder(); sb.Append(string.Format("Exception Offset={0:X4} ", ex2Args.Offset)); switch (ex2Args.EventType) { case CorDebugExceptionCallbackType.DEBUG_EXCEPTION_FIRST_CHANCE: sb.Append("FirstChance"); break; case CorDebugExceptionCallbackType.DEBUG_EXCEPTION_USER_FIRST_CHANCE: sb.Append("UserFirstChance"); break; case CorDebugExceptionCallbackType.DEBUG_EXCEPTION_CATCH_HANDLER_FOUND: sb.Append("CatchHandlerFound"); break; case CorDebugExceptionCallbackType.DEBUG_EXCEPTION_UNHANDLED: sb.Append("Unhandled"); break; default: sb.Append("Unknown"); break; } return sb.ToString(); case DebugCallbackType.MDANotification: var mdan = (MDANotificationDebugCallbackEventArgs)e; var mda = mdan.CorMDA; if (mda == null) return "MDA Notification"; return string.Format("MDA Notification: TID={0} {1} {2}", mda.OSThreadId, mda.Name, mda.Description); } return e.Type.ToString(); }
public DebugEventBreakpointConditionContext(DnDebugger debugger, DnDebugEventBreakpoint bp, DebugCallbackEventArgs e) : base(debugger) { this.bp = bp; this.e = e; }
public DebuggerState(DebugCallbackEventArgs e) : this(e, null, null, null) { }
void DnDebugger_DebugCallbackEvent(DnDebugger dbg, DebugCallbackEventArgs e) { try { DebugCallbackEvent_counter++; if (DebugCallbackEvent_counter > 1) return; if (e.Type == DebugCallbackType.Exception2) { var ee = (Exception2DebugCallbackEventArgs)e; if (ee.EventType == CorDebugExceptionCallbackType.DEBUG_EXCEPTION_UNHANDLED) UnhandledException(ee); } else if (e.Type == DebugCallbackType.DebuggerError) OnDebuggerError((DebuggerErrorDebugCallbackEventArgs)e); } finally { DebugCallbackEvent_counter--; } }
bool HasQueuedCallbacks(DebugCallbackEventArgs e) { var thread = Current.Thread; if (thread == null) return false; int qcbs; int hr = e.CorDebugController.HasQueuedCallbacks(thread.CorThread.RawObject, out qcbs); return hr >= 0 && qcbs != 0; }
void InitializeCurrentDebuggerState(DebugCallbackEventArgs e, DnProcess process) { if (process == null) { SetDefaultCurrentProcess(e); return; } AddDebuggerState(new DebuggerState(e, process, null, null)); }
void HandleManagedCallback(DebugCallbackEventArgs e) { bool b; DnProcess process; DnAppDomain appDomain; DnAssembly assembly; CorClass cls; switch (e.Type) { case DebugCallbackType.Breakpoint: var bpArgs = (BreakpointDebugCallbackEventArgs)e; InitializeCurrentDebuggerState(e, null, bpArgs.AppDomain, bpArgs.Thread); break; case DebugCallbackType.StepComplete: var scArgs = (StepCompleteDebugCallbackEventArgs)e; InitializeCurrentDebuggerState(e, null, scArgs.AppDomain, scArgs.Thread); StepInfo stepInfo; bool calledStepInfoOnCompleted = false; var stepperKey = scArgs.CorStepper; if (stepperKey != null && stepInfos.TryGetValue(stepperKey, out stepInfo)) { stepInfos.Remove(stepperKey); if (stepInfo.OnCompleted != null) { calledStepInfoOnCompleted = true; stepInfo.OnCompleted(this, scArgs); } } // Don't stop on step/breakpoints when we're evaluating if (!calledStepInfoOnCompleted && !IsEvaluating) scArgs.AddStopState(new StepStopState(scArgs.Reason)); break; case DebugCallbackType.Break: var bArgs = (BreakDebugCallbackEventArgs)e; InitializeCurrentDebuggerState(e, null, bArgs.AppDomain, bArgs.Thread); break; case DebugCallbackType.Exception: var ex1Args = (ExceptionDebugCallbackEventArgs)e; InitializeCurrentDebuggerState(e, null, ex1Args.AppDomain, ex1Args.Thread); break; case DebugCallbackType.EvalComplete: var ecArgs = (EvalCompleteDebugCallbackEventArgs)e; InitializeCurrentDebuggerState(e, null, ecArgs.AppDomain, ecArgs.Thread); break; case DebugCallbackType.EvalException: var eeArgs = (EvalExceptionDebugCallbackEventArgs)e; InitializeCurrentDebuggerState(e, null, eeArgs.AppDomain, eeArgs.Thread); break; case DebugCallbackType.CreateProcess: var cpArgs = (CreateProcessDebugCallbackEventArgs)e; hasReceivedCreateProcessEvent = true; process = TryAdd(cpArgs.Process); if (process != null) { process.CorProcess.EnableLogMessages(debugOptions.LogMessages); process.CorProcess.DesiredNGENCompilerFlags = debugOptions.JITCompilerFlags; process.CorProcess.SetWriteableMetadataUpdateMode(WriteableMetadataUpdateMode.AlwaysShowUpdates); process.CorProcess.EnableExceptionCallbacksOutsideOfMyCode(debugOptions.ExceptionCallbacksOutsideOfMyCode); process.CorProcess.EnableNGENPolicy(debugOptions.NGENPolicy); } InitializeCurrentDebuggerState(e, process); break; case DebugCallbackType.ExitProcess: var epArgs = (ExitProcessDebugCallbackEventArgs)e; process = processes.TryGet(epArgs.Process); InitializeCurrentDebuggerState(e, process); if (process != null) process.SetHasExited(); processes.Remove(epArgs.Process); OnProcessTerminated(process); if (processes.Count == 0) ProcessesTerminated(); break; case DebugCallbackType.CreateThread: var ctArgs = (CreateThreadDebugCallbackEventArgs)e; process = TryGetValidProcess(ctArgs.Thread); if (process != null) { process.TryAdd(ctArgs.Thread); //TODO: ICorDebugThread::SetDebugState } InitializeCurrentDebuggerState(e, null, ctArgs.AppDomain, ctArgs.Thread); break; case DebugCallbackType.ExitThread: var etArgs = (ExitThreadDebugCallbackEventArgs)e; InitializeCurrentDebuggerState(e, null, etArgs.AppDomain, etArgs.Thread); process = TryGetValidProcess(etArgs.Thread); if (process != null) process.ThreadExited(etArgs.Thread); break; case DebugCallbackType.LoadModule: var lmArgs = (LoadModuleDebugCallbackEventArgs)e; InitializeCurrentDebuggerState(e, null, lmArgs.AppDomain, null); assembly = TryGetValidAssembly(lmArgs.AppDomain, lmArgs.Module); if (assembly != null) { var module = assembly.TryAdd(lmArgs.Module); module.CorModule.EnableJITDebugging(debugOptions.ModuleTrackJITInfo, debugOptions.ModuleAllowJitOptimizations); module.CorModule.EnableClassLoadCallbacks(debugOptions.ModuleClassLoadCallbacks); module.CorModule.JITCompilerFlags = debugOptions.JITCompilerFlags; module.CorModule.SetJMCStatus(true); module.InitializeCachedValues(); AddBreakpoints(module); CallOnModuleAdded(module, true); } break; case DebugCallbackType.UnloadModule: var umArgs = (UnloadModuleDebugCallbackEventArgs)e; InitializeCurrentDebuggerState(e, null, umArgs.AppDomain, null); assembly = TryGetValidAssembly(umArgs.AppDomain, umArgs.Module); if (assembly != null) { var module = assembly.TryGetModule(umArgs.Module); OnModuleUnloaded(module); } break; case DebugCallbackType.LoadClass: var lcArgs = (LoadClassDebugCallbackEventArgs)e; InitializeCurrentDebuggerState(e, null, lcArgs.AppDomain, null); cls = lcArgs.CorClass; if (cls != null) { var module = TryGetModule(lcArgs.CorAppDomain, cls); if (module != null) { if (module.CorModuleDef != null) module.CorModuleDef.LoadClass(cls.Token); foreach (var bp in ilCodeBreakpointList.GetBreakpoints(module.SerializedDnModule)) bp.AddBreakpoint(module); } } break; case DebugCallbackType.UnloadClass: var ucArgs = (UnloadClassDebugCallbackEventArgs)e; InitializeCurrentDebuggerState(e, null, ucArgs.AppDomain, null); cls = ucArgs.CorClass; if (cls != null) { var module = TryGetModule(ucArgs.CorAppDomain, cls); if (module != null && module.CorModuleDef != null) module.CorModuleDef.UnloadClass(cls.Token); } break; case DebugCallbackType.DebuggerError: var deArgs = (DebuggerErrorDebugCallbackEventArgs)e; InitializeCurrentDebuggerState(e, deArgs.Process, null, null); break; case DebugCallbackType.LogMessage: var lmsgArgs = (LogMessageDebugCallbackEventArgs)e; InitializeCurrentDebuggerState(e, null, lmsgArgs.AppDomain, lmsgArgs.Thread); break; case DebugCallbackType.LogSwitch: var lsArgs = (LogSwitchDebugCallbackEventArgs)e; InitializeCurrentDebuggerState(e, null, lsArgs.AppDomain, lsArgs.Thread); break; case DebugCallbackType.CreateAppDomain: var cadArgs = (CreateAppDomainDebugCallbackEventArgs)e; process = TryGetValidProcess(cadArgs.Process); if (process != null && cadArgs.AppDomain != null) { b = cadArgs.AppDomain.Attach() >= 0; Debug.WriteLineIf(!b, string.Format("CreateAppDomain: could not attach to AppDomain: {0:X8}", cadArgs.AppDomain.GetHashCode())); if (b) process.TryAdd(cadArgs.AppDomain); } InitializeCurrentDebuggerState(e, cadArgs.Process, cadArgs.AppDomain, null); break; case DebugCallbackType.ExitAppDomain: var eadArgs = (ExitAppDomainDebugCallbackEventArgs)e; InitializeCurrentDebuggerState(e, eadArgs.Process, eadArgs.AppDomain, null); process = processes.TryGet(eadArgs.Process); if (process != null) { OnAppDomainUnloaded(process.TryGetAppDomain(eadArgs.AppDomain)); process.AppDomainExited(eadArgs.AppDomain); } break; case DebugCallbackType.LoadAssembly: var laArgs = (LoadAssemblyDebugCallbackEventArgs)e; InitializeCurrentDebuggerState(e, null, laArgs.AppDomain, null); appDomain = TryGetValidAppDomain(laArgs.AppDomain); if (appDomain != null) appDomain.TryAdd(laArgs.Assembly); break; case DebugCallbackType.UnloadAssembly: var uaArgs = (UnloadAssemblyDebugCallbackEventArgs)e; InitializeCurrentDebuggerState(e, null, uaArgs.AppDomain, null); appDomain = TryGetAppDomain(uaArgs.AppDomain); if (appDomain != null) { OnAssemblyUnloaded(appDomain.TryGetAssembly(uaArgs.Assembly)); appDomain.AssemblyUnloaded(uaArgs.Assembly); } break; case DebugCallbackType.ControlCTrap: var cctArgs = (ControlCTrapDebugCallbackEventArgs)e; InitializeCurrentDebuggerState(e, cctArgs.Process, null, null); break; case DebugCallbackType.NameChange: var ncArgs = (NameChangeDebugCallbackEventArgs)e; InitializeCurrentDebuggerState(e, null, ncArgs.AppDomain, ncArgs.Thread); appDomain = TryGetValidAppDomain(ncArgs.AppDomain); if (appDomain != null) appDomain.NameChanged(); var thread = TryGetValidThread(ncArgs.Thread); if (thread != null) thread.NameChanged(); CallOnNameChanged(appDomain, thread); break; case DebugCallbackType.UpdateModuleSymbols: var umsArgs = (UpdateModuleSymbolsDebugCallbackEventArgs)e; InitializeCurrentDebuggerState(e, null, umsArgs.AppDomain, null); break; case DebugCallbackType.EditAndContinueRemap: var encrArgs = (EditAndContinueRemapDebugCallbackEventArgs)e; InitializeCurrentDebuggerState(e, null, encrArgs.AppDomain, encrArgs.Thread); break; case DebugCallbackType.BreakpointSetError: var bpseArgs = (BreakpointSetErrorDebugCallbackEventArgs)e; InitializeCurrentDebuggerState(e, null, bpseArgs.AppDomain, bpseArgs.Thread); break; case DebugCallbackType.FunctionRemapOpportunity: var froArgs = (FunctionRemapOpportunityDebugCallbackEventArgs)e; InitializeCurrentDebuggerState(e, null, froArgs.AppDomain, froArgs.Thread); break; case DebugCallbackType.CreateConnection: var ccArgs = (CreateConnectionDebugCallbackEventArgs)e; InitializeCurrentDebuggerState(e, ccArgs.Process, null, null); break; case DebugCallbackType.ChangeConnection: var cc2Args = (ChangeConnectionDebugCallbackEventArgs)e; InitializeCurrentDebuggerState(e, cc2Args.Process, null, null); break; case DebugCallbackType.DestroyConnection: var dcArgs = (DestroyConnectionDebugCallbackEventArgs)e; InitializeCurrentDebuggerState(e, dcArgs.Process, null, null); break; case DebugCallbackType.Exception2: var ex2Args = (Exception2DebugCallbackEventArgs)e; InitializeCurrentDebuggerState(e, null, ex2Args.AppDomain, ex2Args.Thread); break; case DebugCallbackType.ExceptionUnwind: var euArgs = (ExceptionUnwindDebugCallbackEventArgs)e; InitializeCurrentDebuggerState(e, null, euArgs.AppDomain, euArgs.Thread); break; case DebugCallbackType.FunctionRemapComplete: var frcArgs = (FunctionRemapCompleteDebugCallbackEventArgs)e; InitializeCurrentDebuggerState(e, null, frcArgs.AppDomain, frcArgs.Thread); break; case DebugCallbackType.MDANotification: var mdanArgs = (MDANotificationDebugCallbackEventArgs)e; InitializeCurrentDebuggerState(e, mdanArgs.Controller as ICorDebugProcess, mdanArgs.Controller as ICorDebugAppDomain, mdanArgs.Thread); break; case DebugCallbackType.CustomNotification: var cnArgs = (CustomNotificationDebugCallbackEventArgs)e; InitializeCurrentDebuggerState(e, null, cnArgs.AppDomain, cnArgs.Thread); break; default: InitializeCurrentDebuggerState(e, null); Debug.Fail(string.Format("Unknown debug callback type: {0}", e.Type)); break; } }
void InitializeCurrentDebuggerState(DebugCallbackEventArgs e, ICorDebugProcess comProcess, ICorDebugAppDomain comAppDomain, ICorDebugThread comThread) { if (comThread != null) { if (comProcess == null) comThread.GetProcess(out comProcess); if (comAppDomain == null) comThread.GetAppDomain(out comAppDomain); } if (comAppDomain != null) { if (comProcess == null) comAppDomain.GetProcess(out comProcess); } var process = TryGetValidProcess(comProcess); DnAppDomain appDomain; DnThread thread; if (process != null) { appDomain = process.TryGetAppDomain(comAppDomain); thread = process.TryGetThread(comThread); } else { appDomain = null; thread = null; } if (thread == null && appDomain == null && process != null) appDomain = process.AppDomains.FirstOrDefault(); if (thread == null) { if (appDomain != null) thread = appDomain.Threads.FirstOrDefault(); else if (process != null) thread = process.Threads.FirstOrDefault(); } if (process == null) SetDefaultCurrentProcess(e); else AddDebuggerState(new DebuggerState(e, process, appDomain, thread)); }
void DnDebugger_DebugCallbackEvent(DnDebugger dbg, DebugCallbackEventArgs e) { if (e.Kind == DebugCallbackKind.Exception2) OnException((Exception2DebugCallbackEventArgs)e); }
// Called in our dndbg thread void OnManagedCallbackInDebuggerThread(DebugCallbackEventArgs e) { DebugVerifyThread(); if (hasTerminated) return; managedCallbackCounter++; if (disposeValues.Count != 0) { foreach (var value in disposeValues) value.DisposeHandle(); disposeValues.Clear(); } try { HandleManagedCallback(e); CheckBreakpoints(e); if (DebugCallbackEvent != null) DebugCallbackEvent(this, e); } catch (Exception ex) { Debug.WriteLine(string.Format("dndbg: EX:\n\n{0}", ex)); ResetDebuggerStates(); throw; } Current.StopStates = e.StopStates; if (HasQueuedCallbacks(e)) { ContinueAndDecrementCounter(e); // DON'T call anything, DON'T write any fields now, the CLR debugger could've already called us again when Continue() was called } else if (ShouldStopQueued()) CallOnProcessStateChanged(); else { ResetDebuggerStates(); ContinueAndDecrementCounter(e); // DON'T call anything, DON'T write any fields now, the CLR debugger could've already called us again when Continue() was called } }
void DnDebugger_DebugCallbackEvent(DnDebugger dbg, DebugCallbackEventArgs e) { if (e.Type == DebugCallbackType.Exception2) OnException((Exception2DebugCallbackEventArgs)e); }
void CheckBreakpoints(DebugCallbackEventArgs e) { // Never check breakpoints when we're evaluating if (IsEvaluating) return; var type = DnDebugEventBreakpoint.GetDebugEventBreakpointType(e); if (type != null) { foreach (var bp in DebugEventBreakpoints) { if (bp.IsEnabled && bp.EventType == type.Value && bp.Condition.Hit(new DebugEventBreakpointConditionContext(this, bp, e))) e.AddStopState(new DebugEventBreakpointStopState(bp)); } } foreach (var bp in AnyDebugEventBreakpoints) { if (bp.IsEnabled && bp.Condition.Hit(new AnyDebugEventBreakpointConditionContext(this, bp, e))) e.AddStopState(new AnyDebugEventBreakpointStopState(bp)); } if (e.Type == DebugCallbackType.Breakpoint) { var bpArgs = (BreakpointDebugCallbackEventArgs)e; //TODO: Use a dictionary instead of iterating over all breakpoints foreach (var bp in ilCodeBreakpointList.GetBreakpoints()) { if (!bp.IsBreakpoint(bpArgs.Breakpoint)) continue; if (bp.IsEnabled && bp.Condition.Hit(new ILCodeBreakpointConditionContext(this, bp))) e.AddStopState(new ILCodeBreakpointStopState(bp)); break; } } if (e.Type == DebugCallbackType.Break && !debugOptions.IgnoreBreakInstructions) e.AddStopReason(DebuggerStopReason.Break); //TODO: DebugCallbackType.BreakpointSetError }
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); } }