If you are careful and follow some guidelines, the amount of debugging you need to do is minimized. The guidelines are:
1. Use splint to identify any problems.
2. Make sure your gcc alias has been set correctly.
3. Compile your code with gcc flags -fmudflapth -lmudflap as they can provide additional information.
gcc flags -fmudflapth -lmudflap my_code.c
4. Run valgrind on your code (see usage information below).
5. if (segmentation fault) {
Use gdb and the where command.
} else {
if (no results) {
a. Program may have an infinite loop (check your loops).
b. Program is waiting for input.
c. Output statements failed.
} else {
/* incorrect results or different in the submit server */
a. Use the diff command to identify the differences.
b. If using diff does not help, simplify the input as much
as possible to see if you can identify the problem.
c. Step through the code using the debugger.
d. If all the above fails, use printf statements to see
values, and the execution path leading to the problem.
}
}
The valgrind utility is mainly use to detect dynamic memory problems,
but it can also be used to detect invalid memory accesses. To use
the utility:
valgrind a.out
If you are using input redirection:
valgrind a.out < public01.in
Other options:
valgrind a.out
valgrind --leak-check=full a.out /* for details of leaked memory */
valgrind --track-origins=yes a.out /* to track use of uninitialized values */