Search Unity

IL2CPP missing line numbers in stack trace

Discussion in 'Unity Cloud Diagnostics' started by BDash2015, Jan 13, 2020.

  1. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    Ok, that makes sense. This won't work until we ship changes to expose the line numbers in stack traces on the client side (without the use of Cloud Diagnostics).

    Sorry, I missed this part of your question. That information is actually not sent over the wire. Cloud Diagnostics only gets an array of function pointers representing the native call stack. Then it reconstructs everything on the server side.

    We don't have a way to expose that information at run time. Once we do ship support for client-side line numbers in stack traces, that information will exist in the runtime, but we don't plan to expose it externally right now.
     
    look001 and bruno-garcia like this.
  2. Haze-Games

    Haze-Games

    Joined:
    Mar 1, 2015
    Posts:
    190
    We are using UCB but stacktraces from IL2CPP release builds on Windows/Mac/Linux without script debugging, always shows lines 00 in stacktraces from Cloud Diagnostics.

    Any information to try and fix this would be greatly appreciated,

    Thanks!
     
  3. Haze-Games

    Haze-Games

    Joined:
    Mar 1, 2015
    Posts:
    190
    Ah forget that, we are on latest TECH and this is only available in Unity 2022 - my bad!

    Cheers,
     
  4. pistoleta

    pistoleta

    Joined:
    Sep 14, 2017
    Posts:
    539
    Is it confirmed it's working in Unity 2022? Working on 2020.3 here but we want those line numbers..
     
  5. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    Yes, this works with Unity 2022.1. It is not something we plan to back port, unfortunately.
     
  6. chakie

    chakie

    Joined:
    Jul 31, 2011
    Posts:
    14
    Is my understanding correct here that it's impossible to get line numbers in stack traces with Unity? We build for iOS and Android and there are errors that happen on test devices that would be nice to be able to track down. Having all line numbers be 00000 is somewhat annoying. We're using the 2021.3.0f1 LTS version. Seems this has been an issue for close to a decade now? I assume it's not exactly a priority when there are more interesting shiny render pipelines to work on instead of things that developers actually want?
     
  7. pistoleta

    pistoleta

    Joined:
    Sep 14, 2017
    Posts:
    539
    You understood well, feature coming in unity 2022 (if lucky)
     
  8. Neto_Kokku

    Neto_Kokku

    Joined:
    Feb 15, 2018
    Posts:
    1,751
    Unity likes to prioritize features which increase the number of people starting projects with it, not finishing and maintaining them.

    Anyway, the problem with stack traces is that with IL2CPP the code that runs (and crashes) on device is not the code you wrote: your C# is compiled into IL bytecode, which is then converted into a very convoluted C++ code, which is then compiled into machine code by Xcode/Clang/MSVC.

    The native symbols produced by the C++ compiler can contain line information, but those lines point to the C++ files generated by IL2CPP. You need some sort of map that associates the lines in the IL2CPP files to the IL bytecode they were generated from. From there, it's possible for find which C# line that instruction maps to using the PDB file produced by Unity's C# compiler.

    There are two problems: first, that IL2CPP-to-DOTNETIL mapping seems to not be generated for release builds. Second, Android/iOS and all other platforms don't care about that: they can only see the native C++ symbols to produce call stacks.

    To produce call stacks with C# line information, Unity would need to manipulate the symbol generation process to change the file and line number mapping of each native instruction. This is certainly possible, but they need to care enough to put people to work on this, even if it's too complicated and doesn't produce pretty pictures to woo investors.
     
    AlexEmbrace likes this.
  9. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    This is pretty much what we have done, and plan to release it in 2022.2. Stay tuned.
     
    JuanPotato, Haze-Games and Neto_Kokku like this.
  10. chakie

    chakie

    Joined:
    Jul 31, 2011
    Posts:
    14
    Our build is (I guess) a development build, not a release build. We set
    BuildOptions.Development
    for the
    BuildPipeline.BuildPlayer()
    call. But this limitation also holds for development builds, I guess? We just migrated our entire project to the brand new 2021 LTS version, but I assume that this version will never ever have properly working backtraces?
     
  11. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    Correct, we don't plan to back port this feature to 2021 versions.
     
  12. Neto_Kokku

    Neto_Kokku

    Joined:
    Feb 15, 2018
    Posts:
    1,751
    Welcome to the Unity debugging experience (until 2022 LTS, at least). Here are some survival tips;

    - Breaking large functions in smaller ones helps narrowing down the actual crash site.
    - 99% of the crashes which are not memory-related are null reference exceptions and out-of-bounds array accesses, so check the offending function for where those could happen. If you have such exceptions in the editor, fix them! A game should not have any of such exceptions happening as part of its normal operation (and no, adding try/catch to them is not a fix).
     
  13. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    Note that you can also enable script debugging and attempt to manually debug the source of the exception in some cases.
     
  14. Neto_Kokku

    Neto_Kokku

    Joined:
    Feb 15, 2018
    Posts:
    1,751
    Really, in my opinion even in development builds and in the editor Unity should stop everything immediately on null/missing reference and out-of-range exceptions and display some large error information or jump straight to the line in Visual Studio.

    These will crash optimized IL2CPP builds, and even if they didn't, exceptions like those put the game in undefined state which manifest as weird seemingly unrelated issues later or, which range from a button no longer working to an infinite loading screen or some other random bizarre occurrence.
     
    joshuacwilde likes this.
  15. nixarn_

    nixarn_

    Joined:
    Jul 25, 2015
    Posts:
    42
    Pretty frustrating how you can't even get line numbers in 2021. Feels like such a standard feature, and it would be only for slower development builds. But I guess we're all out of luck for a year, but then 2022 will most likely break something else.
     
    pistoleta likes this.
  16. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,619
    Haha, I implemented this for a company I worked for a few years ago. It definitely caused people to look at those problems.
     
  17. JuanPotato

    JuanPotato

    Joined:
    Apr 28, 2022
    Posts:
    1
    Looking forward to it! Will this work for all platforms? ;)
     
  18. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    At the first release, no. We expect it to work on standalone players - Windows, macOS, and Linux, plus iOS and Android. Other platforms will come later, as we're waiting on those platforms to catch up on some other internal changes that the stack trace line number implementation depends on.
     
    JuanPotato likes this.
  19. Kujo87

    Kujo87

    Joined:
    Sep 16, 2013
    Posts:
    168
    Just to clarify something with this 2022.x update. Is this ONLY for cloud diagnostics? Or would it also provide correct line numbers when using
    Application.logMessageReceivedThreaded for example?
     
  20. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    For 2022.1, the feature is only in cloud diagnostics. For 2022.2 and later, we're planning to allow it to work client side, so the call stack in Application.logMessageReceivedThreaded would indeed have line numbers and source code files in the call stack.

    This will be an optional feature, as there is a non-zero cost (both at build time and for application size) to include the symbol information with the application. But it will be possible to enable.
     
  21. bruno-garcia

    bruno-garcia

    Joined:
    Nov 8, 2016
    Posts:
    7
    JoshPeterson likes this.
  22. xjjon

    xjjon

    Joined:
    Apr 15, 2016
    Posts:
    613
    Thanks for sharing
    We are using Crashlytics but this is interesting as we can have PC + mobile reporting from the same library.
     
  23. pistoleta

    pistoleta

    Joined:
    Sep 14, 2017
    Posts:
    539
    We have been using Sentry for a few months and it's the best you can find out there. Totally recommended.
     
    look001 and bruno-garcia like this.
  24. pistoleta

    pistoleta

    Joined:
    Sep 14, 2017
    Posts:
    539
    @JoshPeterson I understand Unity creates certain optimizations on the c++ generated code. If those are enabled is still possible to retrieve the c# line numbers on 2022.2 ?
     
  25. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    It is possible to obtain C# line numbers via the Unity Cloud Diagnostics service. We don't yet have support for that in actual player builds on the device, but we're working on that now.
     
  26. waldgeist

    waldgeist

    Joined:
    May 6, 2017
    Posts:
    388
    I was finally able to upgrade to Unity 2020.3. Only to find out that I still do not see any line numbers in Xcode when an exception occurs. I enabled Script Debugging. What elso do I have to do to see line numbers in Xcode?
     
  27. waldgeist

    waldgeist

    Joined:
    May 6, 2017
    Posts:
    388
    Ok. So you first told me that I can get line numbers in 2020, but sadly not in 2019. And now it has been postponed to 2022? Seriously?
     
  28. pistoleta

    pistoleta

    Joined:
    Sep 14, 2017
    Posts:
    539
    Wait, with script debugging enabled should work on 2019,2020 and 2021 too, am I wrong @JoshPeterson ?
     
  29. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    Correct, with script debugging enabled, you should be able to see C# source code line numbers in managed stack traces in Unity 2019 and later.

    @waldgeist: Can you send a screen of what you see in Xcode where they don't show up? I curious about the behavior.
     
  30. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    Hey there! I'm very happy to announce that starting in Unity release 2023.1.0a25 we have support for C# line numbers in managed stack traces with IL2CPP on devices!

    Here is a snippet from the yet-to-be-published documentation for this feature:

    Source code line numbers

    A setting is available to include file and line number information in the managed stack traces. The setting is under the Configuration section of Player settings. To enable the feature, set IL2CPP Stacktrace Information to “Method Name, File Name, and Line Number”.



    When enabled, this feature will include all managed stack frames, no matter which C++ Compiler Configuration is used. Each stack frame will also include the proper C# line number, as long as a managed symbol file (.pdb) is available for the managed assembly (.dll) where that code exists.

    This feature does have a non-zero cost, both for build time and for program size. When it is enabled, the player build process will include an additional step that processes debug symbol files and generates a new data file which includes the necessary symbol formation. This data file is shipped with the built player and used at runtime to determine C# line information in call stacks.

    I know this has been a long time coming - I'm so happy that we can finally deliver it. The 2023.1.0a25 release is scheduled to be publish on or about January 14. I'd love to hear any feedback that you have about this feature.

    EDIT: I had the release incorrect originally. This will show up in 2023.1.0a25
     
    Last edited: Jan 3, 2023
  31. pistoleta

    pistoleta

    Joined:
    Sep 14, 2017
    Posts:
    539
    2023.1.0a24 ? Is this supposed to be good news? How much until 2023.1 becomes LTS and we can migrate "safely" our projects in production to this one ? :D

    Still, thanks for the effort
     
  32. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    Yeah, I wish we could have shipped this sooner, but this is when it was ready.
     
  33. yringel-banditos

    yringel-banditos

    Joined:
    Jul 20, 2016
    Posts:
    4
    Hey Josh, great news! Thanks a lot!!
    Is it possible to backport the solution to LTS versions?
    This is super important and will improve the quality of our games tremendously...
     
    RaskinX and yoavhermon like this.
  34. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    Thanks! Sadly no, we don't plan to take this feature back to any LTS releases.
     
  35. Kamyker

    Kamyker

    Joined:
    May 14, 2013
    Posts:
    1,091
    Would it be possible to use it on per file or class basis in the future? I guess problem with delivering builds with full stack traces would be easier decompilation by hackers/thieves/modders. Here's how I see it working:
    1. Game uses previous stack traces without line numbers
    2. Devs notice bug being reported in online analytics
    3. After being unable to identify root cause they decide to mark file/class with a header to use full stacktraces
    4. Upload new build
    5. Get better stacktrace for only this exact bug

    If that's not possible, is there any other method? Maybe instead of per class/file it could be per asmdef? Rest of pdbs wouldn't generate.
     
  36. baba_s

    baba_s

    Joined:
    Nov 25, 2013
    Posts:
    6
    Hello.

    I have installed and launched Unity 2023.1.0a24.
    However, I could not find the menu "IL2CPP Stacktrace Information" in Player Settings.

    screenshot.png

    Am I doing something wrong in the procedure?
     
  37. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    We've not considered this, although it is possible from a technical perspective. At the moment, any assembly without .pdb files will not have any symbol information sent with the client, so removing the .pdb files from a given assembly (maybe via a post-C# compilation step in a custom build process, I'm not sure). Would give you the behavior you desire at the assembly level. But that is a bit clunky to do.

    I'd like to see how this feature is used to determine our next steps, so I don't expect to implement anything like this now, but it is certainly an interesting idea.
     
    Kamyker likes this.
  38. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    I'm very sorry, our release notes system told me this would be in 2023.1.0a24, but it it looks like it actually missed that release by a few commits. I'll try to track down what went wrong on our end.

    I have confirmed that this will be in 2023.1.0a25, scheduled to be out by January 14. Sorry for the confusion!
     
    Kamyker likes this.
  39. baba_s

    baba_s

    Joined:
    Nov 25, 2013
    Posts:
    6
    I understand! I am looking forward to it. :)
     
  40. joe_nk

    joe_nk

    Joined:
    Jan 6, 2017
    Posts:
    67
    I've upgraded from 2021.3 LTS to 2022.3 LTS expecting to see line numbers in managed stacktraces for release builds via the Unity Cloud Diagnostics platform, but that's not the case. Is there some setting somewhere I need to enable?
     

    Attached Files:

    frikic likes this.
  41. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    The new setting we've added here impacts stack traces that are generated on the client, in the app. It does not impact Cloud Diagnostics. I suspect that is a different option, but I'm not familiar with it. I've asked others about it and will respond here.
     
  42. joe_nk

    joe_nk

    Joined:
    Jan 6, 2017
    Posts:
    67
    Thanks!
     
  43. joe_nk

    joe_nk

    Joined:
    Jan 6, 2017
    Posts:
    67
    Any update here @JoshPeterson? Tempted to open a premium support ticket for this
     
  44. AllanGameSmithing

    AllanGameSmithing

    Joined:
    Aug 10, 2022
    Posts:
    12
    I just found this thread and I'm a bit confused now. So starting in 2022.1, regular, release builds of the game (for Standalone, iOS and Android), should show line numbers in Cloud Diagnostics without any extra steps, correct? The build sent for users, without symbol files, will still work as intended?

    Then, the change in 2023.1 alpha is that you will also get line numbers, if you so choose, in the local logs, like Player.log.

    Am I understanding it correctly?
     
  45. joe_nk

    joe_nk

    Joined:
    Jan 6, 2017
    Posts:
    67
    Correct! But as fair as I am aware from my own testing, and other comments in this thread, Unity 2022.x builds don't actually produce line numbers in Unity Cloud Diagnostics
     
  46. Jay_Mehta_97

    Jay_Mehta_97

    Joined:
    Feb 8, 2023
    Posts:
    1
    Did anyone get a chance to try this with 2023.1?
    Wanted to know if it works with Firebase for Android and iOS.

    Thanks.
     
  47. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    Yes, it might be worth opening a support ticket for this. I'm not involved in the Unity Cloud Diagnostics end of things, so I can't offer any more help with that.
     
    joe_nk likes this.
  48. joe_nk

    joe_nk

    Joined:
    Jan 6, 2017
    Posts:
    67
    I dug into this a bit more and noticed the following warning when building the iOS XCode project:
    The project calls process_symbols.sh, which uploads build symbols to Unity Cloud Diagnostics via usymtool:
    Code (Boo):
    1. #!/bin/sh
    2.  
    3. #  process_symbols
    4. #
    5. #  Copyright (c) 2015 Unity Technologies. All rights reserved.
    6.  
    7. if [ "$(arch)" == "arm64" ]; then
    8.   usymtool="usymtoolarm64"
    9. else
    10.   usymtool="usymtool"
    11. fi
    12.  
    13. if [ "${SYNCHRONOUS_SYMBOL_PROCESSING}" = "TRUE" ]; then
    14.     "$PROJECT_DIR/$usymtool" -symbolPath "$DWARF_DSYM_FOLDER_PATH/$DWARF_DSYM_FILE_NAME" -il2cppOutputPath "$PROJECT_DIR/Il2CppOutputProject/Source/il2cppOutput/"
    15. else
    16.     nohup "$PROJECT_DIR/$usymtool" -symbolPath "$DWARF_DSYM_FOLDER_PATH/$DWARF_DSYM_FILE_NAME" -il2cppOutputPath "$PROJECT_DIR/Il2CppOutputProject/Source/il2cppOutput/" > /dev/null 2>&1 &
    17.     disown
    18. fi
    Notice no il2cppFileRoot argument? I made a post-process script to modify this shell script to add that:
    Code (Boo):
    1. #!/bin/sh
    2.  
    3. #  process_symbols
    4. #
    5. #  Copyright (c) 2015 Unity Technologies. All rights reserved.
    6.  
    7. if [ "$(arch)" == "arm64" ]; then
    8.   usymtool="usymtoolarm64"
    9. else
    10.   usymtool="usymtool"
    11. fi
    12.  
    13. if [ "${SYNCHRONOUS_SYMBOL_PROCESSING}" = "TRUE" ]; then
    14.     "$PROJECT_DIR/$usymtool" -symbolPath "$DWARF_DSYM_FOLDER_PATH/$DWARF_DSYM_FILE_NAME" -il2cppFileRoot "$PROJECT_DIR/Il2CppOutputProject/Source/il2cppOutput/" -il2cppOutputPath "$PROJECT_DIR/Il2CppOutputProject/Source/il2cppOutput/"
    15. else
    16.     nohup "$PROJECT_DIR/$usymtool" -symbolPath "$DWARF_DSYM_FOLDER_PATH/$DWARF_DSYM_FILE_NAME" -il2cppFileRoot "$PROJECT_DIR/Il2CppOutputProject/Source/il2cppOutput/" -il2cppOutputPath "$PROJECT_DIR/Il2CppOutputProject/Source/il2cppOutput/" > /dev/null 2>&1 &
    17.     disown
    18. fi
    19.  
    And the warning disappeared. Made a build and forced a crash and hey presto, line numbers!
    Screenshot 2023-08-17 at 2.42.49 PM.png
     
  49. mnoone_torus

    mnoone_torus

    Joined:
    May 14, 2023
    Posts:
    2
    With this setting and "Copy PDB files" enabled, the line numbers showing don't match the line numbers in our source code. Presumably it's showing the CPP line numbers, is there an extra step required for the line numbers to match the C#?
     
  50. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    It should should C# line numbers. To be clear, can you indicate which settings you have enabled? I want to make sure we are talking about the same thing.