Programming Assignment P3 - Stack Trace

About the Assignment

This assignment is designed to build on your understanding of the stack and pointers you used to create the stack dump function in the recitation. In this assignment you will build a strack trace function to print only the stack frames in an executing program, rather than all of the memory. The function will follow the frame pointer links until there are no frames left. After printing a heading line for the columns in the stack trace, each frame will be printed on a single line and include:

First, read the Getting Started section below. Then study the documentation in trace.h and trace.c to understand the details of the assignment.

Getting Started

Perform the following steps:

  1. Create a new directory for this assignment. We suggest you call it P3, but you may call it anything you like.
  2. Copy the appropriate files into this directory. It is easiest to right click on the link and do a Save Target As....
  3. Open a terminal and go to the directory you created.
  4. In the terminal type the following command to build the executable:
    You should see the following output:
        gcc -m32 -g -std=c11 -Wall -c -DDEBUG -DHALF trace.c
        gcc -m32 -g -std=c11 -Wall -c -DDEBUG -DHALF testTrace.c
        gcc -m32 -o testTrace -g -std=c11 -Wall trace.o testTrace.o
  5. In the terminal type the following tor run the program. It will not produce any output.
You now have a functioning program. You can begin to complete the code to produce a stack trace.

Completing the Code

Before attempting to write any code, study the documentation and plan what you need to do. The best way to complete the code is to follow a edit/compile/test sequence. Do not attempt to write everything at once. Rather choose one function, then write, compile, and test a few lines at a time. This will minimize the amount of code you must consider when debugging. When that code is thoroughly tested, proceed with the next few lines.

Note that the number offset from the top of the stack to the first frame pointer may change. This occurs if your traceStack() function has a different number of local variables than your dumpStack() function. One way to resolve this is to change your dumpStack() function to have the same parameters defined in exactly the same order to determine the appropriate offset.

You should only print the frames for the recursive function. You should not print the frame for the traceStack() function or the frame for the main() function that calls the recursive function.

Your output should match the following format exactly when 1 parameter and 1 local variable are specified. Note the leading zeros in the hexadecimal numbers along with the leading 0x.

FrameAddr     FramePtr      ReturnAddr    Parm1         Local1
0xffceeb08    0xffceeb58    0x0804861e    0x00000000    0xffffffff
0xffceeb58    0xffceeba8    0x0804861e    0x00000001    0x00000000

You should work on the functions in the following order since the second depends on the first. A sample solution contained these approximate line counts, not including empty lines or debugging statements.

Your code should be of similar length (+- 50%). If you find your solution is much longer than stated, you might want to think about how you are approaching problem.

Grading Criteria

This assignment is automatically graded:

For a perfect submission:

Checking in Your Code

You will submit the single file trace.c. You can either submit through the website or use the checkin program:

    ~cs270/bin/checkin P3 trace.c
You are done with the assignment!