@@ -1150,14 +1150,15 @@ print_event(Dev, Event, Name) ->
11501150
11511151terminate (Reason , Msg , # gs2_state { name = Name ,
11521152 mod = Mod ,
1153- state = State ,
1153+ state = ModState0 ,
11541154 debug = Debug ,
11551155 stop_stats_fun = StopStatsFun
11561156 } = GS2State ) ->
11571157 StopStatsFun (stop_stats_timer (GS2State )),
1158- case catch Mod :terminate (Reason , State ) of
1158+ case catch Mod :terminate (Reason , ModState0 ) of
11591159 {'EXIT' , R } ->
1160- error_info (R , Reason , Name , Msg , State , Debug ),
1160+ ModState1 = maybe_format_state (Mod , ModState0 ),
1161+ error_info (R , Reason , Name , Msg , ModState1 , Debug ),
11611162 exit (R );
11621163 _ ->
11631164 case Reason of
@@ -1168,28 +1169,37 @@ terminate(Reason, Msg, #gs2_state { name = Name,
11681169 {shutdown ,_ }= Shutdown ->
11691170 exit (Shutdown );
11701171 _ ->
1171- error_info (Reason , undefined , Name , Msg , State , Debug ),
1172+ ModState1 = maybe_format_state (Mod , ModState0 ),
1173+ error_info (Reason , undefined , Name , Msg , ModState1 , Debug ),
11721174 exit (Reason )
11731175 end
11741176 end .
11751177
1178+ maybe_format_state (M , ModState ) ->
1179+ case erlang :function_exported (M , format_state , 1 ) of
1180+ true ->
1181+ M :format_state (ModState );
1182+ false ->
1183+ ModState
1184+ end .
1185+
11761186error_info (_Reason , _RootCause , application_controller , _Msg , _State , _Debug ) ->
11771187 % % OTP-5811 Don't send an error report if it's the system process
11781188 % % application_controller which is terminating - let init take care
11791189 % % of it instead
11801190 ok ;
1181- error_info (Reason , RootCause , Name , Msg , State , Debug ) ->
1191+ error_info (Reason , RootCause , Name , Msg , ModState , Debug ) ->
11821192 Reason1 = error_reason (Reason ),
11831193 Fmt =
11841194 " ** Generic server ~tp terminating~n "
11851195 " ** Last message in was ~tp~n "
11861196 " ** When Server state == ~tp~n "
11871197 " ** Reason for termination == ~n ** ~tp~n " ,
11881198 case RootCause of
1189- undefined -> format (Fmt , [Name , Msg , State , Reason1 ]);
1199+ undefined -> format (Fmt , [Name , Msg , ModState , Reason1 ]);
11901200 _ -> format (Fmt ++ " ** In 'terminate' callback "
11911201 " with reason ==~n ** ~tp~n " ,
1192- [Name , Msg , State , Reason1 ,
1202+ [Name , Msg , ModState , Reason1 ,
11931203 error_reason (RootCause )])
11941204 end ,
11951205 sys :print_log (Debug ),
0 commit comments