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

Preparing your Program for Debugging

If you have followed the instruction 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. These are optimization flags, and optimization can cause gdb's line-number information to become incorrect. (By default, the STK uses -O2 when debugging is enabled--while that may work, I am in the habit of turning off optimization completely myself.)

For example, if 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 and copy this work] 
``Physical Audio Signal Processing for Virtual Musical Instruments and Digital Audio Effects'', by Julius O. Smith III, (December 2005 Edition).
Copyright © 2006-07-01 by Julius O. Smith III
Center for Computer Research in Music and Acoustics (CCRMA),   Stanford University
CCRMA  [Automatic-links disclaimer]