14

I thought apt-get install mono-dbg would solve it but i was wrong. How do i get debug information with mono? i am using debian squeeze but couldnt figure it out on debian lenny or etch.

I wrote a dummy program below and i was hoping for a line number but i got this instead. This is a copy/paste from the console/terminal.

Unhandled Exception: System.Exception: nooo blah
  at ExceptionTest.Program.func (Int32 a) [0x00000] in <filename unknown>:0
  at ExceptionTest.Program.func (Int32 a) [0x00000] in <filename unknown>:0
  at ExceptionTest.Program.func (Int32 a) [0x00000] in <filename unknown>:0
  at ExceptionTest.Program.Main (System.String[] args) [0x00000] in <filename unknown>:0

Code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ExceptionTest
{
    class Program
    {
        static void Main(string[] args)
        {
            func(3);
        }
        static void func(int a)
        {
            if (a == 18)
                throw new Exception("nooo blah");
            func(a + a + 2);
        }
    }
}

1 Answers1

16

To get file names and line numbers, compile your application with -debug (like gmcs -debug prog.cs) and then run mono --debug prog.exe.

The mono-dbg package gives you debugging symbols for /usr/bin/mono (and libmono).

$ gmcs -debug prog.cs
$ mono --debug prog.exe

Unhandled Exception: System.Exception: nooo blah
  at ExceptionTest.Program.func (Int32 a) [0x0001d] in /tmp/prog.cs:19 
  at ExceptionTest.Program.func (Int32 a) [0x00013] in /tmp/prog.cs:18 
  at ExceptionTest.Program.func (Int32 a) [0x00013] in /tmp/prog.cs:18 
  at ExceptionTest.Program.Main (System.String[] args) [0x00000] in /tmp/prog.cs:12 
Gonzalo
  • 20,805
  • 3
  • 75
  • 78
  • That worked. +1 and accepted. At first i thought "oh it must be bc i compiled with visual studio". But then i realized i have the same problem with another app that HAS been compiled with mono. But thats another distro with different libs and using an IDE. So i dont know whats going on there. Great, now i can work on this problem properly –  Mar 16 '11 at 05:51
  • 2
    Unfortunately that didn't work for me. I tried converting the VS `pdb` files to `mdb` too, but still get no line information. Any ideas? – sunside Apr 13 '11 at 16:00
  • Gonzalo, I think you're slightly wrong about mono-dbg: mono-dbg does provide class libraries debug symbols; the debug symbols for the mono runtime (/usr/bin/mono) are in mono-runtime-dbg package, and the debug symbols for the mono JIT are in libmono-2.0-1-dbg, according to http://packages.ubuntu.com/precise/debug/ , right? – knocte Aug 24 '12 at 17:25
  • Markus, how are you converting the pdb files to mdb? Why not just compile the solution with xbuild or in MonoDevelop, to get the mdb files? – knocte Aug 24 '12 at 18:16