Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: IL2CPP line number processing for dedicated server builds #1522

Merged
merged 7 commits into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
43 changes: 42 additions & 1 deletion package-dev/Runtime/SentryInitialization.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
}
}
}
2 changes: 2 additions & 0 deletions src/Sentry.Unity/ISentryUnityInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 7 additions & 14 deletions src/Sentry.Unity/Il2CppEventProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down Expand Up @@ -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) ||
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -229,8 +223,7 @@ public DebugImageInfo(DebugImage image)
var result = new List<DebugImageInfo>();

// 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)
Expand Down
2 changes: 1 addition & 1 deletion src/Sentry.Unity/SentryUnityOptionsExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
7 changes: 6 additions & 1 deletion test/SharedClasses/TestUnityInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
Loading