Lab 3 Preparation
To prepare for Lab 2 on the gdb debug tool, first copy the source file for the sample debug program (found at ~allisor/Student/misc/debug.c in the lab) and compile and run it. Note that it does not run correctly; this is intentional. Try using both numeric and alphabetic arguments to see if there is any difference in its behaviour.
Now recompile it using the -g option of gcc (show the man page with man 1 gcc, then use /Produce debugging to search for how to set the debug option).
Finally, run the program under the control of gdb by entering this form of command:
gdb my-program-name
where you replace my-program-name with the name of your executable program (no ./ prefix is necessary, but it may be specified if you wish). You are now at the gdb prompt and your program is ready to run.
Here are some of the most frequently needed gdb commands (this list is adapted from the man page:
|
break p |
|
|
run [arg] |
|
|
bt |
|
|
list |
|
|
print e |
|
|
cont |
|
|
next |
|
|
step |
|
|
help [n] |
|
|
quit |
|
A good way to start debugging is to set a breakpoint right at the beginning of the program (break main) and stepping through line by line with next or step, displaying important values with print as you move through it.
There is a good description of command-line arguments in section 5.10 of K&R (Kernighan and Ritchie's "The C Programming Language") starting on page 114.
Now read over the instructions for Lab 3 and follow them carefully.