Skip to content

Commit 893a41d

Browse files
committed
Make pry opt-in on dbg with --dbg pry
1 parent 2410811 commit 893a41d

File tree

7 files changed

+27
-19
lines changed

7 files changed

+27
-19
lines changed

bin/elixir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ while [ $I -le $LENGTH ]; do
114114
C=1
115115
MODE="elixirc"
116116
;;
117-
-v|--no-halt|--no-pry)
117+
-v|--no-halt|--dbg)
118118
C=1
119119
;;
120120
-e|-r|-pr|-pa|-pz|--app|--eval|--remsh|--dot-iex)

bin/elixir.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ if ""==!par:--app=! (set "parsElixir=!parsElixir! --app %~1" && shift && g
143143
if ""==!par:--no-halt=! (set "parsElixir=!parsElixir! --no-halt" && goto startloop)
144144
if ""==!par:--remsh=! (set "parsElixir=!parsElixir! --remsh %~1" && shift && goto startloop)
145145
if ""==!par:--dot-iex=! (set "parsElixir=!parsElixir! --dot-iex %~1" && shift && goto startloop)
146-
if ""==!par:--no-pry=! (set "parsElixir=!parsElixir! --no-pry" && goto startloop)
146+
if ""==!par:--dbg=! (set "parsElixir=!parsElixir! --dbg %~1" && shift && goto startloop)
147147
rem ******* ERLANG PARAMETERS **********************
148148
if ""==!par:--boot=! (set "parsErlang=!parsErlang! -boot %~1" && shift && goto startloop)
149149
if ""==!par:--boot-var=! (set "parsErlang=!parsErlang! -boot_var %~1 %~2" && shift && shift && goto startloop)

bin/iex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ Usage: $(basename "$0") [options] [.exs file] [data]
77
88
The following options are exclusive to IEx:
99
10+
--dbg pry Sets the backend for Kernel.dbg/2 to IEx.pry/0
1011
--dot-iex "FILE" Evaluates FILE, line by line, to set up IEx' environment.
1112
Defaults to evaluating .iex.exs or ~/.iex.exs, if any exists.
1213
If FILE is empty, then no file will be loaded.
1314
--remsh NAME Connects to a node using a remote shell.
14-
--no-pry Doesn't start pry sessions when dbg/2 is called.
1515
1616
It accepts all other options listed by "elixir --help".
1717
USAGE

bin/iex.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ echo Usage: %~nx0 [options] [.exs file] [data]
1111
echo.
1212
echo The following options are exclusive to IEx:
1313
echo.
14+
echo --dbg pry Sets the backend for Kernel.dbg/2 to IEx.pry/0
1415
echo --dot-iex "FILE" Evaluates FILE, line by line, to set up IEx' environment.
1516
echo Defaults to evaluating .iex.exs or ~/.iex.exs, if any exists.
1617
echo If FILE is empty, then no file will be loaded.
1718
echo --remsh NAME Connects to a node using a remote shell
1819
echo --werl Uses Erlang's Windows shell GUI (Windows only)
19-
echo --no-pry Doesn't start pry sessions when dbg/2 is called.
2020
echo.
2121
echo Set the IEX_WITH_WERL environment variable to always use werl.
2222
echo It accepts all other options listed by "elixir --help".

lib/elixir/lib/kernel.ex

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5870,17 +5870,16 @@ defmodule Kernel do
58705870
58715871
## `dbg` inside IEx
58725872
5873-
IEx integrates with `dbg` to provide additional features:
5873+
You can enable IEx to replace `dbg` with its `IEx.pry/0` backend by calling:
58745874
5875-
* If you have IEx running and you call `dbg`, it will start a `pry`
5876-
session where you can interact with the imports, aliases, and
5877-
variables of the current environment at the location of the `dbg` call
5875+
$ iex --dbg pry
58785876
5879-
* If you call `dbg` at the end of a pipeline (using `|>`) within IEx,
5880-
you are able to go through each step of the pipeline one by one by
5881-
entering "next" (or "n")
5877+
In such cases, `dbg` will start a `pry` session where you can interact with
5878+
the imports, aliases, and variables of the current environment at the location
5879+
of the `dbg` call.
58825880
5883-
* You can disable this behaviour by calling `iex --no-pry`
5881+
If you call `dbg` at the end of a pipeline (using `|>`) within IEx, you are able
5882+
to go through each step of the pipeline one by one by entering "next" (or "n").
58845883
58855884
Note `dbg` only supports stepping for pipelines (in other words, it can only
58865885
step through the code it sees). For general stepping, you can set breakpoints

lib/elixir/lib/kernel/cli.ex

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ defmodule Kernel.CLI do
326326
end
327327

328328
defp parse_argv(["+iex" | t], config) do
329-
parse_iex(t, %{config | pry: true})
329+
parse_iex(t, config)
330330
end
331331

332332
defp parse_argv(["-S", h | t], config) do
@@ -416,11 +416,17 @@ defmodule Kernel.CLI do
416416
end
417417

418418
# These clauses are here so that Kernel.CLI does not error out with "unknown option"
419+
defp parse_iex(["--dbg", backend | t], config) do
420+
case backend do
421+
"pry" -> parse_iex(t, %{config | pry: true})
422+
"kernel" -> parse_iex(t, %{config | pry: false})
423+
_ -> {:error, "--dbg : Unknown dbg backend #{inspect(backend)}"}
424+
end
425+
end
426+
419427
defp parse_iex(["--dot-iex", _ | t], config), do: parse_iex(t, config)
420428
defp parse_iex(["--remsh", _ | t], config), do: parse_iex(t, config)
421429

422-
defp parse_iex(["--no-pry" | t], config), do: parse_iex(t, %{config | pry: false})
423-
424430
defp parse_iex([h | t] = list, config) do
425431
case h do
426432
"-" <> _ -> shared_option?(list, config, &parse_iex(&1, &2))

lib/iex/lib/iex.ex

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,16 +173,20 @@ defmodule IEx do
173173
## `dbg` and breakpoints
174174
175175
IEx integrates with `Kernel.dbg/2` and introduces a backend that
176-
can pause code execution:
176+
can pause code execution. To enable it, you must pass `--dbg pry`:
177+
178+
$ iex --dbg pry
179+
180+
For example, take the following function:
177181
178182
def my_fun(arg1, arg2) do
179183
dbg(arg1 + arg2)
180184
... implementation ...
181185
end
182186
183187
When the code is executed with `iex` (most often by calling
184-
`iex -S mix`), it will ask you permission to use "pry". If you
185-
agree, it will start an IEx shell in the context of the function
188+
`iex --dbg pry -S mix`), it will ask you permission to use "pry".
189+
If you agree, it will start an IEx shell in the context of the function
186190
above, with access to its variables, imports, and aliases. However,
187191
you can only access existing values, it is not possible to access
188192
private functions nor change the execution itself (hence the name
@@ -194,7 +198,6 @@ defmodule IEx do
194198
of the steps but stay within the pried process. Type `respawn` when
195199
you want to leave the pried process and start a new shell.
196200
197-
You can disable "pry" as the `dbg/2` backend by calling `iex --no-pry`.
198201
Alternatively, you can start a pry session directly, without `dbg/2`
199202
by calling `IEx.pry/0`.
200203

0 commit comments

Comments
 (0)