Sebb

Sebb

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.

Showing Posts 1 to 4

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.

Sebb

Sebb OP

Thanks for your help. I’m not sure I fully understand, I’ll look into that when I got the time.

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.

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.

— All posts loaded —

Where Next? Top

Trending in Questions Top

Hellowman
Hello everyone! I am new to coding with Elixir/Erlang. And i am looking for some utilities for fuzzing testing like AFL++. Does anyone ...
New
yarrichar
I’m very new to Elixir, so sorry if this is a silly question: I am wondering what happens to the mailbox of a process when the machine i...
New
pragdave
How do I tell Hologram not to escape HTML when substituting into templates? {Textile.render(@product.long_description)} escapes the HTM...
New
Fl4m3Ph03n1x
Background When trying to execute mix release on a Windows 11 machine for a Phoenix project I get the following error: * assembling mark...
New
mandar1045
I load tested a plain Phoenix chat app backed by Postgres with 100 million messages in it, everything on default settings, to see what br...
New
rlipscombe
I’d like to create a file with 600 permissions (rw-------), but there’s a race condition if I create it and then change the permissions. ...
New
saleyn
Is there a way to import record definitions in the iex shell for pretty printing (similar to the rr command in the erl shell)? This woul...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
261 13183 112
New
mudasobwa
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
OndrejValenta
(I just needed to vent somewhere and LinkedIn is full of hope, or hype, I’m not sure which exactly) AI dream has many faces, but general...
New
kip
Localize is the next generation localisation library for Elixir. Think of it as ex_cldr version 3.0. The first version will be released ...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews