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.

Where Next?

Popular in Questions Top

JDanielMartinez
Hi! May someone helps me, please! I have two apps into an umbrella project: the first one is Database, which manages queries, and the se...
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
yawaramin
In the Dialyzer docs ( http://erlang.org/doc/man/dialyzer.html#requesting-or-suppressing-warnings-in-source-files ), there is a way to tu...
New
Kagamiiiii
Student &amp; New to elixir. Nice language. I want to convert a english character, e.g. “a”, which is stored in a variable, to it’s asci...
New
polypush135
As many of you may have realized by now (sorry for all the posts here) I’ve been working on a db problem where I’m trying to aggregate a ...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
Exadra37
Sometimes I want to check if the input into a function is not a blank string. My first approach: defmodule Example do def do_stuff(s...
New
wernerlaude
In AR this is so simple @articles = current_user.articles How to do in Ecto? def index(conn, _params) do current_user = conn.assig...
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
idi527
I’ve been re-reading swift book again and noticed that multiline strings there don’t have a trailing line break, unlike in elixir iex(2)...
New

Other popular topics Top

senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
_russellb
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
mgjohns61585
Could someone help me? I'm making my first elixir program, number guessing game. I can't figure out how to convert the user's guess from ...
New
johnnyicon
Hi all, I've just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I'm trying to use Postg...
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
AstonJ
We’ve put together this wiki for Phoenix LiveView - please feel free to add any info you feel is worth including. What is Phoenix LiveV...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New

We're in Beta

About us Mission Statement