Search Unity

UnityVS Debugging DLLs

Discussion in 'Scripting' started by Leviathan1753, Mar 15, 2015.

  1. Leviathan1753

    Leviathan1753

    Joined:
    Feb 15, 2014
    Posts:
    13
    Hello all,
    I have a question about debugging DLLs using UnityVS and VS. People are saying UnityVS can debug DLLs, as long as the PDB files are there for it to process. However, I'm not able to debug my DLLs when running from the unity scene. When I get to any DLL code, it can't step in, but rather just steps over the line.

    I'm wondering:
    1) If anyone is able to step into DLL code while debugging a unity scene using UnityVS
    2) Does anyone know what I could be doing wrong?

    Here's my setup:
    I've got the latest Unity Pro 5.0 free version, VS 2013, UnityVS.

    I've got a few C# projects that output DLLs and PDBs. I have the projects copy them both into my Unity's assets folder after build. Unity processes them after building, and the DLLs are usable in code of my Unity Project, the scene runs, etc.

    I then try to debug my unity scene. I open VS through UnityVS's menu in Unity. I put in some breakpoints, start Debug mode, start my unity scene.

    It hits the breakpoints outside my DLL code, and then i start stepping through. As soon as I encounter a line calling DLL code, it can only step over, but not in.

    Any ideas?

    Thanks!
    -Lev
     
  2. nixius

    nixius

    Joined:
    Mar 4, 2015
    Posts:
    37
    Bumping this as I'm interested in knowing too!
     
  3. nixius

    nixius

    Joined:
    Mar 4, 2015
    Posts:
    37
    http://unityvs.com/documentation/dll-debugging/

    For unity5 for now (until UnityVS2.0 comes along it seems)
    http://unityvs.com/news/2015/03/11/unity-5-visual-studio-tools-unity-2-0-preview/

    From command prompt I ran

    "C:\Program Files\Unity\Editor\Data\MonoBleedingEdge\bin\cli.bat" "C:\Program Files\Unity\Editor\Data\MonoBleedingEdge\lib\mono\4.5\pdb2mdb.exe" "C:\Program Files\Unity\Editor\Data\MonoBleedingEdge\lib\mono\4.5\MyDLL.dll"

    Which generated an mdb file in the \4.5\ directory, which I then copied to my \plugins\ directory along with my dll (and pdb, although I doubt it's needed) and it worked! You need the dll fle and pdb in the same dir to create the mdb

    To avoid any broken link issues, this is a quote taken from the UnityVS page:

    my setup: Unity5, windows 7, Visual Studio 2013 Pro, UnityVS. Hope this helps.
     
    Last edited: Mar 16, 2015
  4. Leviathan1753

    Leviathan1753

    Joined:
    Feb 15, 2014
    Posts:
    13
    You are a gentleman and a studmuffin. Thanks!

    One last remaining annoyance with the setup is following a reference to a DLL's function shows the metadata "summary" instead of bringing you to the source code itself.

    Thanks again!
     
  5. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,242
    Hello,

    I was using pdb2mdb without problems for a long time, but now that I changed computer it doesn't seem to work at all anymore. Even running it from command line generates this error:
    Code (csharp):
    1. Microsoft.Cci.Pdb.PdbDebugException: Unknown custom metadata item kind: 7
    Did something change with the latest version of Unity (5.1)? I'm on Windows 8, using Visual Studio Community 2015. Any help would be greatly appreciated, since I'm in big troubles here.
     
  6. sveilleux1

    sveilleux1

    Joined:
    Sep 3, 2015
    Posts:
    4
    Hi,

    I have the same problem but using the vanilla Monodevelop IDE shipped with Unity.
    I can launch the debugger but can't step inside the source code of my external dll.

    I'm using Unity 4.7.8 on OSX

    I created a simple test.dll to get a better idea of what the problem could be. This dll is created under Visual Studio 2015 using .net 3.5. I used pdb2mdb.exe shipped with Unity 4.7.8 Windows version to generate the mdb file from test.dll

    call "C:\Program Files (x86)\Unity\Editor\Data\MonoBleedingEdge\bin\cli.bat" "C:\Program Files (x86)\Unity\Editor\Data\MonoBleedingEdge\lib\mono\4.0\pdb2mdb.exe" "$(TargetDir)\$(TargetName).dll"

    The mdb file is correctly generated. I copied the .dll.and mdb (and even the pdb to be sure) files into my Unity project Assets/Plugins folder, refreshed/sync monodevelop solution and made sure the referenced dll is the good one. Also try to reload Unity project.

    But I can't step into the source code of the external dll when debugging. When I press the step-in button it stays on the same line and the line highlighting turns from yellow color to green.
     
  7. Leviathan1753

    Leviathan1753

    Joined:
    Feb 15, 2014
    Posts:
    13
    Hmm, I'm on the latest Unity version, and it seems alright using the 4.5 "bleeding edge" mdb generator. Not totally sure?
    Here's my script:
    xcopy "$(TargetPath)" "$(SolutionDir)..\Unity Project\Assets\DLLs\" /Y
    xcopy "$(TargetDir)$(TargetName).pdb" "$(SolutionDir)..\Unity Project\Assets\DLLs\" /Y

    "C:\Program Files\Unity\Editor\Data\MonoBleedingEdge\bin\cli.bat" "C:\Program Files\Unity\Editor\Data\MonoBleedingEdge\lib\mono\4.5\pdb2mdb.exe" "$(SolutionDir)..\Unity Project\Assets\DLLs\$(TargetName).dll"


    @sveillux
    Sorry, I dont use monodevelop much at all. Maybe start a dedicated thread about monodev instead?

    Also Visual Studio Community is free now, so you could always just switch. I think Unity + Microsoft are getting all buddy buddy and streamlining things pretty well.
     
  8. Leslie-Young

    Leslie-Young

    Joined:
    Dec 24, 2008
    Posts:
    1,148
    Yes. You started using VS2015 :)

    I'm stuck on VS2013 cause I can't generate MDBs when using VS2015 to build some of my DLLs (not all cause the error mind you) Get the error

    Microsoft.Cci.Pdb.PdbDebugException: Unknown custom metadata item kind: 7
     
  9. Leslie-Young

    Leslie-Young

    Joined:
    Dec 24, 2008
    Posts:
    1,148
    I think I figured it out. Seems to work. I build DLLs with Visual Studio 2015 and can generate the MDB so that I get line numbers for error messages in the console.

    Get latest Mono, install it and ....

    "C:\Program Files (x86)\Mono\bin\pdb2mdb.bat" "path_to_some.dll"

    or here is an example from one of my projects' post-build event command lines

    echo f | xcopy "$(TargetPath)" "D:\DevUnity\_SOURCE\_bin\" /Y
    echo f | xcopy "$(TargetDir)$(TargetName).pdb" "D:\DevUnity\_SOURCE\_bin\" /Y
    echo f | "C:\Program Files (x86)\Mono\bin\pdb2mdb.bat" "D:\DevUnity\_SOURCE\_bin\$(TargetFileName)"
    echo f | xcopy "D:\DevUnity\_SOURCE\_bin\$(TargetFileName)" "D:\DevUnity\TileEd2\Assets\plyoung\plyLib\runtime\" /Y
    echo f | xcopy "D:\DevUnity\_SOURCE\_bin\$(TargetFileName).mdb" "D:\DevUnity\TileEd2\Assets\plyoung\plyLib\runtime\" /Y
     
  10. rluks

    rluks

    Joined:
    Jul 16, 2015
    Posts:
    7
    It works with latest Mono. Thanks Leslie
     
  11. cristivp

    cristivp

    Joined:
    Nov 1, 2012
    Posts:
    6
    I've generated the MDB using the latest Mono, and I'm able to set breakpoints and debug, but I can't step into a function call from the DLL code.

    Any ideas?

    I'm on Unity 5.3.5, Visual Studio 2015, UnityVS 2.0, Windows 10

    UPDATE: If I build the DLL in MonoDevelop and use MonoDevelop to debug I can step into the DLL code just fine. So it must be something with Visual Studio
     
    Last edited: Jul 1, 2016