How to disable optimizations when debugging Reference Source

When you debug code in the .NET Framework using the newly available Reference Source functionality in VS 2008, you may notice that many variables are not available for inspection.

image

This is because you're debugging against retail-optimized code.  In many cases, since you can still step through, this is something that's manageable.

But what if you really need to get a better idea of what's going on?  Fortunately, there is a way.

What you need to do is to tell the CLR not to load the pre-JIT (aka NGEN) images.  Here is how to do it. 

First, create a CMD file that sets an environment variable, then launches Visual Studio.  I called mine "NoOptDevEnv.cmd", and it's contents are as follows:

set COMPLUS_ZapDisable=1    
cd /d "%ProgramFiles%\Microsoft Visual Studio 9.0\Common7\ide\"     
start devenv.exe     
exit

I put this cmd file on my desktop.   When I want to disable optimizations, and only when I want to do this, I launch VS from this command. 

Once in my Visual Studio project, do the following steps:

1) Right click on your project file and choose "Properties"

2) Choose the "Debug" tab and uncheck "Enable the Visual Studio Hosting Process"

3) Launch your application in the debugger.

Now, you'll see full local and member variable information:

image

Finally, you may be asking yourself "What is the Visual Studio Hosting Process (aka VSHost), and what happens if I turn it off?"  And this is a good question.

For the most part, disabling VSHost won't have any major impacts, but it will disable two features that you may be using.

First, you will not be able to do "Debug In Zone", which allows you to debug a process in the context of a security zone such as "Internet" or "Intranet".  That won't work without VSHost.

Second, Design Time Expression Evaluation for class libraries will also not work.  What that means, for example, is that if you are developing a Class Library, you won't be able to execute code from it in the Immediate Window while under the debugger.

In general, I recommend re-enabling VSHost (undo step 2 above) when you are finished with your debugging.

Hope that helps!

From:http://blogs.msdn.com/b/sburke/archive/2008/01/29/how-to-disable-optimizations-when-debugging-reference-source.aspx

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值