如何细化调试?
崩溃报告 (SASL) 或多或少地给出了错误发生的位置和原因。 但是否有可能对其进行改进(函数、代码行等)?
Crash report (SASL) gives more or less where and why a bug happens.
But is it possible to refine this (the function, the line de code, etc) ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您可以重现该错误,获取更多信息的最佳方法是在有问题的部分上进行 dbg 跟踪并查看该输出。
这通常对我有用。将 Mod 和 Func 替换为您想要调试的任何模块和函数。
如果您正在寻找更详细的事后日志记录,那么 sasl 和 error_logger 是您的朋友。当然,有时 SASL 无法为您提供足够的信息,如果这种情况在您的系统中经常发生,您可能应该学习更好地理解 SASL 输出或编写自己的日志处理程序。将您自己的错误处理程序插入 SASL 并根据需要输出内容非常容易。
然而,您永远不会获得行号,因为该信息在编译时被破坏,并且虚拟机无法知道哪一行崩溃了。然而,它确实知道哪个函数以及可能使用哪个参数,鉴于此,通常可以找出问题所在。除非你编写很长的函数,否则在我看来这是不好的代码味道,并且表明你应该将代码重构为更小的函数。
If you can reproduce the fault, the best way to get more information is to put a dbg trace on sections in question and review that output.
This usually does the trick for me. Replace Mod and Func with whatever module and function you want to debug.
If you are looking for more detailed post-mortem logging then sasl and the error_logger are your friends. There are of course times when SASL does not give you enough info, if this happens a lot in your system you probably should either learn to understand the SASL output better or write your own log handler. It is quite easy to plug-in your own error handler into SASL and output things as you want.
You will however never get line number as that information is destroyed at compilation time and there is no way for the VM to know which line crashed. It does however know which function and possibly with which arguments, given this it is usually possible to find out where things went wrong. Unless you write very long functions, which IMO is bad code smell and a sign that you should refactor your code to smaller functions.
一般来说,没有。 erlang .beam 文件不包含原始代码的行号,因此很难知道问题发生在哪一行。我在项目中确实使用了许多宏,包括“log.hrl”:
这确实为您提供了程序中的一些日志行以供查找。为了进行调试,我还经常使用 eper 套件中的 redbug 工具:
https://github.com/massemanet/eper
它允许您在发生呼叫时实时跟踪:
我希望这会有所帮助。
In general, no. The erlang .beam files does not contain the line numbers from the original code, so it is hard to know at what line the problem occurred. I do have a number of macros I use in my project, included as
"log.hrl"
:and this does give you some log lines in the program to hunt for. For debugging I often also use the redbug tool from the eper suite:
https://github.com/massemanet/eper
It allows you to trace in realtime whenever a call happens:
I hope this helps.