如何将调试器附加到正在运行的 erlang 进程(rabbitmq)?我有正在运行的同一个兔子版本的源代码。我想在源代码行设置断点,并将调试器附加到正在运行的兔子实例。我不确定erlang是否需要调试符号async_dirty。
在一个完美的世界里,我希望能够在本地和远程做到这一点。
如何将调试器附加到正在运行的 erlang 进程(rabbitmq)?我有正在运行的同一个兔子版本的源代码。我想在源代码行设置断点,并将调试器附加到正在运行的兔子实例。我不确定erlang是否需要调试符号async_dirty。
在一个完美的世界里,我希望能够在本地和远程做到这一点。
从您所说的来看,您实际上并不需要运行调试器。Erlang VM 的并发模型与 stop-everything-and-inspect-style 调试的概念不太吻合。
另一方面,VM 具有强大的内置跟踪功能。该dbg
模块是它们全部暴露的地方,但是该模块的界面很难使用,尤其是如果您是初学者。我建议使用recon_trace
来了解您的流程发生了什么:http: //ferd.github.io/recon/recon_trace.html。
如果您不想安装 recon,请从 Erlang shell 启动程序,然后在该 shell 中键入:
%enable tracing capabilities
1> dbg:tracer().
% Trace Pattern Local-scope
% (tell the tracer to trace every call in YourModule, even unexported functions).
2> dbg:tpl(YourModule, x).
% Tell dbg to print calls from all processes calling your module.
3> dbg:p(all,call).
% Run your traced module
4> YourModule:SomeFun().
% You should see nice(?) traces of inputs, outputs, and
% exceptions in your shell
查看以下会话,我在其中摸索不知道如何使用该queue
模块:
Eshell V6.3 (abort with ^G)
1> dbg:tracer(), dbg:tpl(queue, x), dbg:p(all, call).
{ok,[{matched,nonode@nohost,26}]}
2> X = queue:new().
(<0.33.0>) call queue:new()
(<0.33.0>) returned from queue:new/0 -> {[],[]}
{[],[]}
3> X = queue:cons(1).
** exception error: undefined function queue:cons/1
4> X = queue:cons(X,1).
(<0.39.0>) call queue:cons({[],[]},1)
(<0.39.0>) call queue:in_r({[],[]},1)
(<0.39.0>) exception_from {queue,in_r,2} {error,badarg}
(<0.39.0>) exception_from {queue,cons,2} {error,badarg}
** exception error: bad argument
in function queue:in_r/2
called as queue:in_r({[],[]},1)
5> X = queue:cons(1,X).
(<0.41.0>) call queue:cons(1,{[],[]})
(<0.41.0>) call queue:in_r(1,{[],[]})
(<0.41.0>) returned from queue:in_r/2 -> {[],[1]}
(<0.41.0>) returned from queue:cons/2 -> {[],[1]}
** exception error: no match of right hand side value {[],[1]}
6> X1 = queue:cons(1,X).
(<0.43.0>) call queue:cons(1,{[],[]})
(<0.43.0>) call queue:in_r(1,{[],[]})
(<0.43.0>) returned from queue:in_r/2 -> {[],[1]}
(<0.43.0>) returned from queue:cons/2 -> {[],[1]}
{[],[1]}
希望这有助于您入门。
如果您想了解 Erlang 向导是如何做到的,请观看Mats Cronqvist 的演讲“printf
摆脱printf
调试”。
您可以使用图形调试器或在 shell 中使用int模块。需要使用debug_info选项编译模块。
可以使用 debugger:start(global) 或连接到远程 shell (^G) 从连接的节点远程调试进程。