How to debug an erlang application that won't boot
If i write some erlang code to build a supervision tree and then launch the application at the boot whith the following command, it may be very hard to find out why it doesn't work :
erl -s myapp -pa ebin ... ...
(myapp example module)
-module(myapp).
-export([start/0]).
start() -> application:start(myapp).
Let's say that my app launches a supervisor, myapp_sup. myapp_sup launches at its turn several supervisors (let's say server_sup, database_sup, another_sup).
Theese supervisors will launch some gen_servers.
At some point, if there is a mistake in my code, i cannot find it out !
I wrote a call to somemodule:functionthatdoesntexists() in the init callback of some gen_server.
All the vm says is "init terminating in do boot" and then display error location of a badmatch, precising file and line of my top module (myapp).
(Badmatch because ok = application:start(...) will not match).
I look in th erl_crash.dump file, and there is no information about this undefined function (yet i find it in the atoms list).
So, i wrote some log to see approximatively where is the error, but then i'll have to launch my gen_servers by the hand to get back the correct error information.
What am i missing, how could i figure it out faster ?
Thanks
If your application makes a call to an unknown module, your erl_crash.dump
file will contain a line like this one:
41DABB8:t4:A8:nonexistent_module,A7:unknown,N,N
where the "unknown" in the line indicates that the module nonexistent_module
can't be found. Searching your erl_crash.dump
file for the string "unknown" can help in these cases.
If you suspect a certain module makes a call to a function that doesn't exist, you can find it using the xref tool in an interactive erl shell. Make sure you compile the module with debug information (typically via erlc +debug_info
), then:
1> xref:m(my_module).
[{deprecated,[]},
{undefined,[{{my_module,init,1},{another_module,unknown,0}}]},
{unused,[]}]
Here, xref
shows us that the my_module:init/1
function makes a call to the another_module:unknown/0
function, but the unknown/0
function isn't defined in another_module
.
You can also use xref
to check entire applications; see the documentation for details
添加-init_debug到你的erl命令:)
链接地址: http://www.djcxy.com/p/38186.html上一篇: gen用什么OTP模式
下一篇: 如何调试无法启动的erlang应用程序