2012-02-14 70 views
2

當我跑我的廣播服務器,我得到了錯誤報告:如何在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: {function_clause,[{mymodule2, func2,[{#Port<0.2 
+0

沒有'標準庫中的ts'模塊。它是否來自您正在使用的其他圖書館? – 2012-02-14 09:44:12

+0

「ts」是我自己的模塊,我想知道一個好的調試方法來獲取細節。 – why 2012-02-14 09:51:30

回答

3

在調試錯誤或崩潰時,查看某個函數得到什麼輸入和輸出通常很有用。在eper repo調試工具紅蟲使得它比較容易

例子:

%%% 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" 

因此,在你的代碼,我可能例如看到輸入mymodule1:FUNC1得到:

1>redbug:start("mymodule1:func1"). 
2> %% redo the call that caused the crash 
+0

eper很不錯時,Ruby會給你一個詳細的回溯信息! – why 2012-02-15 01:38:41

3

function_clause只是意味着有對函數mymodule2:func2該參數匹配沒有定義。例如。 http://erlang.2086793.n4.nabble.com/function-badarg-td3645808.html

見的其他故障原因在這裏的列表:http://learnyousomeerlang.com/errors-and-exceptions

爲了調試:

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附帶的debugger

+0

很多人都說:「Erlang擅長定位錯誤」,但是我認爲Ruby更好,因爲當錯誤 – why 2012-02-15 01:37:21