Channels ▼


.NET Development on Linux

Source Code Accompanies This Article. Download It Now.

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:


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 
 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 
Listing Four

Related Reading

More Insights

Currently we allow the following HTML tags in comments:

Single tags


<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags


<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

