diff options
author | Hans Nilsson <hans@erlang.org> | 2020-06-02 15:24:28 +0200 |
---|---|---|
committer | Hans Nilsson <hans@erlang.org> | 2020-06-16 11:42:34 +0200 |
commit | 88ca70b9d7236f5454e446e7f3eeda3dafbbae55 (patch) | |
tree | 0475606295798b7e3a809f9c39457200da7344a9 /lib/ssh/src/ssh_dbg.erl | |
parent | 3a0ff7163a01d26d98b7c4f683d19c9c3204cde2 (diff) | |
download | erlang-88ca70b9d7236f5454e446e7f3eeda3dafbbae55.tar.gz |
ssh: Increase coverage on ssh_dbg code
Diffstat (limited to 'lib/ssh/src/ssh_dbg.erl')
-rw-r--r-- | lib/ssh/src/ssh_dbg.erl | 73 |
1 files changed, 33 insertions, 40 deletions
diff --git a/lib/ssh/src/ssh_dbg.erl b/lib/ssh/src/ssh_dbg.erl index f8391224f8..f8750dc070 100644 --- a/lib/ssh/src/ssh_dbg.erl +++ b/lib/ssh/src/ssh_dbg.erl @@ -67,7 +67,7 @@ ]). -export([shrink_bin/1, - reduce_state/1, + reduce_state/2, reduce_state/3, wr_record/3]). -export([init/1, handle_call/3, handle_cast/2, handle_info/2]). @@ -167,17 +167,22 @@ shrink_bin(T) when is_tuple(T) -> list_to_tuple(shrink_bin(tuple_to_list(T))); shrink_bin(X) -> X. %%%---------------------------------------------------------------- -%% Replace last element (the state) with "#<state-name>{}" -reduce_state(T) -> - try - erlang:setelement(size(T), - T, - lists:concat(['#',element(1,element(size(T),T)),'{}']) - ) - catch - _:_ -> - T - end. +%% Replace any occurence of {Name,...}, with "#Name{}" +reduce_state(T, RecordExample) -> + Name = element(1, RecordExample), + Arity = size(RecordExample), + reduce_state(T, Name, Arity). + +%% Replace any occurence of {Name,...}, with "#Name{}" +reduce_state(T, Name, Arity) when element(1,T) == Name, + size(T) == Arity -> + lists:concat(['#',Name,'{}']); +reduce_state(L, Name, Arity) when is_list(L) -> + [reduce_state(E,Name,Arity) || E <- L]; +reduce_state(T, Name, Arity) when is_tuple(T) -> + list_to_tuple( reduce_state(tuple_to_list(T),Name,Arity) ); +reduce_state(X, _, _) -> + X. %%%================================================================ -record(data, { @@ -341,34 +346,22 @@ switch(X, Types) when is_list(Types) -> %%% {send,Msg,To} %%% {'receive',Msg} -trace_pid({trace,Pid,_}) -> Pid; -trace_pid({trace,Pid,_,_}) -> Pid; -trace_pid({trace,Pid,_,_,_}) -> Pid; -trace_pid({trace,Pid,_,_,_,_}) -> Pid; -trace_pid({trace,Pid,_,_,_,_,_}) -> Pid; -trace_pid({trace_ts,Pid,_,_TS}) -> Pid; -trace_pid({trace_ts,Pid,_,_,_TS}) -> Pid; -trace_pid({trace_ts,Pid,_,_,_,_TS}) -> Pid; -trace_pid({trace_ts,Pid,_,_,_,_,_TS}) -> Pid; -trace_pid({trace_ts,Pid,_,_,_,_,_,_TS}) -> Pid. - -trace_ts({trace_ts,_Pid,_,TS}) -> ts(TS); -trace_ts({trace_ts,_Pid,_,_,TS}) -> ts(TS); -trace_ts({trace_ts,_Pid,_,_,_,TS}) -> ts(TS); -trace_ts({trace_ts,_Pid,_,_,_,_,TS}) -> ts(TS); -trace_ts({trace_ts,_Pid,_,_,_,_,_,TS}) -> ts(TS); -trace_ts(_) -> "-". - -trace_info({trace,_Pid,A}) -> A; -trace_info({trace,_Pid,A,B}) -> {A,B}; -trace_info({trace,_Pid,A,B,C}) -> {A,B,C}; -trace_info({trace,_Pid,A,B,C,D}) -> {A,B,C,D}; -trace_info({trace,_Pid,A,B,C,D,E}) -> {A,B,C,D,E}; -trace_info({trace_ts,_Pid,A,_TS}) -> A; -trace_info({trace_ts,_Pid,A,B,_TS}) -> {A,B}; -trace_info({trace_ts,_Pid,A,B,C,_TS}) -> {A,B,C}; -trace_info({trace_ts,_Pid,A,B,C,D,_TS}) -> {A,B,C,D}; -trace_info({trace_ts,_Pid,A,B,C,D,E,_TS}) -> {A,B,C,D,E}. +%% Pick 2nd element, the Pid +trace_pid(T) when element(1,T)==trace + ; element(1,T)==trace_ts -> + element(2,T). + +%% Pick last element, the Time Stamp, and format it +trace_ts(T) when element(1,T)==trace_ts -> + ts( element(size(T), T) ). + +%% Make a tuple of all elements but the 1st, 2nd and last +trace_info(T) -> + case tuple_to_list(T) of + [trace,_Pid | Info] -> list_to_tuple(Info); + [trace_ts,_Pid | InfoTS] -> list_to_tuple( + lists:droplast(InfoTS)) + end. try_all_types_in_all_modules(TypesOn, Arg, WriteFun, Acc0) -> |