【问题标题】:How to attach erlang dbg to a running process?如何将erlang dbg附加到正在运行的进程?
【发布时间】:2015-06-06 11:53:22
【问题描述】:

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

在一个完美的世界中,我希望能够在本地和远程执行此操作。

【问题讨论】:

标签: debugging erlang rabbitmq rabbitmq-exchange


【解决方案1】:

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

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

【讨论】:

    【解决方案2】:

    根据您的说法,您实际上并不需要运行调试器。 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's talk "Taking the printf out of printf debugging"

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-11-20
      • 1970-01-01
      • 1970-01-01
      • 2016-11-24
      • 2018-02-19
      • 1970-01-01
      • 2014-02-02
      相关资源
      最近更新 更多