2010-03-12 63 views
4

正如你可能知道,它現在可以通過使用短形式跟蹤二郎功能:跟蹤二郎功能 - 短形式

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. 

但我可能是錯的。你知道嗎?

+2

你可能想使用'dbg'包裝:http://github.com/eproxus/erlang_user_utilities (無恥自我推銷) – 2010-03-15 09:03:01

+0

感謝分享。它似乎很有用... – 2010-03-15 10:09:08

+0

漂亮的包裝;讓生活更簡單! – 2010-03-15 12:30:22

回答

5

不是真的,但你可以從dbg:tpl記得在結果saved數量和重用:

1> dbg:tracer(). 
{ok,<0.33.0>} 
2> dbg:p(all,c). 
{ok,[{matched,[email protected],25}]} 
3> dbg:tpl(lists, sort, dbg:fun2ms(fun(_) -> return_trace() end)). 
{ok,[{matched,[email protected],2},{saved,1}]} 
4> dbg:tpl(lists, sum, 1). 
{ok,[{matched,[email protected],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

+1。這很聰明:) – 2010-03-12 14:21:00