private void SessionOnExceptionOccurred(object sender, DebuggeeExceptionEventArgs args) { _logger.WriteLine(LoggerMessageType.Error, "{0} exception occurred in thread {1} with error code {2:X}. {3}.", args.Exception.IsFirstChance ? "First chance" : "Last chance", args.Thread.Id, args.Exception.ErrorCode, args.Exception.Message, args.Exception.Continuable ? string.Empty : "Exception is fatal."); }
private static void DebugSessionOnExceptionOccurred(object?sender, DebuggeeExceptionEventArgs e) { Utils.WriteLog("[Debugger] EXCEPTION!", ConsoleColor.Red); Utils.WriteLog($"[Debugger] Error code: {e.Exception.ErrorCode}", ConsoleColor.Red); Utils.WriteLog($"[Debugger] Message: {e.Exception.Message}", ConsoleColor.Red); Utils.WriteLog($"[Debugger] Is continuable: {e.Exception.Continuable}", ConsoleColor.Red); Utils.WriteLog($"[Debugger] Is first chance: {e.Exception.IsFirstChance}", ConsoleColor.Red); if (e.Exception.Continuable) { e.Session.Continue(DebuggerAction.Continue); } }
private DebuggerAction HandleExceptionDebugEvent(DEBUG_EVENT debugEvent) { var info = debugEvent.InterpretDebugInfoAs <EXCEPTION_DEBUG_INFO>(); var process = GetProcessById((int)debugEvent.dwProcessId); var thread = process.GetThreadById((int)debugEvent.dwThreadId); var nextAction = DebuggerAction.Stop; bool handled = false; switch (info.ExceptionRecord.ExceptionCode) { case ExceptionCode.EXCEPTION_BREAKPOINT: { handled = _executionController.HandleBreakpointEvent(debugEvent, out nextAction); break; } case ExceptionCode.EXCEPTION_SINGLE_STEP: { handled = _executionController.HandleStepEvent(debugEvent, out nextAction); break; } case ExceptionCode.EXCEPTION_GUARD_PAGE: { handled = _executionController.HandlePageGuardViolationEvent(debugEvent, out nextAction); break; } } if (!handled) { // Forward exception to debugger. var eventArgs = new DebuggeeExceptionEventArgs(thread, new DebuggeeException((uint)info.ExceptionRecord.ExceptionCode, info.ExceptionRecord.ExceptionCode.ToString(), info.dwFirstChance == 1, info.ExceptionRecord.ExceptionFlags == 0)); OnExceptionOccurred(eventArgs); nextAction = eventArgs.NextAction; } return(nextAction); }
protected virtual void OnExceptionOccurred(DebuggeeExceptionEventArgs e) { ExceptionOccurred?.Invoke(this, e); }
protected virtual void OnExceptionOccurredEvent(DebuggeeExceptionEventArgs e) { if (ExceptionOccurred != null) ExceptionOccurred(this, e); }
internal void DispatchExceptionOccurredEvent(DebuggeeExceptionEventArgs e) { bool @break = false; switch (e.ExceptionType) { case CorDebugExceptionCallbackType.Unhandled: @break = true; break; case CorDebugExceptionCallbackType.FirstChance: case CorDebugExceptionCallbackType.UserFirstChance: @break = DebuggerBase.Instance.Settings.GetValue<bool>("Exceptions.BreakOnHandledException"); break; case CorDebugExceptionCallbackType.CatchHandlerFound: break; } if (!(e.Continue = !@break)) OnPaused(e); OnExceptionOccurredEvent(e); }
public void Exception(ICorDebugAppDomain pAppDomain, ICorDebugThread pThread, ICorDebugFrame pFrame, uint nOffset, CorDebugExceptionCallbackType dwEventType, uint dwFlags) { var domain = GetProcessWrapper(pAppDomain).GetAppDomain(pAppDomain); var thread = domain.GetThread(pThread); var frame = thread.CurrentFrame; string exceptionType = string.Empty; switch (dwEventType) { case CorDebugExceptionCallbackType.CatchHandlerFound: exceptionType = "Catch handler"; break; case CorDebugExceptionCallbackType.FirstChance: exceptionType = "First chance"; break; case CorDebugExceptionCallbackType.Unhandled: exceptionType = "Unhandled"; break; case CorDebugExceptionCallbackType.UserFirstChance: exceptionType = "User first chance"; break; } Log("{0} exception occured in {1}, thread {2}, at offset {3}", exceptionType, domain.Name, thread.Id, nOffset); var eventArgs = new DebuggeeExceptionEventArgs(domain, thread, nOffset, dwEventType); domain.DispatchExceptionOccurredEvent(eventArgs); FinalizeEvent(eventArgs); }