跟踪Erlang函数-简短形式

跟踪Erlang函数-简短形式,erlang,debugging,trace,Erlang,Debugging,Trace,您可能知道,现在可以使用以下简短形式跟踪Erlang函数: dbg:tpl(Module, Function, x). 与往常不同的是: dbg:tpl(Module, Function, dbg:fun2ms(fun(_) -> exception_trace() end)). 实际上我想知道return\u trace()是否有类似的简短形式。比如: dbg:tpl(Module, Function, r). 而不是: dbg:tpl(Module, Function, dbg:

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

dbg:tpl(Module, Function, x).
与往常不同的是:

dbg:tpl(Module, Function, dbg:fun2ms(fun(_) -> exception_trace() end)).
实际上我想知道
return\u 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.

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

不太清楚,但您可以从
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
1>dbg:tracer()。
{好的,}
2> dbg:p(全部,c)。
{好的,[{匹配,nonode@nohost,25}]}
3> dbg:tpl(列表、排序、dbg:fun2ms(fun()->return_trace()end))。
{好的,[{匹配,nonode@nohost,2},{已保存,1}]}
4> dbg:tpl(列表,总和,1)。
{好的,[{匹配,nonode@nohost,2},{已保存,1}]}
5> 列表:总和([1,2,3])。
6.
6> ()呼叫列表:总和([1,2,3])
()呼叫列表:总和([1,2,3],0)
()呼叫列表:总和([2,3],1)
()呼叫列表:总和([3],3)
()呼叫列表:总和([],6)
()从列表返回:sum/2->6
()从列表返回:sum/2->6
()从列表返回:sum/2->6
()从列表返回:sum/2->6
()从列表返回:sum/1->6

您可能想使用一个
dbg
包装器:(无耻的自我推销)谢谢分享。它似乎很有用…很好的包装;让生活更简单!