Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[tests] enable SubscribeToAppDomainUnhandledException in .NET 6 (#6119)
Context: c1a2ee7 Context: dotnet/runtime#44526 Context: dotnet/runtime#44526 (comment) Context: dotnet/runtime#44526 (comment) Context: start: https://discord.com/channels/732297728826277939/732297837953679412/869330822262587392 Context: end? https://discord.com/channels/732297728826277939/732297837953679412/869343082552893440 Context: dotnet/runtime#57304 Now that we are calling `mono_unhandled_exception()` when an unhandled exception is reported (c1a2ee7), we should be able re-enable the `InstallAndRunTests.SubscribeToAppDomainUnhandledException()` unit test on .NET 6, which was disabled in 6e3e383. What seemed like it should have been a 1-line removal ballooned a bit due to a confluence of factors: 1. Debugger component stubs, and 2. .NET 6 `Console.WriteLine()` behavior. On .NET 6, `JNIEnv.mono_unhandled_exception()` is `monodroid_debugger_unhandled_exception()`, which calls `mono_debugger_agent_unhandled_exception()`; see also e4debf7. The problem is that in our current world order of "Mono components" (0f7a0cd), if the debugger isn't used, then we get "debugger stubs" for the mono debugger agent, which turns `mono_debugger_agent_unhandled_exception()` into an [*assertion*][0]: static void stub_debugger_unhandled_exception (MonoException *exc) { g_assert_not_reached (); } The result is that when an exception is thrown, *before* the `AppDomain.UnhandledException` event can be raised, the runtime dies in a horrible flaming assertion death: E andledexceptio: * Assertion: should not be reached at /__w/1/s/src/mono/mono/component/debugger-stub.c:175 Avoid this issue by checking `Debugger.IsAttached` *before* calling `monodroid_debugger_unhandled_exception()`. Additionally, remove some obsolete comments: .NET 6 couldn't resolve `Debugger.Mono_UnhandledException()` because .NET 6 never had it, so the linker was right to warn about its absence. The problem with .NET 6 & `Console.WriteLine()` is that when format strings are used, the output may be line-wrapped in unexpected ways; see also dotnet/runtime@#57304. Additionally, the `sender` parameter value differs under .NET 6. These two issues broke our unit test; we *expected* `adb logcat` to contain: # Unhandled Exception: sender=RootDomain; e.IsTerminating=True; e.ExceptionObject=System.Exception: CRASH Under .NET 6, `adb logcat` *instead* contained: # Unhandled Exception: sender=System.Object; e.IsTerminating=True; e.ExceptionObject=System.Exception : CRASH Yes, `: CRASH` was on a separate `adb logcat` line. Fix the `SubscribeToAppDomainUnhandledException()` unit test so that `adb logcat` messages can now span multiple lines (which is sure to cause all sorts of GC garbage!), and update the expected message so that we look for the right message under legacy & .NET 6. Co-authored-by: Jonathan Pryor <jonpryor@vt.edu> [0]: https://github.com/dotnet/runtime/blob/16b456426dfb5212a24bfb78bfd5d9adfcc95185/src/mono/mono/component/debugger-stub.c#L172-L176
- Loading branch information