Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Better managed stack traces with IL2CPP

Discussion in 'iOS and tvOS' started by JoshPeterson, Jun 11, 2015.

  1. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,775
    Starting with 5.0.3p1 (today), 4.6.6p2, and 5.1.0p1 (both yet to be released), we have improved managed stack traces reported by IL2CPP. They should be correct now in a all cases, so if you see a problem, please let us know, as it might be a bug.

    We're creating better managed stack traces by parsing the linker map file and generating a binary file with information about method sizes and offsets that we ship with the application. You'll see a native executable named MapFileParser in the Unity editor build directory for your project. We use a Run Shell Script build phase in Xcode to run this utility and generate the data we need at runtime.

    We know that some customers use a build configuration where the Unity Editor on Windows generates an Xcode project that is then copied to an OSX machine to actually build for the device. In this case, the MapFileParser utility won't get into the Xcode project correctly, and the runtime will fall back to the previous stack trace code (which is sometimes incorrect). You should see a message in the Xcode build output indicating that the linker map file could not be used if this happens.

    I'm interested to know how many users are using this Windows -> OSX build process for iOS builds. For those that do use it, do you have a Unity installation on the OSX machine? This will help us determine how to better support this build configuration. Thanks!
     
  2. ajohnson223

    ajohnson223

    Joined:
    Aug 26, 2014
    Posts:
    1
    We use the Windows -> OSX build process you describe. We do not use Unity on the OSX machine at all.

    I tried 5.0.3p1 and tried to publish our project with IL2CPP from windows, but got a failure error that it couldn't find a MapFilterParser executable "C:\Program Files\Unity503p1\Editor\Data\Tools\MapFileParser\MapFileParser". When I went to the "C:\Program Files\Unity503p1\Editor\Data\Tools\MapFileParser" directory, I saw a MapFileParser.exe file in there, but no MapFileParser file. So I made a copy of the MapFileParser.exe called MapFileParser (without extension) in that directory and the publish worked.

    However, once I tried to build inside of XCode, I got yet another error that "MapFileParser" wasn't a valid executable. This makes sense, since it's trying to execute a windows binary on OS X. To fix this, I replaced the MapFileParser file with a shell script that does nothing.

    That worked.

    Long story short, I don't think the fallback logic you describe is working correctly right now, because Unity is still trying to do stuff with the MapFileParser exe when the project is published from Windows -- Both on the Unity side and the XCode side.

    I'm glad I was able to work around it for now, since we've already been waiting on this latest patch to fix another critical ByteCodeStripper error that was preventing us from publishing using IL2CPP for the last couple of months.
     
  3. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,775
    @ajohnson223

    Thanks for letting me know. Can you send me the full Xcode log from the project when the error happens in Xcode due to a missing MapFileParser executable? We should be able to correct both issues for the next patch release.
     
  4. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,775
    @ajohnson223

    Another work around is to copy the MapFileParser utility from an OSX editor installation into that directory (Editor\Data\Tools\MapFileParser\) in the Windows editor installation. Meanwhile, we have a fix for this bug that should make it into the next patch release.
     
  5. Uber6

    Uber6

    Joined:
    Sep 30, 2013
    Posts:
    25
    Hello. I just stumbled upon the same problem with MapFileParser on 5.1.0p on Windows 8.1 (I like to build from windows to a remote location and then run on iOS from X-Code). I am going to try to apply the above workaround for now.
     
  6. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,775
    @Uber6

    Thanks for letting me know. This should be corrected in 5.1.1p1, which will be available in the next few days.
     
  7. John-Chen350

    John-Chen350

    Joined:
    Jan 14, 2015
    Posts:
    53
    I am building from an OSX machine and there are still some minor bugs concerning stacktrace in 5.0.3p2.

    p.s OSX editor sometimes cannot load assemblies without influence on compilation.
     
  8. Uber6

    Uber6

    Joined:
    Sep 30, 2013
    Posts:
    25
    Still the same for me on 5.1.1f1
     
    fprost likes this.
  9. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,775
    @Uber6

    The fix did not make it into 5.1.1f1, but it is in the next patch release, 5.1.1p1, which should be out today or tomorrow.
     
  10. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,775
    @John Chen

    Thanks for letting me know. Can you submit a bug report with a project that demonstrates this problem? We would like to have a look at it. Thanks.
     
  11. davisben85

    davisben85

    Joined:
    Feb 4, 2015
    Posts:
    1
    I am working only on OSX for both the creation of the xcode project and app/ipa. I am running 4.6.6p3 and the file is present in my build output, but I don't think it's valid. I get a Permission Denied error:


    .../IntermediateBuildFilesPath/Unity-iPhone.build/Release-iphoneos/Unity-iPhone.build/Script-033966F41B18B03000ECD701.sh: line 12: .../MapFileParser: Permission denied and it fails my build.

    I trimmed the paths down a bit to remove my environment specific information. Is this a known issue? I am building using batch mode.
     
  12. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,775
    @davisben85

    This is not a know issue. Maybe the MapFileParser is ending up with the wrong permissions after it is copied into the output directory. Can you take a look to see if it has the execute permission? If not we may have a bug where we need to set it correctly.
     
  13. John-Chen350

    John-Chen350

    Joined:
    Jan 14, 2015
    Posts:
    53
    I cannot reproduce it all the time. Mostly speaking it works fine. I've noticed that once due to my previous VB problem: it shows that some code in Standard Assets (shall be Effects right?) wronged but I have never referenced to it.
     
  14. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,775
    @John Chen

    Thanks, let me know if you find something that happens at least somewhat regularly. I suspect the issues is related to how the linker lays out the native code in the binary, so it may be difficult to reproduce in many cases.
     
  15. bigdaddy

    bigdaddy

    Joined:
    May 24, 2011
    Posts:
    153
    Now I'm confused. When I build with IL2CPP I don't get any stack traces. This is an example of what I get:

    *** loading to inventory: LXMXFCgLAlggQGMId210MhQDKB0FVCcHKht/Gi1zDxA3HUkNbCU2VSFjenMFFCkbGV4+FjBWK2Nsc0NdeBEfUiMrPRt/YzE+DRUFGx5FPAc3WjxjenMCHTsL


    (Filename: /Users/builduser/buildslave/unity/build/artifacts/iPhonePlayer-armv7-il2cppGenerated/UnityEngineDebug.cpp Line: 56)

    Should I be getting a full stack trace on Debug.Log statements? (That would be great)

    I'm using 4.6.7. Is there a flag or something that I missed?
     
  16. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,775
    @bigdaddy

    Yes, you should get a stack trace. If I use this script code:

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class NewBehaviourScript : MonoBehaviour {
    5.     void Start () {
    6.         First();
    7.     }
    8.  
    9.     void First() {
    10.         Second();
    11.     }
    12.  
    13.     void Second() {
    14.         Debug.Log("Here Josh");
    15.     }
    16. }
    I get the following output in the Xcode console:

    Here Josh
    UnityEngine.Debug:Internal_Log(Int32, String, Object)
    UnityEngine.Debug:Log(Object)
    NewBehaviourScript:Second()
    NewBehaviourScript:First()
    NewBehaviourScript:Start()
     
  17. bigdaddy

    bigdaddy

    Joined:
    May 24, 2011
    Posts:
    153
    @JoshPeterson - Now this is interesting... Two iPhones connected to MacBook Pro. Game built and run on iPhone 6+ and Xcode console displays this:

    *** loading to inventory: LXMXFCgLAlggQGMId210MhQDKB0FVCcHKht/Gi1zDxA3HUkNbCU2VSFjenMFFCkbGV4+FjBWK2Nsc0NdeBEfUiMrPRt/YzE+DRUFGx5FPAc3WjxjenMCHTsL
    UnityEngine.Debug:Internal_Log(Int32, String, Object)
    UnityEngine.Debug:Log(Object)
    Game.InventoryDBFactory:Load(String)
    System.Action`1:Invoke(GcLeaderboard)
    AIS.MessageKit.Messenger`1:Broadcast(MessageTypes, VirtualItemReward)
    GameVarsLoader:InventoryGameVarLoaded(AISGameVar, PResponse)
    System.Action`2:Invoke(AISGameVar, PResponse)
    <SendRequest>c__Iterator18`1:MoveNext()


    (Filename: /Users/builduser/buildslave/unity/build/artifacts/iPhonePlayer-armv7-il2cppGenerated/UnityEngineDebug.cpp Line: 56)

    Click the Stop button, change drop down to point to the iPhone 5 and running it, the XCode console displays this:
    *** loading to inventory: LXMXFCgLAlggQGMId210MhQDKB0FVCcHKht/Gi1zDxA3HUkNbCU2VSFjenMFFCkbGV4+FjBWK2Nsc0NdeBEfUiMrPRt/YzE+DRUFGx5FPAc3WjxjenMCHTsL

    (Filename: /Users/builduser/buildslave/unity/build/artifacts/iPhonePlayer-armv7-il2cppGenerated/UnityEngineDebug.cpp Line: 56)
     
  18. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,775
    @bigdaddy

    Is the iPhone 5 a 32-bit device (i.e. and iPhone 5 or 5c, not a 5s)? If so, that might explain the difference. This really looks like something we should investigate here. Can you file a bug report?
     
  19. begray

    begray

    Joined:
    May 9, 2013
    Posts:
    6
    Hi, Josh.

    Is it possible to have line numbers in stack traces in projects compiled with il2cpp?

    Code (CSharp):
    1. UnityEngine.Debug:Internal_Log(Int32, String, Object)
    2. UnityEngine.Debug:Log(Object)
    3. NewBehaviourScript:Second()
    4. NewBehaviourScript:First()
    5. NewBehaviourScript:Start()
    Is nice, but it was a lot better with mono. Line numbers are very useful, especially when you're trying to debug using crash reports from HockeyApp.

    Code (CSharp):
    1.  
    2. NullReferenceException
    3.   at UnityEngine.EventSystems.UIBehaviour.IsActive ()
    4.   at UnityEngine.UI.Graphic.SetVerticesDirty ()
    5.   at UnityEngine.UI.Text.set_text (System.String value)
    6.   at LedLifeUnit.HandleLevelChanged (Int32 newLevel) (at Unit/LedLifeUnit.cs:71)
    7.   at EntityExperience.set_CurrentLevel (Int32 value) (at Common/EntityExperience.cs:24)
    8.   at UnitsRaceExperience.SetUnitsLevel (.UnitData unitData, Int32 level) (at Player/UnitsRaceExperience.cs:225)
    9.   at UnitsRaceExperience+Race.LevelUpNow () (at Player/UnitsRaceExperience.cs:129)
    10.   at TrainingRoomController.OnHurryConfirm (Boolean perform, .Race raceExp, System.Func`1 showPredicate) (at Building/Training Room/TrainingRoomController.cs:509)
    11.   at TrainingRoomController+<FinishTraining>c__AnonStorey125.<>m__D2 (Boolean peform) (at Building/Training Room/TrainingRoomController.cs:483)
    12.   at PayConfirmationDialog.OnOk () (at NGUI/PayConfirmationDialog.cs:150)
    13.   at UnityEngine.Events.InvokableCall.Invoke (System.Object[] args)
    14.   at UnityEngine.Events.InvokableCallList.Invoke (System.Object[] parameters)
    15.   at UnityEngine.Events.UnityEventBase.Invoke (System.Object[] parameters)
    16.   at UnityEngine.Events.UnityEvent.Invoke ()
    17.   at UnityEngine.UI.Button.Press ()
    18.   at UnityEngine.UI.Button.OnPointerClick (UnityEngine.EventSystems.PointerEventData eventData)
    19.   at UnityEngine.EventSystems.ExecuteEvents.Execute (IPointerClickHandler handler, UnityEngine.EventSystems.BaseEventData eventData)
    20.   at UnityEngine.EventSystems.ExecuteEvents.Execute[IPointerClickHandler] (UnityEngine.GameObject target, UnityEngine.EventSystems.BaseEventData eventData, UnityEngine.EventSystems.EventFunction`1 functor)
    21.   at UnityEngine.EventSystems.EventSystem:Update()
    (I've removed most of environment specific parts of file paths)

    Is this possible with il2cpp? Am I missing something? Thanks.
     
  20. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,775
    @begray

    I think that this should be possible, but it is not something we've implemented yet for IL2CPP. Since the behavior differs from Mono, I would classify this as a bug. Can you submit a bug report? We an look at implementing it then. Thanks!
     
  21. begray

    begray

    Joined:
    May 9, 2013
    Posts:
    6
    ОК, I've filed a bugreport, case 722931
     
  22. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,775
    @begray

    Excellent, thanks!