Tracing Erlang functions for debugging purposes is probably simpler than you could even imagine. Let say you have the following module and you want trace one of its functions.
sum(A, B) -> A + B.
diff(A, B) -> A - B.
Just start the tracer:
Say the tracer that you are interested in all calls for all processes:
> dbg:p(all, c)
Finally, say it that you want to trace the function sum from the module math:
> dbg:tpl(math, sum, )
Now, try to call the function, as usual. The tracer is active!
> math:sum(2, 3).
To stop the trace:
To trace all the functions within the module math:
> dbg:tpl(math, )
To trace the return value for a given function:
> dbg:tpl(math, sum, dbg:fun2ms(fun(_) -> return_trace() end)).
For more information, refer to the official documentation of the Erlang dbg module.