Search Unity

Debug with Unity released source code

Discussion in 'Editor & General Support' started by hicksplace, Jul 7, 2018.

  1. hicksplace

    hicksplace

    Joined:
    Sep 10, 2017
    Posts:
    4
    I am trying to debug into the Unity Editor with the recent released unity source code and VS2017.
    As an experiment, I am trying to set a breakpoints in the Help->About Unity code.

    The breakpoint always displays this friendly message:
    "The breakpoint will not currently be hit. Unable to find a corresponding location"​

    Installed:
    Unity 2018.1.6f1
    Downloaded branch 2018.1 from GitHub.
    https://github.com/Unity-Technologies/UnityCsReference

    Things I’ve tried:

    1. Open source code solution and attached to Unity debugger:
    In VS2017
    open projects/CSharp/UnityReferenceSource.sln
    ‘Attach Unity Debugger’
    Set breakpoint in UnityEditor->Editor->Mono->GUI->AboutWindows.cs​
    In Unity
    open Help->About Unity​
    Nothing happens​

    2: Compile and replace UnityEditor.dll
    In VS2017
    UnityEditor properties
    Change TargetFramework to: Unity 3.5 .net full Base Class Libraries
    Compile UnityEditor
    Copy compiled UnityEditor.dll to Unity directory in c:\Program Files​
    Run Unity
    Unity crashes​

    3: Make UnityEditor.dll debuggable
    Tried some techniques from this article:
    https://astrangergravity.com/writing/2018/debugging-into-unitys-internals

    convert the UnityEditor.dll to UnityEditor.il
    convert back to UnityEditor.dll with /debug enabled.
    C:\> ildasm UnityEditor.dll /out=UnityEditor.il
    C:\> ilasm /dll /debug /Out:UnityEditor.dll UnityEditor.il

    There already exists a UnityEditor.dll.mdb file so I tried with that. Didn't work

    Took the UnityEditor.pdb from the compiled source code and converted it to UnityEditor.dll.mdb and coped into Unity directory. Again, debugging doesn't work.
    Much appreciate any help
     
  2. DreamPower

    DreamPower

    Joined:
    Apr 2, 2017
    Posts:
    103
    I thought the source code was only for the C# bits, that they didn't include any of the native C++ code. Because Unity doesn't want anybody compiling it for any reason, they make a big point about "this is only for reference"
     
  3. hicksplace

    hicksplace

    Joined:
    Sep 10, 2017
    Posts:
    4
    True, but shouldn't there still be a way to step through the C# bits with a debugger? For me, the best way to 'reference' code is to step through it's execution with a debugger.

    My intent is not to change or recompile the code. That was just a failed experiment to see if I could debug that way.

    I am hopeful this isn't as hard as it seems, and someone else has figured this out.
     
  4. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,610
  5. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,931
    Peter77 likes this.
  6. hicksplace

    hicksplace

    Joined:
    Sep 10, 2017
    Posts:
    4
    So should I infer that there not a way to link the debugger to the editor?
     
  7. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    @hicksplace What problem are you trying to diagnose?
     
  8. hicksplace

    hicksplace

    Joined:
    Sep 10, 2017
    Posts:
    4
    None ... at least not yet.

    Just looking to get an understanding of the Unity Editor by following the code execution in the debugger. I find it painful trying to figure out code just reading in linearly.
     
  9. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,931
    You can debug script code from your project that is running in the Unity editor. You can't debug the Unity C# code though.
     
  10. OndrejP

    OndrejP

    Joined:
    Jul 19, 2017
    Posts:
    304