Debugging and debugging tools in Elixir?
You can use IEx
require IEx
value = {:some, :erlang, :value}
IEx.pry
If you start this program with for example iex -s program.exs
(or iex -S mix
for a project) you'll be asked if you want to allow prying into this code when it is reached and value
will be available for you for inspection.
You can also just do print debugging using IO.inspect
allowing you to output basically any erlang data structure.
Debugging Cowboy apps, and Phoenix apps.
I saw this post in the Elixir rader http://www.jessetrimble.net/iex-pry-elixir, and thought i would just summarise it up here, as it's extremely convenient :-).
In Rails applications (and other), you can simply put in the debugger tag in your controller, and when the path is triggered, it will break at the debugger tag.
When using pry in Phoenix the above will result in
Cannot pry #PID<0.259.0> at web/controllers/posts_controller.ex:8. Is an IEx shell running?
It turns out that the Phoenix process must run within an IEx session, this is done as such
iex -S mix phoenix.server
Now instead you will see
Request to pry #PID<0.266.0> at web/controllers/posts_controller.ex:9. Allow? [Yn]
You can use Quaff.Debug
module from https://github.com/qhool/quaff
The Debug module provides a simple helper interface for running Elixir code in the erlang graphical debugger
I tested it today with Elixir 1.0.4, it works.
Use the Erlang debugger. Example with Phoenix 1.3 and Elixir 1.5.1, source file: ./lib/todo/api/api.ex and the module name is: Todo.API
~/elixir/todo_app/ iex -S mix phx.server
Erlang/OTP 20 [erts-9.0] [source] [smp:1:1] [ds:1:1:10] [async-threads:10] [hipe] [kernel-poll:false]
[info] Running TodoWeb.Endpoint with Cowboy using http://0.0.0.0:4000
Interactive Elixir (1.5.1) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> :debugger.start()
{:ok, #PID<0.373.0>}
iex(2)> :int.ni(Todo.API)
{:module, Todo.API}
In the Erlang debugger:
- The left panel in the Monitor window shows the loaded module.
- The Module menu, the bottom item shows the loaded module with a 'View' and 'Delete' submenu. Use the View menu to see the source with line numbers.
- To place a breakpoint, use the Break menu, Line breaks...
- Run your program until it stops at the specified line. The Monitor windows shows a process with status 'break'. Double click on this line to open the attached process in the debugger. Here you can step, step over (next), continue, go up, inspect values, etc. To step into another module it must be loaded like above as well.
- A breakpoint will be ignored if not correctly placed. If you have a multiline pipeline, place the breakpoint on the last line.