diff options
author | Hans Nilsson <[email protected]> | 2016-06-13 16:02:59 +0200 |
---|---|---|
committer | Hans Nilsson <[email protected]> | 2016-06-13 16:02:59 +0200 |
commit | 0a4a51abc50605038591371a07fe39903f7a2cf6 (patch) | |
tree | 6f1f49e5ba1dcb452c3bdbbce7d39c1604326a57 /lib | |
parent | 701f2f8df8240ddcc83460fb4504111bea979dfa (diff) | |
parent | 4e0bb309fae6449269068fa810e225ed0b828425 (diff) | |
download | otp-0a4a51abc50605038591371a07fe39903f7a2cf6.tar.gz otp-0a4a51abc50605038591371a07fe39903f7a2cf6.tar.bz2 otp-0a4a51abc50605038591371a07fe39903f7a2cf6.zip |
Merge branch 'hans/ssh/cuddle_tests'
Add experimental debugging help in the code. Not used in normal cases.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/ssh/src/ssh.erl | 3 | ||||
-rw-r--r-- | lib/ssh/src/ssh_dbg.erl | 44 |
2 files changed, 38 insertions, 9 deletions
diff --git a/lib/ssh/src/ssh.erl b/lib/ssh/src/ssh.erl index 65f1acc6a6..0570853a9b 100644 --- a/lib/ssh/src/ssh.erl +++ b/lib/ssh/src/ssh.erl @@ -601,10 +601,13 @@ handle_option([{profile, _ID} = Opt|Rest], SocketOptions, SshOptions) -> handle_option(Rest, SocketOptions, [handle_ssh_option(Opt) | SshOptions]); handle_option([{max_random_length_padding, _Bool} = Opt|Rest], SocketOptions, SshOptions) -> handle_option(Rest, SocketOptions, [handle_ssh_option(Opt) | SshOptions]); +handle_option([{tstflg, _} = Opt|Rest], SocketOptions, SshOptions) -> + handle_option(Rest, SocketOptions, [handle_ssh_option(Opt) | SshOptions]); handle_option([Opt | Rest], SocketOptions, SshOptions) -> handle_option(Rest, [handle_inet_option(Opt) | SocketOptions], SshOptions). +handle_ssh_option({tstflg,_F} = Opt) -> Opt; handle_ssh_option({minimal_remote_max_packet_size, Value} = Opt) when is_integer(Value), Value >=0 -> Opt; handle_ssh_option({system_dir, Value} = Opt) when is_list(Value) -> 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))); |