Skip to content

Commit ee85808

Browse files
committed
feat: iOS Native AOT support
1 parent 6d624e1 commit ee85808

File tree

4 files changed

+61
-4
lines changed

4 files changed

+61
-4
lines changed

src/Sentry/Internal/DebugStackTrace.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using Sentry.Internal.Extensions;
22
using Sentry.Extensibility;
3-
using Sentry.Native;
43
using Sentry.Internal.ILSpy;
54
using Sentry.Protocol;
65

@@ -17,8 +16,11 @@ internal class DebugStackTrace : SentryStackTrace
1716
private readonly Dictionary<Guid, int> _debugImageIndexByModule = new();
1817
private const int DebugImageMissing = -1;
1918
private bool _debugImagesMerged;
19+
20+
#if NET6_0_OR_GREATER
2021
private Dictionary<long, DebugImage>? _nativeDebugImages;
2122
private HashSet<long> _usedNativeDebugImages = new();
23+
#endif
2224

2325
/*
2426
* NOTE: While we could improve these regexes, doing so might break exception grouping on the backend.
@@ -220,6 +222,7 @@ private IEnumerable<SentryStackFrame> CreateFrames(StackTrace stackTrace, bool i
220222
}
221223
}
222224

225+
#if NET6_0_OR_GREATER
223226
/// <summary>
224227
/// Native AOT implementation of CreateFrame.
225228
/// Native frames have only limited method information at runtime (and even that can be disabled).
@@ -237,7 +240,15 @@ private IEnumerable<SentryStackFrame> CreateFrames(StackTrace stackTrace, bool i
237240
frame.ImageAddress = imageAddress;
238241
frame.InstructionAddress = stackFrame.GetNativeIP();
239242

240-
_nativeDebugImages ??= C.LoadDebugImages(_options.DiagnosticLogger);
243+
#if __ANDROID__
244+
// TODO there will be support for NativeAOT in the future.
245+
_nativeDebugImages ??= new();
246+
#elif __IOS__ || MACCATALYST
247+
_nativeDebugImages ??= Sentry.iOS.C.LoadDebugImages(_options.DiagnosticLogger);
248+
#else
249+
_nativeDebugImages ??= Sentry.Native.C.LoadDebugImages(_options.DiagnosticLogger);
250+
#endif
251+
241252
if (!_usedNativeDebugImages.Contains(imageAddress) && _nativeDebugImages.TryGetValue(imageAddress, out var debugImage))
242253
{
243254
_usedNativeDebugImages.Add(imageAddress);
@@ -261,6 +272,7 @@ internal static SentryStackFrame ParseNativeAOTToString(string info)
261272
}
262273
return frame;
263274
}
275+
#endif
264276

265277
/// <summary>
266278
/// Default the implementation of CreateFrame.
@@ -352,7 +364,9 @@ internal static SentryStackFrame ParseNativeAOTToString(string info)
352364
internal SentryStackFrame? CreateFrame(IStackFrame stackFrame)
353365
{
354366
var frame = TryCreateManagedFrame(stackFrame);
367+
#if NET6_0_OR_GREATER
355368
frame ??= TryCreateNativeAOTFrame(stackFrame);
369+
#endif
356370
if (frame is null)
357371
{
358372
return null;
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using Sentry.Extensibility;
2+
using Sentry.Internal.Extensions;
3+
4+
namespace Sentry.iOS;
5+
6+
internal static class C
7+
{
8+
internal static Dictionary<long, DebugImage> LoadDebugImages(IDiagnosticLogger? logger)
9+
{
10+
logger?.LogDebug("Collecting a list of native debug images.");
11+
var result = new Dictionary<long, DebugImage>();
12+
try
13+
{
14+
var cList = SentryCocoaHybridSdk.DebugImages;
15+
logger?.LogDebug("There are {0} native debug images, parsing the information.", cList.Length);
16+
foreach (var cItem in cList)
17+
{
18+
if (cItem.ImageAddress?.ParseHexAsLong() is { } imageAddress)
19+
{
20+
result.Add(imageAddress, new DebugImage()
21+
{
22+
CodeFile = cItem.CodeFile,
23+
ImageAddress = imageAddress,
24+
ImageSize = cItem.ImageSize?.LongValue,
25+
DebugId = cItem.DebugID,
26+
Type = cItem.Type,
27+
});
28+
}
29+
}
30+
}
31+
catch (Exception e)
32+
{
33+
logger?.LogWarning("Error loading the list of debug images", e);
34+
}
35+
return result;
36+
}
37+
}

src/Sentry/Sentry.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
<!-- Platform-specific props included here -->
2222
<Import Project="Platforms\Android\Sentry.Android.props" Condition="'$(TargetPlatformIdentifier)' == 'android'" />
2323
<Import Project="Platforms\iOS\Sentry.iOS.props" Condition="'$(TargetPlatformIdentifier)' == 'ios' Or '$(TargetPlatformIdentifier)' == 'maccatalyst'" />
24-
<Import Project="Platforms\Native\Sentry.Native.targets"/>
24+
<Import Project="Platforms\Native\Sentry.Native.targets"
25+
Condition="'$(TargetPlatformIdentifier)' != 'android' and '$(TargetPlatformIdentifier)' != 'ios' and '$(TargetPlatformIdentifier)' != 'maccatalyst'"/>
2526

2627
<PropertyGroup Condition="'$(FrameworkSupportsAot)' == 'true'">
2728
<IsAotCompatible>true</IsAotCompatible>

src/Sentry/buildTransitive/Sentry.targets

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,12 @@
128128
<!-- Native AOT publishing
129129
While '_IsPublishing' looks a bit "private", it's also OK if it suddenly stops working and this step runs anyway.
130130
See https://github.com/dotnet/sdk/issues/26324#issuecomment-1169236993 -->
131-
<PropertyGroup Condition="'$(PublishDir)' != '' and '$(PublishAot)' == 'true' and '$(_IsPublishing)' == 'true'">
131+
<PropertyGroup Condition="
132+
'$(PublishDir)' != ''
133+
and '$(PublishAot)' == 'true'
134+
and '$(_IsPublishing)' == 'true'
135+
and $([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) != 'ios'
136+
and $([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) != 'maccatalyst'">
132137
<SentryCLIUploadNativeAOT>true</SentryCLIUploadNativeAOT>
133138
<SentryCLIUploadDirectory>$(PublishDir)</SentryCLIUploadDirectory>
134139
<!-- We must run after "_CopyAotSymbols" (not "Publish"), because that is the one that actually copies debug symbols to the publish directory. -->

0 commit comments

Comments
 (0)