



























Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




























Current context Monday, October 15, 2012 4:38 PM
Actually a misnomer. You aren't "debugging a program." You're "debugging your understanding" of it. The art of debugging Original metaphor: moths in the relays. Modern analogues: none. Modern hardware does exactly what you tell it to do. So, we need a different concept of what a bug is. What is a bug? Debugging Wednesday, October 10, 2012 9:51 AM
Bugs are not in the code, they are in the comments! It is your understanding that contains the bug. Do not write a line of code that you don't think you understand. Programming by osmosis simply doesn't work. Periodically verify your understanding via proof-of-concept experiments. To repair a defect, try to understand what is happening before changing a program. Try to repair the defect only with a verified understanding in hand. Couch's principles of debugging Debugging requires writing a lot of code that is not in the program under test. Couch's principles of debugging Wednesday, October 10, 2012 9:52 AM
Arrogance kills; if you think you really understand something and you don't, or -- equivalently -- you are absolutely sure that a component is bug-free, bugs in that component can evade you indefinitely. Verifying your understanding "you always find the bug in the last place you look." Verifying understanding Wednesday, October 10, 2012 10:18 AM
It is possible to search forever for a defect if your search is not structured. Sherlock Holmes principle of debugging: "If one eliminates the probable, then whatever remains -- however improbable -- is the truth." In other words, most effective debugging strategies involve some kind of sieve approach in which possibilities are eliminated one by one. Or you'll be sorry… Or you'll be sorry… Wednesday, October 10, 2012 10:09 AM
Instruction pipelining. Cache effects. One cannot actually single-step a program on a modern architecture, due to Debuggers (e.g., gdb, xxgdb, etc) simulate single-stepping rather than really stepping the processor. Thus it is possible for a debugger to change the behavior of a program, due to imperfections in the simulation. At best, the concept of where the program counter points in a source program -- according to a debugger -- is a polite fiction ; the C and C++ optimizers move code around. Thus, when you single-step the program, you will see the PC "jump" non-locally around your code! A caution about "debuggers" A caution about debuggers Wednesday, October 10, 2012 10:23 AM
It is a common misconception that defects are attributes of the code of the application. Where can defects hide? In deviations from proper versions of required library code. In deviations in where necessary system files are located. In deviations from preconditions necessary in the environment in which the program runs (its "configuration") They can also occur: Where can defects hide? Monday, October 15, 2012 2:29 PM
Control the experiment. Limit variation. Reconstruct exact conditions. Often, locating a defect requires significant programming in itself, to Scaffolding: running the subsystem that exhibits the defect in isolation from others. Stubbing: writing versions of lower-level routines that serve to reproduce the defect condition. Trace-driven reconstruction: storing a trace of inputs for "playback" in order to reproduce the bug (in coordination with scaffolding and/or stubbing). Some important defect isolation techniques It is nearly impossible to repair a defect without being able to reliably reproduce it. "Reproducing" the defect Monday, October 15, 2012 10:07 AM
A "Heisenbug" is a defect that occurs so sporadically that it is impossible to hypothesize and/or reproduce the conditions under which it occurs. Source of the name: the Heisenberg uncertainty principle : it is impossible to know exactly "where" an electron is located, because trying to measure its location changes that location! Coping with "Heisenbugs" Document what effects occur as a result, i.e., what changes in postconditions occur. Test for those conditions with antibugging. If antibugging detects the defect, report the context of the defect. Refine hypotheses based upon context data. Best strategy for Heisenbugs: set a trap for them: Coping with "Heisenbugs" Monday, October 15, 2012 10:48 AM
Most of you are used to a model where debugging writes are written to the terminal of the user. System console Reporting through a web service (SOAP or REST) Other common antibugging mechanisms include: Antibugging and reporting User isn't aware. Doesn't conflict with user use. Doesn't affect user perceptions. Advantages Slower than printing. There are privacy concerns. May change the timing and resulting behavior. Disadvantages Antibugging and reporting Monday, October 15, 2012 10:52 AM
In this case, the bug isn't gone; it is just a timing problem that logging cures. You might "squash the bug" by adding logging. The bug isn't gone; its manifestation is all that disappeared. You might "squash the bug" by adding or removing print statements. Some caveats on logging see http://www.cs.tufts.edu/comp/250PSD/examples/Debugging/enigma.c Putting a printf between two calls doesn't break anything... ... unless the printf has an argument! for details of such a situation. Some caveats on logging Monday, October 15, 2012 2:41 PM
Always work from a hypothesis about what is wrong. Construct tests to refute or support the hypothesis. Document results of each test. Refine the hypothesis based upon results. Working from hypotheses: Control the experiment. Rule out options. Localize causes. At each step Couch's comprehensive method for understanding software defects: #1: work from hypotheses. Wednesday, October 10, 2012 10:28 AM
Scaffolding and/or stubbing. Trace-driven reconstruction. Reproduce the defect , via a variety of methods Document the invariants of all data structures. If a guard violation is found, localize when and in what context by projection pursuit. If not, next step. Write guard clauses that detect violation of the invariants. If a discrepancy is found, localize when and where it arose by projection pursuit. Otherwise, next step. Choose one use case exhibiting the defect, and document the specific states of data structures that should occur. Test this against states that do occur, and check for discrepancies. … Couch's simplified defect removal process A simplified defect location and removal process Wednesday, October 10, 2012 11:40 AM
Problems in the code itself. Problems in the environment. Problems in the execution model. Kinds of defects Some defects arise from the compilation model or runtime execution model, rather than the code itself. Defects that arise from the execution model Monday, October 15, 2012 12:08 PM