Non-intrusive intercept

Siri Hansen (EAB) siri@REDACTED
Tue Jan 14 08:54:58 CET 2003


Hello Anders!

You can use tracing. In OTP there are several ways of doing this. Have
a look at the runtime_tools and observer(R9) applications. Here
is a very simple example using the dbg module in runtime_tools. It
produces a printout in the erlang shell when the traced function is called:


6> % start at tracer
6> dbg:tracer().
{ok,<0.37.0>}
7> 
7> % set the 'call' trace flag on all processes
7> dbg:p(all,call).
{ok,[{matched,nonode@REDACTED,24}]}
8> 
8> % set a trace pattern (here []) on the function to trace
8> % First an exported function  
8> dbg:tp(m,f,0,[]). 
{ok,[{matched,nonode@REDACTED,1}]}
9> % then an internal function
9> dbg:tpl(m,internal,0,[]).
{ok,[{matched,nonode@REDACTED,0}]}
10> 
10> m:f().           
(<0.25.0>) call m:f()
{3,2,1}
(<0.25.0>) call m:internal()
11> 
11> % clear all trace patterns
11> dbg:ctp('_').
{ok,[]}
12> % stop trace tool
12> dbg:stop().
ok

runtime_tools and observer also provide functions for directing the
trace result to e.g. a file instead of the erlang shell.

See also the documentation of the trace BIF (Ref man for the erlang
module in the kernel application), and match specifications (for
setting trace patterns) in the ERTS user guide.

Good luck!

/siri

Anders Fluur (EAB) wrote:
> Hi,
>  
> I am writing a test application and I would like to verify that the tested application makes a call: module_x:function_y()!
> Preferrably, this should be performed as a call to my testapplication.
> How can I do this without modifying the tested application?
>  
> Best regards,
> Anders



More information about the erlang-questions mailing list