English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

3 answers

You need to know the language well enough to be able to
produce something that compiles.

If you've got that, you simply put in printf() statements
throughout the code printing out key variables and telling
you where the computer is currently executing.

This is known as "When in doubt, write it out."

The idea here is simple: The computer can't do it if you can't.
That is, you should be able to step through each line of code
figuring out what you want it to do vs. what it is actually doing.

So ...

Scatter your program with printf()s. Alternately, learn your
local symbolic debugger (gdb, dbx come to mind). This will
allow you to actually execute single instructions and print out
the value of variables ... but you end up having to learn about
program stacks which may be more than you want to know.

I *HIGHLY* recommend: When in doubt, write it out.

2006-09-25 17:04:08 · answer #1 · answered by Elana 7 · 0 0

Debugging is more an art than science. Some general principles are as follows:
1. First analyze the behavior of the program and try to note down as much as possible which could provide you some clue on what the problem is.
2. Try to narrow down the scope/region where the problem is residing.
3. Generously place asserts within your code to validate your assumptions on what the function should accept or do.
4. There is a simple trace class that you can include at the beginning of the function(s) that you wish to track.
class Trace {
private:
char d_name[100];
public:
Trace(const char *name) {
strcpy(d_name, name);
printf(">> Entered Function: %s\n", d_name);
}
~Trace() {
printf(">> Exiting Function: %s\n", d_name);
}
}; // Trace

void function_to_track() {
Trace("function_to_track");
called_function();
}

void called_function() {
Trace("called_function");
}
==== Output ===
>>Entered function: function_to_track
>>Entered function: called_function
<< Exited function: called_function
<< Exited function: function_to_track

5. The above simple techniques will help you to debug C programs of small-medium size. However if you have 10K+ lines of code a good debugger with facilities for putting breakpoints and watchpoints would be your best bet.

2006-09-26 02:41:49 · answer #2 · answered by swami060 3 · 1 0

sorry buddy but you need to give us some specifics about the software that you are using. Manual debugging will only work if its a very simple program and then you can do it on paper, look to see if there are any missing }'s or semicolons, etc.

2006-09-26 00:01:25 · answer #3 · answered by Anonymous · 0 0

fedest.com, questions and answers