views:

82

answers:

1

As you might know, it's now possible to trace Erlang functions by using the short form:

dbg:tpl(Module, Function, x).

Instead of the usual:

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

I'm actually wondering if a similar short form is available for return_trace(). Something like:

dbg:tpl(Module, Function, r).

Instead of:

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

The source code in the dbg module seems to suggest not:

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.

But I might be wrong. Do you know of any?

+4  A: 

Not really, but you can remember the saved number in the result from dbg:tpl and reuse it:

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
legoscia
+1. That's clever :)
Roberto Aloi