I need to debug some module in foreign system. The module has public function foo()
- how can I know place (module and function name)
from which foo() given module
This might work:
where_am_i() ->
try throw(a)
catch throw:a ->
erlang:get_stacktrace()
end.
Except that it doesn't work for tail calls. For example, given these two functions:
foo() ->
where_am_i().
bar() ->
X = where_am_i(),
{ok, X}.
I get these results:
4> foo:foo().
[{foo,where_am_i,0},
{erl_eval,do_apply,5},
{shell,exprs,6},
{shell,eval_exprs,6},
{shell,eval_loop,3}]
5> foo:bar().
{ok,[{foo,where_am_i,0},
{foo,bar,0},
{erl_eval,do_apply,5},
{shell,exprs,6},
{shell,eval_exprs,6},
{shell,eval_loop,3}]}
That is, I can only see bar
, since foo
's call frame has been left already when where_am_i
is called.