Skip to content

The Debugger

Audience: everyone · ~8 min read · Prerequisites: Running a model

The Debugger pane paused at a breakpoint, with numbered controls

What it is

The debugger runs your program under the built-in evaluator and pauses it at places you choose, so you can look at the current values of variables and step through the program node by node. A breakpoint is a mark on a node that says "stop here". The debugger works for every language, because it uses the evaluator rather than real Python. It has a toolbar, a list of breakpoints and a table of variables. It has no watch expressions and no call-stack view; the Variables table is how you inspect state.

When you'd use it

  • A result is wrong and you want to see the values as the program goes.
  • You want to follow a recursive function call by call.
  • A loop never ends and you want to stop it (the debugger can Pause and Stop it).

How to debug

  1. Open View > Tool Windows > Right > Debugger (Ctrl/Cmd+K, V, B, command Toggle Debugger). It opens on the right.
  2. Set a breakpoint on a statement, any of three ways:
    • right-click the node and choose Toggle Breakpoint (the item reads Remove Breakpoint when one is already set);
    • click the dot in the gutter (the left strip with line numbers) next to the statement;
    • put the caret on the node and press Alt+Shift+G (the editor's own key; Increase Editor Font no longer shares it). A right-click in the gutter offers the same item for the line you last focused.
  3. Press Shift+F9 (Run with Debugger, works even with no breakpoints), or click Run in the Debugger pane. F5 (Run Program) never opens the debugger: it runs the program straight through, whether or not breakpoints exist.
  4. The status line reads Paused at <statement> (for example Paused at a = fib(n - 1)), the node is highlighted in the editor, and the Variables table fills in.
  5. Use Step, Continue, Pause and Stop (below) until the program finishes. The result, if any, is printed as → value in the Messages view.

The right-click menu on a node, with Toggle Breakpoint

What each button does

  • Step on a Core program (real Python) advances one statement and pauses again; a call's body is entered, so stepping a = fib(n - 1) goes into fib. For a language that runs on the evaluator it advances one evaluation node, which is finer than a line: stepping through a = fib(n - 1) stops on the call, its arguments and so on.
  • Step over advances to the next step at the same nesting level, skipping what is nested inside the current one.
  • Step out runs until the current call returns to its caller and pauses there. Called at the top level, it behaves like Continue.
  • Continue runs to the next breakpoint, or to the end.
  • Pause asks for a pause at the next node while the program is running. Use it for a loop that does not end. On a Core program the pause arrives at its next statement within about a quarter second.
  • Stop aborts the run.

Debugging a rule engine

A language can register its own debug engine (src/debug-engines.ts), and a model of that language is then debugged by its rule engine instead of the expression evaluator. A rule engine that fires rules in a fixpoint steps like this: Run with Debugger replays each test case: it pauses at the case, then twice per rule firing (before: the objects the rule is bound to and the values it read; after: what it changed), then at the verdict. Step over skips a firing's after-step. A breakpoint on a rule node stops before that rule fires. It is a replay of a recording, so nothing can be edited mid-run, and a rule that changed nothing is not a step.

Reading the Variables table

  • Every variable in the current scope is listed with its value.
  • Strings are shown in quotes, lists in brackets, functions as <function>; empty values as null.
  • Names that start with __ are hidden.
  • The table updates on each pause. Before the first pause it says "(paused — variables will appear here)"; with nothing in scope, "(no local variables)".

Good to know

  • A breakpoint whose node no longer exists (you deleted the statement, or it came from an earlier session) is removed automatically; a debug run reports "Removed N unresolved breakpoint(s)."
  • Breakpoints that belong to a node in another tab or model are skipped, with a message "Skipped N breakpoint(s) set in a different tab/model."
  • Only one debug session exists at a time. Starting a run in another tab while one is live is refused with "Not run: a debug session is already running in another tab. Stop it there first." Pressing Run again in the same tab stops its own live session.
  • The debugger refuses to start while the model has errors ("Not run: fix this error first: …", naming the first error).
  • A breakpoint on a node that is never evaluated never fires.
  • Try Guess the number (a loop with variables) first. The Debugging Walkthrough root of the Python language tour sample (a recursive Fibonacci function) currently reports an error in the Problems panel in some builds, and a run then stops with "fix the reported errors first"; see Troubleshooting.

Every control

# Button/Option What it does Where Shortcut Gotcha
1 Run (pane) Starts a run under the debugger Debugger pane Shift+F9 Disabled while running or paused
2 Pause Pauses at the next node Debugger pane — Enabled only while running
3 Step Advances one evaluation node Debugger pane — Enabled only while paused
4 Continue Runs to the next breakpoint or the end Debugger pane — Enabled only while paused
5 Stop Aborts execution Debugger pane — Enabled while running or paused
6 Status line Idle, Running…, or Paused at ... Debugger pane —
7 Breakpoint row Shows the statement's text (hover for details) Debugger pane — "Unresolved breakpoint (id N)" means its node is not in this tab
8 Clear all Removes every breakpoint Debugger pane —
9 × on a breakpoint row Removes that breakpoint Debugger pane —
10 Variables table Current variable values Debugger pane — Read-only
11 Toggle Breakpoint / Remove Breakpoint (node and gutter context menus) Sets or clears a breakpoint Debugger pane Alt+Shift+G Gutter menu uses the last-focused line
12 Gutter dot Click to set or clear a breakpoint Debugger pane Click Only eligible statement lines have one
13 Run with Debugger Menu: Run > Execute Run > Execute menu Shift+F9 Works without breakpoints
14 Toggle Debugger Shows or hides the pane View > Tool Windows menu Ctrl/⌘+K, V, B
15 Step over Advances to the next step at the same level, skipping what is nested (a call's body; for a rule engine, a firing's after-step) Debugger pane — Enabled only while paused
16 Step out Runs until the current call returns to its caller, then pauses; at the top level it runs on to the next breakpoint or the end Debugger pane — Enabled only while paused