2015-04-01 64 views
2

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

在一个完美的世界中,我希望能够做到这一点,无论是本地和远程。

我是这样一个erlang初学者,我甚至不会说我是erlang的新手。我只是想在我调试一些rabbitmq插件时学习它。

回答

5

从你所说的话来看,你并不需要运行一个调试器。 Erlang虚拟机的并发模型并不适用于stop-everything-and-inspect-style调试的概念。

另一方面,VM具有很好的内置跟踪功能。 dbg模块是他们全部暴露的地方,但该模块的界面非常难以使用,特别是如果您是初学者。 我建议使用recon_trace来了解您的流程发生了什么:http://ferd.github.io/recon/recon_trace.html

如果你不喜欢安装侦察,从Erlang 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,[email protected],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向导如何执行此操作,请参见this presentation

0

您可以使用图形debugger或使用int模块的shell。 需要使用debug_info选项编译模块。

可以使用调试器从连接的节点远程调试进程:start(global)或连接到远程shell(^ G)。

相关问题