aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/stdlib/src/gen_fsm.erl38
-rw-r--r--lib/stdlib/src/gen_server.erl14
-rw-r--r--lib/stdlib/src/gen_statem.erl50
-rw-r--r--lib/stdlib/test/gen_fsm_SUITE.erl4
4 files changed, 60 insertions, 46 deletions
diff --git a/lib/stdlib/src/gen_fsm.erl b/lib/stdlib/src/gen_fsm.erl
index 6be12437bb..49e3f5981e 100644
--- a/lib/stdlib/src/gen_fsm.erl
+++ b/lib/stdlib/src/gen_fsm.erl
@@ -417,7 +417,7 @@ decode_msg(Msg,Parent, Name, StateName, StateData, Mod, Time, HibernateAfterTime
handle_msg(Msg, Parent, Name, StateName, StateData, Mod, Time, HibernateAfterTimeout);
_Msg ->
Debug1 = sys:handle_debug(Debug, fun print_event/3,
- {Name, StateName}, {in, Msg}),
+ Name, {in, Msg, StateName}),
handle_msg(Msg, Parent, Name, StateName, StateData,
Mod, Time, HibernateAfterTimeout, Debug1)
end.
@@ -453,7 +453,7 @@ system_replace_state(StateFun, [Name, StateName, StateData, Mod, Time, Hibernate
%% Format debug messages. Print them as the call-back module sees
%% them, not as the real erlang messages. Use trace for that.
%%-----------------------------------------------------------------
-print_event(Dev, {in, Msg}, {Name, StateName}) ->
+print_event(Dev, {in, Msg, StateName}, Name) ->
case Msg of
{'$gen_event', Event} ->
io:format(Dev, "*DBG* ~tp got event ~tp in state ~tw~n",
@@ -462,6 +462,16 @@ print_event(Dev, {in, Msg}, {Name, StateName}) ->
io:format(Dev,
"*DBG* ~tp got all_state_event ~tp in state ~tw~n",
[Name, Event, StateName]);
+ {'$gen_sync_event', {From,_Tag}, Event} ->
+ io:format(Dev,
+ "*DBG* ~tp got sync_event ~tp "
+ "from ~tw in state ~tw~n",
+ [Name, Event, From, StateName]);
+ {'$gen_sync_all_state_event', {From,_Tag}, Event} ->
+ io:format(Dev,
+ "*DBG* ~tp got sync_all_state_event ~tp "
+ "from ~tw in state ~tw~n",
+ [Name, Event, From, StateName]);
{timeout, Ref, {'$gen_timer', Message}} ->
io:format(Dev,
"*DBG* ~tp got timer ~tp in state ~tw~n",
@@ -474,11 +484,11 @@ print_event(Dev, {in, Msg}, {Name, StateName}) ->
io:format(Dev, "*DBG* ~tp got ~tp in state ~tw~n",
[Name, Msg, StateName])
end;
-print_event(Dev, {out, Msg, To, StateName}, Name) ->
+print_event(Dev, {out, Msg, {To,_Tag}, StateName}, Name) ->
io:format(Dev, "*DBG* ~tp sent ~tp to ~tw~n"
" and switched to state ~tw~n",
[Name, Msg, To, StateName]);
-print_event(Dev, return, {Name, StateName}) ->
+print_event(Dev, {noreply, StateName}, Name) ->
io:format(Dev, "*DBG* ~tp switched to state ~tw~n",
[Name, StateName]).
@@ -522,11 +532,11 @@ handle_msg(Msg, Parent, Name, StateName, StateData, Mod, _Time, HibernateAfterTi
case catch dispatch(Msg, Mod, StateName, StateData) of
{next_state, NStateName, NStateData} ->
Debug1 = sys:handle_debug(Debug, fun print_event/3,
- {Name, NStateName}, return),
+ Name, {noreply, NStateName}),
loop(Parent, Name, NStateName, NStateData, Mod, infinity, HibernateAfterTimeout, Debug1);
{next_state, NStateName, NStateData, Time1} ->
Debug1 = sys:handle_debug(Debug, fun print_event/3,
- {Name, NStateName}, return),
+ Name, {noreply, NStateName}),
loop(Parent, Name, NStateName, NStateData, Mod, Time1, HibernateAfterTimeout, Debug1);
{reply, Reply, NStateName, NStateData} when From =/= undefined ->
Debug1 = reply(Name, From, Reply, Debug, NStateName),
@@ -573,10 +583,10 @@ from(_) -> undefined.
reply({To, Tag}, Reply) ->
catch To ! {Tag, Reply}.
-reply(Name, {To, Tag}, Reply, Debug, StateName) ->
- reply({To, Tag}, Reply),
+reply(Name, From, Reply, Debug, StateName) ->
+ reply(From, Reply),
sys:handle_debug(Debug, fun print_event/3, Name,
- {out, Reply, To, StateName}).
+ {out, Reply, From, StateName}).
%%% ---------------------------------------------------
%%% Terminate the server.
@@ -698,11 +708,11 @@ format_log(#{label:={gen_fsm,no_handle_info},
get_msg_str({'$gen_event', _Event}) ->
"** Last event in was ~tp~n";
get_msg_str({'$gen_sync_event', _From, _Event}) ->
- "** Last sync event in was ~tp from ~p~n";
+ "** Last sync event in was ~tp from ~tw~n";
get_msg_str({'$gen_all_state_event', _Event}) ->
"** Last event in was ~tp (for all states)~n";
get_msg_str({'$gen_sync_all_state_event', _From, _Event}) ->
- "** Last sync event in was ~tp (for all states) from ~p~n";
+ "** Last sync event in was ~tp (for all states) from ~tw~n";
get_msg_str({timeout, _Ref, {'$gen_timer', _Msg}}) ->
"** Last timer event in was ~tp~n";
get_msg_str({timeout, _Ref, {'$gen_event', _Msg}}) ->
@@ -711,9 +721,9 @@ get_msg_str(_Msg) ->
"** Last message in was ~tp~n".
get_msg({'$gen_event', Event}) -> [Event];
-get_msg({'$gen_sync_event', From, Event}) -> [Event,From];
+get_msg({'$gen_sync_event', {From,_Tag}, Event}) -> [Event,From];
get_msg({'$gen_all_state_event', Event}) -> [Event];
-get_msg({'$gen_sync_all_state_event', From, Event}) -> [Event,From];
+get_msg({'$gen_sync_all_state_event', {From,_Tag}, Event}) -> [Event,From];
get_msg({timeout, Ref, {'$gen_timer', Msg}}) -> [{timeout, Ref, Msg}];
get_msg({timeout, _Ref, {'$gen_event', Event}}) -> [Event];
get_msg(Msg) -> [Msg].
@@ -737,7 +747,7 @@ format_status(Opt, StatusData) ->
StatusData,
Header = gen:format_status_header("Status for state machine",
Name),
- Log = [{Ev, St} || {Ev, St, _FormFunc} <- sys:get_log(Debug)],
+ Log = [SysEvent || {SysEvent,_,_} <- sys:get_log(Debug)],
Specfic = format_status(Opt, Mod, PDict, StateData),
Specfic = case format_status(Opt, Mod, PDict, StateData) of
S when is_list(S) -> S;
diff --git a/lib/stdlib/src/gen_server.erl b/lib/stdlib/src/gen_server.erl
index 3f7c392c12..f57c136296 100644
--- a/lib/stdlib/src/gen_server.erl
+++ b/lib/stdlib/src/gen_server.erl
@@ -773,10 +773,10 @@ handle_common_reply(Reply, Parent, Name, From, Msg, Mod, HibernateAfterTimeout,
terminate({bad_return_value, BadReply}, ?STACKTRACE(), Name, From, Msg, Mod, State, Debug)
end.
-reply(Name, {To, Tag}, Reply, State, Debug) ->
- reply({To, Tag}, Reply),
+reply(Name, From, Reply, State, Debug) ->
+ reply(From, Reply),
sys:handle_debug(Debug, fun print_event/3, Name,
- {out, Reply, To, State} ).
+ {out, Reply, From, State} ).
%%-----------------------------------------------------------------
@@ -810,7 +810,7 @@ system_replace_state(StateFun, [Name, State, Mod, Time, HibernateAfterTimeout])
print_event(Dev, {in, Msg}, Name) ->
case Msg of
{'$gen_call', {From, _Tag}, Call} ->
- io:format(Dev, "*DBG* ~tp got call ~tp from ~w~n",
+ io:format(Dev, "*DBG* ~tp got call ~tp from ~tw~n",
[Name, Call, From]);
{'$gen_cast', Cast} ->
io:format(Dev, "*DBG* ~tp got cast ~tp~n",
@@ -818,8 +818,8 @@ print_event(Dev, {in, Msg}, Name) ->
_ ->
io:format(Dev, "*DBG* ~tp got ~tp~n", [Name, Msg])
end;
-print_event(Dev, {out, Msg, To, State}, Name) ->
- io:format(Dev, "*DBG* ~tp sent ~tp to ~w, new state ~tp~n",
+print_event(Dev, {out, Msg, {To,_Tag}, State}, Name) ->
+ io:format(Dev, "*DBG* ~tp sent ~tp to ~tw, new state ~tp~n",
[Name, Msg, To, State]);
print_event(Dev, {noreply, State}, Name) ->
io:format(Dev, "*DBG* ~tp new state ~tp~n", [Name, State]);
@@ -885,7 +885,7 @@ error_info(_Reason, application_controller, _From, _Msg, _Mod, _State, _Debug) -
%% of it instead
ok;
error_info(Reason, Name, From, Msg, Mod, State, Debug) ->
- Log = [{Ev, St} || {Ev, St, _FormFunc} <- sys:get_log(Debug)],
+ Log = [SysEvent || {SysEvent,_,_} <- sys:get_log(Debug)],
?LOG_ERROR(#{label=>{gen_server,terminate},
name=>Name,
last_message=>Msg,
diff --git a/lib/stdlib/src/gen_statem.erl b/lib/stdlib/src/gen_statem.erl
index 82f875d6a9..3eb9ff3aca 100644
--- a/lib/stdlib/src/gen_statem.erl
+++ b/lib/stdlib/src/gen_statem.erl
@@ -680,7 +680,7 @@ enter(
data = Data,
hibernate_after = HibernateAfterTimeout},
CallEnter = true,
- NewDebug = ?sys_debug(Debug, {Name,State}, {enter,Event,State}),
+ NewDebug = ?sys_debug(Debug, Name, {enter,State}),
case call_callback_mode(S) of
#state{} = NewS ->
loop_event_actions_list(
@@ -827,26 +827,30 @@ format_status(
sys_debug(Debug, NameState, Entry) ->
sys:handle_debug(Debug, fun print_event/3, NameState, Entry).
-print_event(Dev, SystemEvent, {Name,State}) ->
+print_event(Dev, SystemEvent, Name) ->
case SystemEvent of
- {in,Event} ->
+ {in,Event,State} ->
io:format(
Dev, "*DBG* ~tp receive ~ts in state ~tp~n",
[Name,event_string(Event),State]);
- {in,Event,code_change} ->
+ {code_change,Event,State} ->
io:format(
Dev, "*DBG* ~tp receive ~ts after code change in state ~tp~n",
[Name,event_string(Event),State]);
{out,Reply,{To,_Tag}} ->
io:format(
- Dev, "*DBG* ~tp send ~tp to ~p in state ~tp~n",
- [Name,Reply,To,State]);
- {terminate,Reason} ->
+ Dev, "*DBG* ~tp send ~tp to ~tw~n",
+ [Name,Reply,To]);
+ {enter,State} ->
+ io:format(
+ Dev, "*DBG* ~tp enter in state ~tp~n",
+ [Name,State]);
+ {terminate,Reason,State} ->
io:format(
Dev, "*DBG* ~tp terminate ~tp in state ~tp~n",
[Name,Reason,State]);
- {Tag,Event,NextState}
- when Tag =:= enter; Tag =:= postpone; Tag =:= consume ->
+ {Tag,Event,State,NextState}
+ when Tag =:= postpone; Tag =:= consume ->
StateString =
case NextState of
State ->
@@ -862,7 +866,7 @@ print_event(Dev, SystemEvent, {Name,State}) ->
event_string(Event) ->
case Event of
{{call,{Pid,_Tag}},Request} ->
- io_lib:format("call ~tp from ~w", [Request,Pid]);
+ io_lib:format("call ~tp from ~tw", [Request,Pid]);
{EventType,EventContent} ->
io_lib:format("~tw ~tp", [EventType,EventContent])
end.
@@ -1004,13 +1008,13 @@ loop_receive_result(Parent, ?not_sys_debug, S, Type, Content) ->
loop_event(Parent, ?not_sys_debug, S, Events, Type, Content);
loop_receive_result(
Parent, Debug, #state{name = Name, state = State} = S, Type, Content) ->
+ Event = {Type,Content},
NewDebug =
case S#state.callback_mode of
undefined ->
- sys_debug(
- Debug, {Name,State}, {in,{Type,Content},code_change});
+ sys_debug(Debug, Name, {code_change,Event,State});
_ ->
- sys_debug(Debug, {Name,State}, {in,{Type,Content}})
+ sys_debug(Debug, Name, {in,Event,State})
end,
%% Here is the queue of not yet handled events created
Events = [],
@@ -1321,13 +1325,13 @@ parse_actions_reply(
?STACKTRACE(), Debug]
end;
parse_actions_reply(
- StateCall, Debug, #state{name = Name, state = State} = S,
+ StateCall, Debug, #state{name = Name} = S,
Actions, TransOpts, From, Reply) ->
%%
case from(From) of
true ->
reply(From, Reply),
- NewDebug = sys_debug(Debug, {Name,State}, {out,Reply,From}),
+ NewDebug = sys_debug(Debug, Name, {out,Reply,From}),
parse_actions(StateCall, NewDebug, S, Actions, TransOpts);
false ->
[error,
@@ -1356,7 +1360,7 @@ parse_actions_next_event(
Actions, TransOpts, Type, Content) ->
case event_type(Type) of
true when StateCall ->
- NewDebug = sys_debug(Debug, {Name,State}, {in,{Type,Content}}),
+ NewDebug = sys_debug(Debug, Name, {in,{Type,Content},State}),
NextEventsR = TransOpts#trans_opts.next_events_r,
parse_actions(
StateCall, NewDebug, S, Actions,
@@ -1473,14 +1477,14 @@ loop_event_done(
true ->
[?sys_debug(
Debug_0,
- {S#state.name,State},
- {postpone,Event_0,NextState}),
+ S#state.name,
+ {postpone,Event_0,State,NextState}),
Event_0|P_0];
false ->
[?sys_debug(
Debug_0,
- {S#state.name,State},
- {consume,Event_0,NextState})|P_0]
+ S#state.name,
+ {consume,Event_0,State,NextState})|P_0]
end,
{Events_2,P_2,
Timers_2} =
@@ -1883,7 +1887,7 @@ do_reply_then_terminate(
NewDebug =
?sys_debug(
Debug,
- {S#state.name,S#state.state},
+ S#state.name,
{out,Reply,From}),
do_reply_then_terminate(
Class, Reason, Stacktrace, NewDebug, S, Q, Rs);
@@ -1938,7 +1942,7 @@ terminate(
end.
terminate_sys_debug(Debug, S, State, Reason) ->
- ?sys_debug(Debug, {S#state.name,State}, {terminate,Reason}).
+ ?sys_debug(Debug, S#state.name, {terminate,Reason,State}).
error_info(
@@ -1949,7 +1953,7 @@ error_info(
state_enter = StateEnter,
postponed = P} = S,
Q) ->
- Log = [{Ev, St} || {Ev, St, _FormFunc} <- sys:get_log(Debug)],
+ Log = [SysEvent || {SysEvent,_,_} <- sys:get_log(Debug)],
?LOG_ERROR(#{label=>{gen_statem,terminate},
name=>Name,
queue=>Q,
diff --git a/lib/stdlib/test/gen_fsm_SUITE.erl b/lib/stdlib/test/gen_fsm_SUITE.erl
index 4c463ff0d2..c942695a6a 100644
--- a/lib/stdlib/test/gen_fsm_SUITE.erl
+++ b/lib/stdlib/test/gen_fsm_SUITE.erl
@@ -527,7 +527,7 @@ error_format_status(Config) when is_list(Config) ->
receive
{error,_GroupLeader,{Pid,
"** State machine "++_,
- [Pid,badreturn,{Parent,_},idle,{formatted,StateData},
+ [Pid,badreturn,Parent,idle,{formatted,StateData},
{bad_return_value,badreturn}|_]}} ->
ok;
Other ->
@@ -547,7 +547,7 @@ terminate_crash_format(Config) when is_list(Config) ->
receive
{error,_GroupLeader,{Pid,
"** State machine "++_,
- [Pid,stop,{Parent,_},idle,{formatted, StateData},
+ [Pid,stop,Parent,idle,{formatted, StateData},
{crash,terminate}|_]}} ->
ok;
Other ->