Debugging in .NET in Release Mode

Some time ago I read an article about the CLR, where the author showed that if the project is compiled in DEBUG mode, a NOP command comes in front of each statement, which allows you to debug the code. However, today I discovered that we can also debug in release mode ... Please help understand the difference.

+6
source share
3 answers

You can debug in Release mode to some extent. Debugging and release is just building configurations (from which you can create a lot), the real difference is that the Debug configuration does not optimize the generated binary code (optimized code complicates debugging). It also generates additional debugging data that is not released.

+1
source

Debugging .net code, allowing you to execute source code while it is being executed, usually requires three things:

  • Symbols (associated .pdb file) that were created with the .dll or .exe assembly
  • Source (related .cs, .vb files, etc.)
  • Executable machine code must not be optimized

Characters controlled by / debug: {full | pdbonly} . If you specify /debug:full (even in the release build, when disabling compiler optimization), you can connect to an already running process and execute the code. If you have /debug:pdbonly , you must use the debugger to run the program (and cannot see the characters when connecting to an already running process).

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

+6
source

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

The debugging mode is designed to make it easier for the debugger to follow, so it splits lines of code using NOP and does not optimize the resulting binary.

+2
source

Source: https://habr.com/ru/post/918204/


All Articles