From e1310b8f92a14809dccfca1100a4bf22921991b4 Mon Sep 17 00:00:00 2001 From: Siri Hansen Date: Fri, 30 Jun 2017 14:32:01 +0200 Subject: observer: Improve handling of Unicode --- lib/observer/src/observer_trace_wx.erl | 49 +++++++++++++++++----------------- 1 file changed, 25 insertions(+), 24 deletions(-) (limited to 'lib/observer/src/observer_trace_wx.erl') diff --git a/lib/observer/src/observer_trace_wx.erl b/lib/observer/src/observer_trace_wx.erl index b960c61ff0..8127248262 100644 --- a/lib/observer/src/observer_trace_wx.erl +++ b/lib/observer/src/observer_trace_wx.erl @@ -683,7 +683,7 @@ handle_event(#wx{id=?REMOVE_NODES}, #state{n_view=Nview, nodes=Ns0} = State) -> {noreply, State#state{nodes = Ns}}; handle_event(#wx{id=ID, event = What}, State) -> - io:format("~p:~p: Unhandled event: ~p, ~p ~n", [?MODULE, ?LINE, ID, What]), + io:format("~p:~p: Unhandled event: ~p, ~tp ~n", [?MODULE, ?LINE, ID, What]), {noreply, State}. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -729,7 +729,7 @@ handle_info({update_ms, NewMs}, State) -> {noreply, State#state{match_specs=NewMs}}; handle_info(Any, State) -> - io:format("~p~p: received unexpected message: ~p\n", [?MODULE, self(), Any]), + io:format("~p~p: received unexpected message: ~tp\n", [?MODULE, self(), Any]), {noreply, State}. terminate(_Reason, #state{nodes=_Nodes}) -> @@ -1046,33 +1046,33 @@ format_trace(Trace, Size, TS0={_,_,MS}) -> case element(4, Trace) of {dbg,ok} -> ""; Message -> - io_lib:format("~s (~100p) << ~100p~n", [TS,From,Message]) + io_lib:format("~s (~100p) << ~100tp~n", [TS,From,Message]) end; 'send' -> Message = element(4, Trace), To = element(5, Trace), - io_lib:format("~s (~100p) ~100p ! ~100p~n", [TS,From,To,Message]); + io_lib:format("~s (~100p) ~100p ! ~100tp~n", [TS,From,To,Message]); call -> case element(4, Trace) of MFA when Size == 5 -> Message = element(5, Trace), - io_lib:format("~s (~100p) call ~s (~100p) ~n", [TS,From,ffunc(MFA),Message]); + io_lib:format("~s (~100p) call ~ts (~100tp) ~n", [TS,From,ffunc(MFA),Message]); MFA -> - io_lib:format("~s (~100p) call ~s~n", [TS,From,ffunc(MFA)]) + io_lib:format("~s (~100p) call ~ts~n", [TS,From,ffunc(MFA)]) end; return_from -> MFA = element(4, Trace), Ret = element(5, Trace), - io_lib:format("~s (~100p) returned from ~s -> ~100p~n", [TS,From,ffunc(MFA),Ret]); + io_lib:format("~s (~100p) returned from ~ts -> ~100tp~n", [TS,From,ffunc(MFA),Ret]); return_to -> MFA = element(4, Trace), - io_lib:format("~s (~100p) returning to ~s~n", [TS,From,ffunc(MFA)]); + io_lib:format("~s (~100p) returning to ~ts~n", [TS,From,ffunc(MFA)]); spawn when Size == 5 -> Pid = element(4, Trace), MFA = element(5, Trace), - io_lib:format("~s (~100p) spawn ~100p as ~s~n", [TS,From,Pid,ffunc(MFA)]); + io_lib:format("~s (~100p) spawn ~100p as ~ts~n", [TS,From,Pid,ffunc(MFA)]); Op -> - io_lib:format("~s (~100p) ~100p ~s~n", [TS,From,Op,ftup(Trace,4,Size)]) + io_lib:format("~s (~100p) ~100p ~ts~n", [TS,From,Op,ftup(Trace,4,Size)]) end. %%% These f* functions returns non-flat strings @@ -1080,24 +1080,24 @@ format_trace(Trace, Size, TS0={_,_,MS}) -> %% {M,F,[A1, A2, ..., AN]} -> "M:F(A1, A2, ..., AN)" %% {M,F,A} -> "M:F/A" ffunc({M,F,Argl}) when is_list(Argl) -> - io_lib:format("~100p:~100p(~s)", [M, F, fargs(Argl)]); + io_lib:format("~100p:~100tp(~ts)", [M, F, fargs(Argl)]); ffunc({M,F,Arity}) -> - io_lib:format("~100p:~100p/~100p", [M,F,Arity]); -ffunc(X) -> io_lib:format("~100p", [X]). + io_lib:format("~100p:~100tp/~100p", [M,F,Arity]); +ffunc(X) -> io_lib:format("~100tp", [X]). %% Integer -> "Integer" %% [A1, A2, ..., AN] -> "A1, A2, ..., AN" fargs(Arity) when is_integer(Arity) -> integer_to_list(Arity); fargs([]) -> []; -fargs([A]) -> io_lib:format("~100p", [A]); %% last arg -fargs([A|Args]) -> [io_lib:format("~100p,", [A]) | fargs(Args)]; -fargs(A) -> io_lib:format("~100p", [A]). % last or only arg +fargs([A]) -> io_lib:format("~100tp", [A]); %% last arg +fargs([A|Args]) -> [io_lib:format("~100tp,", [A]) | fargs(Args)]; +fargs(A) -> io_lib:format("~100tp", [A]). % last or only arg %% {A_1, A_2, ..., A_N} -> "A_Index A_Index+1 ... A_Size" ftup(Trace, Index, Index) -> - io_lib:format("~100p", [element(Index, Trace)]); + io_lib:format("~100tp", [element(Index, Trace)]); ftup(Trace, Index, Size) -> - [io_lib:format("~100p ", [element(Index, Trace)]) + [io_lib:format("~100tp ", [element(Index, Trace)]) | ftup(Trace, Index+1, Size)]. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -1125,18 +1125,19 @@ get_config(#state{def_proc_flags = ProcFlags, write_file(Frame, Filename, Config) -> Str = - ["%%%\n%%% This file is generated by Observer\n", + ["%%% ",epp:encoding_to_string(utf8), "\n" + "%%%\n%%% This file is generated by Observer\n", "%%%\n%%% DO NOT EDIT!\n%%%\n", - [io_lib:format("~p.~n",[MSTerm]) || + [io_lib:format("~tp.~n",[MSTerm]) || MSTerm <- proplists:get_value(match_specs, Config)], io_lib:format("~p.~n",[lists:keyfind(procflags, 1, Config)]), io_lib:format("~p.~n",[lists:keyfind(portflags, 1, Config)]), - io_lib:format("~p.~n",[lists:keyfind(output, 1, Config)]), - [io_lib:format("~p.~n",[ModuleTerm]) || + io_lib:format("~tp.~n",[lists:keyfind(output, 1, Config)]), + [io_lib:format("~tp.~n",[ModuleTerm]) || ModuleTerm <- proplists:get_value(trace_p, Config)] ], - case file:write_file(Filename, list_to_binary(Str)) of + case file:write_file(Filename, unicode:characters_to_binary(Str)) of ok -> success; {error, Reason} -> @@ -1200,7 +1201,7 @@ make_ms(MS) -> make_ms(Name,Term,FunStr). make_ms(Name, Term, FunStr) -> - #match_spec{name=Name, term=Term, str=io_lib:format("~w", Term), func = FunStr}. + #match_spec{name=Name, term=Term, str=io_lib:format("~tw", Term), func = FunStr}. parse_tp({tp, Mod, FAs}, State) -> Patterns = [#tpattern{m=Mod,fa={F,A}, ms=make_ms(List)} || -- cgit v1.2.3