Debugging in .NET in Release mode

落花浮王杯 提交于 2019-12-04 03:23:08

问题


Some time ago I've read an article on CLR, where author showed that if a project is compiled in DEBUG mode, before each operator comes a NOP command, thus allowing to debug a code. Nevertheless, today I discovered that we can also debug in release mode as well... Please help to understand the difference.


回答1:


You can debug in Release mode to an extent. Debug and Release are simply build configurations (of which you can create many), the real difference is that Debug configuration doesn't optimize the generated binary code (optimized code complicates debugging). It also generates additional debug data which release does not.




回答2:


Debugging .net code so that you can step through the source code while it is executed usually requires three things:

  • Symbols (the related .pdb file) that were built along with the assembly .dll or .exe
  • Source (the related .cs, .vb, etc. files)
  • The executing machine code must be unoptimized

Symbols are controlled by the /debug:{full | pdbonly} flag. If you specify /debug:full (even in a release build, with compiler optimizations turned off) you may attach to an already running process and step through code. If you have /debug:pdbonly, then you must use the debugger to start the program (and cannot view symbols when attaching to an already running process).

Optimization is controlled granularly by the /debug compiler option, but can be further controlled by the /optimize-.




回答3:


Compiling in release mode optimizes the resulting binary, which makes it harder (but not impossible) for the debugger to know which binary code came from which line line of source code.

Debug mode is designed to make it easier for the debugger to 'follow along', so it separates lines of code with NOP, and does not optimize the resulting binary.



来源:https://stackoverflow.com/questions/11054183/debugging-in-net-in-release-mode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!