O'Reilly logo

The Art of Debugging with GDB and DDD by Peter Jay Salzman, Norman Matloff

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Introductory Debugging Session

Now we will present a complete debugging session. As mentioned, the sample program is in the source file ins.c and does an insertion sort. This is not an efficient sorting method, of course, but the simplicity of the code makes it good for illustrating the debugging operations. Here is the code:

// // insertion sort, several errors // // usage: insert_sort num1 num2 num3 ..., where the numi are the numbers to // be sorted int x[10], // input array y[10], // workspace array num_inputs, // length of input array num_y = 0; // current number of elements in y void get_args(int ac, char **av) { int i; num_inputs = ac - 1; for (i = 0; i < num_inputs; i++) x[i] = atoi(av[i+1]); } void scoot_over(int jj) { int k; for (k = ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required