Debugging
CIE A-Level Computer ScienceΒ· Unit 12: Software DevelopmentΒ· 10 min read
1. Types of Program Errorsβ β ββββ± 3 min
Before debugging can begin, errors must be classified by their type, as this guides your choice of debugging approach. CIE 9618 regularly examines your ability to distinguish between the three core categories of program error.
Core Program Error Types
Three main categories of error encountered during software development, each with distinct symptoms and requiring different debugging approaches.
Example:
Syntax errors, runtime errors, logic errors
Syntax errors: Violations of the programming language's grammar rules, caught by compilers or interpreters before execution starts. The program will not run at all.
Runtime errors: Errors that occur during program execution, causing the program to crash or abort unexpectedly before it completes.
Logic errors: Errors where the program runs to completion without crashing, but produces incorrect output or behaves in an unexpected way.
Classify the following error: A Python program divides a user's input by zero, and stops execution with a ZeroDivisionError message.
- 1
Step 1: Confirm the program compiled/interpreted successfully and started execution before failing.
- 2
Step 2: Note the outcome: the program stopped execution unexpectedly rather than producing wrong output.
- 3
Step 3: Match the symptoms to the error type definition.
- 4
Conclusion: This is a runtime error.
Exam tip:
Always check if the program runs at all: if it runs but output is wrong, it is a logic error, not a runtime error.
2. Common Debugging Methodsβ β β βββ± 4 min
Debugging is often confused with testing, but the two processes have distinct goals. Testing confirms that a bug exists; debugging locates and fixes that bug. There are several established methods for locating bugs efficiently.
Debugging
The systematic process of locating, identifying, and resolving bugs (errors) in a computer program.
Manual walkthrough: Tracing through code line by line manually to follow execution flow and variable values.
Print statement debugging: Adding temporary print statements to output variable values at key points in code.
Binary search debugging: Dividing code into halves repeatedly to narrow down the location of a bug efficiently.
IDE tool debugging: Using built-in IDE tools to pause execution and inspect program state at runtime.
A 100-line program crashes halfway through execution. How would you use binary search to locate the bug?
- 1
Step 1: Add a print statement or breakpoint at the midpoint of the code (line 50).
- 2
Step 2: Run the program. If it crashes before reaching line 50, the bug is in the first 50 lines. If not, it is between lines 51β100.
- 3
Step 3: Repeat the process on the half that contains the bug, narrowing the range each time.
- 4
Step 4: Stop when you have narrowed the bug down to a single line or small code block.
3. Debugging Toolsβ β β βββ± 3 min
Modern integrated development environments (IDEs) include powerful built-in debugging tools that make locating runtime and logic errors much faster than manual methods. CIE expects you to know the function of the most common tools.
Breakpoint
A marker set on a line of code that tells the debugger to pause execution when it reaches that line, allowing you to inspect the current program state.
Watch expression: A variable or expression added to the debugger watch list, so its current value is displayed whenever execution is paused.
Step into: Execute the next line of code, and if that line calls a function, pause execution inside the function.
Step over: Execute the next line of code, and run through any called functions without pausing inside them.
Step out: Continue execution until the current function returns, then pause again.
A function calculateTotal(price, tax) returns an incorrect total of $102 instead of the expected $120 for input price=100, tax=0.2. How would you use a breakpoint and watch to find the error?
- 1
Step 1: Set a breakpoint on the first line inside the
calculateTotalfunction. - 2
Step 2: Run the program with the test inputs price = 100, tax = 0.2.
- 3
Step 3: When execution pauses, add
price,taxand the running total to the debugger watch list. - 4
Step 4: Step through each line of the function one by one, checking the total value after each step to see where it deviates from the expected value.
- 5
Step 5: Once the incorrect line is identified, fix the error and re-test the function.
4. Systematic Debugging Processβ β ββββ± 3 min
Effective debugging follows a repeatable systematic process rather than guessing what the problem is. This reduces time spent and ensures the bug is fully resolved, with no new issues introduced.
Reproduce the bug consistently with a minimal test case.
Form a hypothesis about where the bug is located based on error symptoms.
Test the hypothesis by inspecting code and program state.
If the hypothesis is wrong, form a new hypothesis and repeat testing.
Once the bug is located, implement a fix for the error.
Test the fix to confirm the bug is resolved and no new bugs were introduced.
Check your understanding of core concepts:
What is the first step in systematic debugging?
Fix the bug
Reproduce the bug
Form a hypothesis
Set a breakpoint
Reveal answer
Reproduce the bug βYou must first be able to consistently reproduce the bug to investigate it properly.
Which of these is a logic error?
Missing semicolon that stops compilation
Division by zero that crashes the program
Calculating percentage by dividing by 10 instead of 100, outputting 1000% instead of 10%
Forgetting to close a bracket in Python
Reveal answer
Calculating percentage by dividing by 10 instead of 100, outputting 1000% instead of 10% βA logic error runs without crashing but gives the wrong output, which matches this case.
Exam tip:
CIE often tests the distinction between testing and debugging: remember testing finds bugs, debugging fixes them.
5. Common Pitfalls
Wrong move:
Confusing testing with debugging in exam answers
Why:
Testing only confirms a bug exists, it does not locate or fix it
Correct move:
Always clarify: testing identifies the presence of bugs, debugging locates and resolves them
Wrong move:
Classifying a logic error as a runtime error because output is wrong
Why:
Runtime errors always cause the program to crash or abort, logic errors do not
Correct move:
If the program runs to completion but gives wrong output, it is a logic error
Wrong move:
Skipping reproducing the bug and jumping straight to changing code
Why:
Without consistent reproduction, you cannot confirm if your fix actually worked
Correct move:
Always create a minimal test case that reproduces the bug before starting debugging
Wrong move:
Confusing step into and step over in debugger descriptions
Why:
Mixing these up is a common exam mistake that costs marks
Correct move:
Step into enters a function to debug inside it; step over runs through the function without pausing
Wrong move:
Not retesting after fixing the bug
Why:
Fixing one bug can introduce a new bug in a different part of the program
Correct move:
Always run all relevant tests after fixing a bug to confirm the fix works
6. Quick Reference Cheatsheet
Category | Item | Key Exam Fact |
|---|---|---|
Error Type | Syntax Error | Caught before execution, program won't run |
Error Type | Runtime Error | Occurs during execution, crashes program |
Error Type | Logic Error | No crash, wrong output, hardest to debug |
Debug Tool | Breakpoint | Pauses execution to inspect program state |
Debug Tool | Step Into | Pauses inside called functions for inspection |
Debug Tool | Step Over | Runs through functions without pausing |
Debug Method | Binary Search | Fast bug location in large codebases |
Process Step | First Step | Reproduce the bug consistently |
When this came up on past exams
AI-estimated based on syllabus patterns β cross-check with official past papers for accuracy. Use only as revision-focus signals.
- 2022 Β· 12
Classify types of program error
- 2023 Β· 11
Describe debugging tool functions
- 2021 Β· 13
Outline systematic debugging process
Going deeper
What's Next
Debugging is a core practical and theoretical skill for CIE A-Level Computer Science, building on your understanding of the software development life cycle and program design. The systematic approach to bug location and resolution you learned here applies to all programming paradigms, and will be useful both for exam questions and your own practical programming coursework. After mastering debugging, you can deepen your knowledge of software quality by exploring different types of software testing, advanced error handling techniques, and version control tools that support debugging in collaborative development environments.
