# Debugging

URL: https://softwaredictionary.org/terms/debugging
Category: Programming Fundamentals
Last updated: 2026-09-30
In Turkish: Hata ayıklama

In short: Debugging is the process of finding out why a program misbehaves, locating the faulty code and fixing it, often with the help of a tool called a debugger.

## What is debugging?

Debugging is the work of tracking down and fixing bugs, the mistakes that make software crash, produce wrong results or behave unexpectedly. It usually follows a loop: reproduce the problem reliably, narrow down where it happens, form a hypothesis about the cause, test it, apply a fix, and confirm that the problem is gone without breaking anything else.

Developers use several techniques. The simplest is adding print or log statements to see values as the program runs. A debugger is a tool that lets you pause a running program at a breakpoint, step through it line by line, inspect variables and the call stack, and watch values change; browsers, code editors and command-line tools like `gdb` and Python's `pdb` all provide one. Other approaches include reading error messages and stack traces carefully, explaining the code out loud to someone else, known as rubber duck debugging, and searching through commits with `git bisect` to find the change that introduced a bug.

Debugging is a lot like detective work: you gather evidence, rule out suspects and follow clues until one explanation fits every fact. The hardest bugs are the ones that don't reproduce consistently, such as race conditions and flaky tests, because observing the program can change its timing. Good logging, small reproducible test cases and version control make these much easier to track down.

Debugging is often confused with testing. Testing tells you that something is wrong by checking the program against expected results, while debugging figures out why it's wrong and where. A failing test is often the starting point for debugging, and after the fix, a new regression test makes sure the same bug doesn't come back.

## Key takeaways

- Debugging means finding the cause of a bug and fixing it.
- Start by reproducing the problem reliably, then narrow down where it happens.
- Debuggers let you pause at breakpoints, step through code and inspect variables.
- Testing reveals that something is wrong; debugging explains why.
- Add a regression test after fixing a bug so it can't silently return.

## Example: Pausing a Python program in the debugger

```python
def average(values):
    total = sum(values)
    breakpoint()  # pauses here and opens the pdb debugger
    return total / len(values)

average([])  # ZeroDivisionError: division by zero

# Inside the debugger you can type commands such as:
#   p values    print a variable (shows [])
#   n           run the next line
#   c           continue running
```

## Frequently asked questions

**Where does the word debugging come from?**

Engineers used "bug" for hardware faults long before computers existed. A famous 1947 logbook entry from the Harvard Mark II team records a real moth found in a relay, taped in as the "first actual case of bug being found", which helped make the term popular in computing.

**What is a breakpoint?**

A breakpoint is a marker you set on a line of code that tells the debugger to pause the program when it reaches that line. While paused, you can inspect variables, step through the following lines and see exactly what the program is doing.

**What is rubber duck debugging?**

It's the practice of explaining your code, line by line, to another person or even an object like a rubber duck. Putting the logic into words often reveals the mistake without any tools.

---

Software Dictionary: https://softwaredictionary.org/ · https://softwaredictionary.org/llms.txt
