1. Set a breakpoint at line 14, and stop when you get there, and answer the following questions... A. What is the highest address in the stack frame (the top of the frame)? : 0x7fffffffe410 (the value of %rbp) (gdb) p $rbp B. What is the lowest address in the stack frame (the bottom of the frame)? : 0x7fffffffe3f0 (the value of %rsp) (gdb) p $rsp C. What is the size of main's stack frame (including the 8 bytes pointed to by %rbp)? : 40 bytes ( 0x20 +8 = 32 + 8 ) D. Does the "main" function use the red zone? : no If so, why can main use the red zone? : It can't If not, why not? : Because main calls lower level functions. It is not a leaf function E. Several values are kept in main's stack frame. Complete the following table: Variable | Offset from %rbp | gdb display cmd | Current Value | ---------+------------------+-----------------+----------------+ argc | -0x14 | x /dw $rbp-0x14 | 2 | argv | -0x20 | x /a $rbp-0x20 | 0x7fffffffe4f8 | n | -0x04 | x /dw $rbp-0x4 | 6 | Note: Since we are in the main function, and have been called by the operating system, and the operating system does not follow all of the expected conventions, we cannot ask questions about main's CALLER's stack frame. 2. Set a breakpoint at line 28 in fib.c when the parameter "n" has a value of 3. (Note... make sure this is the FIRST time you have gotten to line 20 with n==3. If not, you will get the wrong answers.) A. What is the highest address in the stack frame (the top of the frame)? : 0x7fffffffe380 (the value of %rbp) (gdb) p $rbp B. What is the lowest address in the stack frame (the bottom of the frame)? : 0x7fffffffe360 (the value of %rsp) (gdb) p $rsp C. What is the size of fib's stack frame (including the 8 bytes pointed to by %rbp)? : 40 bytes ( 0x20 +8 = 32 + 8 ) D. Does the "fib" function use the red zone? : no If so, why can main use the red zone? : It can't If not, why not? : Because fib calls itself recursively. It is not a leaf function E. Several values are kept in fib's stack frame. Complete the following table: Variable | Offset from %rbp | gdb display cmd | Current Value | ---------+------------------+-----------------+----------------+ n | -0x14 | x /dw $rbp-0x14 | 3 | answer | -0x04 | x /dw $rbp-0x4 | 0 | n1 | -0x08 | x /dw $rbp-0x8 | 1 | n2 | -0x0c | x /dw $rbp-0xc | 1 | 3. Still at this same breakpoint, but now concentrating on the SECOND stack frame, ABOVE the current stack frame (the caller's stack frame) A. What is the highest address in the caller's stack frame (the top of the caller's stack frame?) : 0x7fffffffe3b0 (the value in the %rbp address in memory) (gdb) x /a $rbp B. What is the lowest address in the caller's stack frame (the bottom of the caller's stack frame?) : 0x7fffffffe388 (8 bytes above the top of my stack frame) (gdb) p $rbp+8 C. What is the return address for the current function? : 0x5555555547b7 (the value at the bottom of the caller's stack frame) (gdb) x /a $rbp+8 D. What line of C code does the return address come from? : line 27 (fib starts at 76a + 77(10) = 7b7 which is line 27) E. Several values are found in the fib stack frame ABOVE the current stack frame. HINT: I used the gdb command "set $crbp = 0x7fffffffe3b0" to make it easy to reference my caller's %rbp. Using the caller's stack frame, complete the following table: Variable | Offset from %rbp | gdb display cmd | Current Value | ---------+------------------+-----------------+----------------+ n | -0x14 | x /dw $crbp-0x14| 4 | answer | -0x04 | x /dw $crbp-0x4 | 0 | n1 | -0x08 | x /dw $crbp-0x8 | 1 | n2 | -0x0c | x /dw $crbp-0xc | 0 | 4. Still at this same breakpoint, but now concentrating on the THIRD stack frame, the caller's caller's stack frame. A. What is the highest address in the caller's caller's stack frame? : 0x7fffffffe3e0 (the value at the caller's rbp in memory) (gdb) x /a $crbp B. What is the lowest address in the caller's caller's stack frame (the bottom of the caller's caller's stack frame?) : 0x7fffffffe3b8 (8 bytes above the top of the caller's stack frame) (gdb) p /x $crbp+8 C. What is the return address for the current function? : 0x5555555547a7 (the value at the bottom of the caller's caller's stack frame) (gdb) x /a $crbp+8 D. What line of C code does the return address come from? : line 26 (fib starts at 76a + 61(10) = 7a7 which is line 26) E. What is the value of "n" in the caller's caller's stack frame? : 6 (gdb) x /dw $ccrbp-0x14 5. Still at this same breakpoint... no point in continuing up the stack frames, you should get an idea of what is going on by now. Instead, to summarize, look at the result of a gdb "where" command: (gdb) where #0 fib (n=3) at fib.c:28 #1 0x00005555555547b7 in fib (n=4) at fib.c:27 #2 0x00005555555547a7 in fib (n=6) at fib.c:26 #3 0x0000555555554747 in main (argc=2, argv=0x7fffffffe4f8) at fib.c:14 A. Which line of the gdb "where" output is associated with the current stack frame; #0, #1, #2, or #3? : #0 B. Which line of the gdb "where" output is assocaited with the caller's stack frame; #0, #1, #2, or #3? : #1 C. Which line of the gdb "where" output is associated with the caller's caller's stack frame; #0, #1, #2, or #3? : #2 6. Extra credit: If lines 27 and 26 are switched in fib.c, and you set a break point at line 28 the first time n has a value of 3, what would the results of the gdb "where" command look like? (gdb) where #0 fib (n=3) at fib.c:28 #1 0x00005555555547b7 in fib (n=4) at fib.c:26 #2 0x00005555555547b7 in fib (n=5) at fib.c:26 #3 0x00005555555547b7 in fib (n=6) at fib.c:26 #4 0x0000555555554747 in main (argc=2, argv=0x7fffffffe4f8) at fib.c:14