xxia

xxia

Can Elixir Kernel functions be traced by :dbg?

I’m new to Elixir and playing around with tracing. Following an example, I successfully setup :dbg to trace Enum.map/2 when executed inside iex. The trace event is created.

iex(3)> :dbg.tp(Enum, :map, [])   
{:ok, [{:matched, :nonode@nohost, 1}]}
iex(4)> :dbg.p(:all, :c)
{:ok, [{:matched, :nonode@nohost, 61}]}
iex(5)> Enum.map()
** (UndefinedFunctionError) function Enum.map/0 is undefined or private. Did you mean one of:

      * map/2

    (elixir 1.12.1) Enum.map()
(<0.109.0>) call 'Elixir.Enum':map([{1.0,map,2}],#Fun<Elixir.UndefinedFunctionError.7.56279482>)
iex(5)> 

I then tried to trace Kernel.rem/2 . This doesn’t appear to work. I tried a couple of other Kernel functions and they all didn’t produce a trace event.

iex(6)> :dbg.tp(Kernel, :rem, [])      
{:ok, [{:matched, :nonode@nohost, 1}]}
iex(7)> rem(1,1)
0
iex(8)> Kernel.rem(1,1)
0

Why are they not traced? Thank you

Marked As Solved

voltone

voltone

That’s because Kernel.rem/2 is “inlined by the compiler”, as mentioned in the documentation for that function (guard). It basically gets translated to an Erlang operator, so no function invocation takes place.

This is something to keep in mind when using :dbg and other tools that use BEAM tracing: the code you see in the editor/IEx may get optimized by the various compiler stages and this may impact what you can trace.

Last Post!

xxia

xxia

Thank you for that explanation and that makes sense!

Where Next?

Popular in Questions Top

New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New

Other popular topics Top

KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 36654 110
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
AstonJ
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
AngeloChecked
What learn first? Rust or Elixir Hi Elixir community! I’m here because i want learn a new language. I’m a junior developer and mainly i ...
New

We're in Beta

About us Mission Statement