Lab - GDB Refresher
For this lab you will be using
gdb to analyze a binary. 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 and the internet for tips and tricks.
You should solve this lab on either
- Download and unpack the starter files from here. (You should probably download them directly onto the remote unix server using
- 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.
Using GDB to view assembly
- Use GDB to view the assembly code for orange and red. After you successfully do this, if you are a remote student then download this document containing the source code for orange. If you are in class, then simply ask the instructor for a print out of the document.
- On the document, 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 RSP into RBP”, 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 right before the call to
- 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 may require typing 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. If you are an in-person student, submit your papers to the instructor before leaving class. If you are a remote student, email them to the instructor before leaving class.