예제 #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.AddPauseReason(DebuggerPauseReason.Exception);
		}
예제 #2
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);
			}
		}