4

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?

Aquarius_Girl
  • 21,790
  • 65
  • 230
  • 411
  • 1
    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 08 '12 at 08:15
  • 1
    You also want to see this question: http://stackoverflow.com/questions/2290509/debug-vs-ndebug :) – LihO May 08 '12 at 08:18

3 Answers3

5

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

Mankarse
  • 39,818
  • 11
  • 97
  • 141
5

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.

Mat
  • 202,337
  • 40
  • 393
  • 406
4

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.

Potatoswatter
  • 134,909
  • 25
  • 265
  • 421
  • Note that in environments where performance isn't an issue, it is usual to not define `NDEBUG` even in production code. – James Kanze May 08 '12 at 08:37