[Date Prev] [Date Next] [Thread Prev] [Thread Next] Date Index Thread Index Search archive:
Date:Mon Mar 25 19:57:44 1993 
Subject:Re: Inspecting the runnable saved state of a pop process 
From:Steve Knight 
Volume-ID:930325.03 

Luc asks:
> Is there a way to examine the saved state of a pop process from outside
> of that process (i.e., by using the process as an index to itself)? REF
> * PROCESS doesn't say anything about process access procedures. I'd like
> to be able to look at a process's user stack from outside.

The short answer is that there is no *perfect* way of doing this.  And I
consider this an omission (and doubtless Luc does, too!)  

However, if you are prepared to put up with the fact that the following won't
work on "system" processes, you can try redefining "suspend" as shown.
Note that to do this job properly, you'd need to do "resume" and any
other ways of suspending from a process (but I can't think of any right now).

Steve 

PS. Please excuse any typos since I'm doing this from memory ...



;;; -- Examining processes -- by subverting suspend -------------------------

;;; Take a copy of the system version.
constant procedure sys_suspend = suspend;
sysprotect( "sys_suspend" );

lvars want_to_peek = false;

define do_in_process( proc, want_to_peek );
    lvars proc;
    dlocal want_to_peek;
    runproc( 0, proc )
enddefine;


define peeking_suspend() with_nargs 1;
    sys_suspend();
    if want_to_peek then
        lvars n = #| want_to_peek() |#;
        false -> want_to_peek;
        chain( n, peeking_suspend );
    endif;
enddefine;

;;; Now redefine the system variable.
sysunprotect( "suspend" );
peeking_suspend -> suspend;
sysprotect( "suspend" );


;;; -- Example --------------------------------------------------------------

;;; A boring generator style process.
define next( n ); lvars n;
    repeat
        n;  ;;; stick -n- on the stack, to give us something to look at.
        suspend( n, 1 );
        n + 1 -> n
    endrepeat
enddefine;

vars proc = consproc( 23, 1, next );

;;; What's on the stack?
define stack_peek() -> L;
    lvars L = stacklength().conslist;
    L.explode;
enddefine;

;;; Now we can sneak around inside the process.  First we'll check out the
;;; user stack.

do_in_process( proc, stack_peek ) =>
** [23]

;;; Then we'll run it a couple of times.

proc( 0 ) =>
** 24

proc( 0 ) =>
** 25

;;; What does the stack look like now?

do_in_process( proc, stack_peek ) =>
** [23 24 25]

;;; Is everything ok?  (Natch, otherwise I wouldn't write this.)

proc( 0 ) =>
** 26