You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: getting-started/debugging.markdown
+12-45
Original file line number
Diff line number
Diff line change
@@ -118,50 +118,6 @@ When code calling `dbg` is executed via `iex`, IEx will ask you to "stop" the co
118
118
119
119
Similar to `dbg`, once a breakpoint is reached code execution stops until `continue` or `next` are invoked. However, `break!/2` does not have access to aliases and imports from the debugged code as it works on the compiled artifact rather than on source code.
120
120
121
-
## Debugger
122
-
123
-
For those who enjoy breakpoints but are rather interested in a visual debugger, Erlang/OTP ships with a graphical debugger conveniently named `:debugger`. Let's define a module in a file named `example.ex`:
124
-
125
-
```elixir
126
-
defmoduleExampledo
127
-
defdouble_sum(x, y) do
128
-
hard_work(x, y)
129
-
end
130
-
131
-
defphard_work(x, y) do
132
-
x =2* x
133
-
y =2* y
134
-
135
-
x + y
136
-
end
137
-
end
138
-
```
139
-
140
-
Now let's compile the file and run an IEx session:
141
-
142
-
```console
143
-
$ elixirc example.ex
144
-
$ iex
145
-
```
146
-
147
-
Then start the debugger:
148
-
149
-
```elixir
150
-
iex>:debugger.start()
151
-
{:ok, #PID<0.87.0>}
152
-
iex>:int.ni(Example)
153
-
{:module, Example}
154
-
iex>:int.break(Example, 3)
155
-
:ok
156
-
iex>Example.double_sum(1, 2)
157
-
```
158
-
159
-
> If the `debugger` does not start, here is what may have happened: some package managers default to installing a minimized Erlang without WX bindings for GUI support. In some package managers, you may be able to replace the headless Erlang with a more complete package (look for packages named `erlang` vs `erlang-nox` on Debian/Ubuntu/Arch). In others managers, you may need to install a separate `erlang-wx` (or similarly named) package.
160
-
161
-
When you start the debugger, a Graphical User Interface will open on your machine. We call `:int.ni(Example)` to prepare our module for debugging and then add a breakpoint to line 3 with `:int.break(Example, 3)`. After we call our function, we can see our process with break status in the debugger:
For debugging complex systems, jumping at the code is not enough. It is necessary to have an understanding of the whole virtual machine, processes, applications, as well as set up tracing mechanisms. Luckily this can be achieved in Erlang with `:observer`. In your application:
@@ -171,7 +127,18 @@ $ iex
171
127
iex>:observer.start()
172
128
```
173
129
174
-
> Similar to the `debugger` note above, your package manager may require a separate installation in order to run Observer.
130
+
> When running `iex` inside a project with `iex -S mix`, `observer` won't be available as a dependency. To do so, you will need to call the following functions before:
131
+
>
132
+
> ```elixir
133
+
> iex>Mix.ensure_application!(:wx)
134
+
> iex>Mix.ensure_application!(:runtime_tools)
135
+
> iex>Mix.ensure_application!(:observer)
136
+
> iex>:observer.start()
137
+
> ```
138
+
>
139
+
>If any of the calls above fail, here is what may have happened: some package managers default to installing a minimized Erlang without WX bindings forGUI support. In some package managers, you may be able to replace the headless Erlangwith a more complete package (look for packages named `erlang` vs `erlang-nox` on Debian/Ubuntu/Arch). In others managers, you may need to install a separate `erlang-wx` (or similarly named) package.
140
+
>
141
+
>There are conversations to improve this experience in future releases.
175
142
176
143
The above will open another GraphicalUserInterface that provides many panes to fully understand and navigate the runtime and your project:
0 commit comments