sentry-unity icon indicating copy to clipboard operation
sentry-unity copied to clipboard

Mono JIT Code missing from reports

Open DrummerB opened this issue 2 years ago • 3 comments

Environment

How do you use Sentry? sentry.io

Which version of the SDK? 0.20.1

How did you install the package? (Git-URL, Assetstore) UPM, git-url

Which version of Unity? 2021.3.3f1 LTS

Is this happening in Unity (editor) or on a player like Android, iOS, Windows? Windows Editor and Windows Player

Steps to Reproduce

  1. Enable native integration.
  2. Trigger a native crash.

Expected Result

  • The event that is reported to sentry.io contains the stacktrace with the same information that I usually get in the Player.log.
  • The Player.log contains the usual crash report and stacktrace at the end.

Actual Result

  • The reported event is missing the most relevant part of the stacktrace, which is the Mono JIT Code, which is usually logged in the Player.log file.
  • The Player.log is missing the stacktrace as well. This means that if Sentry is enabled with native integration, this information is lost completely.

Comments

It appears that the crash log is added to Player.log just before crashing by the Player itself, and not the UnityCrashHandler. How does the Player append this info and does Sentry not have access to the same info? It seems, that sentry somehow overrides the crash handling behavior built into the Player, since it blocks the stacktrace from being written to the log.

The only workaround I can think of currently is to disable the native integrations and manually parse any crash logs from previous runs.

Any logs or screenshots

In the Player.log, without Sentry, normally you would see something like below. Note the Mono part. It contains the most relevant and useful information from user code.

ERROR: SymGetSymFromAddr64, GetLastError: 'Attempt to access invalid address.' (Address: 00007FF845D77D9D) 0x00007FF845D77D9D (UnityPlayer) (function-name not available) ERROR: SymGetSymFromAddr64, GetLastError: 'Attempt to access invalid address.' (Address: 00007FF8458E3A84) 0x00007FF8458E3A84 (UnityPlayer) (function-name not available) 0x0000018C2E3E193A (Mono JIT Code) (wrapper managed-to-native) UnityEngine.ComputeBuffer:DestroyBuffer (UnityEngine.ComputeBuffer) 0x0000018C2E3E1813 (Mono JIT Code) UnityEngine.ComputeBuffer:Dispose (bool) 0x0000018C2E3E1783 (Mono JIT Code) UnityEngine.ComputeBuffer:Dispose () 0x0000018C2E46973B (Mono JIT Code) Redacted.Rendering.TransferFunction:Dispose (bool) 0x0000018C2E4696AA (Mono JIT Code) Redacted.Rendering.TransferFunction:Finalize () 0x0000018BC5A2052C (Mono JIT Code) (wrapper runtime-invoke) object:runtime_invoke_virtual_void__this__ (object,intptr,intptr,intptr) 0x00007FF844A2F215 (mono-2.0-bdwgc) mono_callspec_cleanup 0x00007FF844CA79EE (mono-2.0-bdwgc) mono_breakpoint_clean_code 0x00007FF844A30889 (mono-2.0-bdwgc) mono_gc_finalize_notify 0x00007FF8449CB94B (mono-2.0-bdwgc) mono_security_set_mode 0x00007FF8449CBB26 (mono-2.0-bdwgc) mono_security_set_mode 0x00007FF8C43954E0 (KERNEL32) BaseThreadInitThunk 0x00007FF8C554485B (ntdll) RtlUserThreadStart

========== END OF STACKTRACE ===========

This info is completely missing from sentry.io

image

DrummerB avatar Jul 11 '22 10:07 DrummerB

It seems the debug symbols were not uploaded. Did you set the options in the sentry cli tab?

bruno-garcia avatar Jul 11 '22 12:07 bruno-garcia

@bruno-garcia I am now trying this in a new empty project. I just followed the setup wizard and have native integration and symbol uploading enabled:

image image

This is how I trigger the crash:

public class SentryTest : MonoBehaviour
{
	void OnGUI()
	{
		if (GUI.Button(new Rect(10, 10, 150, 100), "Crash"))
			CrashIn3();
	}

        // Just to get a bit of a stacktrace:
	static void CrashIn3() { CrashIn2(); }
	static void CrashIn2() { CrashIn1(); }
	static void CrashIn1() { CrashNow(); }
	static void CrashNow() => UnityEngine.Diagnostics.Utils.ForceCrash(ForcedCrashCategory.AccessViolation);
}

And this is how I built it: image image

The stacktrace does not contain any symbolicated Mono JIT code. Is this actually supposed to work? image

image

It does show an error at the top, but clicking Expand, just collapses the whole panel again. image

These are listed as missing images, but seem all irrelevant: image

DrummerB avatar Jul 11 '22 13:07 DrummerB

The two stack traces in the original description and in the example code given seem unrelated. I was able to reproduce the given example and yes, the stack trace is cut off. Seems like it's because the stack frames don't have any image (library) info in the memory dump. This is what a stack trace from the given example looks like in WinDbg: image

As far as I can tell, there's currently nothing we can do when running in Mono JIT mode because there's just no symbol mapping available to the native crash handler. See https://github.com/mono/mono/issues/18469

Unless someone is aware of any way to extract Mono JIT stack trace info at the time of a crash (memory dump), we shall document this as a known limitation.

vaind avatar Aug 31 '22 14:08 vaind

Docs are update, closing this issue

vaind avatar Oct 31 '22 13:10 vaind