elixir icon indicating copy to clipboard operation
elixir copied to clipboard

Debugger does not stop at the breakpoints in tests for Elixir 1.15.0 on OTP 25

Open RomanKotov opened this issue 3 years ago • 13 comments

Elixir and Erlang/OTP versions

Elixir 1.15.0 (compiled with Erlang/OTP 24) Elixir 1.15.0 (compiled with Erlang/OTP 25)

Erlang 25.3.2 Erlang 25.3.2.2

Operating system

macOS

Current behavior

Elixir does not stop on breakpoints, in shell.

Steps to reproduce:

  1. Use Erlang 25.3.2, or 25.3.2.2 and Elixir 1.15.0.
  2. Create new mix project mix new test.
  3. Add breakpoints to the test/test_test.exs file, like these:
defmodule TestTest do
  use ExUnit.Case
  doctest Test

  test "greets the world" do
    require IEx; IEx.pry
    dbg()
    assert Test.hello() == :world
  end
end
  1. Run tests with either iex --dbg pry -S mix test or iex -S mix test.

Debugged does not stop on the breakpoints, but prints this information:

Cannot pry #PID<0.145.0> at TestTest."test greets the world"/1 (test/test_test.exs:6). Is an IEx shell running?

It seems, it does not work for mix test. I was able to reach breakpoint with iex --dbg pry -S mix phx.server.

It works for Erlang 26.0.1 for tests too.

Expected behavior

Breakpoints should work in tests too.

RomanKotov avatar Jun 20 '23 21:06 RomanKotov

Same here, was able to stop on breakpoint with $ iex -S mix test --trace on Elixir 1.14.0, Erlang 25.1.1

stevencch99 avatar Jun 21 '23 07:06 stevencch99

I'm not able to stop with dbg() in my application code with elixir 1.15.1-otp-26 and erlang 26.0.2.

I'm running the session with: iex --dbg pry -S mix phx.server

It stops but when pry is requested and the prompt shows: Allow? [Yn] it doesn't matter if you choose Y or n, same behaviour (n) is applied.

Anyone with the same problem here?

sergiorjsd avatar Jul 27 '23 09:07 sergiorjsd

Can you please try on v1.15.4?

josevalim avatar Jul 27 '23 13:07 josevalim

@josevalim I've tried with Elixir 1.15.4-otp-26 on my machine and the result is the same as @sergiorjsd mentioned.

My machine: MacBook M2 Pro, macOS Ventura 13.2.1, Phoenix 1.7.2

stevencch99 avatar Jul 27 '23 13:07 stevencch99

I am also encountering this same issue with:

elixir 1.15.5-otp-26 erlang 26.0.2

efleming avatar Sep 22 '23 17:09 efleming

I cannot reproduce it on 1.15.7 with neither OTP 25 nor OTP 26. So if someone can provide the precise steps to reproduce, it will be appreciated.

josevalim avatar Oct 18 '23 18:10 josevalim

Hi @josevalim I encounter the same problem with this repository: https://github.com/etalab/transport-site

Steps to reproduce:

  1. Install following README instructions – no need to feed with data, an empty database with just mix ecto.create and mix ecto.migrate does the job
  2. Insert a dbg() breakpoint in a page that doesn’t need data, like in the info_producteur function in apps/transport/lib/transport_web/controllers/page_controller.ex, write dbg() in the beggining of the function
  3. Run with iex --dbg pry -S mix phx.server
  4. Access in your browser the page http://localhost:5000/infos_producteurs

Expected behaviour: it should stop in the local context and give access to a console in this context Observed behaviour: it prints previous variables in the terminal and then continues

I can observe it with the Elixir & Erlang versions in .tool_versions as well as with elixir 1.15.5-otp-26 and erlang 26.1.2

vdegove avatar Nov 06 '23 14:11 vdegove

Updating Elixir from 1.15.4 to 1.15.7 fixed it for me, OTP 26.

MarcosNBJ avatar Nov 11 '23 06:11 MarcosNBJ

@vdegove can you confirm it works on v1.15.7 for you?

josevalim avatar Nov 11 '23 07:11 josevalim

@josevalim thanks for checking it out, unfortunately it doesn’t work with 1.15.7.

My .tool-versions look like this:

elixir 1.15.7-otp-26
erlang 26.1.2

I’m redacting the file transport-site/apps/transport/lib/transport_web/controllers/page_controller.ex like this:

  def infos_producteurs(conn, _params) do
    dbg() # Hi all!
    conn
    |> assign(:mailchimp_newsletter_url, Application.get_env(:transport, :mailchimp_newsletter_url))
    |> render("infos_producteurs.html")
  end

Then: iex --dbg pry -S mix phx.server

Open a browser, open the page http://localhost:5000/infos_producteurs

Result: the request goes through entirely without halting.

It does print things when it hits dbg():

binding() #=> [
  _params: %{},
  conn: %Plug.Conn{
    adapter: {Plug.Cowboy.Conn, :...},
    assigns: %{ … }
    …
    halted: false,
    …
]

But doesn’t halt.

Perhaps I’m misunderstanding how I should use it, or there is something special in the project? The whole code is here https://github.com/etalab/transport-site/ so anybody can test.

vdegove avatar Nov 21 '23 09:11 vdegove

I had the same issue, it seems to be working for me after upgrading to

elixir 1.15.7-otp-26
erlang 26.1.2

deviprsd avatar Nov 21 '23 20:11 deviprsd

@vdegove because you have Kino as a dependency, Kino is changing the dbg_callback when it boots, and the default fallback does not fallback to pry. I will fix this on Kino side.

josevalim avatar Nov 23 '23 15:11 josevalim

Wow, good debugging, thanks a lot for checking it, I’m glad the report helped :)

vdegove avatar Nov 24 '23 08:11 vdegove