This lab will give you practice with the debugger on our system,
gdb. The file debug.C
contains code that manipulates pointers, but there are several errors
in the code. You must fix the code, and will use gdb to
find out where the program is crashing and learn more about why.
The program uses a Node structure like the one in the last
lab, and links together a short list of them. (It does not use
any sort of list class -- it manipulates the pointers directly.) After
building the list the code prints out its contents, then tests a function
called Member that looks to see if a particular value is in
the list.
Perform the following steps:
cp ~cs102/Lab9/* .)
-g flag.
(g++ -g debug.C)
Segmentation fault.)
gdb a.out to start the debugger
run at the gdb prompt to start
the program running.
where command
to see where the program died.
list command to see the lines of code
immediately surrounding the fatal line.
run again. (Type "help
break" if you don't remember how to set breakpoints.)
next to
execute a line at a time until the program dies again. At each
step, use print to display the value of relevant
variables to see how they're changing.
-g flag.