mono debug information with exceptions on debian?

2020-02-28 02:44发布

问题:

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:

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