Skip to content

CIDER Debugλ︎

, d b calls the cider-debug-defn-breakpoint command that sets breakpoints on the expression under the cursor. If the expression is a function definition, then its name is marked as instrumented by the debug along with any calls to that function.

A debug menu appears above the expression, press n to step through each expression and see the inline result.

Spacemacs Clojure cider debug menu

Switch to Emacs Edit mode for full menu

C-z after starting cider-debug to use c e i p s menu keys as otherwise they call the Evil normal state commands. C-z to switch back to Evil normal state.

Cider debugging

Conditional break pointsλ︎

:break/when metadata on a #dbg directive defines a condition when a breakpoint is triggered, allowing the evaluation to iterate until a desirable point is reached.

Setting a condition is especially useful when there are many iterations required before reaching a point of issue, for example iterating through a large data set.

A #break can be added on any Clojure form. In this example the evaluation will break on each iteration of the sequence, showing the local value of the index.

(dotimes [index 10]
  #break index)

Add a break condition within the expression to be evaluated and the evaluation will iterate until the condition is met and then break

n to continue to the next break point will complete the evaluation as the break condition is no longer met

(dotimes [index 10]
  #dbg ^{:break/when (= index  7)}
  index)

The evaluation will break each time a condition is met, so a break will occur multiple times when the value of index is odd

(dotimes [index 10]
  #dbg ^{:break/when (odd? index)}
   index)

Skip over lazy functionsλ︎

o (out) will jump out of evaluating an expression.

Use out to jump over evaluating code that has functions generating lazy infinite sequences, such as range or cycle. Cider debug will then evaluate those functions in their outer expression where it should be safe to do so.

Referencesλ︎


Last update: December 25, 2022