[Python-Dev] playback debugging

Guido van Rossum guido@python.org
Wed, 08 Jan 2003 21:12:26 -0500


> Would it be possible to save every function return/stack in a running
> python program and then playback the results in a debugger?
> The article linked from /. 
> http://web.media.mit.edu/~lieber/Lieberary/Softviz/CACM-Debugging/CACM-Debugging-Intro.html#Intro
> 
> mentions that a lisp interpreter (Lisp stepper ZStep 95) did something
> like this that then let you replay a program from the end back to the
> beginning.
> 
> The idea would be that every function return replays the orignal return
> even if the outcome is different.  core operations that call out to
> C wouldn't actually make the call, so random() would always return the
> same value that it orignally did at that spot.  Ditto for file.read().  
> The pure python code would almost by definition do excatly the same thing,
> b/c the inputs would always be identical.  If this isn't always possible a 
> warning could be issued and the orignal value be returned regardless.
> 
> This would require work on the interpreter and the debugger,
> but does anyone see a reason why this is technically impossible?
> 
> Async IO programs would be SOL.  And large or long running programs
> would be infeasable.  I run everything under mod_python which essentially
> means a series of very short one-off programs.  This would be a huge
> win IMO.  I currently save the input parameters and can re-run them
> outside of apache.  This is non-ideal as some server side state is lost,
> but works most of the time.  A large number of python programs would
> reap a huge reward from this, but please correct me if I'm missing
> the obvious.

This sounds like a really cool idea, and I think it would probably be
possible for small example programs.  I don't know how much work it
would be, but I support you in trying to get this to work -- as long
as it doesn't mean extra work for me (I simply have no time).
Ideally, you would define a *very* small set of changes to the
existing Python VM that would let you write the rest of the logic of
this code in Python (even if it had to be ugly Python).  You might
even try to see if the existing debugger hooks will let you do this --
you can trap Python function entries and exits.  But I don't think you
can trap calls to functions implemented in C, so I expect you'll need
more hooks.  The smaller the hooks are, the more likely they are to be
accepted in the codebase.  Oh, and they have to be safe -- it should
not be possible to cause segfaults or other nastiness by abusing the
hooks.

--Guido van Rossum (home page: http://www.python.org/~guido/)