代码之家  ›  专栏  ›  技术社区  ›  Roberto Aloi

跟踪Erlang函数-短格式

  •  4
  • Roberto Aloi  · 技术社区  · 15 年前

    正如您可能知道的,现在可以使用以下简短形式跟踪Erlang函数:

    dbg:tpl(Module, Function, x).
    

    而不是通常的:

    dbg:tpl(Module, Function, dbg:fun2ms(fun(_) -> exception_trace() end)).
    

    我想知道是否有类似的短表格 return_trace() . 类似:

    dbg:tpl(Module, Function, r).
    

    而不是:

    dbg:tpl(Module, Function, dbg:fun2ms(fun(_) -> return_trace() end)).
    

    中的源代码 dbg 模块似乎建议不要:

    new_pattern_table() ->
        PT = ets:new(dbg_tab, [ordered_set, public]),
        ets:insert(PT, 
               {x, 
            term_to_binary([{'_',[],[{exception_trace}]}])}),
        ets:insert(PT, 
               {exception_trace, 
            term_to_binary(x)}),
        PT.
    

    但我可能错了。你知道吗?

    1 回复  |  直到 15 年前
        1
  •  5
  •   legoscia    15 年前

    不是真的,但你可以记住 saved 结果中的数字来自 dbg:tpl 再用它:

    1> dbg:tracer().
    {ok,<0.33.0>}
    2> dbg:p(all,c).
    {ok,[{matched,nonode@nohost,25}]}
    3> dbg:tpl(lists, sort, dbg:fun2ms(fun(_) -> return_trace() end)).
    {ok,[{matched,nonode@nohost,2},{saved,1}]}
    4> dbg:tpl(lists, sum, 1).
    {ok,[{matched,nonode@nohost,2},{saved,1}]}
    5> lists:sum([1,2,3]).
    6
    6> (<0.31.0>) call lists:sum([1,2,3])
    (<0.31.0>) call lists:sum([1,2,3],0)
    (<0.31.0>) call lists:sum([2,3],1)
    (<0.31.0>) call lists:sum([3],3)
    (<0.31.0>) call lists:sum([],6)
    (<0.31.0>) returned from lists:sum/2 -> 6
    (<0.31.0>) returned from lists:sum/2 -> 6
    (<0.31.0>) returned from lists:sum/2 -> 6
    (<0.31.0>) returned from lists:sum/2 -> 6
    (<0.31.0>) returned from lists:sum/1 -> 6