gpt4 book ai didi

debugging - 如何在 Erlang 中调试?

转载 作者:行者123 更新时间:2023-12-04 17:23:16 26 4
gpt4 key购买 nike

当我运行我的广播服务器时,我收到了错误报告:

=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

最佳答案

调试错误或崩溃时,查看某个函数获得的输入和输出通常很有用。 eper repo 中的调试实用程序 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"

因此,在您的代码中,我将例如查看输入 mymodule1:func1 获取的内容:

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

关于debugging - 如何在 Erlang 中调试?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9273901/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com