Python debugger

  • Thread starter Guillermo Fernandez
  • Start date
G

Guillermo Fernandez

Hi,

I'm trying to play with the python debugger. The idea is to put lines in the
code to automatically define breakpoints at the starting of the debugger.

(like:

1 def a():
2 #--- break
3 print 'done'

would automatically insert a break in the line number 2)

I did the code appended (I'm still quite a beginner...) but it makes me problems.
Traceback (most recent call last):
File "C:\Python23\lib\site-packages\sm\scriptutils.py", line 52, in run
sdb.run('exec codeObject in mainDict', locals(), mainDict)
File "C:\Python23\lib\site-packages\sm\spedb.py", line 29, in run
Sdb().run(statement, globals, locals)
File "C:\Python23\lib\site-packages\sm\spedb.py", line 23, in run
pdb.Pdb.do_break(self, str(linenbr))
File "C:\Python23\lib\pdb.py", line 262, in do_break
filename = self.defaultFile()
File "C:\Python23\lib\pdb.py", line 278, in defaultFile
filename = self.curframe.f_code.co_filename
AttributeError: Sdb instance has no attribute 'curframe'
Exception raised while running script <source>

I run the program as:
import spedb
mainDict=__main__.__dict__
# mainDict can also be another argument passed,
# I think it's also locals() by default
mainDict['codeObject']=codeObject
spedb.run('exec codeObject in mainDict', locals(), mainDict)


I think it's because the breakpoint it's instaured before the run, but I really
don't know how to put the breakpoint "inside" the run.

Furthermore, if I define the method run like:
def run(self, statement, globals, locals):
bdb.Bdb.run(self, statement, globals, locals)
it does not even prompt the usual prompt (not any prompt at all...)!
I got this:Script '<source>' returned exit code 0

Could someone give me a hint about:
1) Why it does not work?
2) How to modify it the way I want?

Thanks a lot.

G

import pdb
import bdb

class Sdb(bdb.Bdb,pdb.Pdb):
def __init__(self):
pdb.Pdb.__init__(self)
bdb.Bdb.__init__(self)

def run(self, statement, globals, locals):
functions={
'#--- break' : pdb.Pdb.do_break
}
lines=globals['source'].splitlines()
linenbr=0
for line in lines:
linenbr+=1
if line in functions:
pdb.Pdb.do_break(self, str(linenbr))
bdb.Bdb.run(self, statement, globals, locals)

def run(statement, globals=None, locals=None):
Sdb().run(statement, globals, locals)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,563
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top