2010-09-20 32 views
0

之間pdbonly差我跟着斯科特Hanselmans網頁下面這個例子: http://www.hanselman.com/blog/ReleaseISNOTDebug64bitOptimizationsAndCMethodInliningInReleaseBuildCallStacks.aspx調試:2的.Net和.Net 4

我的目標是獲得來自哪里哪里被抓的沒有拋出異常的行號。

當我編譯下面的生成腳本代碼它不會工作

SET FXROOT=%Systemroot%\Microsoft.NET\Framework\v4.0.30319 

DEL *.exe /q 

"%FXROOT%\csc.exe" /t:exe /out:NormalRelease.exe /debug:pdbonly /o+ NormalProgram.cs 

NormalRelease.exe > NormalRelease32.txt 

輸出:

System.ApplicationException: generic bad thing 
    at NormalProgram.Main(String[] args) in c:\Development\DebugSymbols\DebugSymConsole\NormalProgram.cs:line 8 

當我編譯這個構建腳本的代碼,將工作

SET FXROOT=%Systemroot%\Microsoft.NET\Framework\v2.0.50727 

DEL *.exe /q 

"%FXROOT%\csc.exe" /t:exe /out:NormalRelease.exe /debug:pdbonly /o+ NormalProgram.cs 

NormalRelease.exe > NormalRelease32.txt 

輸出:

System.ApplicationException: generic bad thing 
    at NormalProgram.badMethod() in c:\Development\DebugSymbols\DebugSymConsole\NormalProgram.cs:line 18 
    at NormalProgram.Main(String[] args) in c:\Development\DebugSymbols\DebugSymConsole\NormalProgram.cs:line 8 

不同的是,在我的第一個例子,我編譯反對.NET2的框架,並在我的第二個例子中,我對.NET4框架編譯。

我的問題的任何解決方案,將不勝感激,謝謝。

回答

2

如果您希望從發佈配置中生成的代碼生成行號,這是您將不得不處理的事情。 JIT編譯器的優化器已啓用,它將移動代碼以創建更高效​​的機器代碼。這將影響報告行號的準確性。

這裏的具體解決方法是將此屬性設置爲「badMethod」:

using System.Runtime.CompilerServices; 
... 
     [MethodImpl(MethodImplOptions.NoInlining)] 
     void badMethod() { 
      // etc... 
     } 

這不是一個快樂的解決方法,內聯是一個重要的優化,尤其是對財產的getter/setter方法。 .NET 2.0和4.0之間的不同之處是因爲它們具有不同的規則,用於決定何時應該內聯一個方法。