Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to debug the system .NET DLL's as unoptimized?

Tags:

.net

debugging

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.

like image 894
scobi Avatar asked Feb 20 '10 02:02

scobi


2 Answers

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

like image 64
DenNukem Avatar answered Oct 20 '22 23:10

DenNukem


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

like image 20
scobi Avatar answered Oct 21 '22 01:10

scobi