Computer
Systems

Fall 2010
course
navigation

sep 28

asides

homework

sep28 homework

gdb

Play around in class with gdb and a small C program, to get a feel for how to use it; try it for example on the attached small.c code.
Here are some notes on gdb :
gdb can be used for either C debugging, or assembler executable debugging. For looking at C source while running, the program should be compiled with the "-g" switch. But that isn't our main point here, when we're trying to use gdb on the x86 assembler, not the C code per se.
Also, gdb refers to the program registers with $, not %, e.g. $esp rather than %esp .
# First, compile the program (making sure you're getting x86, eh? $ gcc -O0 -m32 small.c -o small # Then debug the executable (or the .o, which will be smaller) $ gdb small (gdb) # Here are some commands to try in gdb (gdb) break swap # set a break point at the swap function (gdb) help (gdb) help x (gdb) run (gdb) info registers # show all the integer registers: ebp, ... (gdb) info functions # *long* list of all function names (even without -g) (gdb) disass main # show assembly starting at given address (gdb) disass swap swap+10 # 10 instructions (gdb) stepi # step 1 assembly instruction (gdb) nexti # similar, but move through sub calls (gdb) info program # where are we? (gdb) bt # backtrace; show function calls (gdb) x/s 0x8+$esp # look at 0x8(%ebp) as a string (gdb) step # continue running until this function exits
So ... work on understanding the small* executable code, and figuring out what it's doing.
For next time: Read 3.6 on Control forms, and 3.7 on Procedure calls. We'll discuss on Thu.
http://cs.marlboro.edu/ courses/ fall2010/systems/ notes/ sep_28
last modified Tuesday September 28 2010 12:28 pm EDT

attachments [paper clip]

     name last modified size
[COD]small.c Sep 28 2010 12:28 pm 648B