aboutsummaryrefslogtreecommitdiffstats
path: root/lib/ssh
diff options
context:
space:
mode:
authorHans Nilsson <[email protected]>2016-06-10 12:33:22 +0200
committerHans Nilsson <[email protected]>2016-06-13 15:43:07 +0200
commitb686b7f7beb46dfdcd83e23cccca74839e373f1e (patch)
tree207088afdf928815a0fc00846fee3d814accede8 /lib/ssh
parent1280c70da91b90592ae4be88f1f045956e716de7 (diff)
downloadotp-b686b7f7beb46dfdcd83e23cccca74839e373f1e.tar.gz
otp-b686b7f7beb46dfdcd83e23cccca74839e373f1e.tar.bz2
otp-b686b7f7beb46dfdcd83e23cccca74839e373f1e.zip
ssh: Additions to experimental ssh_dbg module
- reorg - ssh_dbg:stop/0 - formating of send and receive debugging
Diffstat (limited to 'lib/ssh')
-rw-r--r--lib/ssh/src/ssh_dbg.erl44
1 files changed, 35 insertions, 9 deletions
diff --git a/lib/ssh/src/ssh_dbg.erl b/lib/ssh/src/ssh_dbg.erl
index fbf85cfcfc..480795cfc7 100644
--- a/lib/ssh/src/ssh_dbg.erl
+++ b/lib/ssh/src/ssh_dbg.erl
@@ -23,7 +23,8 @@
-module(ssh_dbg).
-export([messages/0,
- messages/1
+ messages/1,
+ stop/0
]).
-include("ssh.hrl").
@@ -40,34 +41,59 @@ messages() -> messages(fun(String,_D) -> io:format(String) end).
messages(Write) when is_function(Write,2) ->
catch dbg:start(),
-
- Handler = fun msg_formater/2,
- InitialData = #data{writer = Write},
- {ok,_} = dbg:tracer(process, {Handler, InitialData}),
-
+ setup_tracer(Write),
dbg:p(new,c),
+ dbg_ssh_messages().
+
+dbg_ssh_messages() ->
dbg:tp(ssh_message,encode,1, x),
dbg:tp(ssh_message,decode,1, x),
dbg:tpl(ssh_transport,select_algorithm,3, x).
+%%%----------------------------------------------------------------
+stop() ->
+ dbg:stop().
+
%%%================================================================
msg_formater({trace,Pid,call,{ssh_message,encode,[Msg]}}, D) ->
fmt("~nSEND ~p ~s~n", [Pid,wr_record(shrink_bin(Msg))], D);
-
+msg_formater({trace,_Pid,return_from,{ssh_message,encode,1},_Res}, D) ->
+ D;
+
+msg_formater({trace,_Pid,call,{ssh_message,decode,_}}, D) ->
+ D;
msg_formater({trace,Pid,return_from,{ssh_message,decode,1},Msg}, D) ->
fmt("~nRECV ~p ~s~n", [Pid,wr_record(shrink_bin(Msg))], D);
+msg_formater({trace,_Pid,call,{ssh_transport,select_algorithm,_}}, D) ->
+ D;
msg_formater({trace,Pid,return_from,{ssh_transport,select_algorithm,3},{ok,Alg}}, D) ->
fmt("~nALGORITHMS ~p~n~s~n", [Pid, wr_record(Alg)], D);
-msg_formater(_, D) ->
- D.
+msg_formater({trace,Pid,send,ErlangMsg,Dest}, D) ->
+ fmt("~nERL MSG ~p SEND TO ~p~n ~p~n", [Pid,Dest, shrink_bin(ErlangMsg)], D);
+
+msg_formater({trace,Pid,'receive',ErlangMsg}, D) ->
+ fmt("~nERL MSG ~p RECIEVE~n ~p~n", [Pid,shrink_bin(ErlangMsg)], D);
+
+msg_formater(M, D) ->
+ fmt("~nDBG ~n~p~n", [shrink_bin(M)], D).
+
+%% msg_formater(_, D) ->
+%% D.
fmt(Fmt, Args, D=#data{writer=Write,acc=Acc}) ->
D#data{acc = Write(io_lib:format(Fmt, Args), Acc)}.
%%%----------------------------------------------------------------
+setup_tracer(Write) ->
+ Handler = fun msg_formater/2,
+ InitialData = #data{writer = Write},
+ {ok,_} = dbg:tracer(process, {Handler, InitialData}),
+ ok.
+
+%%%----------------------------------------------------------------
shrink_bin(B) when is_binary(B), size(B)>100 -> {'*** SHRINKED BIN',size(B),element(1,split_binary(B,20)),'***'};
shrink_bin(L) when is_list(L) -> lists:map(fun shrink_bin/1, L);
shrink_bin(T) when is_tuple(T) -> list_to_tuple(shrink_bin(tuple_to_list(T)));