18

I want to use IEx.pry to go step by step in my elixir code, like byebug in ruby or debug point in Java. I tried looking into the documentation here : https://github.com/elixir-lang/elixir/blob/4f68c4f10502e0f54a21093bb9a33957e63a9ac4/lib/iex/lib/iex.ex but did not find anything. Could anyone suggest a way to do this ?

3
  • Maybe you will find this useful: github.com/qhool/quaff Oct 18, 2015 at 22:09
  • @PatrickOscity, I usually work on a remote machine. Is there a way to run the quaff tool in command line only ? Oct 31, 2015 at 22:23
  • @VoodooChild: You can use ssh -Y when you ssh into your remote machine so any window will be redirected to your host machine.
    – Batou99
    Oct 7, 2016 at 5:56

4 Answers 4

15

It is not possible as pry is not a debugger. Pry simply allows you to interact with a particular context.

3
  • 3
    If pry isn't the answer to setting a breakpoint and stepping through a running Elixir program, what is?
    – sma
    Feb 17, 2016 at 20:12
  • 3
    @sma , as Patrick pointed out, github.com/qhool/quaff is a tool which you can use Feb 18, 2016 at 8:02
  • Can't believe I did not know about quaff until now. Thansk @sma Apr 26, 2017 at 2:07
1

I was hoping for a way to step through Elixir code via IEx.pry as well, but that's not possible. Erlang does have a debugger that you can use for Elixir code.

You can start the debugger by running: :debugger.start()

I learned about it here: http://blog.plataformatec.com.br/2016/04/debugging-techniques-in-elixir-lang/

1

As the other answers pointed out, pry does not offer this functionality.

As a workaround you could add multiple IEx.pry instructions, inspect and use continue to go to the next one.

1
  • 2
    continue is used to continue the execution, the question is about step functionality.
    – Daniel
    May 28, 2020 at 7:42
0

After elixir 1.14, you can use the next/0 function after setting a breakpoint on the function you wanna debug.

To se a breakpoint you need to enter your iex terminal and use the function break!/2 and pass the function and the arity, so said function receives a breakpoint. Like this:

break! MyModule.function_to_be_debugged/2

And then, when you call said function, you will be able to debug it, line by line with the next/0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.