gen_server:format_status/2 only works with registered processes

Raimo Niskanen raimo.niskanen@REDACTED
Mon Mar 24 13:52:24 CET 2003


Vance Shipley wrote:
 > OK, I found the problem.  The following patch to lists.erl does it:
 >
 > *** lists.erl.dist      Thu Mar 20 17:56:16 2003
 > --- lists.erl   Thu Mar 20 17:58:26 2003
 > ***************
 > *** 280,285 ****
 > --- 280,286 ----
 >   thing_to_list(X) when integer(X) -> integer_to_list(X);
 >   thing_to_list(X) when float(X)         -> float_to_list(X);
 >   thing_to_list(X) when atom(X)  -> atom_to_list(X);
 > + thing_to_list(X) when pid(X)   -> pid_to_list(X);
 >   thing_to_list(X) when list(X)  -> X.          %Assumed to be a string
 >
 >   %% flatten(List)
 >

I am sorry, I do not think that is the correct(tm) solution. It seems 
that lists:thing_to_list/1 handles items that look the same in a 
parseable Erlang source file as when printed. Some types that are 
missing are: pid(), port(), reference(), all not parseable from their 
string representation.

So I think it is gen_server:format_status/2 that is faulty, trying to 
call lists:concat/1 with a pid(). See the diff following.

/ Raimo Niskanen, Erlang/OTP




Note that the following diff might not patch as it is since it is not 
from the R9B-1 version of the file.

***************
*** 670,676 ****
   %%-----------------------------------------------------------------
   format_status(Opt, StatusData) ->
       [PDict, SysState, Parent, Debug, [Name, State, Mod, _Time]] = 
StatusData,
!     Header = lists:concat(["Status for generic server ", Name]),
       Log = sys:get_debug(log, Debug, []),
       Specfic =
         case erlang:function_exported(Mod, format_status, 2) of
--- 670,681 ----
   %%-----------------------------------------------------------------
   format_status(Opt, StatusData) ->
       [PDict, SysState, Parent, Debug, [Name, State, Mod, _Time]] = 
StatusData,
!     NameTag = if pid(Name) ->
!                     pid_to_list(Name);
!                atom(Name) ->
!                     Name
!             end,
!     Header = lists:concat(["Status for generic server ", NameTag]),
       Log = sys:get_debug(log, Debug, []),
       Specfic =
         case erlang:function_exported(Mod, format_status, 2) of


 >
 >
 > 	-Vance
 >
 > Vance Shipley
 > Motivity Telecom Inc.
 > +1 519 240 3684
 > vances@REDACTED
 >
 > On Thu, Mar 20, 2003 at 04:36:04PM -0500, Vance Shipley wrote:
 > }
 > }  Now the problem is that, at least in R9B-[0|1], this only works if the
 > }  process is registered!  In the following example I am peeking at a
 > }  couple gen_server processes the system runs.  I am referring to each
 > }  by PID but the process which is not registerd fails.
 > ...
 > }  Error in process <0.25.0> with exit value: 
{function_clause,[{lists,thing_to_list,[<0.23.0>]},{lists,flatmap,2},{gen_server,format_status,2},{erl_eval,expr,3},{erl_eval,exprs,4},{shell,eval_loop,2}]}
 > }




Vance Shipley wrote:
> Background
> 
> Both gen_server.erl and gen_fsm.erl have a (undocumented) function 
> which is used to pretty print the persistent data they keep.  The
> way it works is that you first call sys:get_status/1 (documented)
> to retrieve the process's status and then format the state data
> in a contextually relevant way with gen_[server|fsm]:format_status/2.
> The nice thing is that gen_[server|fsm]:format_status/2 will check
> to see if the user's callback module has exported a format_status/2
> and if so it will call that function to get an even more contextually
> relevant way to present the data.  I find this all very handy.
> 
> Problem
> 
> Now the problem is that, at least in R9B-[0|1], this only works if the
> process is registered!  In the following example I am peeking at a 
> couple gen_server processes the system runs.  I am referring to each
> by PID but the process which is not registerd fails.
> 
> 	-Vance
> 
> 
> $ erl
> Erlang (BEAM) emulator version 5.2.3.3 [source] [hipe] [threads:0]
> 
> Eshell V5.2.3.3  (abort with ^G)
> 1> i().
> Pid                   Initial Call                          Heap     Reds Msgs
> Registered            Current Function                     Stack              
> ...
> <0.17.0>              code_server:init/1                     377    46225    0
> code_server           gen_server:loop/6                       12              
> ...
> <0.23.0>              kernel_config:init/1                   233       45    0
>                       gen_server:loop/6                       12              
> ...
> 
> 2> {_,_,_,StatusData} = sys:get_status(list_to_pid("<0.17.0>")),
> 2> gen_server:format_status([], StatusData).
> [{header,"Status for generic server code_server"},
>  {data,[{"Status",running},{"Parent",<0.9.0>},{"Logged events",[]}]},
>  {data,[{"State",
>          {state,"/usr/local/lib/erlang",
>                 [".",
>                  "/usr/local/lib/erlang/lib/kernel-2.8.1.1/ebin",
>                  "/usr/local/lib/erlang/lib/stdlib-1.11.4.1/ebin",
>                  "/usr/local/lib/erlang/lib/webtool-0.7.1/ebin",
>                  "/usr/local/lib/erlang/lib/tv-2.0.4/ebin",
>                  "/usr/local/lib/erlang/lib/tools-2.2/ebin",
>                  "/usr/local/lib/erlang/lib/toolbar-1.1.0/ebin",
>                  "/usr/local/lib/erlang/lib/ssl-2.3.5/ebin",
>                  "/usr/local/lib/erlang/lib/snmp-3.3.8/ebin",
>                  "/usr/local/lib/erlang/lib/sasl-1.9.4/ebin",
>                  "/usr/local/lib/erlang/lib/runtime_tools-1.3/ebin",
>                  "/usr/local/lib/erlang/lib/pman-2.4.1/ebin",
>                  "/usr/local/lib/erlang/lib/parsetools-1.2/ebin",
>                  "/usr/local/lib/erlang/lib/os_mon-1.6.0.2/ebin",
>                  "/usr/local/lib/erlang/lib/orber-3.4/ebin",
>                  "/usr/local/lib/erlang/lib/observer-0.9.3/ebin",
>                  "/usr/local/lib/erlang/lib/mnesia_session-1.1.5/ebin"|...],
>                 9,
>                 10,
>                 interactive}}]}]
> 3> f(StatusData).
> ok
> 4> {_,_,_,StatusData} = sys:get_status(list_to_pid("<0.23.0>")),
> 4> gen_server:format_status([], StatusData).
> ** exited: {function_clause,[{lists,thing_to_list,[<0.23.0>]},
>                              {lists,flatmap,2},
>                              {gen_server,format_status,2},
>                              {erl_eval,expr,3},
>                              {erl_eval,exprs,4},
>                              {shell,eval_loop,2}]} **
> 
> =ERROR REPORT==== 20-Mar-2003::16:31:37 ===
> Error in process <0.25.0> with exit value: {function_clause,[{lists,thing_to_list,[<0.23.0>]},{lists,flatmap,2},{gen_server,format_status,2},{erl_eval,expr,3},{erl_eval,exprs,4},{shell,eval_loop,2}]}
> 




More information about the erlang-questions mailing list