TopAn Input/Output Library?Debugging Support

Debugging Support

The one final complication is that I want you to include directives to the assembler that will enable it to pass enough information about your source program on to the interpreter to make symbolic debugging of the original Co program possible. The format of these directives, named STAB directives (for Symbol TABle), is described in the assembler handout. However, I have tried to make it possible for you to include these directives in your output without learning much about their format (and without writing much code).

To do this, I will give you yet another file of C code, stabgen.c and a new version of main.c. The new version of main.c differs from the old one in that it assumes you will give it a file name to read Co source code. This is important, because it enables your compiler to tell the assembler (and ultimately the interpreter) where the Co source code can be found. This is done by including an STAB-FILE directive at the start of your output file. The new main.c arranges to output this directive by calling one of the routines provided in stabgen.c.

I have given you the source code for stabgen.c, but I suspect you will not have to modify it. Nevertheless, you should make your own copy of this source file and add its name to the SRC line of your Makefile. It contains two routines that should provide you with an easy way to output all the STAB directives required.

The procedure outputmainstabs should be called just before you begin generating code for the main program. It expects a pointer to the root of the program syntax tree as its operand. It will print STAB directives describing all the types and global variables used in the compiled program. Obviously, it depends on your symbol table structures to determine this information.

The procedure outputprocstabs should be called once for each procedure in the source program just before you begin to generate code for that procedure. It expects a pointer to the Nprocdefn or Nfuncdefn node for the procedure as a parameter. It outputs STAB directives for all the parameters and locals of the procedure.

In addition to enabling the interpreter to provide debugging facilities for your Co programs, it is hoped that the somewhat readable nature of the STAB directives will make them useful when examining your compiler's output. In particular, for each variable, these directives provide a way to determine the displacement your compiler assigned to the variable. Thus, to some degree, they can replace the DumpDclDescs output.


Computer Science 434
Department of Computer Science
Williams College

TopAn Input/Output Library?Debugging Support