Make sure you do a debug build, not a regular build (i.e. the -g option should be passed to cc, and not -O or -O2, which are optimize flags). The compiler can optimize code in very interesting ways, and is totally confusing in the debugger since things seem to execute all out of order, only execute once when you think it should happen multiple times, etc.