MonoDevelop 4 (Xamarin Studio) Debugging for Unity


This weekend I took some time to try and port the MonoDevelop.Debugger.Soft.Unity addins to Xamarin Studio. As it turns out it wouldn’t work, even when the addin compiled and loaded, because it relied on functionality that was added to the base MonoDebugger.Debugger.Soft namespace by Levi Bard; this add-in is built with MonoDevelop/Xamarin so instead I elected to fork the MonoDevelop 4.0 project from github, reintegrate these changes and build a MonoDevelop 4.0 package with the Unity soft debugger included.

Refer to GitHUB if you are interested in the source.

GitHub: MonoDevelop fork, MonoDevelop.Debugger.Soft.Unity fork, DebuggerLibs, Boo, Boo-Extensions, Boo-MD-Addins, UnityScript

Update 2013-08-19 

The Add-In has been released on the MonoDevelop Add-In Alpha channel. You will need to enable this channel to install the plugin. Also there is a UnityUtilities plugin which will give you syntax highlighting for shader lab, cg, and quick access to the Script Reference (in the Help Menu).

Barring a few exceptions which you can safely ignore that will be resolved in a future release of MonoDevelop (changes were merged and just need to be released). The add-in works well in Unity 3.5.

Unity 4.0+ has a few issues that I am currently investigating. You must RUN the application before attaching the debugger, and detach before stopping the application or you will crash Unity. There seem to be minute differences in the way the debugging protocol is being used between Xamarin and MonoDevelop 2.0 at the heart of this (I think).

MonoDevelop-Unity Attach to Process Screen Shot 2013-05-18 at 17.22.00For those who are curious, this is the project I’ve been working on Globulous available on the OUYA, Android, and iOS.

 

80 thoughts on “MonoDevelop 4 (Xamarin Studio) Debugging for Unity

  1. Lszt

    Hi !
    I’m really interested by your project ! Have you build a windows exe ? I download your archive for windows but monodevelop.exe seems not work :(.

    Reply
      1. Lszt

        Mmm I try but it doesn’t work.
        Maybe it’s because on Mono website I grab the Mono 3.0.X with your link and I must grab the 4 (Xamarin) + Gtk 2.20 and not 2.12 as the one which is in the archive.

        Another thing, must I put your archive in a specific location ?

        Reply
        1. Lszt

          Finally I installed it with Unity.
          But I noticed some bugs (I use Windows 7 & Vista 64)

          - I can’t open only one instance of Xamarin with Unity. When I double-clic on a script, it opens another Xamarin instance.
          - Xamarin sometimes has its top bar (with tab foreach script) which is blocked and I can’t click or close each script. I must closed it then re-opened it.
          - Debugger sometimes throw a lot of exceptions and don’t allow me to debug with unity-debugger & Xamarin.
          I f I notice other thing, I can post them here but I don’t think you can solve them all due to the unofficial add-ins :(

          Reply
          1. Lukasz

            Hi, how actually did u install it and run?

            Because I have some problems with it…

            @Clifford : u are the greatest man ! :D

          2. admin Post author

            Windows? Yes, it seemed to work for me in my vm (OSX user, sorry). But it didn’t work at my office. The MonoDevelop 4.0.10 beta is available now, so I imagine they will be releasing it any time. Once it is released, you should be able to fetch the addin from the addin repository with no issues (give a day or two for me to publish the addin).

  2. Alexander Biggs

    Hey, this is awesome! One problem I’m having though is that the top menu bar is completely empty besides the bolded MonoDevelop section, which prevents me from attaching the debugger. Any idea what could be causing this?

    Reply
    1. Alexander Biggs

      Also, attaching the debugger by making a keyboard shortcut for it causes a crash if I start or stop the scene afterwards. It works fine as long as I attach the debugger after starting and detach before stopping. This is on Mac OS X 10.8.3.

      Reply
      1. admin Post author

        I’ll look into these issue over the next two weeks or so as I make everything into a portable add-in module.

        Reply
          1. admin Post author

            Thanks, I’ve not forgotten about it, I am currently the throws of finishing up a personal project.

  3. Tim Keating

    Hey, what’s going on with this? I’m interested in contributing to this process, and I’d rather not start from scratch, but it seems like you haven’t actually committed your changes to github yet — they both appear to be clean forks of their source repos. Unless of course I am misreading them somehow…

    Reply
    1. admin Post author

      Tim;

      Thanks for your interest. There is a branch in my MonoDevelop project called UnitySoftDebugger. It’s a small amount of work so far, but I am trying to reduce that amount of work I have to push back to the MonoDevelop project to complete the AddIn.

      I am currently in the process of finishing up a personal project which I think should take no longer than another 3 weeks of my time, then a couple of days of sleep, and then I can refocus on completing the add in.

      Reply
  4. cesarpo

    Any news about this?

    In Mountain Lion, the menu doesn’t appear, so is impossible to attach the debugger.

    I’m writing this while waiting for monodelop to reload the solution, lol

    Reply
  5. greg

    hey Clifford,

    Thanks for your efforts – Unity with MonoDevelop 2.x is horrible! I tried your build above (MonoDevelop-Unity-4.0.9.15.dmg) along with the current Xamarin Studio installs (XamarinStudio-4.0.9, XamarinStudio-4.0.10beta) on OSX 10.8.4 but none of them work unfortunately. The main application menu doesn’t appear when using your MonoDevelop-Unity-4.0.9.15 or XamarinStudio-4.0.9, and XamarinStudio-4.0.10beta fails to start with an “add-in MacPlatform,4.0″ error at launch. Hopefully things get fixed up soon and your add-in for debugging works… (and/or the Unity devs sort things out properly.)

    Reply
    1. admin Post author

      A quick search on Google shows that Xamarin studio has been having some odd issues with menu occasionally disappearing, the solution seems to be to uninstall Mono, and install the later (updated) version. Per this forum: http://forums.xamarin.com/discussion/3920/xamarin-studio-fail-mac

      Xamarin 4.0.10beta is also giving me problems, won’t launch… but it is a beta, hopefully this is resolved soon. Similarly, I am unable to even build addins for Xamarin 4.0.10 right now as their builder service seems to be offline. I’ll keep an eye on this so that hopefully shortly after 4.0.10 is working or released I can get the adding formally available.

      Reply
        1. admin Post author

          Yup!

          Bad news though, my changes didn’t get included in 4.0.10–I was mistaken when I checked the 4.0.10 branch on github, they should be in the 4.1 release though.

          MonoDevelop 4.1.0 beta is available, but their addin system isn’t configured for this version yet, as soon as the addin build bot comes online for 4.1 I will push it out if it doesn’t happen automatically.

          Sorry to for the confusion, just a little bit longer though.

          Reply
          1. greg

            Thanks, Clifford. I’m glad someone understands all this stuff… I just want to be able to edit and debug project code, etc. I have no idea how all the magic .net ide stuff under the hood works :)

  6. Esteban

    Hello there I just want to say great work and thanks a lot for sharing with the community.
    I’ve being looking for a better code editor for Unity quite some time without any luck, Xamarin seems to be very good, at least has all things I need the only thing is that I’m not able to get the debugger to attach the Unity process. I added the MonoDevelop.Debugger.Soft.Unity-unity-staging to Content/MacOS/lib/monodevelop/AddIns and I’m able to see the attach to process command under run in Xamarin but when the attach to process window opens there is not process to select.
    Is there anything I’m doing wrong?
    Is there a way that you can tell me the steps to get it to work?

    I would really appreciate your help. Thank again.
    Esteban Padilla

    Reply
    1. admin Post author

      If you have not also grabbed the source from MonoDevelop and rebuilt, MonoDevelop.Debugger.Soft.DebuggerSession is going to silently throw a NotImplementedException when you try to attach the debugger, as MonoDevelop never actually implemented Attach to Process.

      We either have to wait for MonoDevelop 4.1 which should incorporate all the changes I made and pushed back to MonoDevelop, or you will need to grab the MonoDevelop sources and rebuild to ensure that you have a compatible MonoDevelop.Debugger.Soft library.

      Reply
  7. Esteban

    Thanks so much for your reply I really appreciate.
    I tried to build monoDevelop following the instructions on:
    http://monodevelop.com/Developers/Mac_Support/Building_MonoDevelop_on_OS_X
    I ran ./configure and selected only Main, then I ran make and I got the errors:

    if test -d “.git”; then
    git submodule update –init –recursive || exit 1;
    fi
    Making all in external
    make -C monomac/src
    make: *** monomac/src: No such file or directory. Stop.
    make[2]: *** [all] Error 2
    make[1]: *** [all-recursive] Error 1
    make: *** [all-recursive] Error 1

    Google this without result so I decided to try building using monodevelop by opening the solution (Main.sln) also get many errors relate to: using Mono.Addins. Google these error also without result, it seems weird that this is only happening to me.

    These are the packages I had install on my mac.
    XamarinStudio-4.0.10-7.dmg
    MonoFramework-MDK-3.2.0.macos10.xamarin.x86.pkg

    Did you face this type of problems when you build Mono or do you have any ideas on how to approach this issues?
    Thank you again.
    Esteban

    Reply
      1. admin Post author

        Really hard to say… probably the best place to look is to open Console and check the Xamarin Studio log output. If something is crashing, it will usually report it there. Also check your addin manager to make sure that it says the module is loaded.

        Also, for clarity.. there isn’t a Unity debugging option so much as there is just a menu item called “Attach to Process” which is normally available in MonoDevelop.

        If you continue to have problems, could you get me any available information from the Xamarin log and what branch you built from MonoDevelop and email it to clifford.roche(at)–GMAIL–.com

        Reply
    1. admin Post author

      The beta is out, yes. But their addin repository is not yet building 4.1 modules yet. Also, when I tried this weekend to create an addin and load it myself it failed due to a bug in MonoDevelop itself. I’ll keep checking the beta weekly as Xamarin move fairly quickly on stabilizing.

      Reply
  8. Esteban

    Thank you again for you help I really appreciate.

    This is what I just did, I build using the https://github.com/cmroche/monodevelop link on your post, since I figured the debugger adding was not getting included and the problem could be that I was not using the correct fork. On this build the Attach to process is not showing up either, I look into the package content after I created the MonoDevelop.app but not adding with the Unity name is list there on MacOS/lib/monodevelop/AddIns so this makes me think they are not getting include on the build.

    Opening the Add-in Manager I was able to enable Utilities for use with Unity, this is a progress I think. This is the only add-in list for unity on the Add-in Manager.

    So my guest is that I’m not building the correct project since not Unity debugger add-in is listed under the Extras folder, perhaps is getting added during the build creation?

    Again I follow the instructions on: http://monodevelop.com/Developers/Mac_Support/Building_MonoDevelop_on_OS_X
    but I changed: git clone git://github.com/mono/monodevelop.git for git clone git://github.com/cmroche/monodevelop.git expecting the add-ins were include on this fork.

    The log is not giving me any error.

    Any ideas?

    Thanks again for you time and effort.
    Esteban

    Reply
  9. Pingback: Firestarter Games | MonoDevelop 4 (Xamarin Studio) Debugging for Unity

  10. Sean K

    Thank you so much for your efforts. I just installed MonoDevelop 4.0.12 on Windows 8, went to the add-in manager, and added the add-in from the alpha channel. As it tries to install, it says:

    “The installation failed!

    There was an error while scanning assembly: C:Program Files(x86)Xamarin StudioAddInsVersionControlSharpSvn-SASL21-23-Win32.dll”

    After this, if I click on the Unity Debugger in the options menu, I get the “an error has occured” dialog box.

    Any ideas on how to resolve this? Thanks again.

    Reply
    1. admin Post author

      Sounds like a dependency issue with your Xamarin install. I have not tried on Windows myself yet, but I suspect you may want to start with reinstalling Xamarin Studio.

      Reply
      1. Sean K

        Tried uninstalling, reinstalling, but still the same problem. I also tried downloading the SharpSvn file from another site, thinking it may be a corrupt file, but still the same problem. I even tried downloading the addin from addins.monodevelop.com and installing from file (as some people had suggested on another site with another addin), but still the same thing. Has anyone else tried installing on Windows?

        Anyway, appreciate the reply and for working on this project.

        Reply
        1. admin Post author

          SharpSVN is not linked to in the Unity Soft Debugger addin, this sounds fairly exclusively an issue with Xamarin. In MonoDevelop 4.0.11 they updated the SVN bindings to support svn 1.7 as I recall, you may want to consider filing a bug report.

          Reply
          1. Sean K

            Just wanted to give an update to my posts:

            Using Lukasz’s instructions below, I was able to get the debugger working on Windows 8 and Unity 4.2.

            Hoping the addin problem with Xamarin will be resolved in their future updates.

            Many thanks to you Mr. Roche for making this a reality.

          2. admin Post author

            Thanks for your support. I’ve started looking into the issue this weekend, from what I can see the Xamarin debugger works on Unity 3.5 without any issues, and the MonoDevelop debugger works on Unity 4.0+ without any issues. As such my current suspicion are minute differences to the debugging protocol (or order commands are called) between Xamarin Studio and MonoDevelop 2.

            To investigate this issue further I will have to capture and compare the network communication between the two debuggers and unity. The captures are done, but to really understand what is happening I will need to write a protocol dissector for Wireshark, a task that has also been recently started.

            The goal is to have this dissector complete on the upcoming weekend, and start looking at what is being sent on the wire. Then make changes to the add-in or MonoDevelop to emulate the older protocol.

          3. Sean K

            That sounds pretty complicated to me… it seems like it would take me quite a few years to get to that level of knowledge.

            It’s not that important, but is double-clicking an error in the console to open a script on that line a possibility with MonoDevelop 4+?

            Appreciate your time.

            Oh btw, have you seen the new live coding tool in the asset store called Livity? Seems pretty cool, but it’s not available for C# yet.

          4. admin Post author

            Livity, looks pretty interesting. Neat that the updates appear to be near realtime. There is another really cool tool on the Asset Store you should also check out if you like things that update in realtime, and it works in C#: Remote Tuning Tool, basically it works like a remote variable inspector, but lets you save your data when the game is running, even when running your game on iOS or Android.

            It is possible to get double click behaviours working, however in Unity you must use “Assets/Synch MonoDevelop Project” first, which will update your solution files and launch your selected IDE environment. Once you do this, contextual items start to point to the correct line in the file. You may need to make sure you have the “Editor Attaching” option enabled in your preferences as well, though I have not tested directly if this has any impact.

  11. Tim

    I just grabbed 4.0.12 and gave the alpha plugin a try – although I can connect and have had a little success debugging, I’ve found that Unity tends to crash either immediately or after a short while. The Unity version I’m using is 4.1.5, on OSX.

    I’ll try 4.2 later today.

    Reply
    1. admin Post author

      Thanks Tim!

      I tested this morning at work, and yes.. it crashed for me on Unity 4.1 and 4.2, which is odd since I don’t see any changes in their debugger in github for years. Hopefully not something hidden. In any case I opened an issue and will look into this over the weekend.

      You can follow it here:

      https://github.com/cmroche/MonoDevelop.Debugger.Soft.Unity/issues/1

      Currently though, the debugger work on 3.5 (what I use at home) and I am pretty sure it still works on 4.0, but I could not say for certain right now as it has been a little bit since I tested.

      Reply
  12. Relok

    Hi, I tried to install the 4.0.12 plus the alpha and beta unity addins (one for the debugger, the other for shaderlab) I couldn’t get to work any of them.

    This image summarize the problem:
    http://i.snag.gy/28KBE.jpg

    I can’t also get to work Syntax Highlighting or code completion for UnityEngine Namespace.

    Any idea on how to fix these problems ?

    Reply
      1. Relok

        Sorry, No I don’t have the 3.2.1 that’s for OSX, I’ve Windows 7 version, though I’ve not installed any Mono.

        I installed Gtk# for .NET, I’ll try with Mono for Windows, Gtk#, and XSP from the mono page you pointed.

        Reply
  13. Relok

    I Installed the 2.10.9 Mono for Windows (I’m on W7 x64), in the Options menu I’ve set Mono as the default Runtime in the options, but it never switch to it, It always says: “Xamarin Studio is currently running on Microsoft.NET”

    When trying to install the 2 Unity addins I always get the same error.

    Anyway do I need to setup custom Assembly Folders to point to a particular directory of the MonoDevelop Install(the one Installed By Unity) to get code completion for the UnityEngine namespace ?

    Reply
    1. admin Post author

      So it seems I get an plugin install error no matter what plugin I install in MonoDevelop 4.0.12 on Windows. I would think the install errors are a problem with the Beta. It seems though that installing the plugins, and restarting Xamarin, works… even despite the error. When I restart the plugins are loaded… I have not tested them as the plugins are known to make Unity 4.2 crash, but I will look into that this weekend.

      Reply
      1. Lukasz

        I solved this problem. Before launching Xamarin, I’ve removed VersionControl catalog from AddIns. Then install the plugins for Unity. After that I put VersionControl catalog back. Little hack but works.

        Also I’ve have many problems with debugging in Unity. (below two ways to reproduce crash)
        1.If I attach to process in Xamarin before the Editor is playing, launch Editor, makes crash for Unity.
        The problem is not present if I first launch Editor in Unity then make attach to process in Xamarin.
        2.If I’m debugging in Unity with Xamarin and stop the editor, makes crash in Unity.
        The problem is not present if I first detach in Xamarin and then turn off Editor.

        I’m working in Windows 7, Unity 4.0.1f2
        Xamarin Studio 4.0.12
        rest stuff – update.

        Reply
        1. admin Post author

          Thanks for this information. I think you have helped clarify some of the Unity 4.0 crashes people are getting with the debugger. I opened issues on the GitHub page and will look into this today

          Reply
        2. Tomas

          Uff .. I cannot seem to find “Unity Soft Debugger” plugin in the Xamarin alpha channel. The only plugin I get is the Unity utilities.

          Do you know the name of that plugin for debugging ?

          Thanks!

          Reply
  14. senritsu

    Did you also manage to get Boo support working by any chance?
    I saw that you also cloned the boo and boo addin repositories, but i couldn’t figure out how to include them with MonoDevelop 4.0.12

    Reply
    1. admin Post author

      No, not yet. There are some notable problems with Boo. The project really isn’t being maintained any more and the Boo and Unity Script extensions for MonoDevelop were written in Boo and no longer compile due to what appear to be compatibility issues with Boo with newer .net libraries. I think the boo and unity script extensions for MonoDevelop will simply need to be rewritten in C#, unfortunately that will take time, especially since there are no scripts to convert Boo to C# automatically.

      Reply
      1. senritsu

        I see, that’s too bad D:
        I really prefer using boo over C# for it’s concise pythonic syntax, but there really is not a single good IDE for it available, i had hoped maybe MonoDevelop 4 might fix that.

        Thank you for your information, and great job on the addin :)

        Reply
  15. Dominik

    Hi, first of all: Awesome what you’re doing there for us :-)
    Secondly – it’s sadly not working for me. I switched to alpha channel and installed the add-in, but Unity (4.2, latest version) is always crashing (and yes, I’m attaching the debugger after starting to “play” in Unity. Have you had already the time to investigate this problem?

    Reply
    1. admin Post author

      Should be available again, for 4.0 only though… I have not built for 4.1. I’ll do that this weekend. There was an error in their automated build service and it gave up and didn’t rely NY plugin, I guess that is why it got unpublished.

      Reply
  16. Stephen

    Well I got it to work.

    When I tried to install it said it had an error:
    “The installation failed!

    There was an error while scanning assembly: C:Program Files(x86)Xamarin StudioAddInsVersionControlSharpSvn-SASL21-23-Win32.dll”

    But I started the game, attached the debugger, added a checkpoint, and it successfully hit it. I then looked at some variable data, and stepped through the code, and all looked fine. There is an issue that you have to only attach after you hit Play in Unity, and hit Play again to stop the game only after you detach the debugger, (otherwise Unity crashes), but it seems to actually work fine.

    I’m not sure I’ll keep it, since the extra two steps annoy me, and MonoDevelop 4.0 has a couple other issues (like not loading the UnityScript projects/assemblies), but I thought I’d mention it in case others are thinking about trying it.

    Note that I got it working using the latest version of Unity (4.2.0f4), and the latest stable version of MonoDevelop (4.0.12).

    Reply
  17. gfgruvin

    Hi,

    I have been waiting for this plug-in for a long time. Thanks, for all your hard work. I tried it out with Unity 4.2 on my mac. I am able to attach to the Unity process. I then set the break point in the code. The debugger places me at the end of the code block {} in which I set the break point. If I step one line, the debugger moves to the line of my break point. If I step once more, the debugger continues through the code as if I had just hit the play button. I had high hopes for this. Hopefully this feedback can help you out.

    Mac OS 10.7.5
    Unity 4.2.0f4
    Xamarin Studio 4.0.12

    Reply
    1. xiaopihang

      so you have resolved the problem below ?
      Unity 4.0+ has a few issues that I am currently investigating. You must RUN the application before attaching the debugger, and detach before stopping the application or you will crash Unity.

      Beside that, I that is so exciting add-on.

      Reply
      1. admin Post author

        No, since the very shortly upcoming Unity 4.3 release will ship with and support MonoDevelop 4 I am waiting for that release to see if the bug still exists. As the bug is in mono, it is reasonable to assume that they will have fixed the issues by the time Unity 4.3 releases.

        Reply
        1. xiaopihang

          > it is reasonable to assume that they will have fixed the issues by the time Unity 4.3 releases.
          I seem to the problem still exists in Unity 4.3 which I have upgrade my unity version.

          Reply
  18. Tim Keating

    When it crashes on me, here’s the error I’m seseing in the Unity logfile:

    * Assertion at debugger-agent.c:1912, condition `tls’ not met

    That looks to me like an error from the Mono runtime… it seems the fix ought to be as simple as enabling TLS for all outbound debugger connections. I don’t have the code for the plugin in front of me, but does it perhaps try to connect over an unsecured socket or something, then only enable TLS if it is rejected?

    Reply
    1. admin Post author

      Unfortunately, in this instance, TLS refers to Thread Local Storage, not Transport Layer Security. Actually the debugging connection is unencrypted. Basically when the mono end of the debugger receives certain events it is asserting that the TLS state is invalid. The best I can figure is that this is probably a bug in the Unity mono implementation, but it isn’t practical for me to ask them to support my plugin. Realistically I should be able to better emulate the older debugger protocol to address this.

      Though, if you caught the Unite 2013 keynote, Unity will be releasing MonoDevelop 4 with Unity 4.3. My plugins may start working again, also they may be largely unnecessary for Unity 4 users–though I will maintain them for Unity 3.5 users (like myself).

      I’m going to hold off further work on my debugging utilities until Unity 4.3 then check to see if the bug exists. Good chance the bug in their mono implementation is fixed by that point.

      Reply
      1. Tim Keating

        …but you already knew that. Should have refreshed the page before I replied to my own post!

        Actually, I missed them talking about supporting MonoDevelop 4 with 4.3. Exciting!

        Reply
  19. Marc Tanenbaum

    Thanks for getting this into an easily installable plugin. Working pretty well for me with:
    Unity 4.2.1
    Xamarin 4.0.12
    OSX 10.8.4

    The work you’re doing is a huge benefit to the Unity3D community. Much appreciated!

    Reply
  20. jantje

    Has anyone got this working in Mavericks OS X 10.9 and unity 4.2.2? I currently use the 2.8.2 version of MonoDevelop, and Unity crashes whenever it hits a breakpoint in Mavericks (and had had no issue previous to updating my machine). I’d love to try this solution, but will just have to wait until 4.3 if it wouldn’t work.

    Incidentally, what is the current versions of the various part that are recommended to get this working on a Mac?

    It sounds awesome!

    Reply
    1. admin Post author

      Xamarin Studio 4.0.13 (get it at http://www.monodevelop.com), I have not yet tested Xamarin 4.1.

      I have not yet tested Mavericks and don’t know if it works, though I plan on upgrading this weekend. I would suspect thought that if Unity crashes in Mavericks when you hit breakpoints, that the same will happen with my plugins in Xamarin Studio as they work nearly identically.

      Reply
    1. admin Post author

      Yes, unfortunately Mavericks is definitely causing crashes for me, both using their MonoDevelop and Xamarin Studio.

      I think we’re going to have to wait for either a fix from Unity. In my opinion, Unity 4.3 should be releasing any day now anyway.

      Reply
  21. Pingback: Getting Started with Unity3D here is the 1 stop of shop of great resources - Microsoft UK Faculty Connection - Site Home - MSDN Blogs

  22. Pingback: Mohamed Emam | Windows Game Development With Unity3D

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>