??? 01/20/08 22:44 Modified: 01/20/08 22:46 Read: times |
#149787 - comments on clarifications Responding to: ???'s previous message |
Now, let me state one opinion: debugging by means of inserting printf statements is the crappiest method anyone ever has devised.
Can't agree with that. To be fair, since I do application code instead of embedded work these days My opinions etc in this forum relate to 'embedded work' what relates to other types of work is a subject for another forum. In 'embedded work' in particular the potential for injecting a timing error is just too large. Also, see comments below. In the worst case, where you know everything was kosher at point A but something was amiss at point B, and there were a gazillion instructions executed between A and B, do what I call a "binary search for the bug". Insert a carefully chosen printf half way between A and B. If everything is copacetic move the printf to half way between that point and point B. Otherwise go the other way. SOP, but why use printf(). With an ICE you just move the breakpoint, with priontf you need to edit, recompile, relink and reload for every new 'binary point' I can almost always find the bug more quickly using printf than using a debugger. On those occasions where that doesn't apply, I use the debugger. Whatever is likely to make the work faster and easier. if printf works for you (doing applications), go ahead. For embedded systems, you could use Jan's idea of the "embedded printf". I've done that or similar many times, with good results. again edit, recompile, relink and reload for every step. The most important point in debugging is to make sure the code is correct. Too many times I've seen someone identify the cause of a problem and "fix it" by changing a line or two of code because that makes the problem "go away". Only later, if at all, do they realize that their "fix" broke something else because they didn't really understand the code and didn't bother to analyze either the code or their fix to make sure it was correct. Here, Jeff, we do agree. Much like some of my students who get the right answer for the wrong reason. That's why I try to get them to understand the concepts and not just memorize formulas. Students in statistics are particularly bad in that regard, but even algebra students make truly astounding mistakes. I once had a young lady who worked out an interest rate problem about purchasing a $20,000 car at some interest rate for so many months. She computed the total of payments to be slightly over 2 million dollars, and for some reason this didn't bother her at all. Made me consider a third career as an auto salesman ;-) I see the same again and again. We who grew up with pencil ans slapstick .. eh sliderule learned to check our results. The generation that grew up with a calculator have no idea whether the result is a keypress error or not. Once someone tried to give me more change than the bill I paid with. Erik |