Debugging C# applications on Linux…

Now you might be thinking that I’ve filed this under the wrong category but I actually really am here to talk about debugging C# applications on Linux (and on Eclipse, no less). Maybe Microsoft (or Novell?) will provide some .NET tooling for Eclipse in the future, but I suppose we’re just going to have to make do with what we’ve got for the time being from what Harald has done thus far on Emonic.

In any case, let’s get this party started.

  1. Grab the Mono 1.9 ‘Other Linuxes’ installer binary from their website.
  2. Run the installer. You’ll probably need to use chmod +x on it first though. This guide assumes that you did not opt in on modifying your ~/.bashrc file. I will assume that you installed it into some place like ~/mono-1.9/.
  3. Start Eclipse up and point it at a new workspace. You mise well start fresh, right? Note that this has been tested on Eclipse 3.2.2 but since we don’t make any internal API calls, future versions should be a-okay also.
  4. Checkout edu.arizona.cs.mbel2, emonic.base, org.emonic.debug.core, org.emonic.debug.ui, org.emonic.debugger, emonicinformator, and Emonic.DebugFrontend from SourceForge. You can use the handy CVS “path” below to fill up the wizard faster:
    :pserver:anonymous@emonic.cvs.sourceforge.net:/cvsroot/emonic
  5. Now we need to change the DebugFrontend.build build file located in the Emonic.DebugFrontend project. Point its debuggerLibs property to /home/username/mono-1.9/lib/mono/mono-debugger/.
  6. Next, we need to change the Emonic.DebugFrontend project’s build_release.sh file’s TARGET variable. Point that at /home/username/workspacename/emonic.debugger.
  7. We also need to change the build_release.sh file in the emonicinformator project. Change ~/workspace_new/ to wherever your workspace is.
  8. Open a terminal and run source ~/mono-1.9/bin/setup.sh.
  9. Invoke the build_release.sh script from the Emonic.DebugFrontend folder in the same terminal.
  10. Now invoke the other build_release.sh script that’s in the emonicinformator project.
  11. Back in Eclipse, we need to create a new ‘Eclipse Application’ launch configuration that includes edu.arizona.cs.mbel2, org.emonic.base, org.emonic.debug.core, org.emonic.debug.ui, and org.emonic.debugger.
  12. Next, we need to switch to the ‘Environment’ tab. Set LD_LIBRARY_PATH to /home/username/mono-1.9/lib/ and PKG_CONFIG_PATH to /home/usernamemono-1.9/mono/lib/pkgconfig/. I think this step isn’t necessary if you did opt in to change your ~/.bashrc file, but since I’d rather not have my readers taint their setup needlessly, I decided to walk you all through the “long” way.
  13. Make sure ‘Append environment to native environment’ at the bottom of the tab is set. This should be what it is by default.
  14. Run the second Eclipse.
  15. In your second Eclipse, open up the preference page and then go to the ‘.NET > Installed Frameworks’ preference page and add a framework that points to /home/username/mono-1.9. Now switch over to the ‘.NET > Building’ preference page and then click ‘OK’.
  16. Open the preferences again, you should be on the .NET > Building page, configure the NAnt command and point it at /home/username/mono/bin/nant. It is imperative that you followed these past two steps correctly. There is a bug that causes the values to not persist properly and resort to their defaults when switching pages and the like. If in doubt, redo it again.
  17. Create a new .NET project. Accept the defaults, the build mechanism should default to ‘nant’.
  18. Using the created src folder in the project, create a new C# class through the wizard. You’ll need to create a new target, give it a name.
  19. Write some code. Two print statements would be a good test.
  20. Right-click on the margin and select ‘Toggle Breakpoint’ on the line with the first print statement (although it is very primitive).
  21. Create a new debug launch configuration for a ‘.NET Application’. Point it at your project and then browse to the compiled .NET executable that should be in the bin folder.
    launch configuration. NAnt should’ve been run every time you saved, otherwise, the .NET executable may not have been created.
  22. On the ‘Common’ tab, unselect ‘Allocate Console (necessary for input)’.
  23. Click ‘Apply’ and then ‘Debug’.
  24. After a bit of waiting, switch to the ‘Debug’ perspective by hand. To those that prefer the perspective switching to happen automatically, sorry, that hasn’t been implemented yet.
  25. The application should’ve stopped at the first print statement.
  26. Try hitting F6 and see that the print statement appears properly.
  27. Enjoy!

All feature requests should go here and all bug reports should go here. If you want to leave any comments about the debugger, you should consider posting them here. For personal compliments (or hate mail if applicable), please route them to Harald as I don’t handle the debugger integration on Emonic. This is very much still in alpha, so don’t expect too much.

Yes, we know that creating a regular ‘Run’ configuration doesn’t make anything show up on the ‘Debug’ side. Due to the decoupled nature of our current plug-ins, the two are not tied together.

And no, it doesn’t work on Windows because there is no ‘mdb’ on the Windows Mono build (at least, I didn’t see one when I installed it on Vista). If someone wants to try and write a debugger for us (ahahaha, who am I kidding?) or provide an interface with MDbg or something, please let us know.

Leave a Reply