如何将erlang dbg附加到正在运行的进程?

pol*_*olo 2 debugging erlang rabbitmq rabbitmq-exchange

如何将调试器附加到正在运行的erlang进程(rabbitmq)?我有正在运行的相同兔子版本的源代码.我想在源代码行上设置断点,并将调试器附加到正在运行的Rabbit实例.我不确定erlang是否需要调试符号async_dirty.

在一个完美的世界里,我希望能够在本地和远程做到这一点.

我是一个二郎初学者,我甚至不会说我是二郎的新手.我正在尝试学习它,因为我调试了一些rabbitmq插件.

小智 6

根据您的说法,您不需要运行调试器.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
Run Code Online (Sandbox Code Playgroud)

看看下面的会话,我不知道如何使用该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]}
Run Code Online (Sandbox Code Playgroud)

希望这有助于您入门.

如果您想了解Erlang向导是如何做到的,请参阅此演示文稿.