Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a debug mode w.r.t C++?

Tags:

c++

debugging

From here: http://google-glog.googlecode.com/svn/trunk/doc/glog.html

Debug Mode Support
Special "debug mode" logging macros only have an effect in debug mode and are compiled away to nothing for non-debug mode compiles.

What does "debug mode" mean w.r.t C++ program?

Can we say a program is in debug mode when we are using GDB on it?

like image 657
Aquarius_Girl Avatar asked Dec 09 '22 00:12

Aquarius_Girl


2 Answers

There's three sides to "debug mode".

A lot of libraries (including standard libraries) will insert debug-helping code (array bounds checking, invariant assertions, that sort of thing) when they are compiled in debug mode. They remove these checks in production/non-debug mode to help performance.

Compilers have debug switches. The set debug macros that the libraries use to detect whether you are compiling for debug or not, and insert debug symbols in the produced binaries. This helps debuggers make the link between the binary code that is running and the source code that generated it.

Running an program in a debugger is a "runtime debug mode". You can run an executable in a debugger whether or not it was built for debugging. You'll get more information with a debug build.

All three of these "debug modes" are independent. You could (usually) compile library debug checks in a production build by setting the appropriate macros/defines manually without asking the compiler to output debug symbols.

None of this is specific to C++ (or C). A lot of other languages have these concepts.

like image 100
Mat Avatar answered Dec 25 '22 04:12

Mat


"Debug mode" can refer to a lot of things, but in this case it refers to compiling without the NDEBUG macro defined. From the page that you linked to (emphasis mine):

The DFATAL severity logs a FATAL error in debug mode (i.e., there is no NDEBUG macro defined), but avoids halting the program in production by automatically reducing the severity to ERROR.

like image 29
Mankarse Avatar answered Dec 25 '22 04:12

Mankarse