在lager.elr(https://github.com/basho/lager的主要模块)中没有名称为“debug”的函数,但我有一个应用程序从lager模块调用debug函数,如: lager:debug(Str,Args)
我是Erlang的初学者,但我知道当我们从模块lile“mymodule:myfunction”调用一个函数时,文件mymodule.erl中应该有一个名为“myfunction”的函数,但是在这种情况下我在lager中搜索。 erl for function“debug”我找不到它。
答案 0 :(得分:6)
您没有看到提及lager:debug/2
的原因是因为lager使用解析转换。因此,在编译代码时,它通过lagers parse转换进行,并且对lager:debug/2
的调用将替换另一个模块函数的调用。
如果使用正确的分析变换选项编译代码,则代码可以正常工作。
答案 1 :(得分:1)
“我给CRAP答案”对这种奇怪的行为做了很好的解释。我在这里发布一个代码,它应该显示在beam文件中生成的代码:
在shell中:
效用:反编译([yourfile.beam])
%% Author: PCHAPIER
%% Created: 25 mai 2010
-module(utility).
%%
%% Include files
%%
%%
%% Exported Functions
%%
-export([decompile/1, decompdir/1]).
-export([shuffle/1]).
%%
%% API Functions
%%
decompdir(Dir) ->
Cmd = "cd " ++ Dir,
os:cmd(Cmd),
L = os:cmd("dir /B *.beam"),
L1 = re:split(L,"[\t\r\n+]",[{return,list}]),
io:format("decompdir: ~p~n",[L1]),
decompile(L1).
decompile(Beam = [H|_]) when is_integer(H) ->
io:format("decompile: ~p~n",[Beam]),
{ok,{_,[{abstract_code,{_,AC}}]}} = beam_lib:chunks(Beam ++ ".beam",[abstract_code]),
{ok,File} = file:open(Beam ++ ".erl",[write]),
io:fwrite(File,"~s~n", [erl_prettypr:format(erl_syntax:form_list(AC))]),
file:close(File);
decompile([H|T]) ->
io:format("decompile: ~p~n",[[H|T]]),
decompile(removebeam(H)),
decompile(T);
decompile([]) ->
ok.
shuffle(P) ->
Max = length(P)*10000,
{_,R}= lists:unzip(lists:keysort(1,[{random:uniform(Max),X} || X <- P])),
R.
%%
%% Local Functions
%%
removebeam(L) ->
removebeam1(lists:reverse(L)).
removebeam1([$m,$a,$e,$b,$.|T]) ->
lists:reverse(T);
removebeam1(L) ->
lists:reverse(L).
答案 2 :(得分:0)
你没有在lager.erl文件中看到它,因为它位于lager.erl顶部的lager.hrl文件中。 Erlang允许您包含带有-include(“filename.hrl”)指令的文件。作为惯例,包含文件以hrl扩展名结尾,但它实际上可以是任何内容。
https://github.com/basho/lager/blob/master/include/lager.hrl