Saturday 12 November 2011

What Tools Should Be Used to Debug a Program? in C programming

What Tools Should Be Used to Debug a Program?

There are many tools that the skilled programmer can use to help him debug his program. These include an
array of debuggers, “lint” programs, and, last but not least, the compiler itself.

Debuggers are really wonderful for finding logic errors in programs, and consequently they are what most
programmers choose as their primary debugging tools. Debuggers commonly enable the programmer to
complete the following tasks:

1. Observe the program’s execution.

This capability alone would make the typical debugger invaluable. Very frequently, even with code that you have carefully written over a period of several months, it is not always clear what the program is doing at all times. Forgotten if statements, function calls, and branches might cause blocks of code to be skipped or executed when this is not what the programmer would expect. In any case, being able to see which lines of code are being executed at all times, especially during odd behavior, gives the programmer a good idea of what the program is doing and where the error lies.

2. Set breakpoints.

By setting a breakpoint, you can cause a program to halt its execution at a certain point. This feature is useful if you know where the error in your program is. You can set the breakpoint before the questionable code, inside the code itself, or immediately after the code. When your program encounters the breakpoint and ceases execution, you can then examine the state of all the local variables, parameters, and global data. If everything is OK, the execution of the program can be resumed, until it encounters the breakpoint again or until the conditions that are causing the proble assert themselves.

3. Set watches.

Debuggers enable the programmer to watch a variable. “Watch a variable” means that you can constantly monitor the variable’s value or contents. If you are aware that a variable should never stray out of a certain range or should always have valid contents, this capability can quickly point out the source of an error. Additionally, you can cause the debugger to watch the variable for you and halt the execution of the program when a variable strays out of a predefined range, or when a condition has been met. If you are aware of what all your variables should do, this is quite easy. Good debuggers often have additional features that are designed to ease the task of debugging. A debugger, however, is not the only tool that can be used to debug your programs. Programs such as “lint” and your compiler itself can provide valuable insight into the workings of your code.

NOTE

Lint is a program that knows of hundreds of common programmer mistakes and points out all of
them in your program. Many are not real errors, but most are worth addressing.

What these tools typically offer that a debugger cannot are compile-time checks. While they are compiling your

code, they can look for questionable code, code that might have unintended effects, and common mistakes.
Examining a few instances in which this kind of checking is used can be helpful.

No comments:

Post a Comment