erlang的调试配置

distel可以断点调试erlang,但是步骤非常繁琐

以下面的测试脚本为例说明

geometry.erl

1 -module(geometry).
2 -export([area/1]).
3 
4 area({rectangle,Width,Height})->
5     Width*Height;
6 area({square,X}) ->
7     X*X;
8 area({circle,R}) ->
9     3.14159*R*R.

调试步骤如下:(步骤一步都不能少,否则会出问题)

进入distel菜单,选择start new shell,执行c(geometry,[debug_info]).
编译成功以后,c-c c-d L重新载入erl脚本
c-c c-d i进入交互模式,如果提示node,就输入在emacs的distel配置里面的这个(setq inferior-erlang-machine-options '("-sname" "localhost"))
c-x space,在行上设置断点,应该能看到红色的行了
最后在shell里面直接调用,例如我们的geometry:area({circle,123}).

调试需要源码带调试标记编译

c(xxx,[debug_info]).
make:all([debug_info]).
debugger:start().
im().

都可以,两个是一样的

注:erlang的debugger单步step in需要module先被interpret

原文地址:https://www.cnblogs.com/ziyouchutuwenwu/p/3523238.html