How many entries are included in Erlang stack traces?
First of all, if the stack trace is printed as an Erlang term, note that it io:format
can truncate the list if it's deep enough. If this happens, you will see ...
the output.
Second, if there are no entries in the middle of the stack trace, it is likely due to tail call optimization. If the last thing the function does is a call to another function, then the caller's freeze frame is discarded and will not appear in the stack trace.
In addition, only the last (innermost) frames of the eight stacks are included in the stack trace. For example, given a program that signals an error twelve frames deep (see list below), you get this result:
1> foo:one().
** exception error: this_is_twelve
in function foo:twelve/0 (foo.erl, line 49)
in call from foo:eleven/0 (foo.erl, line 45)
in call from foo:ten/0 (foo.erl, line 41)
in call from foo:nine/0 (foo.erl, line 37)
in call from foo:eight/0 (foo.erl, line 33)
in call from foo:seven/0 (foo.erl, line 29)
in call from foo:six/0 (foo.erl, line 25)
in call from foo:five/0 (foo.erl, line 21)
Note that the outermost four entries are missing from the stack trace, and only the innermost eight are left.
This is foo.erl
. Agents x
exist to prevent function calls by tail calls, which would mean that the caller's stack frame would be removed from the stack trace.
-module(foo).
-compile(export_all).
one() ->
two(),
x.
two() ->
three(),
x.
three() ->
four(),
x.
four() ->
five(),
x.
five() ->
six(),
x.
six() ->
seven(),
x.
seven() ->
eight(),
x.
eight() ->
nine(),
x.
nine() ->
ten(),
x.
ten() ->
eleven(),
x.
eleven() ->
twelve(),
x.
twelve() ->
error(this_is_twelve),
x.
source to share