Okay, just follow along, questions will be denoted with a Q.
See a short (and still incomplete) GDB quick reference
ulimit -c unlimited
gcc -o bug3 bug3.c
Q 1What happened when you ran bug3? Use ls -ot, see if there are any new files in your directory.
Even if you didn't compile w/the extra debug info, and you don't read the instructions for the given chipset, the debugger can still be useful. For example, we can use backtrace (bt) to look at the runtime stack, see in which function we were when we dumped:
$ gdb bug3 -c core
Q 2 In which function did it bomb?
To run programs in a debugger (and see stuff that looks familiar to you) you must compile all files w/the -g flag.
Okay, now, use GDB to debug these other programs.
Q 3 For each, below, record what the problem was, and how you fixed it.
driverBug.c compiled with quicksortBug.c.
simple bug in the quicksort program from the text - how would you find it? What assertions could you put into the code to check that the algorithm was implemented properly?
To generate the error run driverBug with the input in
sort2.c uses qsort to sort an array of strings. The error comes from passing qsort a function to compare integers rather than strings.
Q 4 Why can't the compiler catch this? You can uncover the problem by looking at a stack trace from when the program crashed (see the lab on how to do this).
Q 5 What happens if you are using qsort to sort integers and accidently pass the string comparison function?