Debugging third party code with IEx

Published June 11, 2019 by Toran Billups

I was trying to inspect something in Plug recently and found that my intuition was completely off.

The problem

My JavaScript background tricked me into thinking I could simply open the dependency `deps/plug/lib/plug/conn.ex` and then add `IEx.pry` at any line number I wanted to debug. Imagine my surprise when I started up Phoenix with iex and the debugger didn't prompt me with the usual Y/n.

Luckily debugging 3rd party code wasn't difficult to figure out. The radical shift from my JavaScript days is simply that you set breakpoints with IEx programatically instead.

    break! Plug.Conn.put_resp_cookie/4
  

The example above shows how you would set a breakpoint to pause execution within IEx to debug the `put_resp_cookie` method inside of Plug.


Buy Me a Coffee

Twitter / Github / Email