调试:pdbonly .Net 2 和 .Net 4 之间的区别

发布于 2024-09-19 21:02:39 字数 1500 浏览 3 评论 0原文

我按照 Scott Hanselmans 网页上的这个例子进行操作: http://www.hanselman.com/blog/ReleaseISNOTDebug64bitOptimizationsAndCMethodInlinedInReleaseBuildCallStacks.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 进行编译的。

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

I followed this example from Scott Hanselmans webpage:
http://www.hanselman.com/blog/ReleaseISNOTDebug64bitOptimizationsAndCMethodInliningInReleaseBuildCallStacks.aspx

My goal is to get the line number from where the exception is thrown not where it is caught.

When I compile the code with the following build-script it wont work

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

Output:

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

When I compile the code with this build-script it will work

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

Output:

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

The difference is that in my first example i compiled against the .net2-framework, and in my second example I compiled against the .net4-framework.

Any solutions to my problem would be appreciated, thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

小鸟爱天空丶 2024-09-26 21:02:39

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

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

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

这不是一个令人愉快的解决方法,内联是一个重要的优化,特别是在属性 getter/setter 上。 .NET 2.0 和 4.0 之间存在差异的原因是,它们在决定何时内联方法时具有不同的抖动和不同的规则。

This is something you are going to have to deal with if you expect to generate line numbers from code generated in the Release configuration. The JIT compiler's optimizer is enabled and it is going to move code around to create more efficient machine code. That's going to affect the accuracy of the reported line number.

The specific workaround here is to apply this attribute to "badMethod":

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

This is not a joyful workaround, inlining is an important optimization, especially on property getter/setters. The reason it is different between .NET 2.0 and 4.0 is because they have different jitters with different rules for deciding when a method should be inlined.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文