Take the 2-minute tour ×

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?

share|improve this question
Which compiler? With g++, you enable debug mode by using -g on the command line. Then when it runs, it's in debug mode. While you can start up GDB with a program not compiled with the switch, I don't believe you call it "debug mode" then. (And you can't do things like setting breakpoints etc.) –  Mr Lister May 8 '12 at 8:15
You also want to see this question: stackoverflow.com/questions/2290509/debug-vs-ndebug :) –  LihO May 8 '12 at 8:18
@MrLister Thanks for the info, and LihO thanks -will look in there. –  TheIndependentAquarius May 8 '12 at 8:20

3 Answers 3

up vote 5 down vote accepted

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.

share|improve this answer
thanks for the helpful answer. –  TheIndependentAquarius May 8 '12 at 8:26

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

share|improve this answer
thanks for the info. –  TheIndependentAquarius May 8 '12 at 8:26

C++ programs (like C) usually have different build configurations based on preprocessor macros, which can be passed from the command line.

The canonical debug mode flag is the macro NDEBUG, which if defined means you are not in debug mode. (It could be more clearly named PRODUCTION, but sadly it's named in terms of what it's not.)

NDEBUG is standard, and ancient. It is used by the <cassert> header, which is known as <assert.h> in C. Its official function is to make the assert macro into a no-op, but it also usually affects the C++ standard library in terms of checking bounds and requirements.

For example, g++ -DNDEBUG myProg.cpp -o myProg should compile without runtime features related to debugging.

Note that this is different from producing symbolic support for the debugger, which is controlled with -g on GCC, or other flags for other platforms.

share|improve this answer
thanks to you too. –  TheIndependentAquarius May 8 '12 at 8:27
Note that in environments where performance isn't an issue, it is usual to not define NDEBUG even in production code. –  James Kanze May 8 '12 at 8:37

Your Answer


