Compile-time and run-time debugging
The goal of this lab is to learn how to use the tools in Eclipse to help with debugging programs.
Typically, errors in programs are put into two categories: compile-time errors, which are typically
syntactic in nature; and run-time errors, which are typically errors in your programming logic.
Prior to the advent of IDEs like Eclipse, a programmer would typically use the compiler to uncover syntactic errors (hence the term compile-time errors), often working through the program line by line. Eclipse also uses the compiler, but is able to highlight the errors in the source file in the edit window, often even making a good guess what type of error you made.
Run-time errors are generally more difficult to deal with, since they often arise fairly subtle logic errors that might not always manifest themselves when running the program. Eclipse provides a very nice graphical debugger that allows you to step through the code and examine the values of the variables.
I am providing an auxiliary document which you should read while doing this lab:
You may, in fact, want to peruse this first before doing the lab. At any rate, by the end of this lab you should have completely read this other documents.
Compile-time errors (1 point)
This step will will create a project containing a file
stats.ccwhich is a simple program that finds the mean, median and mode of an unsorted array. It almost works, but needs your help in fixing it. Do this as follows:
- create a new makefile C++ project called Statistics
- in that project create a new source file called
- put the contents of
stats.ccinto that file
Even though the file contains compile-time errors, create the
makefilenow that will compile and link this file into an executable file called
stats. You can do this by emulating how we created the makefile in the first lab, but take this opportunity to read the online notes in Using g++ to understand the commands you are issuing in the
Since Eclipse highlights syntactic errors in the source file and often even guesses what types of errors they are, you be able to dorrect these errors wuite quickly. Do so.
Check-off: After you have corrected these errors, show me that you have successfully compiled your program. Ask to be checked off for this part.
Run-time (or logic) error (1 point)
Run this program, either in Eclipse or in a terminal window. Can you tell there is something wrong? This type of error, which occurs at run-time, tends to be significantly more tricky to correct than compile-time errors. It is for this type of error that the debugger is particularly helpful.
At this point, you should examine the program, and experiment with debugger to isolate the error (which function is likely to be responsible?). In particular, you will need to tell it to break at a given procedure), examine the contents of variables, and step through program statements.
We reassure you that the error can be corrected by changing only one line. When you think you have found the error: correct it, save the file, rebuild and run the program to see if the problem is solved.
Check-off: Ask to be checked off on this portion of the lab. You should have on your screen the line(s) of the program you changed. I will also want you to demonstrate to me that you can see the values in the array as you step through the procedure that had the error.