liveBook · Manning

Dbg

As explained in Elixir in Action, Third Edition

Kernel.dbg/2 is an Elixir debugging macro that prints an expression, its value, and related evaluation information while returning the value.

dbg is an Elixir debugging macro for development-time diagnosis. Like IO.inspect, it returns the expression’s value, while also printing richer evaluation details such as intermediate results in a pipe chain. section 13.3.1

Inspecting a pipeline

Wrap an expression or pipe stage with dbg to observe how values propagate while preserving the surrounding program behavior: expression |> dbg(). Remove the debugging call after finding the error. section 13.3.1

How Elixir in Action, Third Edition covers it

How deep it goes
Explains generated return-value behavior and intermediate pipe results, but does not detail macro expansion internals.
Examples
Uses wrapped expressions and pipe chains to reveal propagated values before removing temporary diagnostics.
What it assumes
Assumes familiarity with Elixir expressions and pipe chains, and avoids expressions that bind variables.
What you can do after
Apply it via Kernel.dbg/2 to inspect expression results and pipe intermediates while preserving returned values.
How it connects
Connects to IO.inspect, pipe chains, IEx.pry, automated tests, and stack-trace-based debugging.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Elixir in Action, Third Edition. The section links point to the parts of the book it draws on.