Lab 1: GDB Refresher
For this lab you should be using a Linux machine with 32-bit libraries. This will make things line up much better with both the slides and the homework. You will notice that this handout does not give you specific, line-by-line commands to execute. This is intentional. You are free to consult each other for tips and tricks.
- Download and unpack the starter files from here.
- Look at the source code to make sure you understand what this simple code does.
- Use the Makefile to compile the binary.
- Run the program.
- Use the objdump command to view the assembly code for orange and red. When you can do this, show the instructor and he will give you a print-out containing the assembly for orange.
- On the printout, write comments next to each line describing its purpose. You need to described the purpose, not the functionality. For example, don’t say “Move the value of ESP into EBP”, instead say “Save the current stack pointer as the base pointer for this frame”.
Using GDB to Analyze the Stack
Now that you can download and run the program, you will use GDB to analyze it and write down a copy of the stack frame (by hand, on paper).
- Load the program inside GDB.
- Set a breakpoint on the function red.
- Run the program, and when the breakpoint triggers, take out a piece of paper and draw a diagram showing the current contents of the stack. Label each item on the stack with its purpose. (Note: This step will take you a while and includes multiple GDB commands.) Only include items related to stack frames for the functions orange and red.
When you finish, you should have two pieces of paper. The first contains an annotated version of the assembly code for orange. The second contains a diagram of the stack that shows the addresses, contents, and purpose of every item on the stack related to the stack frames for orange and red. Feel free to compare your results with that of other students, but do not copy from other students. Do the work yourself. Submit your papers to the instructor before leaving class.