调试与发布-两全其美

Mark Pearce posted in the comments about my Debug vs. Release post some valuable tips that deserved being shared in a formal post.   Mark reminds us of the little-known little-used [.NET Framework Debugging Control] section of a {gasp} .INI file.  These help guide and control the JIT.  From MSDN:

马克·皮尔斯(Mark Pearce)在有关“调试与发布”的评论中发布了一些有价值的技巧,值得在正式文章中分享。 Mark让我们想起了{gasp} .INI文件中鲜为人知的鲜为人用的[.NET Framework调试控件]部分。 这些帮助指导和控制JIT。 从MSDN

This JIT configuration has two aspects:

此JIT配置包含两个方面:

  • You can request the JIT-compiler to generate tracking information. This makes it possible for the debugger to match up a chain of MSIL with its machine code counterpart, and to track where local variables and function arguments are stored.

    您可以请求JIT编译器生成跟踪信息。 这使调试器可以将MSIL链与其对应的机器代码匹配,并跟踪存储本地变量和函数参数的位置。

  • You can request the JIT-compiler to not optimize the resulting machine code.

    您可以请求JIT编译器不优化生成的机器代码。

So Mark suggested this (emphasis mine):

因此,马克建议这样做(强调我的意思)

You can have the best of both worlds with a rather neat trick. The major differences between the default debug build and default release build are that when doing a default release build, optimization is turned on and debug symbols are not emitted. So:
Step 1: Change your release config to emit debug symbols. This has virtually no effect on the performance of your app, and is very useful if (when?) you need to debug a release build of your app.
Step 2: Compile using your new release build config, i.e. *with* debug symbols and *with* optimization. Note that 99% of code optimization is done by the JIT compiler, not the language compiler, so read on...
Step 3: Create a text file in your app's folder called xxxx.ini (or dll or whatever), where xxxx is the name of your executable. This text file should initially look like:
[.NET Framework Debugging Control]
GenerateTrackingInfo=0
AllowOptimize=1
Step 4: With these settings, your app runs at full speed. When you want to debug your app by turning on debug tracking and possibly turning off (CIL) code optimization, just use the following settings:
[.NET Framework Debugging Control]
GenerateTrackingInfo=1
AllowOptimize=0

您可以通过巧妙的技巧来两全其美 缺省调试版本和缺省发行版本之间的主要区别在于,当执行缺省发行版本时,将打开优化并且不发出调试符号 所以: 步骤1:更改发布配置以发出调试符号 这实际上对应用程序的性能没有影响,如果(何时?)需要调试应用程序的发布版本,这将非常有用。 第2步:使用新发行版的配置文件进行编译,即* with *调试符号和* with *优化。 请注意,代码优化的99%是由JIT编译器而不是语言编译器完成的,因此请继续阅读... 步骤3:在应用程序的文件夹中创建一个名为xxxx.ini(或dll或其他名称)的文本文件,其中xxxx是可执行文件的名称。 该文本文件最初应如下所示: [.NET Framework调试控件] GenerateTrackingInfo = 0 AllowOptimize = 1 第4步:使用这些设置,您的应用将全速运行 当您想通过打开调试跟踪并可能关闭(CIL)代码优化来调试应用程序时,只需使用以下设置: [.NET Framework调试控件] GenerateTrackingInfo = 1 AllowOptimize = 0

Great stuff Mark!  I'm going to go see how this would work with ASP.NET (do I use an ASPNET_WP.EXE.ini(?) and I'll probably have to recycle the ASP.NET worker process.) 

好东西马克! 我要去看看如何做到这一点与ASP.NET的工作(我使用ASPNET_WP.EXE。INI(?),我可能就会回收ASP.NET工作进程。)

翻译自: https://www.hanselman.com/blog/debug-vs-release-the-best-of-both-worlds

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值