Contents

Engineering Craft › Debugging

Debugger

A tool to pause code, inspect variables and step through execution.

Also known as: interactive debugger, debug mode, step debugger

A debugger lets you pause a running program, look at the values of its variables and run it one step at a time. Instead of guessing from output, you watch what actually happens.

The core moves

  1. Set a breakpoint on a line you’re curious about.
  2. Run the program in debug mode. It stops just before that line.
  3. Inspect: hover or look at the variables panel to see their current values.
  4. Step through the code with step over / into / out:
    • over: run this line and stop at the next,
    • into: go inside the function being called,
    • out: finish the current function and return to the caller.
  5. Continue to run until the next breakpoint.

Most tools also have a call stack view (how you got here), watch expressions and conditional breakpoints that stop only when something is true.

Where to find one

  • Editors and IDEs: VS Code, JetBrains IDEs and others have debuggers built in for most languages.
  • The browser: the Sources panel in DevTools.
  • Command line: Python has breakpoint() (which opens pdb); Node can be started with --inspect.
def total(items):
    breakpoint()          # pauses here in the debugger
    return sum(i.price for i in items)

Debugger or print statements?

Print debugging is quick and works anywhere. A debugger is better when you don’t yet know which value matters, since you can look at everything at that moment without re-running. Learn both. Remove breakpoint() and debugger; before committing.