<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<div class="moz-cite-prefix">On 11/06/2012 03:33 PM, Attila Rajmund
Nohl wrote:<br>
</div>
<blockquote
cite="mid:CAFkcMa_eCynwy8peB+k0WQc2NJZbB5H3NZ0B5qkaUg1QUu+6ag@mail.gmail.com"
type="cite">
<pre wrap="">Hello!
I can trace a function call with specific arguments with a command like this:
dbg:tpl(foo, bar, dbg:fun2ms(fun([baz,_]) -> return_trace(),
exception_trace() end)).
However, it's a long to type, I'd like to have a wrapper around it.
The naive solution doesn't even compile:
-module(d).
-export([mfa/3]).
mfa(M, F, A) ->
dbg:tpl(M, F, dbg:fun2ms(fun(Args) when Args==A -> return_trace(),
exception_trace() end)).
</pre>
</blockquote>
As described in the docs (
<meta http-equiv="content-type" content="text/html;
charset=ISO-8859-1">
<a href="http://www.erlang.org/doc/man/dbg.html#fun2ms-1">http://www.erlang.org/doc/man/dbg.html#fun2ms-1</a>),
you'll need to include ms_transform.hrl if calling dbg:fun2ms inside
a module, so this:<br>
---------------<br>
-module(d).<br>
-include_lib("stdlib/include/ms_transform.hrl").<br>
-export([mfa/3]).<br>
<br>
mfa(M, F, A) -><br>
dbg:tpl(M, F, dbg:fun2ms(fun(Args) when Args==A ->
return_trace(),<br>
exception_trace() end)).<br>
----------------<br>
compiles and works to a certain extent. <br>
<blockquote
cite="mid:CAFkcMa_eCynwy8peB+k0WQc2NJZbB5H3NZ0B5qkaUg1QUu+6ag@mail.gmail.com"
type="cite">
<pre wrap="">
because there are no return_trace() and exception_trace() functions in
the module. Even if it'd compile, I couldn't call it like this:
d:mfa(foo, bar, [baz, _]).</pre>
</blockquote>
This is more tricky, you cannot send unbound variables to a function
- it has little to do with dbg:fun2ms. Either you have to write your
own parse_transform, which cannot be used from the shell, or you
could use the match_spec syntax for the variables in the argument
list and skip fun2ms altogether...<br>
Look at this in the shell:<br>
1> dbg:fun2ms(fun([baz,A,_]) ->
return__trace(),exception_trace() end).<br>
[{[baz,'_'],[],[{return_trace},{exception_trace}]}]<br>
The argument list is translated so that anonymous variables become
the atom '_' and named variables become '$n', where n is an integer
> 0. You can write your function as:<br>
<br>
mfa(M, F, A) -><br>
dbg:tpl(M, F, [{A,[],[{return_trace},{exception_trace}]}]).<br>
<br>
and call it as:<br>
d:mfa(foo,bar,[baz,'_']).<br>
<br>
In that case you will not need the parse_transform.<br>
<br>
BTW, you can remove return_trace, exception_trace includes
return_trace.<br>
<br>
Cheers,<br>
/Patrik<br>
<br>
<blockquote
cite="mid:CAFkcMa_eCynwy8peB+k0WQc2NJZbB5H3NZ0B5qkaUg1QUu+6ag@mail.gmail.com"
type="cite">
<pre wrap="">
because the _ variable is not bound. Is there a simple workaround or
shall I start to read up on parse_transforms?
_______________________________________________
erlang-questions mailing list
<a class="moz-txt-link-abbreviated" href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a>
<a class="moz-txt-link-freetext" href="http://erlang.org/mailman/listinfo/erlang-questions">http://erlang.org/mailman/listinfo/erlang-questions</a>
</pre>
</blockquote>
<br>
</body>
</html>