[erlang-questions] get_stacktrace() question

1 view
Skip to first unread message

Kaiduan Xie

unread,
Jan 4, 2009, 10:13:50 PM1/4/09
to erlang-q...@erlang.org
erlang:get_stacktrace() only returns the list of {Module, Function, Arity} (The Arity field in the first tuple may be the argument list of that function call instead of an arity integer, depending on the exception). Is there any way to return the argument list for ALL functions?

Thanks,

kaiduan

Richard Carlsson

unread,
Jan 5, 2009, 4:14:25 AM1/5/09
to Kaiduan Xie, erlang-q...@erlang.org

No. You could use tracing to get more information about your program,
but the stacktrace functionality does not provide this.

/Richard
_______________________________________________
erlang-questions mailing list
erlang-q...@erlang.org
http://www.erlang.org/mailman/listinfo/erlang-questions

Bjorn Gustavsson

unread,
Jan 5, 2009, 2:22:13 AM1/5/09
to Kaiduan Xie, erlang-q...@erlang.org
2009/1/5 Kaiduan Xie <kaid...@gmail.com>:

No. The way the BEAM virtual machine works, the arguments are discarded
as soon as they are no longer needed. Only values that will be used again
will be saved in the stack frame.

/Bjorn
--
Björn Gustavsson, Erlang/OTP, Ericsson AB

Thomas Lindgren

unread,
Jan 7, 2009, 7:39:10 AM1/7/09
to erlang-q...@erlang.org


--- On Mon, 1/5/09, Richard Carlsson <rich...@it.uu.se> wrote:
> Kaiduan Xie wrote:
> > erlang:get_stacktrace() only returns the list of
> {Module, Function, Arity}
> > (The Arity field in the first tuple may be the
> argument list of that
> > function call instead of an arity integer, depending
> on the exception). Is
> > there any way to return the argument list for ALL
> functions?
>
> No. You could use tracing to get more information about
> your program,
> but the stacktrace functionality does not provide this.

Unfortunately, it seems difficult to get this right -- parameters are normally passed in beam registers x(0)...x(N-1), but these registers are basically reused at each call, with only live parameters (or subterms of parameters) saved in the stack frame. So not all variables may be available. The curse of efficiency, I guess.

One approach might be to add a debug mode where parameters are passed on the stack instead, but that's somewhat nontrivial compiler surgery. Also, doing this introduces space leaks: it hangs on to values after they ought to be dead. And undead values can't be GCd. (Could the erlang interpreter do stacktraces right? I haven't tried using it in ages ...)

Best,
Thomas

Reply all
Reply to author
Forward
0 new messages