Getting Output

Last modified: "September 10, 1999 13:53:57 by evett"


Dear Matt,

My program compiles great, but when I try to run it, the program crashes. I've tried everything!! What's wrong??!!

--A Frazzled Student

Dear Frazzled,

This is like going to your car mechanic and telling her, "Help! My car won't work!" The mechanic may be sympathetic, but you've not given her enough information to get started. What's even worse, is that you're supposed to be a mechanic (read, "programmer") in-training, so you really ought to be able to phrase your question better.

The first questions a mechanic would ask is: "why do you think your car won't work?" and "what are the symptoms?" The first questions a programmer should ask is: "where does the program crash?" and "what are the symptoms?" To answer the first question, you will have to use a debugger, such as xxgdb or gdb (in Unix), or the debugger of your Borland or Visual IDE that learned about in COSC238.

Unix people:

Make sure you have compiled and linked your program using the "-g" flag. To run the debugger, use the Unix command, "xxgdb FOO", where FOO is the name of your executable. Click on the "Run" button. When the program crashes, the top xxgdb window will use a small arrow to point to the line of code that was last being executed when the program crashed. This may not be your code, but my instead be in library code, such as CPstring.cc, etc. Use the xxgdb "Stack" command to see which functions called which to get you into this mess. In the Stack window you will see (far enough down) a function that you wrote. You can use the "Up" xxgdb command to move to that stack entry. When you do that, you'll see your program file, and the xxgdb arrow pointing with the offending line therein.

Borland and Visual people:

Basically, you want to do the same thing as outlined for the Unix users: open the debugger window and run the program. When the program crashes, the debugger should highlight the line of the program where the crash occurred. You should be able to examine the values of local variables for this routine. Use the Stack window to examine the variables of the functions that called this one. (Keep in mind that the error might not be located at exactly where the program halted!)

Note that in the debugger you can view the values of variables, Vectors, vector elements, etc. You must learn to use the debugger!! It is a tool you will use countless times in your professional career.