Lecture%2007%20-%20Debugging

Lecture%2007%20-%20Debugging - Lecture 07 Debugging...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Copyright @ 2009 Ananda Gunawardena Lecture 07 Debugging Programs with GDB In this lecture What is debugging Most Common Type of errors Process of debugging Examples Further readings Exercises What is Debugging Debugging is the process of finding compile time and run time errors in the code. Compile time errors occur due to misuse of C language constructs. Most of the compile time errors can be overcome with careful attention to language syntax and use. Finding syntax errors is the first step in a debugging process. A typical C project that contains main.c, lib.h and lib.c can be compiled at once with % gcc –ansi –Wall –pedantic lib.c main.c –o exec It is also good to compile all source code files separately, so programmer can deal with errors more locally. For example, the main.c and lib.c in the above example can be compiled separately with –c flag. % gcc –c –ansi –Wall –pedantic main.c % gcc –c –ansi –Wall –pedantic lib.c In this case, no executable is created and two files named main.o and lib.o will be created if source code is successfully compiled. Later on, one can create the executable by % gcc lib.o main.o –o exec Often dealing with syntax errors is the easiest part of debugging. Once you remove common errors like, missing semicolons, variable type mismatches, incorrect passing of
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Copyright @ 2009 Ananda Gunawardena arguments, undefined or out of scope variables etc we can begin to execute the code. Run time errors are the hardest to deal with. Run time errors can cause program to crash, or give you the incorrect output. First step in dealing with run time errors is to remove reasons for program to crash. Some of the most common errors of program crash are, dereferencing memory that has not been allocated, freeing memory that was already freed once, opening a file that does not exists, reading incorrect or non-existent data or processing command line arguments that have not been provided. Although debugging a program is an art, it is important to develop a systematic process to debug. Often the best way to deal with errors is to not to introduce them in the first place. Developing individual functions and testing them to make sure they perform as expected is quite important. For each function, you provide the input and test for the expected output. You also need to deal with edge cases as they are most often the cause of the problem. Also it is important to test the input files to make sure
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 11/27/2009 for the course CS 123 taught by Professor Bajkzek during the Fall '08 term at Carnegie Mellon.

Page1 / 10

Lecture%2007%20-%20Debugging - Lecture 07 Debugging...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online