How to debug an erlang application that does not load

If I write some erlang code to build an observation tree, and then run the application upon loading with the following command, it can be very difficult to find out why this does not work:

erl -s myapp -pa ebin ... ... 

(myapp example module)

 -module(myapp). -export([start/0]). start() -> application:start(myapp). 

Say my application launches the myapp_sup dispatcher. myapp_sup, in turn, runs several supervisors (say server_sup, database_sup, another_sup).

These executives launched some gen_servers.

At some point, if there is an error in my code, I cannot find it!

I wrote a call to somemodule: functionthatdoesntexists () in the init callback of some gen_server.

All vm say that "init exits in boot" and then displays the location of the badmatch error, specifying the file and line of my top module (myapp).

(Badmatch, because ok = application: start (...) will not match).

I look in the erl_crash.dump file and there is no information about this function undefined (until I find it in the list of atoms).

So, I wrote some journal to see an example where the error is, but then I will have to run my gen_servers manually to return the correct error information.

What am I missing, how can I understand this faster?

thanks

+4
source share
2 answers

If your application makes an unknown module call, your erl_crash.dump file will contain a line like this:

 41DABB8:t4:A8:nonexistent_module,A7:unknown,N,N 

where “unknown” in the line indicates that nonexistent_module cannot be found. A search in your erl_crash.dump file for the string "unknown" may help in these cases.

If you suspect that a particular module is making a call to a function that does not exist, you can find it using the xref tool in the erl interactive shell. Make sure you compile the module with debugging information (usually via erlc +debug_info ), and then:

 1> xref:m(my_module). [{deprecated,[]}, {undefined,[{{my_module,init,1},{another_module,unknown,0}}]}, {unused,[]}] 

Here xref shows that the function my_module:init/1 calls the function another_module:unknown/0 , but the unknown/0 function is not defined in another_module .

You can also use xref to test all applications; see documentation for details

+1
source

Add -init_debug to the erl command :)

+2
source

All Articles