Search Unity

Resolved Line numbers in exceptions in release builds

Discussion in 'Editor & General Support' started by Guedez, Jan 13, 2022.

  1. Guedez

    Guedez

    Joined:
    Jun 1, 2012
    Posts:
    827
    How do I do that?
    I work on a two man team that can't spend ages testing development builds and I don't want the development build console or "dev build" watermark. All I want is my release build to show line numbers on it's exceptions. Copying the "Assembly-CSharp.pdb" don't work, Copy PBD files does nothing besides increase my build size (What is that even meant to accomplish? My stack traces still lack line numbers)
    upload_2022-1-13_12-15-8.png
    I want to know, how can I make a "Not Development Build" whose stack traces contain line numbers, that's all I need and want.
     
    achimmihca likes this.
  2. Guedez

    Guedez

    Joined:
    Jun 1, 2012
    Posts:
    827
    Turns out I've managed to make it work. Here's how:
    Turn on Copy PDB files. Although that itself does not solve the issue, it is crucial, as that option will create a folder in *YourProject*/Temp/ManagedSymbols with the PDB files.
    Then run this script or similar:

    Code (CSharp):
    1. using System;
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using System.IO;
    5. using System.Linq;
    6. using UnityEditor;
    7. using UnityEditor.Callbacks;
    8. using UnityEngine;
    9.  
    10. public class CopyFoldersPostBuild {
    11.     [PostProcessBuild(1)]
    12.     public static void OnPostprocessBuild(BuildTarget target, string pathToBuiltProject) {
    13.         pathToBuiltProject = Path.GetDirectoryName(pathToBuiltProject) + "/";
    14.         DirectoryCopyPBD("Temp/ManagedSymbols", pathToBuiltProject + "Everyday Life Edengrall_Data/Managed/", pathToBuiltProject);
    15.     }
    16.    
    17.     private static void DirectoryCopyPBD(string sourceDirName, string destDirName, string pathToBuiltProject) {
    18.         if (File.Exists(pathToBuiltProject + "lib_burst_generated.pdb")) {
    19.             File.Delete(pathToBuiltProject + "lib_burst_generated.pdb");
    20.         }
    21.  
    22.         if (File.Exists(pathToBuiltProject + "UnityPlayer_Win64_mono_x64.pdb")) {
    23.             File.Delete(pathToBuiltProject + "UnityPlayer_Win64_mono_x64.pdb");
    24.         }
    25.  
    26.         if (File.Exists(pathToBuiltProject + "WindowsPlayer_Master_mono_x64.pdb")) {
    27.             File.Delete(pathToBuiltProject + "WindowsPlayer_Master_mono_x64.pdb");
    28.         }
    29.  
    30.         if (File.Exists(pathToBuiltProject + "WindowsPlayerHeadless.pdb")) {
    31.             File.Delete(pathToBuiltProject + "WindowsPlayerHeadless.pdb");
    32.         }
    33.  
    34.         DirectoryInfo dir = new DirectoryInfo(sourceDirName);
    35.         DirectoryInfo dst = new DirectoryInfo(destDirName);
    36.         if (!dir.Exists) {
    37.             throw new DirectoryNotFoundException(
    38.                 "Source directory does not exist or could not be found: "
    39.                 + sourceDirName);
    40.         }
    41.  
    42.         FileInfo[] files = dir.GetFiles();
    43.         foreach (FileInfo file in files) {
    44.             string tempPath = Path.Combine(destDirName, file.Name);
    45.             file.CopyTo(tempPath, true);
    46.         }
    47.     }
    48. }
    This code will copy the PDB files from the TEMP folder and delete the useless PDB files in the build root that do nothing.
     
    lumeriith, Wappenull and achimmihca like this.
  3. achimmihca

    achimmihca

    Joined:
    Feb 13, 2016
    Posts:
    283
    This is nuts! Knowing where a bug occurs is crucial for production support.
    And Unity does not provide an easy way to include debug symbols in the built game?

    Your script does not work for me. Temp/ManagedSymbols is empty in my project after build (Unity 2022.2.2f1).
     
  4. Guedez

    Guedez

    Joined:
    Jun 1, 2012
    Posts:
    827
    I am on 2020.3, so it has probably changed
     
  5. Wappenull

    Wappenull

    Joined:
    Oct 29, 2013
    Posts:
    51
    @achimmihca That hack is huge for me, I can now release my game in release build, get rid of the "Dev Build" watermark and still get line number for Cloud Diagnostic report.

    Disclaimer: Reader be aware that this is black magic hack, not sure if copying those will result in downside or consequence in the long run. Do it at your own risk.

    2022.1.15 here
    I found it to be here instead
    UNITYPROJECT\Library\Bee\PlayerScriptAssemblies

    Copying this to Game's Data/Managed will make the standalone build to be able to output line number even on the release setting, in my case enough for when error/exception happened and sent to cloud diagnostic.

    Screenshot showing what being output to Cloud Diagnostic report, before/after the hack.
    upload_2024-1-24_14-28-25.png

    What's being output to player.log after applying this hack:
    upload_2024-1-24_14-29-16.png

    About Copy PDB files option
    I left it off, my guess is that it copy those PDB you mentioned on the game root.
    This is likely for debugging the game EXE using native debugger (x86-64 assembly language) and could be used when reporting EXE hard crash, which could happen in C++ code or C++ plugin. So if you want hard crash, you probably have to turn this on, but at cost of +20 +30 MB to build size.

    PDB in Data/Managed which are for C# mono backend is what we are aiming in this case to output script line number in player log, so note to reader that you should not be confused with those PDB in root folder which serve another purpose.
     
    Last edited: Jan 24, 2024