Skip to content

Symbolication for AOT-compiled stack traces on iOS #2180

Closed

Description

@mattjohnsonpint

Package

Sentry.Maui

.NET Flavor

.NET

.NET Version

7.0.102

OS

iOS

SDK Version

3.28.1

Steps to Reproduce

  1. Make a new MAUI application
  2. Add Sentry.Maui
  3. Write code that throws an exception
  4. Configure MSBuild with org and project
  5. Build in Release mode
  6. Deploy to a real iOS device (not the simulator)
  7. Run the app and cause the exception to fire

Expected Result

Error in Sentry should include file names and line numbers in the stack trace.

Actual Result

No symbolication occurs.

image

Event:
https://sentry-sdks.sentry.io/issues/3936606932/events/6292f7f7ec3744e6a410e0bd111879ce/?project=5428537

The JSON of the event does not contain any debug_meta information, symbolication is not attempted.

Activity

  1. mattjohnsonpint commented on Feb 14, 2023

    @mattjohnsonpint
    ContributorAuthor

    Note - works in debug mode. Also works in debug or release mode on the simulator - just not on a real device.

  2. mattjohnsonpint commented on Feb 14, 2023

    @mattjohnsonpint
    ContributorAuthor
  3. mattjohnsonpint commented on Feb 14, 2023

    @mattjohnsonpint
    ContributorAuthor

    Found I can get at at the logs in release mode by connecting the iOS device via USB and running:

    /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/bin/mtouch --logdev | grep Sentry
    

    With SentryOptions.Debug = true, I now can see the problem:

    Feb 14 14:05:33 mattjs-iPhone Sentry.Samples.Maui[809] <Notice>:    Info: Capturing event.
    Feb 14 14:05:33 mattjs-iPhone Sentry.Samples.Maui[809] <Notice>:   Debug: Running processor on exception: This exception was thrown and captured manually, without crashing the app.
    Feb 14 14:05:33 mattjs-iPhone Sentry.Samples.Maui[809] <Notice>:   Debug: Creating SentryStackTrace. isCurrentStackTrace: False.
    Feb 14 14:05:33 mattjs-iPhone Sentry.Samples.Maui[809] <Notice>:    Info: Skipping DebugImage for module 'Sentry.Samples.Maui.dll' because DebugId couldn't be determined
    Feb 14 14:05:33 mattjs-iPhone Sentry.Samples.Maui[809] <Notice>:   Debug: Created DebugStackTrace with 1 frames.
    Feb 14 14:05:33 mattjs-iPhone Sentry.Samples.Maui[809] <Notice>:   Debug: Running main event processor on: Event 42dbc64b0868418cad97794f1f95c39d
    Feb 14 14:05:33 mattjs-iPhone Sentry.Samples.Maui[809] <Notice>:   Debug: Merging 0 debug images from stacktrace.
    
  4. mattjohnsonpint commented on Feb 15, 2023

    @mattjohnsonpint
    ContributorAuthor

    Well, I found the problem.

    if (!entry.IsPortableCodeView)

    This is returning false. It's defined as:

    public bool IsPortableCodeView => MinorVersion == PortablePdbVersions.PortableCodeViewVersionMagic;

    And in the case of the released iOS app, MinorVersion is 0. I can get some parts of it working if I test with entry.Type == DebugDirectoryEntryType.CodeView instead. But the debug id doesn't fully match the PDB.

    The problem appears to be caused by dotnet assembly trimming, which is not something that can be disabled for iOS apps. (I've tried various options with no success as of yet.)

    Building in release mode will create a regular dll and pdb where you'd expect them. For example:

    • bin/Release/net6.0-ios/ios-arm64/Sentry.Samples.Maui.dll
    • bin/Release/net6.0-ios/ios-arm64/Sentry.Samples.Maui.pdb

    But then it will write a trimmed dll to the app bundle at:

    • bin/Release/net6.0-ios/ios-arm64/Sentry.Samples.Maui.app/Sentry.Samples.Maui.dll

    Both dll's will have the same guid part of the debug id, but the last component (the timestamp) will vary.

    Check with sentry-cli:

    matt@XHFHLG2CJP Sentry.Samples.Maui % sentry-cli dif check bin/Release/net6.0-ios/ios-arm64/Sentry.Samples.Maui.dll
    Debug Info File Check
      Type: pe executable
      Contained debug identifiers:
        > Debug ID: c66dceee-2c72-4bf6-9a15-6e2aad6ab8fb-1
          Code ID:  d0a102d41c000
          Arch:     arm64
      Contained debug information:
        > none
      Usable: no (missing debug or unwind information)
    matt@XHFHLG2CJP Sentry.Samples.Maui % sentry-cli dif check bin/Release/net6.0-ios/ios-arm64/Sentry.Samples.Maui.pdb
    Debug Info File Check
      Type: portablepdb debug companion
      Contained debug identifiers:
        > Debug ID: c66dceee-2c72-4bf6-9a15-6e2aad6ab8fb-d0a102d4
          Arch:     unknown
      Contained debug information:
        > debug, sources
      Usable: yes
    matt@XHFHLG2CJP Sentry.Samples.Maui % sentry-cli dif check bin/Release/net6.0-ios/ios-arm64/Sentry.Samples.Maui.app/Sentry.Samples.Maui.dll 
    Debug Info File Check
      Type: pe executable
      Contained debug identifiers:
        > Debug ID: c66dceee-2c72-4bf6-9a15-6e2aad6ab8fb-1
          Code ID:  63ec4f2fc000
          Arch:     x86
      Contained debug information:
        > none
      Usable: no (missing debug or unwind information)
    
    • The PDB was uploaded with DebugID: c66dceee-2c72-4bf6-9a15-6e2aad6ab8fb-d0a102d4
    • The non-trimmed version will match: c66dceee-2c72-4bf6-9a15-6e2aad6ab8fb-d0a102d4
    • The trimmed version has a different one: c66dceee-2c72-4bf6-9a15-6e2aad6ab8fb-63ec4f2f

    (Note the output of sentry-cli is showing -1 but the first 8 digits of the Code ID are what will actually be used there.)

    I can see the same detail in Rider's "Assembly Explorer":

    The non-trimmed DLL's debug headers:

    image

    The trimmed DLL's debug headers:

    image

    Notice that the non-trimmed version has valid values for MajorVersion and MinorVersion, the TimeDateStamp is a pseudo-timestamp (due to deterministic builds), and the Deterministic entry indicator is present.

    In the non- trimmed headers, MajorVersion and MinorVersion are zero, and the TimeDateStamp field is a real value (the UTC time the linker ran), and the Deterministic entry is absent.

  5. mattjohnsonpint commented on Feb 15, 2023

    @mattjohnsonpint
    ContributorAuthor

    Not sure what to do about this. At runtime, we need the debug_meta information to contain the full original Debug ID to match with the one in the PDB sent to Sentry. There is no corresponding PDB to upload that will match the trimmed version.

    One thought I had was that it might be possible to use an MSBuild tasks with ILLink custom steps to read the full debug ID from the un-trimmed assembly and write it to another location (such as an AssemblyMetadata attribute) in the trimmed assembly. We could read it from there at runtime.

    @bruno-garcia @vaind - thoughts?

  6. mattjohnsonpint commented on Feb 15, 2023

    @mattjohnsonpint
    ContributorAuthor

    Oh, and note that both parts of the Code ID differ as well.

    Debug ID: c66dceee-2c72-4bf6-9a15-6e2aad6ab8fb-d0a102d4
    Code ID: d0a102d41c000
    Signature: c66dceee-2c72-4bf6-9a15-6e2aad6ab8fb
    TimeDateStamp: d0a102d4
    SizeOfData: 1c000

    vs.

    Debug ID: c66dceee-2c72-4bf6-9a15-6e2aad6ab8fb-63ec4f2f
    Code ID: 63ec4f2fc000
    Signature: c66dceee-2c72-4bf6-9a15-6e2aad6ab8fb
    TimeDateStamp: 63ec4f2f
    SizeOfData: c000

    ... which makes sense because the trimmed version is smaller, and the timestamp of the non-trimmed version is deterministic

  7. vaind commented on Feb 15, 2023

    @vaind
    Contributor

    Notice that the non-trimmed version has valid values for MajorVersion and MinorVersion, the TimeDateStamp is a pseudo-timestamp (due to deterministic builds), and the Deterministic entry indicator is present.

    In the non- trimmed headers, MajorVersion and MinorVersion are zero, and the TimeDateStamp field is a real value (the UTC time the linker ran), and the Deterministic entry is absent.

    Seems to match the specification

    Not sure what to do about this. At runtime, we need the debug_meta information to contain the full original Debug ID to match with the one in the PDB sent to Sentry. There is no corresponding PDB to upload that will match the trimmed version.

    We may need to change the lookup logic to support this properly @Swatinem ?

  8. mattjohnsonpint commented on Feb 15, 2023

    @mattjohnsonpint
    ContributorAuthor

    @vaind - I think you're saying that I'm seeing the first part of the spec there (Version Major=0, Minor=0...), and we've designed only for the second part (Version Major=any, Minor=0x504d...)? In that case should we be sending the Age instead of the TimeDateStamp? Even then, I'm not sure how it would match up on the server side, as the pdb would still have the TimeDateStamp in its debug_id.

  9. vaind commented on Feb 15, 2023

    @vaind
    Contributor

    I'm not very familiar with the symbolication part of this, that's why I've tried pinging @Swatinem, I think he have originally programmed that.

  10. vaind commented on Feb 15, 2023

    @vaind
    Contributor

    But yes, my suspicion is we're not handling both scenarios.

  11. 13 remaining items

  12. mattjohnsonpint commented on Apr 17, 2023

    @mattjohnsonpint
    ContributorAuthor
  13. removed their assignment
    on Jun 20, 2023
  14. bruno-garcia commented on Jul 24, 2023

    @bruno-garcia
    Member

    We possibly can support iOS through Native AOT for apps targeting .NET 8 and later. Assuming this lands:

    If so, this ticket, given its complexity, becomes lower priority. That is, if Mono AOT can be replaced with Native AOT.

    And what we could focus on is:

  15. SamMonoRT commented on Aug 11, 2023

    @SamMonoRT

    We possibly can support iOS through Native AOT for apps targeting .NET 8 and later. Assuming this lands:

    If so, this ticket, given its complexity, becomes lower priority. That is, if Mono AOT can be replaced with Native AOT.

    And what we could focus on is:

    We'll encourage you to try steps for NativeAOT targetting iOS as mentioned in this blog post on any .NET8 Preview 6 or 7 builds and give us feedback - https://devblogs.microsoft.com/dotnet/announcing-dotnet-8-preview-6/#support-for-targeting-ios-platforms-with-nativeaot

  16. moved this to Waiting for: Product Owner in GitHub Issues with 👀on Aug 11, 2023
  17. moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀on Aug 14, 2023
  18. self-assigned this
    on Oct 20, 2023
  19. added this to the 4.0.0 milestone on Oct 20, 2023
  20. vaind commented on Nov 11, 2023

    @vaind
    Contributor

    @bruno-garcia @SamMonoRT support for NativeAOT on .net8-ios works fine with Sentry, I'm preparing a PR #2820

  21. vaind commented on Dec 5, 2023

    @vaind
    Contributor

    For completeness, it doesn't look like we can add support for this to MonoAOT because of the missing information. This is all the info we have available at runtime:

            var realFrame = stackFrame.Frame as StackFrame;
            _options.LogDebug("Capturing frame {0}", frame.ToUtf8Json());
            _options.LogDebug("### ToString = {0}", realFrame!.ToString());
            _options.LogDebug("### Has Native Image = {0}", realFrame.HasNativeImage());
            _options.LogDebug("### Native Image Base = 0x{0:x}", realFrame.GetNativeImageBase());
            _options.LogDebug("### Native Interface pointer = 0x{0:x}", realFrame.GetNativeIP());
            _options.LogDebug("### Offset = {0}", realFrame.GetNativeOffset());
            _options.LogDebug("### FileName = {0}", realFrame.GetFileName());
            _options.LogDebug("### Line no = {0}", realFrame.GetFileLineNumber());
            _options.LogDebug("### HasMethod = {0}", realFrame.HasMethod());
            _options.LogDebug("### Method = {0}", realFrame.GetMethod());
            _options.LogDebug("### ILOffset = {0}", realFrame.GetILOffset());
            _options.LogDebug("====================");

    Has the following output (the first line is from another log line above in the normal code):

    Got debug image for 'Sentry.Samples.Ios.dll' having Debug ID: 04ef1045-df1d-4429-ad12-eb7d79019d57-1
    Capturing frame {"FileName":"","Function":"void Program.\u003CMain\u003E$(?)","Module":"Program","LineNumber":null,"ColumnNumber":null,"AbsolutePath":null,"ContextLine":null,"InApp":null,"Package":"Sentry.Samples.Ios, Version=4.0.0.0, Culture=neutral, PublicKeyToken=fba2ec45388e2af0","Platform":null,"ImageAddress":null,"SymbolAddress":null,"InstructionAddress":null,"AddressMode":"rel:1","FunctionId":1}
    ### ToString = void Program.<Main>$(?)
    ### Has Native Image = False
    ### Native Image Base = 0x0
    ### Native Interface pointer = 0x0
    ### Offset = 63
    ### FileName =
    ### Line no = 0
    ### HasMethod = True
    ### Method = Void <Main>$(System.String[])
    ### ILOffset = 0
    
  22. jurganson commented on Mar 10, 2025

    @jurganson

    @vaind Just to clarify - so if we are using MonoAOT, we can expect that AOT compiled stack traces are not symbolicated? And working on switching to NativeAOT could help alleviate that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

BugFramework: MAUIPlatform: iOS

Projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions