Example #1
0
        void OnException(Exception2DebugCallbackEventArgs e)
        {
            if (e.EventType != CorDebugExceptionCallbackType.DEBUG_EXCEPTION_FIRST_CHANCE)
                return;
            var thread = e.CorThread;
            if (thread == null)
                return;
            var exValue = thread.CurrentException;
            if (exValue == null)
                return;
            var exType = exValue.ExactType;
            if (exType == null)
                return;
            var exTypeName = exType.ToString(TypePrinterFlags.ShowNamespaces);
            var key = new ExceptionInfoKey(ExceptionType.DotNet, exTypeName);
            ExceptionInfo info;
            if (!exceptions.TryGetValue(key, out info))
                info = otherExceptions[(int)ExceptionType.DotNet];
            if (!info.BreakOnFirstChance)
                return;

            e.AddStopReason(DebuggerStopReason.Exception);
        }
Example #2
0
        void UnhandledException(Exception2DebugCallbackEventArgs e)
        {
            if (UnhandledException_counter != 0)
                return;
            try {
                UnhandledException_counter++;

                Debug.Assert(e.EventType == CorDebugExceptionCallbackType.DEBUG_EXCEPTION_UNHANDLED);
                var thread = e.CorThread;
                var exValue = thread == null ? null : thread.CurrentException;

                var sb = new StringBuilder();
                AddExceptionInfo(sb, exValue, "Exception");
                var innerExValue = EvalUtils.ReflectionReadExceptionInnerException(exValue);
                if (innerExValue != null && innerExValue.IsReference && !innerExValue.IsNull)
                    AddExceptionInfo(sb, innerExValue, "\n\nInner Exception");

                var process = DebugManager.Instance.Debugger.Processes.FirstOrDefault(p => p.Threads.Any(t => t.CorThread == thread));
                CorProcess cp;
                var processName = process != null ? Path.GetFileName(process.Filename) : string.Format("pid {0}", (cp = thread.Process) == null ? 0 : cp.ProcessId);
                BringMainWindowToFrontAndActivate();
                var res = MainWindow.Instance.ShowMessageBox(string.Format("An unhandled exception occurred in {0}\n\n{1}\n\nPress OK to stop, and Cancel to let the program run.", processName, sb), MessageBoxButton.OKCancel);
                if (res != MsgBoxButton.Cancel)
                    e.AddStopReason(DebuggerStopReason.UnhandledException);
            }
            finally {
                UnhandledException_counter--;
            }
        }
Example #3
0
		void UnhandledException(Exception2DebugCallbackEventArgs e) {
			if (UnhandledException_counter != 0)
				return;
			try {
				UnhandledException_counter++;
				theDebugger.SetUnhandledException(UnhandledException_counter != 0);

				Debug.Assert(e.EventType == CorDebugExceptionCallbackType.DEBUG_EXCEPTION_UNHANDLED);
				var thread = e.CorThread;
				var exValue = thread?.CurrentException;

				var sb = new StringBuilder();
				AddExceptionInfo(sb, exValue, dnSpy_Debugger_Resources.ExceptionInfo_Exception);
				var innerExValue = EvalUtils.ReflectionReadExceptionInnerException(exValue);
				if (innerExValue != null && innerExValue.IsReference && !innerExValue.IsNull)
					AddExceptionInfo(sb, innerExValue, "\n\n" + dnSpy_Debugger_Resources.ExceptionInfo_InnerException);

				var process = TheDebugger.Debugger.Processes.FirstOrDefault(p => p.Threads.Any(t => t.CorThread == thread));
				CorProcess cp;
				var processName = process != null ? Path.GetFileName(process.Filename) : string.Format("pid {0}", (cp = thread.Process) == null ? 0 : cp.ProcessId);
				BringMainWindowToFrontAndActivate();
				var res = messageBoxService.Show(string.Format(dnSpy_Debugger_Resources.Error_UnhandledExceptionOccurred, processName, sb), MsgBoxButton.OK | MsgBoxButton.Cancel);
				if (res != MsgBoxButton.Cancel)
					e.AddPauseReason(DebuggerPauseReason.UnhandledException);
			}
			finally {
				UnhandledException_counter--;
				theDebugger.SetUnhandledException(UnhandledException_counter != 0);
			}
		}