Lab 1: GDB Refresher

For this lab you should be using a 32-bit Linux machine. 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.

Getting Started

  1. Download and unpack the starter files from here.
  2. Look at the source code to make sure you understand what this simple code does.
  3. Use the Makefile to compile the binary.
  4. Run the program.

Using objdump

  1. 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 red.
  2. 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).

  1. Load the program inside GDB.
  2. Set a breakpoint on the function red.
  3. 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.

Submission

When you finish, you should have two pieces of paper. The first contains an annotated version of the assembly code for red. 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.