PDB does not allow jumping to first statement?

rocky.bernstein at gmail.com rocky.bernstein at gmail.com
Tue Mar 27 05:59:31 EDT 2007


On Mar 26, 6:06 pm, "Chris Lasher" <chris.las... at gmail.com> wrote:
> Hi all,
>
> I have a simple script:
>
> ---
> #!/usr/bin/envpython
>
> a = 1
> b = 2
>
> c = a + b
>
> print c
> ---
>
> I launch said script withpdb:
>
> python-mpdbsimple.py
>
> I noticed that I absolutely cannot jump back to the first statement
> (line 3, "a = 1") using the jump command. I can jump to any other line
> BUT the first statement's using the "jump <line number>" command. I
> experience the same behavior with Winpdb and rpdb2. Why is this?
>
> Stumped,
> Chris

I tried on GNU/Linux and Python versions 2.4 and 2.5 and get the same
behavior. Best as I can tell, it looks like a bug in Python. pdb,
pydb, rpdb2 all handle the "jump" command by changing the frame
f_lineno value. When the corresponding code pointer has offset 0 (or
equivalently and more simlply as you put it, is the first statement)
this doesn't seem to work properly. But this also implies that all you
need to do is add something as the first statement. A docstring
comment, e.g.
"this is what my program does..."
comes to mind :-)

Lastly, I'll mention that I what most folks want to do is not jump to
the beginning of the program but rather *restart* it. The difference
here as applied to your example is seen in the way variables (e.g. a,
b, and c) are handled. In a "restart", those names would go back to
being undefined and referring to them before assigning to them would
cause a NameError exception. With "jump", they retain their existing
values.

In pydb (http://bashdb.sf.net/pydb) there are two variations of
restarting a program, one which preserves debugger state ("run") and
one which doesn't ("restart") as it is just a re-exec of the program.
In the presence of multiple threads the exec restart the only reliable
way I know of to force a restart.

Recently in Python's SVN the patch I submitted over a year ago was
applied, so if you prefer pdb and want the "run"-like restart, you can
use that.




More information about the Python-list mailing list