Glossary termPractice

Debugging

Also known as: Bug fixing, Troubleshooting

Process of finding, diagnosing and fixing defects in software or hardware that cause it to behave incorrectly or unexpectedly.

Debugging is the work of locating and removing the causes of incorrect behavior in a program. It typically starts with a symptom, such as a crash, a wrong result or a slow response, and proceeds by reproducing the problem reliably, narrowing down where it originates, forming a hypothesis about the cause, testing that hypothesis and then fixing the code and confirming the fix. The hardest part is usually not the repair but the search: understanding the gap between what the programmer believes the code does and what it actually does.

Programmers use many tools. Interactive debuggers, such as GDB and those built into editors like Visual Studio Code, let a developer pause a running program at breakpoints, step through it line by line and inspect variables. Print statements and logs show the program's path, profilers find performance problems and git bisect locates the commit that introduced a bug by binary search through history. Calling engineering defects bugs predates computers, but a 1947 page from the Harvard Mark II logbook, with a moth taped to it after operators found the insect trapped in a relay, became a famous emblem of debugging, popularized in stories told by Grace Hopper.

Debugging consumes a large share of programming time, and doing it well is partly technical and partly psychological. Explaining the problem aloud, as in rubber duck debugging, often exposes a faulty assumption. Writing a failing test that reproduces a bug before fixing it guards against the bug returning, a habit that builds on unit testing. Intermittent problems such as race conditions are notoriously difficult, because observing a program can change its timing. Good logging, clear error messages and small, frequent changes all make future debugging easier.

Key points

  • Debugging moves from a symptom to a reproducible case, a hypothesis about the cause and a verified fix.
  • Debuggers let developers pause programs at breakpoints, step through code and inspect variables.
  • Git bisect finds the commit that introduced a bug by binary search through a project's history.
  • Writing a test that reproduces a bug before fixing it helps prevent the bug from returning.

Related entries

Glossary term

Rubber Duck Debugging

ProgrammingIdeas and Culture

Debugging method in which a programmer explains code line by line to an inanimate object, often a rubber duck, to expose the source of a bug.

Glossary term

Unit Testing

Programming

Practice of verifying that small, individual pieces of code, such as single functions or classes, behave correctly when tested in isolation.

Glossary term

Static Analysis

ProgrammingCybersecurity

Examination of source code or binaries without executing them, using automated tools to find bugs, security flaws and quality issues.

Glossary term

Linting

Programming

Automated checking of source code for likely errors, suspicious constructs and style violations using a tool called a linter.

Glossary term

Race Condition

ProgrammingCybersecurity

Flaw in which a system's behavior depends on the uncontrolled timing or ordering of events, such as two threads updating the same data at once.

Person

Grace Hopper

Programming

American computer scientist and US Navy rear admiral who developed early compilers and helped create the COBOL programming language.

Glossary term

Off-by-One Error

Programming

Common programming mistake in which a loop or calculation goes one step too far or stops one step short, often at array boundaries.

Glossary term

Version Control

ProgrammingDevOps

System that records changes to files over time so that people can track history, revert mistakes and collaborate on the same codebase.

Featured in guides

Referenced by

Other entries that discuss or point to Debugging.