At any time while you are in gdb, you can use the "help" command to get more info on a particular command. For example, help next or just h next as a shortcut. For a more complete information on gdb, see the on-line gdb manual.
To start the gnu debugger, at the prompt type :
gdb <executable-name>
In our case it will be
gdb a.out
Once the debugger is loaded, type the following:
break main
run
display/i $pc
1) What line do you see printed to the screen
2) What happens if you type step at this point? Why?
(you will need to type run again to be able to do the following)
Type list. This should show you about 10 lines from your main program.
(you can type list at any point during the debugging process
and it will show you the "C" code that is around the line you are executing)
do stepi until you see the following line :
<printHello+4>: sethi %hi(0x20400), %o0
3) Type x/s $i0. What do you see printed to the screen?
4) Do nexti until you see the following line :
<printHello+24>: ret
Print out the value of %o0. It should contain the return value from
the printf function (printf returns the number of characters it printed out)
To view this value you will have to use print command.
Type p/d $o0. What value do you see?
Type disassemble. This should show you about 10 lines from your printHello.s file.
(you can type disassemble at any point during the debugging process and it will show you
the "assembly" code that is around the line you are executing)
5) What is a breakpoint? How do you set one?
6) What function are you debugging if gdb displays:
<foobar+32>: sethi %hi(0x20400), %o6
7) What is the difference between step and next?
What is the difference between step/next and stepi/nexti?
8) What are $o0, $i0, etc, refering to?
9) What is the difference between the x and p commands?
- Which should you use to look at the contents of a register?
- Which should you use to look at something in memory?
- What do x/s and p/d mean (what do the /s and /d specify)?
To finish running the executable, type next until the program exits
Type q to quit the debugger and return to the shell prompt.
If you need to debug a program after getting a core dump, start gdb as
gdb <executable_name> core
Turn in
HOW TO TURN IN AN ASSIGNMENT:
- First, you need to have all the relevant files
in a sub-directory of your home directory.
The sub-directory should be named: pa#,
where # is the number of the homework
assignment.
Besides your source/header files, you may also have one
or more of the following files. Note the capitalization
and case of each letter of each file.
Makefile:
To compile your program with make -- usually provided
or you will be instructed to modify an existing Makefile.
README:
Information regarding your program.
(This file will be graded, so make sure you turn it in.
Specifications for README for pa0 are provided above)
Again, we emphasize the importance of using the
above names *exactly* otherwise our Makefiles won't
find your files.
When you are ready to submit your pa0, type
cd
turnin pa0
to submit your files. Additionally, you can type
verify pa0
to verify that everything was submitted properly.
Failure to follow the procedures outlined here will result
in your assignment not being collected properly and will
result in a loss of points. Late assignments WILL NOT
be accepted. Therefore, you MUST follow the instructions correctly.
If, at a later point (but before the respective deadlines)
you wish to make another submittal, simply type
cd
turnin pa0
(or whatever the current pa# is) again and the new archive will
replace the old one. The files aren't actually collected until
after the deadline, so the turnin command merely "packages" the files
for turnin. To verify the time on your submission file,
simply type verify pa0 and it will show you the
time and date of your most recent submission. The governing
time will be the one which appears on that file, (the system
time). The system time may be obtained by typing "date".
Your files must be located in a subdirectory of your home
directory which is named paX (where X is the assignment
number). If the files aren't located there, they cannot
be properly collected. Remember to cd to your home directory
first before running turnin.
If there is anything in these procedures which needs
clarifying, please feel free to ask any tutor, the instructor, or
post on the Discussion Board.
Make
Lint is a static source code checker for C programs. It is advisable to use lint even before using gcc to compile your code. Lint is designed to check C code and does not work on assembly. Lint checks for blatant syntax errors and other errors due to implicit declarations, undeclared headers, and incompatible types.
Example:
You are highly encouraged to use Subversion with all your programming assignments. See the Subversion Notes for this class.
A Subversion module setup script is available at