【问题标题】:debug:pdbonly difference between .Net 2 and .Net 4调试:pdbonly .Net 2 和 .Net 4 之间的区别
【发布时间】:2010-09-20 15:22:37
【问题描述】:

我从 Scott Hanselmans 网页上遵循了这个例子: http://www.hanselman.com/blog/ReleaseISNOTDebug64bitOptimizationsAndCMethodInliningInReleaseBuildCallStacks.aspx

我的目标是从引发异常的位置获取行号,而不是从捕获异常的位置获取行号。

当我使用以下构建脚本编译代码时,它不会工作

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-framework 进行编译,而在我的第二个示例中,我针对 .net4-framework 进行了编译。

任何解决我的问题的方法都将不胜感激,谢谢。

【问题讨论】:

    标签: c# visual-studio .net-2.0 .net-4.0


    【解决方案1】:

    如果您希望从发布配置中生成的代码生成行号,您将不得不处理这些问题。 JIT 编译器的优化器已启用,它将移动代码以创建更高效​​的机器代码。这会影响报告的行号的准确性。

    这里的具体解决方法是将此属性应用于“badMethod”:

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

    这不是一个令人愉快的解决方法,内联是一个重要的优化,尤其是在属性 getter/setter 上。 .NET 2.0 和 4.0 不同的原因是它们有不同的抖动,有不同的规则来决定何时应该内联方法。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-04-20
      • 2011-05-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-20
      • 2016-10-30
      相关资源
      最近更新 更多