Debugging and Running Mono Applications
The MonoDevelop development team is working on an integrated debugger, but for now you can debug your applications using the mdb debugger. After building a debug version of DigitsOfPi, select Applications/Terminal and enter the following commands to run the mdb debugger.
- The b (breakpoint) command sets a breakpoint.
- The c (continue) command runs the program to the next breakpoint.
- The s (single step) command executes the current line.
- Use the p (print) command to determine a variable's value.
- The quit command stops the debugger and the application being debugged.
- Use the help command to read documentation on all debugger commands.
Listing Four is a transcript from one of my debugging sessions.
Use /usr/bin/mono to run your .NET applications on Linux. For example, the following command launches the debug version of DigitsOfPi:
/usr/bin/mono/home/user/DigitsOfPi/DigitsOfPi/bin/Debug/DigitsOfPi.exe
Linux distributions have achieved impressive usability levels in the last few years, especially Ubuntu. If you haven't taken a recent look at Linux, do it now. VMware Server makes it painless to experiment with Linux distributions on your Windows machine. And thanks to the Mono project and MonoDevelop, you can leverage your C# .NET skills to create full-fledged Linux applications. At least for the present, .NET development on Linux is not a developer's utopia. I found MonoDevelop's Gtk GUI designer to be a bit crash prone, and there isn't an integrated debugger yet. While I was able to build console applications with MonoDevelop and run them on my Windows machine, I wasn't able to do the same with Gtk# applications. Unfortunately, the proper version of the Gtk# library is not available for the Windows platform yet. Also, MonoDevelop is not as feature-rich or as polished as Microsoft Visual Studio. But Linux is a great platform, and it's wonderful to be able to use C# and .NET to develop Linux apps. If you haven't tried .NET development on Ubuntu, start up a VM and give it a try. Linux and Mono have come a long way in a short amount of time, and I expect them to only improve as we move forward.
$ cd /home/user/DigitsOfPi/DigitsOfPi $ mdb bin/Debug/DigitsOfPi.exe Mono Debugger (mdb) start Starting program: bin/Debug/DigitsOfPi.exe ... Thread @1 stopped at #0: 0xb78e023f in DigitsOfPi.MainClass. Main(string[])+0x7 at /home/user/DigitsOfPi/DigitsOfPi/Main.cs:10. 10 Application.Init (); (mdb) b Plouffe_Bellard.cs:131 Breakpoint 4 at Plouffe_Bellard.CalculatePiDigits(int):131 (mdb) c ... Thread @1 hit breakpoint 4 at #0: 0xb63fce24 in Plouffe_Bellard. CalculatePiDigits(int)+0x84 at /home/user/DigitsOfPi/DigitsOfPi/Plouffe_Bellard.cs:131. 131 for (int a = 3; a <= (2 * N); a = next_prime(a)) (mdb) p N (int) 69 (mdb) s Thread @1 stopped at #0: 0xb63fd045 in Plouffe_Bellard. CalculatePiDigits(int)+0x2a5 at /home/user/DigitsOfPi/DigitsOfPi/Plouffe_Bellard.cs:131. 131 for (int a = 3; a <= (2 * N); a = next_prime(a))