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