diff --git a/CHANGELOG.md b/CHANGELOG.md index f56822e16..60ebc3c62 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ ### Fixes +- The SDK no longer fails to resolve the debug symbol type on dedicated server builds ([#1522](https://github.com/getsentry/sentry-unity/pull/1522)) - Fixed screenshots not being attached to iOS native crashes ([#1517](https://github.com/getsentry/sentry-unity/pull/1517)) ### Dependencies diff --git a/package-dev/Runtime/SentryInitialization.cs b/package-dev/Runtime/SentryInitialization.cs index 84fae5034..7cefc142b 100644 --- a/package-dev/Runtime/SentryInitialization.cs +++ b/package-dev/Runtime/SentryInitialization.cs @@ -328,6 +328,47 @@ public bool IsNativeSupportEnabled(SentryUnityOptions options, RuntimePlatform p default: return false; } - } + } + + + public bool IsSupportedBySentryNative(RuntimePlatform platform) + { + return platform == RuntimePlatform.Android + || platform == RuntimePlatform.LinuxPlayer + || platform == RuntimePlatform.WindowsPlayer +#if UNITY_2021_3_OR_NEWER + || platform == RuntimePlatform.WindowsServer + || platform == RuntimePlatform.OSXServer + || platform == RuntimePlatform.LinuxServer +#endif + ; + } + + public string GetDebugImageType(RuntimePlatform platform) + { + switch (platform) + { + case RuntimePlatform.Android: + return "elf"; + case RuntimePlatform.IPhonePlayer: + return "macho"; + case RuntimePlatform.OSXPlayer: + return "macho"; + case RuntimePlatform.LinuxPlayer: + return "elf"; + case RuntimePlatform.WindowsPlayer: + return "pe"; +#if UNITY_2021_3_OR_NEWER + case RuntimePlatform.WindowsServer: + return "pe"; + case RuntimePlatform.OSXServer: + return "macho"; + case RuntimePlatform.LinuxServer: + return "elf"; +#endif + default: + return "unknown"; + } + } } } diff --git a/src/Sentry.Unity/ISentryUnityInfo.cs b/src/Sentry.Unity/ISentryUnityInfo.cs index 50eb18874..51792851a 100644 --- a/src/Sentry.Unity/ISentryUnityInfo.cs +++ b/src/Sentry.Unity/ISentryUnityInfo.cs @@ -10,6 +10,8 @@ public interface ISentryUnityInfo public bool IsKnownPlatform(); public bool IsLinux(); public bool IsNativeSupportEnabled(SentryUnityOptions options, RuntimePlatform platform); + public bool IsSupportedBySentryNative(RuntimePlatform platform); + public string GetDebugImageType(RuntimePlatform platform); } public class Il2CppMethods diff --git a/src/Sentry.Unity/Il2CppEventProcessor.cs b/src/Sentry.Unity/Il2CppEventProcessor.cs index 5e2ac549e..a365fb4de 100644 --- a/src/Sentry.Unity/Il2CppEventProcessor.cs +++ b/src/Sentry.Unity/Il2CppEventProcessor.cs @@ -13,12 +13,14 @@ namespace Sentry.Unity internal class UnityIl2CppEventExceptionProcessor : ISentryEventExceptionProcessor { private readonly SentryUnityOptions _options; + private static ISentryUnityInfo UnityInfo = null!; // private static will be initialized in the constructor private readonly Il2CppMethods _il2CppMethods; - public UnityIl2CppEventExceptionProcessor(SentryUnityOptions options, Il2CppMethods il2CppMethods) + public UnityIl2CppEventExceptionProcessor(SentryUnityOptions options, ISentryUnityInfo unityInfo) { _options = options; - _il2CppMethods = il2CppMethods; + UnityInfo = unityInfo; + _il2CppMethods = unityInfo.Il2CppMethods ?? throw new ArgumentNullException(nameof(unityInfo.Il2CppMethods), "Unity IL2CPP methods are not available."); _options.SdkIntegrationNames.Add("IL2CPPLineNumbers"); } @@ -94,7 +96,7 @@ public void Process(Exception incomingException, SentryEvent sentryEvent) var instructionAddress = (ulong)nativeFrame.ToInt64(); // We cannot determine whether this frame is a main library frame just from the address - // because even relative address on the frame may correspond to an absolute addres of a loaded library. + // because even relative address on the frame may correspond to an absolute address of a loaded library. // Therefore, if the frame package matches known prefixes, we assume it's a GameAssembly frame. var isMainLibFrame = frame.Package is not null && ( frame.Package.StartsWith("UnityEngine.", StringComparison.InvariantCultureIgnoreCase) || @@ -132,15 +134,7 @@ public void Process(Exception incomingException, SentryEvent sentryEvent) mainLibImage ??= DebugImagesSorted.Value.Find((info) => string.Equals(NormalizeUuid(info.Image.DebugId), mainImageUUID))?.Image; mainLibImage ??= new DebugImage { - Type = Application.platform switch - { - RuntimePlatform.Android => "elf", - RuntimePlatform.IPhonePlayer => "macho", - RuntimePlatform.OSXPlayer => "macho", - RuntimePlatform.LinuxPlayer => "elf", - RuntimePlatform.WindowsPlayer => "pe", - _ => "unknown" - }, + Type = UnityInfo.GetDebugImageType(Application.platform), // NOTE: il2cpp in some circumstances does not return a correct `ImageName`. // A null/missing `CodeFile` however would lead to a processing error in sentry. // Since the code file is not strictly necessary for processing, we just fall back to @@ -229,8 +223,7 @@ public DebugImageInfo(DebugImage image) var result = new List(); // Only on platforms where we actually use sentry-native. - if (ApplicationAdapter.Instance.Platform - is RuntimePlatform.WindowsPlayer or RuntimePlatform.Android or RuntimePlatform.LinuxPlayer) + if (UnityInfo.IsSupportedBySentryNative(Application.platform)) { var nativeDebugImages = C.DebugImages.Value; foreach (var image in nativeDebugImages) diff --git a/src/Sentry.Unity/SentryUnityOptionsExtensions.cs b/src/Sentry.Unity/SentryUnityOptionsExtensions.cs index 6a5cea69c..e8d5b13ee 100644 --- a/src/Sentry.Unity/SentryUnityOptionsExtensions.cs +++ b/src/Sentry.Unity/SentryUnityOptionsExtensions.cs @@ -67,7 +67,7 @@ internal static void AddIl2CppExceptionProcessor(this SentryUnityOptions options { if (unityInfo.Il2CppMethods is not null) { - options.AddExceptionProcessor(new UnityIl2CppEventExceptionProcessor(options, unityInfo.Il2CppMethods)); + options.AddExceptionProcessor(new UnityIl2CppEventExceptionProcessor(options, unityInfo)); } else { diff --git a/test/SharedClasses/TestUnityInfo.cs b/test/SharedClasses/TestUnityInfo.cs index c7bcb3e58..277bbdab7 100644 --- a/test/SharedClasses/TestUnityInfo.cs +++ b/test/SharedClasses/TestUnityInfo.cs @@ -6,20 +6,25 @@ public class TestUnityInfo : ISentryUnityInfo private readonly bool _isKnownPlatform; private readonly bool _isLinux; private readonly bool _isNativeSupportEnabled; + private readonly bool _isSupportedBySentryNative; public bool IL2CPP { get; set; } public string? Platform { get; } public Il2CppMethods? Il2CppMethods { get; } - public TestUnityInfo(bool isKnownPlatform = true, bool isLinux = false, bool isNativeSupportEnabled = true) + public TestUnityInfo(bool isKnownPlatform = true, bool isLinux = false, bool isNativeSupportEnabled = true, bool isSupportedBySentryNative = true) { _isKnownPlatform = isKnownPlatform; _isLinux = isLinux; _isNativeSupportEnabled = isNativeSupportEnabled; + _isSupportedBySentryNative = isSupportedBySentryNative; } public bool IsKnownPlatform() => _isKnownPlatform; public bool IsLinux() => _isLinux; public bool IsNativeSupportEnabled(SentryUnityOptions options, RuntimePlatform platform) => _isNativeSupportEnabled; + public bool IsSupportedBySentryNative(RuntimePlatform platform) => _isSupportedBySentryNative; + + public string GetDebugImageType(RuntimePlatform platform) => "debug"; }