mono's mdb file vs csc's pdb file

2019-05-05 20:13发布

问题:

I have this post that teaches me about pdb file and StackTrace.

This is the code.

using System;

// https://stackoverflow.com/questions/4474259/c-exception-handling-with-a-string-given-to-a-constructor

class WeekdayException : Exception {
    public WeekdayException(String wday) : base("Illegal weekday: " + wday) {}
}

class TryCatchFinally 
{
    public static void Main() 
    {
        try
        {
            throw new WeekdayException("thrown by try");
        }
        catch(WeekdayException weekdayException) {
            Console.WriteLine(weekdayException.Message);
            Console.WriteLine(weekdayException.StackTrace);
        }
    }
}

With mono, I run

dmcs /debug error.cs
mono error.exe

And I get this message that's the same when I deleted the /debug option.

Illegal weekday: thrown by try
  at TryCatchFinally.Main () [0x00000] in <filename unknown>:0 

With Visual Studio 2010, I run

csc /debug error.cs
error

To get this message with line number as expected.

Illegal weekday: thrown by try
   at TryCatchFinally.Main() in c:\error.cs:line 15
  • Q : Why mono doesn't show the line number with mdb file? Am I missing something?

回答1:

You have to pass --debug to mono. I do not know why this is, I never thought about it before.

dmcs /debug error.cs
mono --debug error.exe