Debugging 如何在Erlang中调试?
当我运行广播服务器时,我收到了错误报告:Debugging 如何在Erlang中调试?,debugging,erlang,Debugging,Erlang,当我运行广播服务器时,我收到了错误报告: =ERROR REPORT==== 14-Feb-2012::16:22:29 === Error in process <0.757.0> with exit value: {badarg,[{mymodule1,func1,1}]} =ERROR REPORT==== 14-Feb-2012::16:22:30 === Error in process <0.751.0> with exit value: {functio
=ERROR REPORT==== 14-Feb-2012::16:22:29 ===
Error in process <0.757.0> with exit value: {badarg,[{mymodule1,func1,1}]}
=ERROR REPORT==== 14-Feb-2012::16:22:30 ===
Error in process <0.751.0> with exit value: {function_clause,[{mymodule2, func2,[{#Port<0.2
=错误报告===2012年2月14日::16:22:29===
进程中存在错误,退出值为:{badarg,[{mymodule1,func1,1}]}
=错误报告===2012年2月14日::16:22:30===
处理退出值时出错:{function_子句,[{mymodule2,func2,[{{code>function_子句
意味着没有与参数匹配的functionmymodule2:func2
定义
func2({X, Y}) -> ... %% only accepts a tuple of size 2
func2([1, 2, 3])%% called with a list instead; will fail with function_clause
由于内置函数的参数错误,可能会抛出函数的badarg
:
请参见此处的其他故障原因列表:
对于调试:1)最新的Erlang版本(R15B)应在异常消息中包含行号;2)您可以使用Erlang附带的。在调试错误或崩溃时,查看特定函数的输入和输出通常很有用。中的调试实用程序redbug使调试变得相当简单 示例:
%%% Trace a function:
1>redbug:start("lists:sort")
2>lists:sort([3,1,2]).
21:41:00 <{erlang,apply,2}> {lists,sort,[[3,1,2]]}
%%% Trace a module and also get the return value
3>redbug:start("string->return")
4>string:to_upper("foo").
21:41:10 <{erlang,apply,2}> {string,to_upper,["foo"]}
21:41:10 <{erlang,apply,2}> {string,'-to_upper/1-lc$^0/1-0-',["foo"]}
...
21:41:10 <{erlang,apply,2}> {string,to_upper,1} -> "FOO"
标准库中没有
ts
模块。您使用的是其他库吗?“ts”是我自己的模块,我想知道一种很好的调试方法来获取详细信息。许多人说:“Erlang善于定位bug”,但我认为Ruby更好,因为Ruby可以在出现错误时为您提供详细的回溯
1>redbug:start("mymodule1:func1").
2> %% redo the call that caused the crash