Lab 02 Part I Addresses in descending hex order. the bottom of main's stack frame (this is stored in register $fp) 0x7fffffffe500 the top of main's stack frame (this is stored in register $sp) 0x7fffffffe4e0 the local variable 'x' in main 0x7fffffffe4e8 what 'x' is pointing to; the value of 'x' is in heap-dynamic data section 0x601010 the bottom of foobar's stack frame (this the stored in $fp) 0x7fffffffe4d0 'w' in function foobar (this is an argument in foobar's stack frame) 0x7fffffffe4bc 'y' in function foobar (this is a local var in foobar's stack frame) 0x7fffffffe4c4 &MAX (this is a variable in the static data section) 0x600930 the first instruction in main 0x400513 the last instruction in main 0x400561 Visual depiction of process image from high to low addresses: -------------------------------------------- | 0x7fffffffe500 bottom of main frame +------------------------------------------- | 0x7fffffffe4e8 local var x +------------------------------------------- | 0x7fffffffe4e0 bottom of main frame +------------------------------------------- | V ^ | -------------------------------------------- | 0x601010 heap +------------------------------------------- | 0x600930 static data +------------------------------------------- | 0x400561 .text segment - last instruction in main | 0x400513 .text segment - first instruction in main +------------------------------------------- Sample session: (gdb) break main Breakpoint 1 at 0x40051b: file lab02.c, line 79. (gdb) break foobar Breakpoint 2 at 0x4004f0: file lab02.c, line 72. (gdb) run Starting program: /home/fac/donna/public_html/cs224/examples/week02/lab02 Breakpoint 1, main () at lab02.c:79 79 int *x = (int *) malloc(sizeof(int)); // a ptr is stored in heap (gdb) p $fp $1 = (void *) 0x7fffffffe500 (gdb) p $sp $2 = (void *) 0x7fffffffe4e0 (gdb) (gdb) p &x $2 = (int **) 0x7fffffffe4e8 (gdb) p x $3 = (int *) 0x601010 (gdb) cont Continuing. Breakpoint 2, foobar (w=1, x=2.5) at lab02.c:72 72 y = w; (gdb) p $fp $4 = (void *) 0x7fffffffe4d0 (gdb) p &w $5 = (int *) 0x7fffffffe4bc (gdb) p &y $6 = (int *) 0x7fffffffe4c4 (gdb) p &MAX $7 = (int *) 0x600930 (gdb) p main $8 = {int (void)} 0x400513
(gdb) s 73 z = x / y; (gdb) s 74 } (gdb) s main () at lab02.c:83 83 int MAX = 5; (gdb) p $pc $9 = (void (*)()) 0x400561 (gdb) cont Program exited normally.