[erlang-questions] UI Debugger

Serge Aleynikov <>
Wed Sep 6 15:11:03 CEST 2006


Jean Verger wrote:
> Hi,
> thanks for your reply. I have already tried that. Following that
> approach, I can login remotely (similar as ssh I believe) ...After
> that .. what debugger can I run? debugger:start(). doesn't work since
> is remote  ... :( I don't know how to make the X11 work remotely.
> 
> Ah, thanks for your comment on q(). , ^G and halt, something new I
> learn today :)
> 
> regards,
> 
> jean

Aside from using the dubbuger interface, another way to debug a program 
on a production node is to use the dbg's tracing facility.

Below you can find a sample user_default.erl file that you can load on a 
remote system using "~/.erlang" file:

$ cat .erlang
code:load_abs("/opt/erlang/usr/user_default").

It'll expand the shell with convenient tracing shortcuts.  The tracing 
output will be printed to the screen.  Run help() at the shell to ensure 
that the module is loaded:

[: ~]
$ erl
Erlang (BEAM) emulator version 5.5 [source] [async-threads:0] [hipe] 
[kernel-poll:false]

Eshell V5.5  (abort with ^G)
1> help().
...
** user extended commands **
dbgtc(File)   -- use dbg:trace_client() to read data from File
dbgon(M)      -- enable dbg tracer on all funs in module M
dbgon(M,Fun)  -- enable dbg tracer for module M and function F
dbgon(M,File) -- enable dbg tracer for module M and log to File
dbgadd(M)     -- enable call tracer for module M
dbgadd(M,F)   -- enable call tracer for function M:F
dbgdel(M)     -- disable call tracer for module M
dbgdel(M,F)   -- disable call tracer for function M:F
dbgoff()      -- disable dbg tracer (calls dbg:stop/0)

Note that tracing (as well as debugging) does slow down performance, and 
may have significant impact on performance of a production node unless 
you know what you are doing.

Regards,

Serge

--------------------------------------------

-module(user_default).
-author('').

-export([help/0,dbgtc/1, dbgon/1, dbgon/2,
          dbgadd/1, dbgadd/2, dbgdel/1, dbgdel/2, dbgoff/0]).

-import(io, [format/1]).

help() ->
     shell_default:help(),
     format("** user extended commands **~n"),
     format("dbgtc(File)   -- use dbg:trace_client() to read data from 
File\n"),
     format("dbgon(M)      -- enable dbg tracer on all funs in module M\n"),
     format("dbgon(M,Fun)  -- enable dbg tracer for module M and 
function F\n"),
     format("dbgon(M,File) -- enable dbg tracer for module M and log to 
File\n"),
     format("dbgadd(M)     -- enable call tracer for module M\n"),
     format("dbgadd(M,F)   -- enable call tracer for function M:F\n"),
     format("dbgdel(M)     -- disable call tracer for module M\n"),
     format("dbgdel(M,F)   -- disable call tracer for function M:F\n"),
     format("dbgoff()      -- disable dbg tracer (calls dbg:stop/0)\n"),
     format("l()           -- load all changed modules\n"),
     format("nl()          -- load all changed modules on all known 
nodes\n"),
     format("mm()          -- list modified modules\n"),
     true.

dbgtc(File) ->
    Fun = fun({trace,_,call,{M,F,A}}, _) ->
                 io:format("call: ~w:~w~w~n", [M,F,A]);
             ({trace,_,return_from,{M,F,A},R}, _) ->
                 io:format("retn: ~w:~w/~w -> ~w~n", [M,F,A,R]);
             (A,B) ->
                 io:format("~w: ~w~n", [A,B])
          end,
    dbg:trace_client(file, File, {Fun, []}).

dbgon(Module) ->
    case dbg:tracer() of
    {ok,_} ->
       dbg:p(all,call),
       dbg:tpl(Module, [{'_',[],[{return_trace}]}]),
       ok;
    Else ->
       Else
    end.

dbgon(Module, Fun) when is_atom(Fun) ->
    {ok,_} = dbg:tracer(),
    dbg:p(all,call),
    dbg:tpl(Module, Fun, [{'_',[],[{return_trace}]}]),
    ok;

dbgon(Module, File) when is_list(File) ->
    {ok,_} = dbg:tracer(file, dbg:trace_port(file, File)),
    dbg:p(all,call),
    dbg:tpl(Module, [{'_',[],[{return_trace}]}]),
    ok.

dbgadd(Module) ->
    dbg:tpl(Module, [{'_',[],[{return_trace}]}]),
    ok.

dbgadd(Module, Fun) ->
    dbg:tpl(Module, Fun, [{'_',[],[{return_trace}]}]),
    ok.

dbgdel(Module) ->
    dbg:ctpl(Module),
    ok.

dbgdel(Module, Fun) ->
    dbg:ctpl(Module, Fun),
    ok.

dbgoff() ->
    dbg:stop().




More information about the erlang-questions mailing list