pdbtrack fails for subclasses

Bug #709218 reported by charles.fox@gmail.com
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
python-mode.el
Fix Released
High
Andreas Roehler

Bug Description

Hi I'm not sure if this is a python-mode or a pdbtrack issue (or how the two fit together), so if's pdbtrack could you please forward it to the pdbtrack author.

The problem is that interactive debugging stops working on subclasses. In the example below, there's a big in Cat.hello but tracking is lost. It's important because many people rely on the ability to step through subclass code and to edit the code instantly on error lines -- my debuigging time takes about 10 times as long without this ability!

[Animal.py]
class Animal:
    def hello(self):
        print "hello"

[Cat.py]
from Animal import *
class Cat(Animal):
    def hello(self):
        print "meow"
        a=b/8

[main.py]
class Animal:
    def hello(self):
        print "hello"

Revision history for this message
Barry Warsaw (barry) wrote : Re: [Bug 709218] [NEW] pdbtrack fails for subclasses

On Jan 28, 2011, at 12:51 PM, <email address hidden> wrote:

>Hi I'm not sure if this is a python-mode or a pdbtrack issue (or how the two
>fit together), so if's pdbtrack could you please forward it to the pdbtrack
>author.
>
>The problem is that interactive debugging stops working on subclasses.
>In the example below, there's a big in Cat.hello but tracking is lost.
>It's important because many people rely on the ability to step through
>subclass code and to edit the code instantly on error lines -- my
>debuigging time takes about 10 times as long without this ability!
>
>[Animal.py]
>class Animal:
> def hello(self):
> print "hello"
>
>[Cat.py]
>from Animal import *
>class Cat(Animal):
> def hello(self):
> print "meow"
> a=b/8
>
>[main.py]
>class Animal:
> def hello(self):
> print "hello"

Sorry, I don't understand the example. You have two Animal classes, one in
main.py and one in Animal.py. Your Cat subclass is using the one from
Cat.py. It's not clear where your break point is.

Please provide more information so we can reproduce your problem. FWIW, I
trace through subclasses all the time.

Revision history for this message
charles.fox@gmail.com (charles-fox-gmail) wrote :
Download full text (5.9 KiB)

Thanks Barry -- the program in this example dies (by design) at the line
    a=b/8
(because b is undefined) and that's where I would expect pdtrack/python-mode to kick in. But it doesn't. Running from M-x pdb, I get,

Current directory is ~/test/
> /home/charles/test/main.py(1)<module>()
-> from Cat import *
(Pdb) r
meow
--Return--
> /home/charles/test/main.py(4)<module>()->None
-> c.hello()
(Pdb)

...and the pdb window shows the arrow in the main.py file,
c=Cat()
=>hello()

...rather than the arrow pointing in Cat.py : hello() where it ought to be.

I wonder if this is actually a pdb issue rather than pythonmode or pdbtrack, as I can't get pdb itself to print the code around the error line either,

Current directory is ~/test/
> /home/charles/test/main.py(1)<module>()
-> from Cat import *
(Pdb) r
meow
--Return--
> /home/charles/test/main.py(4)<module>()->None
-> c.hello()
(Pdb) l
  1 from Cat import *
  2
  3 c=Cat()
  4 -> c.hello()
[EOF]
(Pdb) bt
  /usr/lib/python2.6/bdb.py(368)run()
-> exec cmd in globals, locals
  <string>(1)<module>()->None
> /home/charles/test/main.py(4)<module>()->None ...

Read more...

Changed in python-mode:
assignee: nobody → Andreas Roehler (a-roehler)
status: New → In Progress
Changed in python-mode:
milestone: none → 6.1
Changed in python-mode:
importance: Undecided → Medium
Revision history for this message
Andreas Roehler (a-roehler) wrote :

Hi,

don't see anything we can do based on the info given.

you are saying

> /home/charles/test/main.py(1)<module>()
-> from Cat import *

However, don't see in your main.py any import statement.

Maybe I'm mistaking something...

Flag that "incomplete"

Changed in python-mode:
status: In Progress → Incomplete
Revision history for this message
charles.fox@gmail.com (charles-fox-gmail) wrote :

Hi there, it's been ages since I filed this bug (and I actually switched from emacs to vi for my python work partly because of it! ... so I can't test it right now as I no longer have that emacs setup). However, I'm guessing the files should have looked something like this:

[Animal.py]
class Animal:
    def hello(self):
        print "hello"

[Cat.py]
from Animal import *
class Cat(Animal):
    def hello(self):
        print "meow"
        a=b/8

[main.py]
from Cat import *
c = Cat()
c.hello() #causes error, but emacs tracking fails

The point was that the tracking fell over when the error occurred inside a subclass method.

Charles

Revision history for this message
Andreas Roehler (a-roehler) wrote : Re: [Bug 709218] Re: pdbtrack fails for subclasses

Am 26.10.2011 12:18, schrieb <email address hidden>:
> Hi there, it's been ages since I filed this bug (and I actually switched
> from emacs to vi for my python work partly because of it! ... so I can't
> test it right now as I no longer have that emacs setup). However, I'm
> guessing the files should have looked something like this:
>
> [Animal.py]
> class Animal:
> def hello(self):
> print "hello"
>
> [Cat.py]
> from Animal import *
> class Cat(Animal):
> def hello(self):
> print "meow"
> a=b/8
>
> [main.py]
> from Cat import *
> c = Cat()
> c.hello() #causes error, but emacs tracking fails
>
>
> The point was that the tracking fell over when the error occurred inside a subclass method.
>
> Charles
>

Thanks a lot! May confirm the bug that way:

Current directory is MY-PATH/
 > MY-PATH/Main.py(4)<module>()
-> from Cat import *
(Pdb) n
 > MY-PATH/Main.py(5)<module>()
-> c = Cat()
(Pdb) n
 > MY-PATH/Main.py(6)<module>()
-> c.hello() #causes error, but emacs tracking fails
(Pdb) n
meow
NameError: "global name 'b' is not defined"

BTW had to make pdb working before

with the help of

PdbNotes from http://www.emacswiki.org/emacs/PdbNotes:

For running python in GdbMode you need to set the pdb-path variable in
.emacs or wherever.

The advice defaults to the current buffer name when invoking M-x pdb,
and comes from here:

http://lists.gnu.org/archive/html/help-gnu-emacs/2003-10/msg00577.html

The rest worked automagically in 22.2.1

  ;;pdb setup, note the python version
  (setq pdb-path '/usr/lib/python2.5/pdb.py
        gud-pdb-command-name (symbol-name pdb-path))
  (defadvice pdb (before gud-query-cmdline activate)
    "Provide a better default command line when called interactively."
    (interactive
     (list (gud-query-cmdline pdb-path
        (file-name-nondirectory buffer-file-name)))))

Changed in python-mode:
status: Incomplete → Confirmed
importance: Medium → High
milestone: 6.1 → 6.0.4
Changed in python-mode:
milestone: 6.0.4 → 6.1
Revision history for this message
Andreas Roehler (a-roehler) wrote :

Am 26.10.2011 12:18, schrieb <email address hidden>:
> Hi there, it's been ages since I filed this bug (and I actually switched
[ ... ]

Hi Charles,

seems fixed in trunk

pdb says

NameError: global name 'b' is not defined

also the correct line is displayed - see png.

Cheers,

Andreas

Changed in python-mode:
status: Confirmed → Fix Committed
Revision history for this message
charles.fox@gmail.com (charles-fox-gmail) wrote :

Thanks guys :-)
(I actually switched over to vi for my python stuff, but looking forward to seeing this fixed back in emacs world too!)

Changed in python-mode:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.