7.6.5 Options for Debugging

The following options are used for debugging.

Table 7-10. Debugging Options
OptionDefinition
-gProduce debugging information.

The compiler supports the use of -g with -O making it possible to debug optimized code. The shortcuts taken by optimized code may occasionally produce surprising results:

  • Some declared variables may not exist at all;
  • Flow of control may briefly move unexpectedly;
  • Some statements may not be executed because they compute constant results or their values were already at hand;
  • Some statements may execute in different places because they were moved out of loops.

    Nevertheless it proves possible to debug optimized output. This makes it reasonable to use the optimizer for programs that might have bugs.

-QMakes the compiler print out each function name as it is compiled, and print some statistics about each pass when it finishes.
-save-tempsDon’t delete intermediate files. Place them in the current directory and name them based on the source file. Thus, compiling foo.c with -c -save-temps would produce the following files:

foo.i (preprocessed file)

foo.p (pre procedure abstraction assembly language file)

foo.s (assembly language file)

foo.o (object file)