tags:

views:

55

answers:

3

I'm trying to debug some code in the .NET Framework. Unfortunately, many of the variables are optimized away, and I can't reliably set the instruction pointer due to flow optimizations.

Is it possible to force the runtime to NOT use the ngen'd versions of the .NET system DLL's, but instead use the MSIL, forcing optimization to 'off'?

Note: I've tried using the INI trick to set AllowOptimize=false but it made no difference.

A: 

I think you may have to run ngen /Debug on those assemblies.

(Havent tried it though)

leppie
+1  A: 

Why don't you see the code of .NET framework itself with Reflector? Reflector enables you to see the code of any .NET assembly [including the .NET framework itself!], and even recompile it! -- Of course this applies to non-obfuscated assemblies!

Sameh Serag
I'm already stepping through Microsoft's source directly using their reference source server. I've used Reflector to recompile simple assemblies in the past, but the system DLL's are often a mix of native and managed. They're also signed which will probably prevent me from overriding their internal references.
Scott Bilas
+1  A: 

Got the answer from John Robbins. Basically, stick COMPLUS_ZapDisable=1 in your env vars (wrap in a bat to avoid running the whole system unoptimized) and disable the VS hosting process.

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

Another option is the new .NET Reflector Pro that lets you selectively decompile/recompile assemblies unoptimized. Not necessary with reference source but a good backup.

http://www.red-gate.com/products/reflector/features_pro.htm

Scott Bilas