Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debugging in .NET in Release mode

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.

like image 849
Vladislavs Burakovs Avatar asked Jun 15 '12 15:06

Vladislavs Burakovs


People also ask

Can you debug in release mode?

A 'release' build can be debugged.

Can we debug in release mode C#?

The release configuration of your program has no symbolic debug information and is fully optimized. For managed code and C++ code, debug information can be generated in . pdb files, depending on the compiler options that are used.

Can you use breakpoints in release mode?

You can then put a breakpoint on that int declaration line, and it'll be hit, even in release mode. Then just step up the stack in the debugger back to the function you actually wanted a breakpoint in.


1 Answers

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-.

like image 132
agent-j Avatar answered Oct 29 '22 15:10

agent-j