Next  |  Prev  |  Up  |  Top  |  Index  |  JOS Index  |  JOS Pubs  |  JOS Home  |  Search


Preparing your Program for Debugging

If you have followed the instructions of the preceding appendix, you are already prepared for debugging in gdb, and you can skip to the next section. Otherwise, before using gdb, you need to

(1)
compile your program and the STK library with symbols using the `-g' compiler switch, and
(2)
compile without optimization (no '-O', '-O2', '-O3' options, etc.).

For (1), find the CC variable in the Makefile for your program, and add -g to it. This will cause the compiler to leave a symbol table and line-number information in the .o file.

For (2), remove `-O', `-O2', `-O3', or the like, from the CC variable's definition (or change it to `-O0'). These are optimization flags, and optimization can cause gdb's line-number information to become incorrect (when lines of code are optimized away). Furthermore, intermediate variables are also often optimized away, in which case you can no longer inspect them while single-stepping.

For example, suppose the Makefile (e.g., for projects/examples in the STK distribution) contains the following:

        CFLAGS = -O3 -Wall ...
Before running gdb, we need to change this to
        CFLAGS = -g -Wall ...
and recompile by typing ``make'' in that directory.


Next  |  Prev  |  Up  |  Top  |  Index  |  JOS Index  |  JOS Pubs  |  JOS Home  |  Search

[How to cite this work]  [Order a printed hardcopy]

``Physical Audio Signal Processing'', by Julius O. Smith III, (August 2007 Edition).
Copyright © 2008-05-16 by Julius O. Smith III
Center for Computer Research in Music and Acoustics (CCRMA),   Stanford University
CCRMA  [About the Automatic Links]