[Python-Dev] Why do we need Traceback Objects?

Vladimir Marangozov Vladimir.Marangozov@inrialpes.fr
Fri, 7 Apr 2000 00:43:16 +0200 (CEST)


Jeremy Hylton wrote:
> 
>   >> Vladimir Marangozov wrote:
>   >> This reminds me that some time ago I made an experimental patch
>   >> for removing SET_LINENO. There was the problem of generating
>   >> callbacks for pdb (which I think I solved somehow but I don't
>   >> remember the details). I do remember that I had to look at pdb
>   >> again for some reason. Is there any interest in reviving this
>   >> idea?
> 
> I think the details are important.  The only thing the SET_LINENO
> opcode does is to call a trace function if one is installed.  It's
> necessary to have some way to invoke the trace function when the line
> number changes (or it will be relatively difficult to execute code
> line-by-line in the debugger <wink>).

Looking back at the discussion and the patch I ended up with at that time,
I think the callback issue was solved rather elegantly. I'm not positive
that it does not have side effects, though... For an overview of the
approach and the corresponding patch, go back to:

http://www.python.org/pipermail/python-dev/1999-August/002252.html
http://sirac.inrialpes.fr/~marangoz/python/lineno/

What happens is that in tracing mode, a copy of the original code stream
is created, a new CALL_TRACE opcode is stored in it at the addresses
corresponding to each source line number, then the instruction pointer
is redirected to execute the modified code string. Whenever a CALL_TRACE
opcode is reached, the callback is triggered. On a successful return, 
the original opcode at the current address is fetched from the original
code string, then directly goto the dispatch code.

This code string duplication & conditional break-point setting occurs
only when a trace function is set; in the "normal case", the interpreter
executes a code string without SET_LINENO.

-- 
       Vladimir MARANGOZOV          | Vladimir.Marangozov@inrialpes.fr
http://sirac.inrialpes.fr/~marangoz | tel:(+33-4)76615277 fax:76615252