[erlang-questions] How to get the line number of current executable code?

Ahmed Ali ahmed.nawras@REDACTED
Tue Aug 26 21:05:10 CEST 2008

Hi Mats,

I've seen process_display(Pid, backtrace) but never thought to use it
this way. Thanks for the insight.

Best regards,

Ahmed Al-Issaei

On Tue, Aug 26, 2008 at 12:54 PM, Mats Cronqvist
<mats.cronqvist@REDACTED> wrote:
> Richard Carlsson wrote:
>> Ahmed Ali wrote:
>>> Hi All,
>>> This discussion is interesting. Just wanted to know if it is possible
>>> to get the function that called current function. Is this possible?
>> The only way of doing that is to force an exception, and then look
>> at the stack trace.
>  there is no way to reliably get the name of the calling function.
>  it is true that the stack sometimes contain the name of the calling
> function.
>  it is not true that the only way to inspect the stack is by forcing an
> exception.
>  i'm too lazy to write actual code, but try this in the shell;
> (r12@REDACTED)41> {_,BT}=erlang:process_info(self(),backtrace).
> (r12@REDACTED)42> S=fun(B,{_,[_,{F,L}|_]})->
> <<_:F/binary,R:L/binary,_/binary>> =B, R end.
> (r12@REDACTED)43> S(BT,re:run(BT,"Return addr\\s[0-9a-z]+\\s\\(([^\\s]*)")).
> <<"erl_eval:expr/5">>
>  clear as the day!
>  mats

More information about the erlang-questions mailing list