|
|
| Author |
Message |
|
| garazdawi |
Posted: Thu Jul 20, 2006 8:58 am |
|
|
|
User
Joined: 10 Jul 2006
Posts: 20
|
HI, I want to be able to put a trace on a function which receives a specific argument. For inteance if
foo(Bar) -> Bar.
is called with foo(foo) the trace should be outputted in the shell, but if the call foo(bar) is made nothing should be outputted. I've been looking at the matchspec documentation, but I cannot figure out how it should be done. |
_________________ Erlang Training & Consulting |
|
| Back to top |
|
| francesco |
Posted: Thu Jul 20, 2006 3:03 pm |
|
|
|
User
Joined: 07 Jul 2006
Posts: 249
Location: London
|
28> dbg:tracer().
{ok,<0.75.0>}
29> dbg:p(all, [c]).
{ok,[{matched,nonode@nohost,23}]}
30> F = dbg:fun2ms(fun([X]) when X == foo -> ok end).
[{['$1'],[{'==','$1',foo}],[ok]}]
31> dbg:tp(foo, foo, 1, F).
{ok,[{matched,nonode@nohost,1},{saved,1}]}
32> foo:foo(bar).
hello_world
33> foo:foo(foo).
(<0.28.0>) call foo:foo(foo)
hello_world
34> |
|
|
| Back to top |
|
| garazdawi |
Posted: Thu Aug 03, 2006 2:22 pm |
|
|
|
User
Joined: 10 Jul 2006
Posts: 20
|
Nice thanks!
Do you know if there is anyway to use fun2ms with a variable amount of variables?
dbg:fun2ms(fun([X|_]) when X == foo -> ok end).
This does not work for me so when matching on module:function(A,B) and module:function(A) I have to write two seperate commands which is not all that bad, but for more complex matchspecs it might be useful.
Also, is there any documentation about how to use fun2ms? besides the one given in the module documentation of dbg. |
_________________ Erlang Training & Consulting |
|
| Back to top |
|
| francesco |
Posted: Sun Aug 06, 2006 12:04 pm |
|
|
|
User
Joined: 07 Jul 2006
Posts: 249
Location: London
|
From the dbg manual page on fun2ms: Pseudo function that by means of a parse_transform translates the literal fun() typed as parameter in the function call to a match specification as described in the match_spec manual of ERTS users guide. (with literal I mean that the fun() needs to textually be written as the parameter of the function, it cannot be held in a variable which in turn is passed to the function).
The fun() is very restricted, it can take only a single parameter (the parameter list to match), a sole variable or a list. It needs to use the is_XXX guard tests and one cannot use language constructs that have no representation in a match_spec (like if, case, recieve etc). The return value from the fun will be the return value of the resulting match_spec.
More information is provided by the ms_transform manual page in stdlib. |
|
|
| Back to top |
|
|
|
All times are GMT
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You can attach files in this forum You can download files in this forum
|
|
|