Project 3: Re-learning the Stack

Due Monday, April 9

There is a program, p3_program.c, located in the class examples area. Compile it with:
gcc -g -std=c99 p3_program.c -o p3_program
Inside the program source code is a comment indicating a location inside the function bar. At that location, draw the program stack from the arguments to main all the way down through and including the frame generated for function bar. List the contents of each 4 or 8 byte section of memory, as is appropriate to data type. Include both numerical contents and purpose (return location, variable value, etc). Make a table like the following, but for every value on the stack:
AddressNumerical ContentsPurpose
0x7fffffffe8cc768Value of variable g
Note that not all variables on the stack will be the same size! You can use gdb to obtain the data for the address and numerical contents columns, but the purpose will require some thinking. You can use HTML, Word, LaTeX, ASCII text, neat and legible handwriting, or something else I haven't thought of for your table, provided it is clear and easy to understand. Feel free to add code to the program as long as the stack remains reasonably unaffected. In particular, a loop which prints out the values of each location is encouraged as an alternative to extensive GDB use. With some text formatting and consideration for data types, it may be possible to generate the first two columns of your table.
After generating your table, read and understand the article "Smashing the Stack for Fun and Profit", by Aleph One. This and the lab sequence will complete your preparation for Project 4. You don't have to turn in anything to indicate you finished reading the article.