Search code examples
c#releasewindbgdebug-symbolssos

getting line numbers of offending code in debug vs release builds


My understanding is that with crash dump of debug build you can get the line number of stack trace and this does not happen with release build. In order to try this, I created a very simple application that crashes.

class Program  
{  
    static void Main(string[] args)  
    {  
        Console.WriteLine("Press any key to continue");  
        Console.ReadKey();  
        TestMe(null);  
    }  


    static void TestMe(MyClass c)  
    {  
        Console.WriteLine(c.Field);  
    }  
}  

class MyClass  
{  
    public string Field { get; set; }  
}  

I created one debug build and one release build. Ran both of these and catpured crash dump via ADPlus. Below are the stack traces for each build. As you can see I am getting the line number in both builds. Obviously difference is that in release build its not reporting call to TestMe method. Any ideas why? Do I need add symbol path to application pdb files in both cases

Debug build

0:000> !CLRStack  
OS Thread Id: 0x2398 (0)  
Child SP IP       Call Site  
001eee74 003400db ConsoleApplication1.Program.TestMe(ConsoleApplication1.MyClass)*** WARNING: Unable to verify checksum for ConsoleApplication1.exe  
 [c:\ConsoleApplication1\ConsoleApplication1\Program.cs @ 20]  
001eee84 003400a5 ConsoleApplication1.Program.Main(System.String[]) [c:\ConsoleApplication1\ConsoleApplication1\Program.cs @ 14]  
001ef0c8 6ccb21bb [GCFrame: 001ef0c8] 

Release build

0:000> !CLRStack  
OS Thread Id: 0x2e40 (0)  
Child SP IP       Call Site  
003bf5f8 772af8c1 [GCFrame: 003bf5f8] Unknown  
003bf3b4 002b0098 ConsoleApplication1.Program.Main(System.String[])*** WARNING: Unable to verify checksum for ConsoleApplication1.exe  
 [c:\ConsoleApplication1\ConsoleApplication1\Program.cs @ 14]  
003bf5f8 6ccb21bb [GCFrame: 003bf5f8]   

Solution

  • In the release build, the JIT compiler is no doubt inlining the method call - that's why the line number is different.