Now we’re going to use a sample program,
map, for some GDB practice. The
map program is designed to print out its own executing structure. Before you start, be sure to take a look at
recurse.c which form the program. Once you feel familiar with the program, you can compile it by running
Write down the commands you use to complete each step of the following walk-through. Be sure to also record and submit your answers to all questions in bold to Gradescope.
Run GDB on the
Set a breakpoint at the beginning of the program’s execution.
Run the program until the breakpoint.
What memory address does
Describe what’s located at that memory address. (What does
Step until you reach the first call to
What is the memory address of the
Step into the first call to
Step until you reach the
Switch into assembly view.
Step over instructions until you reach the
callqinstruction (or the
callinstruction if you are using QEMU).
What values are in all the registers?
Step into the
Switch back to C code mode.
Now print out the current call stack. Hint: what does the
Now set a breakpoint on the
recurfunction which is only triggered when the argument is 0.
Continue until the breakpoint is hit.
Print the call stack now.
Now go up the call stack until you reach
main. What was
Now step until the return statement in
Switch back into the assembly view.
Which instructions correspond to the
return 0in C?
Now switch back to the source layout.
Finish the remaining 3 function calls.
Run the program to completion.