Breakpoints, print statements, and trace tables are debugging techniques used to follow program execution, inspect variable values, and locate the cause of errors. Breakpoints and print statements are applied to executable code, while trace tables can be used to dry-run an algorithm manually.
How Each Technique Works
Debugging is the systematic process of identifying, locating, and correcting errors in an algorithm or program. These techniques are especially useful for finding logic errors, where a program runs but produces an incorrect result, and runtime errors, which occur while the program is executing.
| Technique | Mechanism | Best use |
|---|---|---|
| Breakpoint | Pauses execution at a selected line in a debugger. The programmer can inspect variables, the call stack, and program state before stepping through subsequent instructions. | Finding the exact instruction at which program state becomes incorrect. |
| Print statement | Outputs selected values or messages during execution, such as print(total). Comparing the output with expected values reveals where the algorithm stops behaving correctly. | Quickly checking control flow, loop iterations, conditions, and changing variable values. |
| Trace table | Records variable values, conditions, outputs, and iteration numbers after each relevant instruction in a manual dry run. Each row represents a step or iteration. | Analysing pseudocode without executing it and predicting an algorithm's output. |
For example, if a loop calculates an incorrect total, a breakpoint can pause each iteration, print statements can display the changing total, and a trace table can record the expected changes manually. Comparing the actual and expected states helps isolate the faulty instruction or condition.
A common misconception is that these techniques automatically correct errors. They do not: they provide evidence that helps the programmer locate the cause before modifying and retesting the code.
IB Exam Technique
For B2.1 Programming fundamentals, be prepared to explain how a named technique identifies an error, not merely define it. When completing a trace table, follow the algorithm exactly, update values only when assignments occur, and include separate rows for relevant iterations or decisions.