Is it possible to debug the system .NET DLL's as unoptimized?
I'm trying to debug some code in the .NET Framewor开发者_C百科k. 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.
Here's another option (from http://martin.bz/asp-net-mvc-source-debugging-the-easy-way):
Go to the directory where System.Web.Mvc .dll is located:
c:\Windows\assembly\GAC_MSIL\System.Web.Mvc\2.0.0.0__31bf3856ad364e35\
Create the file System.Web.Mvc.ini
[.NET Framework Debugging Control] GenerateTrackingInfo=1 AllowOptimize=0
Next time you step into the MVC source code you can inspect all variables.
More details at http://msdn.microsoft.com/en-us/library/9dd8z24x.aspx
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
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!
精彩评论