Sebb

Sebb

Rexbug: get arguments instead of arity in :retn trace-messages

TIL that I can hook my own print functions into Rexbug:

iex(1)> Rexbug.start("Map.get/_ :: return", [print_fun: fn msg -> IO.inspect(msg) end])                                                      
{111, 2}
iex(2)> Map.get(%{a: 1}, :a)
1
{:call, {{Map, :get, [%{a: 1}, :a]}, ""}, ...}
{:call, {{Map, :get, [%{a: 1}, :a, nil]}, ""}, ...}
{:retn, {{Map, :get, 3}, 1}, ...}
{:retn, {{Map, :get, 2}, 1}, ...}

Is there a way to get the arguments for :retn also, as you see I only get the arity.
But I can’t match the :retn with their :call messages without the arguments.

I’d like to visualize a tree-traversal and the plan is to indent the steps using the alternative print_fun/2 with acc. So use acc to keep track of the level, indenting for nodes, not indenting for leaves. But to unindent I need to know what I’m returning from.

Marked As Solved

hauleth

hauleth

In short if you trace single process, then when you have list of calls like:

  1. Call A
  2. Call B
  3. Call C

Then the return list must be in the reverse order, as function cannot return before it’s parent will return.

Also Liked

voltone

voltone

For the sake of completeness: this is true when TCO (tail call optimization) is not active. See the match spec docs, under the return_trace option.

Redbug uses this option, so indeed there should be a return message for every call. But be careful not to trace functions that are intended to loop indefinitely, as this could lead to memory exhaustion.

When tracing with lower level functions (e.g. the :dbg module or :erlang.trace_pattern/3), the return_to flag can be used to trace calls and returns without impacting the TCO behavior, so it is arguably safer to use in production. But it is harder (or impossible) to reliably correlate the return to a prior call.

hauleth

hauleth

Well, you cannot return from any other function that the one you currently are in (I assume that you trace single process), so you can have simple list of :calls and pop the head to get the arguments for current function.

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
LegitStack
I’m hoping you guys can give me some general advice and perhaps code examples if you’re feeling up to it. I’m very interested in Elixir,...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
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
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? https://hexdocs.pm/ecto/Ecto.Repo.h...
New
chrisalley
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New

Other popular topics Top

chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 30048 115
New
shahryarjb
Hello, I get Persian date from my client and convert it to normal calendar like this: def jalali_string_to_miladi_english_number(persi...
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
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
AstonJ
You’re a programmer, so you don’t need spoon feeding with the conventional drivel about “this is an integer.” No. You need to know what’s...
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
malloryerik
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode. The solution seems to be, in a hyphena...
New
script
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this "1000" What is the ...
New

We're in Beta

About us Mission Statement