How can I attach to a crashing standalone player, see stack trace?

Unity 2020.2.3, Windows 10, using Visual Studio 2019. When I “Build and run” my app runs for a little while but then crashes:

Once that green bar fills up it just terminates. I know windows used to offer me to Debug / Retry / Cancel. How can I attach to a crashing app? I know I can modify the build settings to wait for a debugger before starting, but I want to attach to a crash and see what caused it. or at least a stack trace!

I remember back in the Windows XP days there used to be a “Debug / Retry / Cancel” option when an app crashes. I haven’t seen that in a while. is this something I need to configure on windows?

PS: I found the cause of the crash (my code throwing an exception) but that’s even more frustrating because the exception callstack/message are nowhere to be seen.

I simplified things down to see if it’s some burst/x64/il2cpp setting that makes it non-logging. A basic Mono x86 build does not provide crash information either. I could really use some help here. Having standalone builds unable to log/attach when crashing is extremely troubling.

Here are my settings.

a monobehavior with:

    void Start()
    {
        instance = this;
#if UNITY_STANDALONE && !UNITY_EDITOR
        UnityEngine.Diagnostics.Utils.ForceCrash(UnityEngine.Diagnostics.ForcedCrashCategory.Abort);
#endif
    }

build settings:

6812435--791027--upload_2021-2-7_17-43-50.png

Project Settings, Burst disabled:
6812435--791030--upload_2021-2-7_17-44-52.png

Project Settings, Player: Mono with as much debug enabled as possible:

The crash callstack should get printed out to the log. Is it not?

Yes: https://docs.microsoft.com/en-us/visualstudio/debugger/debug-using-the-just-in-time-debugger?view=vs-2019

1 Like

Thank you for the reply Tautvydas! That link really helped. The regkey edits it mentions made the debugger prompt start appearing. However Not for Utils.ForceCrash(ForcedCrashCategory.Abort);. I had to switch to something like ForcedCrashCategory.MonoAbort for the debug attach prompt to show up.

However, when I attach to the process, I don’t get anything useful to debug:

6817508--791837--upload_2021-2-9_0-34-47.png

Is there any way to debug into my game code at this point?

Re Crash callstack in log: I actually didn’t know about that! I found the docs pointing to where it is for the Player: https://docs.unity3d.com/Manual/LogFiles.html and yep, inside that is a stacktrace with 0x000001E5E5710873 (Mono JIT Code) [C:\repos\unity\2021-wip\block-spawn-test\Assets\Scripts\_editor_bridge.cs:59] _editor_bridge:crashTest (int)

So if there isn’t a way to effectively attach to the crashing process, at least the crash log will be useful.

Thank you again for your help.

In Unity, you have two types of code:

  1. Native code - Unity’s runtime and native plugins (generally written in C++);
  2. Managed code - all your C# scripts and managed plugins.

Each of them has its own debugger: managed debugger and native debugger. Managed debuggers allow debugging C# code, while native debuggers allow debugging native code.

In general, managed code cannot bring the game down, even if it throws an exception. Therefore the only things that can make the game crash is native code. Since managed code cannot bring down the game, managed debuggers generally cannot capture crashes. That leaves you with native debuggers, and that’s what you are using in your screenshot.

When looking at a native debugger, you will not immediately be able to see your C# code callstack.

If you’re using Mono scripting backend (like in the screenshot you showed), C# code will show up as bare memory addresses, for instance “000001e5e5710af()”. If you double click on a frame with “mono-2.0-bdwgc.dll”, and load symbols for it, it will enable you to call functions from that DLL from the debugger watch window. If you are in this debugger state, and type in “mono_pmip(0x0001e5e5710af)”, it will tell you the managed function name (the hex number passed to the function is taken from the call stack window).

If you’re using IL2CPP scripting backend, you will see the C++ code that was generated from the original C# code, and you should be able to tell which function it is and where in the function you are, since the original C# source code is emitted as C++ comments.

I can’t load symbols for the “000001e5e5710af()” managed frame. It seems that all symbols are loaded, yet nothing shows up there. Is there a page documenting how to do this? Maybe I need to install some mono sdk?

The documentation is here (note that mono.dll was renamed to mono-2.0-bdwgc.dll): Unity - Manual: Windows debugging

You need to load symbols for mono-2.0-bdwgc.dll, not “000001e5e5710af()”. Make sure to point it to Unity’s symbol server (https://symbolserver.unity3d.com)